Module Listener

This module defines the Listener class, the main entry point for client requests. Listener binds to a given address, waits for connections, and for each connection spawns a new session to handle that connection.

Imported modules

Class Listener

This is the starting point of Zorp services. It listens on the given port, and when a connection is accepted it starts a session and the given service.

Attributes

Table 4-67. Attributes for class Listener

listenA Zorp.Listen instance
servicethe service to be started
bindtobind address
locallocal address where the listener is bound

Constructor __init__

Constructor to initialize a Listen instance

Synopsis

__init__ (
        self,
        bindto,
        service,
        transparent=FALSE,
        )

Description

Creates the instance, sets the initial attributes, and starts the listener

Arguments

Table 4-68. Arguments for Listener.__init__()

selfthis instance
bindtothe address to bind to
servicethe service name to start
transparentTRUE if this is a listener of a transparent service, specifying this is not mandatory but performs additional checks

Exceptions

  • ServiceException

Method accepted

Callback to inform the python layer about incoming connections.

Synopsis

accepted (
        self,
        client,
        fd,
        )

Description

This callback is called by the core when a connection is accepted. Its primary function is to check access control (whether the client is permitted to connect to this port), and to spawn a new session to handle the connection.

Exceptions raised due to policy violations are handled here.

Arguments

Table 4-69. Arguments for Listener.accepted()

self this instance
clientthe address of the client
fd the fd of the connection to the client

Exceptions

  • DACException

Returns

TRUE if the connection is accepted

Method destroy

Stops the listener on the given port

Synopsis

destroy ( self )

Description

Calls the destroy method of the low-level object

Arguments

Table 4-70. Arguments for Listener.destroy()

selfthis instance

Method getService

Returns the service associated with the listener

Synopsis

getService ( self,  session )

Description

Returns the service to start.

Arguments

Table 4-71. Arguments for Listener.getService()

self this instance
sessionsession reference

Class ZoneListener

This class is similar to a simple Listener, but instead of starting a fixed service, it chooses one based on the client zone.

It takes a mapping of services indexed by a zone name, with an exception of the * service, which matches anything.

Attributes

Table 4-72. Attributes for class ZoneListener

servicesservices mapping indexed by zone name

Constructor __init__

Initialize a ZoneListener instance.

Synopsis

__init__ (
        self,
        bindto,
        services,
        )

Description

Initialize a ZoneListener instance and set initial attribute values based on arguments.

Arguments

Table 4-73. Arguments for ZoneListener.__init__()

selfthis instance
bindtobind to this address
servicesa mapping between zone names and services

Method getService

Virtual function which returns the service to be ran

Synopsis

getService ( self,  session )

Description

Called by our base class to find out the service to be used for the current session.

Arguments

Table 4-74. Arguments for ZoneListener.getService()

selfthis instance
sessionsession we are starting