Class PoloBinding

class marcopolo.polo.polobindingssl.PoloBindingSSL(secret, offered_services, user_services, multicast_groups=['224.0.0.112', '224.0.0.113'], verify_regexp='^([\d\w]+):([\d\w]+)$')[source]
__init__(secret, offered_services, user_services, multicast_groups=['224.0.0.112', '224.0.0.113'], verify_regexp='^([\\d\\w]+):([\\d\\w]+)$')[source]

Creates the PoloBinding instance with the data structures to work with. If defined, the offered_services and user_services variables will be treated as references to a dictionaries (i.e. the values will be modified, but the object reference will never be altered).

Parameters:
  • offered_services (dict) – A dictionary which comprises all the dictionaries passed to the offered_services param in the Polo instances. That way the services can be altered by both parties
  • user_services (dict) – A dictionary of all the user services dictionaries (the key is multicast group and the value is the list of user dictionaries passed to the param user_services.
  • multicast_group (str) – The IPv4 address of the multicast group to join to. Important: The multicast_addr is not validated until the reactor is started.
  • verify_regexp (str) – Regular expression used to verify an user service.
dataReceived(datagram)[source]

Receives datagrams from bindings, and verifies the Command field. It emits a response based on the value (if necessary)

Parameters:datagram (bytes) – The byte stream with the message
is_superuser(user)[source]

Returns True if the user is a ‘superuser’ (it is root or it a member of the marcopolo group)

Parameters:user (string) – pwd structure with all the information from the user
publish_service(service, token, multicast_groups=['224.0.0.112', '224.0.0.113'], permanent=False, root=False)[source]

Registers a service during execution time.

Parameters:
  • address (tuple) – A tuple with the requesting address and port
  • service (str) –

    Indicates the unique identifier of the service.

    If root is true, the published service will have the same identifier as the value of the parameter. Otherwise, the name of the user will be prepended (<user>:<service>).

  • uid (int) – The unique user identifier
  • multicast_groups (set) –

    Indicates the groups where the service shall be published.

    Note that the groups must be defined in the polo.conf file, or otherwise the method will throw an exception.

  • permanent (bool) – If set to true a file will be created and the service will be permanently offered until the file is deleted.
  • root (bool) –

    Stores the file in the marcopolo configuration directory.

    This feature is only available to privileged users, by default root and users in the marcopolo group.

publish_service_wrapper(command, args)[source]

A wrapper for the :method:publish_service method

Parameters:
  • command (str) – The command that triggered the function
  • args (dict) – The arguments to pass to :method:publish_service
request_token_service_wrapper(command, args)[source]

A wrapper for the :method:request_token method

Parameters:
  • command (str) – The command that triggered the function
  • args (dict) – The arguments to pass to :method:request_token
startProtocol()[source]

Starts the binding and adds an entry in the log file

unknown_command_handler(command, args)[source]

Handles all unkown commands

Parameters:
  • command (str) – The command that triggered the function
  • args (dict) – The arguments that were passed
unpublish_service(service, token, multicast_groups=['224.0.0.112', '224.0.0.113'], delete_file=False)[source]

Removes a service from the offered services structures and all associated files, upon request.

Parameters:
  • address (tuple) – A tuple with the requesting address and port.
  • service (str) – The id of the service to delete.
  • uid (int) – The uid of the requesting user.
  • multicast_groups (list) – The list of multicast_groups to delete the service from. If not defined, the service is removed from all groups.
  • delete_file (bool) – If set to True and the service is of type permanent, the service file is deleted. If the service is not permanent the parameter is ignored.
unpublish_service_wrapper(command, args)[source]

A wrapper for the :method:unpublish_service method

Parameters:
  • command (str) – The command that triggered the function
  • args (dict) – The arguments to pass to :method:unpublish_service
validate_user(uid)[source]

Returns a pwd structure if the uid is present in the passwd database. Otherwise None is returned

Parameters:uid (string) – The user identifier of the service
write_error(error)[source]

Creates and sends an Error message

Parameters:error (str) – The error reason
write_ok(status)[source]

Creates and sends an OK message

Parameters:status (int) – The status code