wasp_general.network.beacon package¶
Submodules¶
wasp_general.network.beacon.beacon module¶
-
class
wasp_general.network.beacon.beacon.WBeaconConfig(config=None, config_section=None)[source]¶ Bases:
objectAbstract class that represent service discovery beacon configuration
-
class
wasp_general.network.beacon.beacon.WBeaconHandler(config, io_handler, server_mode, transport=None)[source]¶ Bases:
wasp_general.network.service.WNativeSocketHandlerBeacon’s loop-handler. Is capable to create required transport (that is specified in the beacon’s configuration) Depends on configuration value, the following classes is used:
‘broadcast’ (default) -WBroadcastBeaconTransport‘multicast’ -WMulticastBeaconTransport‘unicast_udp’ - not implemented yet ‘unicast_tcp’ - not implemented yet-
setup_handler(io_loop)[source]¶ WIOLoopServiceHandler.setup_handler()implementation. When this object is in ‘non-server mode’ (client mode), then beacon message is sent
-
-
class
wasp_general.network.beacon.beacon.WBeaconIOHandler(config, messenger=None, callback=None)[source]¶ Bases:
wasp_general.network.service.WNativeSocketDirectIOHandlerBasic beacon io-handler.
-
max_size()[source]¶ Return maximum message size. (Minimum between this class ‘message_maxsize’ value and messengers ‘message_maxsize’ value)
Returns: int
-
message_maxsize= 1024¶ Network messages maximum size
-
-
class
wasp_general.network.beacon.beacon.WNetworkBeaconBase(config, io_handler, server_mode, transport, timeout=None)[source]¶ Bases:
wasp_general.network.service.WIOLoopServiceRepresent service discovery beacon that works over the network. This beacon doesn’t interact with network services like zeroconf, but instead it does all the network discovery work itself. The real work is done in
WNetworkServerBeaconandWNetworkClientBeaconclasses.This service automatically creates
WBeaconHandlerobject with the specified io-handler.
-
class
wasp_general.network.beacon.beacon.WNetworkBeaconCallback[source]¶ Bases:
objectAbstract class that represent network beacon callback. Helps to interact with clients or servers. After beacons message received this is the place where all the beacon logic happens.
-
class
wasp_general.network.beacon.beacon.WNetworkClientBeacon(config=None, config_section=None, messenger=None, callback=None, transport=None)[source]¶ Bases:
wasp_general.network.beacon.beacon.WBeaconConfig,wasp_general.network.beacon.beacon.WNetworkBeaconBaseClient beacon sends single request and waits for responses for a period of time. This period is specified in beacons configuration as ‘lookup_timeout’ option. Client waiting period can be interrupted by calling the
WNetworkClientBeacon.stop()method.-
class
Handler(config, messenger=None, callback=None)[source]¶ Bases:
wasp_general.network.beacon.beacon.WBeaconIOHandlerClient handler waits for responses and calls callback if it is available
-
handler_fn(fd, event)[source]¶ WNativeSocketIOHandler.handler_fn()method implementation.
-
-
class
-
class
wasp_general.network.beacon.beacon.WNetworkServerBeacon(config=None, config_section=None, messenger=None, callback=None, process_any=False, transport=None)[source]¶ Bases:
wasp_general.network.beacon.beacon.WBeaconConfig,wasp_general.network.beacon.beacon.WNetworkBeaconBaseServer beacon that is waiting to respond on a valid request and/or process this request with the specified callback.
-
class
Handler(config, messenger=None, callback=None, process_any=False)[source]¶ Bases:
wasp_general.network.beacon.beacon.WBeaconIOHandlerServer’s handler. Responds on a valid requests, if callback was specified, then it process client request. If server has received invalid request and ‘process_any’ flag was set, then callback (if available) will process this request as invalid
-
handler_fn(fd, event)[source]¶ WNativeSocketIOHandler.handler_fn()method implementation.
-
-
class
wasp_general.network.beacon.messenger module¶
-
class
wasp_general.network.beacon.messenger.WBeaconGouverneurMessenger(hello_message, invert_hello=False)[source]¶ Bases:
wasp_general.network.beacon.messenger.WBeaconMessengerBaseBasic and real messenger implementation. Request and response are generated the same way, but have different meaning. Messages are generated the following way: [Message header]<:[Address<:TCP/UDP port>]> “Message header” is the first part of the message and it must be exactly the same for client or server. If server has got message with header that doesn’t match its own header, such messages will be omitted. Next parts are “Address” and “TCP/UDP port”. These parts are separated by the
WBeaconGouverneurMessenger.__message_splitter__separator. “TCP/UDP port” can’t be specified without an “Address” An “Address” field can be an IP address or a domain name.For the client “Address” and “UDP Port” are treated as address where server must send the response. But for the server, they are treated as the address, that the server publish. For both type of messages “Address” and “TCP/UDP port” are generated from a configuration. Options are located in ‘wasp-general::network::beacon’ section. Configuration option “public_address” is used as “Address” value and option “public_port” is used as “UDP Port”
-
has_response(beacon_config, request, client_address)[source]¶ WBeaconMessengerBase.has_response()method implementation. This method compares request header with internal one.
-
hello_message(invert_hello=False)[source]¶ Return message header.
Parameters: invert_hello – whether to return the original header (in case of False value) or reversed one (in case of True value). Returns: bytes
-
invert_hello()[source]¶ Return whether this messenger was constructed with ‘invert_hello’ or not.
Returns: bool
-
request(beacon_config)[source]¶ WBeaconMessengerBase.request()method implementation.
-
response(beacon_config, request, client_address)[source]¶ WBeaconMessengerBase.request()method implementation.
-
response_address(beacon_config, request, client_address)[source]¶ WBeaconMessengerBase.request()method implementation.
-
valid_response(beacon_config, response, server_address)[source]¶ WBeaconMessengerBase.valid_response()method implementation. Response when it has correct header. Response header must be reversed if this messenger was constructed with ‘invert_hello’ flag.
-
-
class
wasp_general.network.beacon.messenger.WBeaconMessenger[source]¶ Bases:
wasp_general.network.beacon.messenger.WBeaconMessengerBaseSimple. Demo/debug messenger. Server side just return original hello message to the sender.
-
has_response(beacon_config, request, client_address)[source]¶ WBeaconMessengerBase.has_response()method implementation. This class has a response only if the request wasn’t empty
-
request(beacon_config)[source]¶ WBeaconMessengerBase.request()method implementation. SendsWBeaconMessenger.__beacon_hello_msg__to a server
-
response(beacon_config, request, client_address)[source]¶ WBeaconMessengerBase.response()method implementation. In response sends the same data as server has got
-
response_address(beacon_config, request, client_address)[source]¶ WBeaconMessengerBase.request()method implementation. Return the same address, that server detects (assume that clients address is correct)
-
valid_response(beacon_config, response, server_address)[source]¶ WBeaconMessengerBase.valid_response()method implementation. Response is valid if it has anything.
-
-
class
wasp_general.network.beacon.messenger.WBeaconMessengerBase[source]¶ Bases:
objectThis is interface for classes, that implement communication (messaging) logic for beacons
see also:
WNetworkBeacon-
has_response(beacon_config, request, client_address)[source]¶ Whether this messenger has response or it must skip the request. Return True if there is a response, otherwise - False. If this method returns False, then calling a
WBeaconMessengerBase.response()method treats as error.Parameters: - beacon_config –
- request –
- client_address –
Returns: bool
-
message_maxsize= 512¶
-
request(beacon_config)[source]¶ Generate client request for beacon. It is calling from client side.
Parameters: beacon_config – client beacon configuration. Returns: bytes
-
response(beacon_config, request, client_address)[source]¶ Generate server response for clients request. Obviously, it is calling from server side
Parameters: - beacon_config – server beacon configuration
- request – client request message
- client_address – client address
Returns: bytes
-
response_address(beacon_config, request, client_address)[source]¶ Return client address where server must send response. It is Possible, that address where server must send response is different then the origin address. In that case, client address is encoded in request message.
Parameters: - beacon_config – server configuration
- request – client request message
- client_address – original client address
Returns: WIPV4SocketInfo
-
-
class
wasp_general.network.beacon.messenger.WHostgroupBeaconMessenger(hello_message, *hostgroup_names, invert_hello=False)[source]¶ Bases:
wasp_general.network.beacon.messenger.WBeaconGouverneurMessengerThis messenger is based on
WBeaconGouverneurMessengerclass. This messenger extendsWBeaconGouverneurMessengerfunctionality by working with host group names. Also, this class doubles maximum message size defined inWBeaconMessengerBase. In cases where no host group name are specified this class works as its basic classWBeaconGouverneurMessenger.Messages format is updated from this:
‘[Message header]<:[Address<:TCP/UDP port>]>’
to this:
‘[Message header]<:[Address<:TCP/UDP port>]><#<[Hostgroup name]>,<[Hostgroup name]…>’>
‘Message header’, ‘Address’ and ‘TCP/UDP port’ work the same way as they specified in
WBeaconGouverneurMessengerclass. At the end of the original message new optional separator is appended. This separator is defined atWHostgroupBeaconMessenger.__message_groups_splitter__. After this separator host group names can be defined. Host group names can contain latin letters and numbers only. Host group names are separated byWHostgroupBeaconMessenger.__group_splitter__If this messenger is constructed with at least one host group name, then it won’not response to requests, that do not have at least one host group name, that this messenger was constructed with.
-
has_response(beacon_config, request, client_address)[source]¶ WBeaconMessengerBase.has_response()method implementation. This method compares request headers asWBeaconGouverneurMessenger.has_response()do and compares specified group names with internal names.
-
message_maxsize= 1024¶ Doubled message size for list of names
-
re_hostgroup_name= re.compile('^[a-zA-Z0-9]+$')¶ Regular expression for host group name validation
-
response_address(beacon_config, request, client_address)[source]¶ WBeaconMessengerBase.response_address()method implementation. It just removes host group names part and returnWBeaconMessengerBase.response_address()result
-
wasp_general.network.beacon.task module¶
-
class
wasp_general.network.beacon.task.WNetworkBeaconTask(config=None, config_section=None, thread_name=None, messenger=None)[source]¶ Bases:
wasp_general.network.beacon.beacon.WNetworkServerBeacon,wasp_general.task.thread.WThreadTaskConvenient way to start WNetworkBeacon server side
wasp_general.network.beacon.transport module¶
-
class
wasp_general.network.beacon.transport.WBroadcastBeaconTransport[source]¶ Bases:
wasp_general.network.transport.WBroadcastNetworkTransportNetwork beacon transport, that uses IPv4 broadcast communication
-
class
wasp_general.network.beacon.transport.WMulticastBeaconTransport[source]¶ Bases:
wasp_general.network.transport.WMulticastNetworkTransportNetwork beacon transport, that uses IPv4 multicast communication
-
wasp_general.network.beacon.transport.client_configuration= <wasp_general.network.transport.WNetworkNativeTransportSocketConfig object>¶ Mainly. ‘address’ and ‘port’ options are used on client side for destination definition (for server destination). This options can be used for address validation on server side also. For example, in
WMulticastBeaconTransportclass ‘address’ checks if it is a valid multicast address, inWBroadcastBeaconTransportclass ‘address’ checks if it is a IPv4 address.
-
wasp_general.network.beacon.transport.server_configuration= <wasp_general.network.transport.WNetworkNativeTransportSocketConfig object>¶ Server side use ‘bind_address’ options to set up listening socket. Server will be able to receive requests only at this address. Default is ‘’ (empty string) that works as ‘0.0.0.0’ address, in this case server will be able to receive requests at any address defined in the system.