nopasaran.controllers.protocol.WorkerServerProtocol¶
- class nopasaran.controllers.protocol.WorkerServerProtocol¶
Bases:
WorkerProtocolProtocol for worker servers.
This protocol is used by worker servers to communicate with clients.
- __init__()¶
Methods
__init__()connectionLost(reason)Handle the connection loss.
Handle the connection made event.
dataReceived(encoded_json_data)Handle received data.
Initiate the disconnection process.
Get the current state as a JSON-encoded string.
Return a prefix matching the class name, to identify log messages related to this protocol instance.
makeConnection(transport)Make a connection to a transport and a server.
send_encoded_data(data)Send encoded data through the transport.
send_sync(content)Send a sync message to the remote endpoint.
Attributes
connectedfactoryis_activelocal_statusqueueremote_statustransport- connectionLost(reason)¶
Handle the connection loss.
This method is called when the connection is lost with the remote endpoint.
- Args:
reason: The reason for the connection loss.
- connectionMade()¶
Handle the connection made event.
This method is called when a client successfully establishes a connection with the server. It sets the local status to CONNECTED, sends the current state to the client, and logs the event.
- dataReceived(encoded_json_data)¶
Handle received data.
This method is called when data is received from the remote endpoint.
- Args:
encoded_json_data (bytes): The received data as bytes.
- disconnecting()¶
Initiate the disconnection process.
This method sets the local status to DISCONNECTING and sends the current state to the remote endpoint.
- get_current_state_json()¶
Get the current state as a JSON-encoded string.
- Returns:
bytes: The JSON-encoded current state.
- logPrefix()¶
Return a prefix matching the class name, to identify log messages related to this protocol instance.
- makeConnection(transport)¶
Make a connection to a transport and a server.
This sets the ‘transport’ attribute of this Protocol, and calls the connectionMade() callback.
- send_encoded_data(data)¶
Send encoded data through the transport.
This method encodes the provided data to JSON, base64, and sends it.
- Args:
data (dict): The data to encode and send.
- send_sync(content)¶
Send a sync message to the remote endpoint.
This method sends a sync message with the specified content to the remote endpoint.
- Args:
content: The content of the sync message.