Control protocol
This module contains the class for the classical communication between Alice and Bob.
- qosst_core.control_protocol.QOSST_VERSION: str = 'QOSST/0.2'
Current version of the control protocol.
- qosst_core.control_protocol.DEFAULT_PORT: int = 8181
Default network port.
- qosst_core.control_protocol.CHALLENGE_LENGTH: int = 15
Length of the challenge for authentication.
- qosst_core.control_protocol.READING_BUFFER: int = 2048
Length of the reading buffer.
Codes
Enumeration of the QOSST/0.2 protocol.
- class qosst_core.control_protocol.codes.QOSSTCodes(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Codes for the QOSST/0.2 protocol.
- UNKOWN_COMMAND = 10
Code for an unkown command.
- UNEXPECTED_COMMAND = 11
Code for an unexpected command.
- INVALID_CONTENT = 12
Code indicating that the content was invalid.
- INVALID_RESPONSE = 13
Code indcating an invalid response.
- INVALID_RESPONSE_ACK = 14
Code to acknowledge an invalid reponse message.
- ABORT = 15
Abort code.
- ABORT_ACK = 16
Acknowledge an abortion code.
- AUTHENTICATION_INVALID = 17
Indicate that an authentication message was invalid.
- CHANGE_PARAMETER_REQUEST = 50
Code to request a change of parameter.
- PARAMETER_INVALID_VALUE = 53
Code to answer to a parameter change request if the requested value is invalid.
- PARAMETER_UNCHANGED = 54
Code to answer to a parameter change request saying that the parameter was not changed.
- IDENTIFICATION_REQUEST = 100
Request the start of the identification process.
- IDENTIFICATION_RESPONSE = 101
Response to a request of identification.
- INVALID_QOSST_VERSION = 102
Response to answer to an identification request if the versions of the QOSST protocols are not compatible.
- INITIALIZATION_REQUEST = 120
Request the start of the initialization process.
- INITIALIZATION_ACCEPTED = 121
Accept the initialization (i.e. configuration).
- INITIALIZATION_DENIED = 122
Deny the initialization (i.e. configuration).
- INITIALIZATION_PROPOSAL = 123
Propose a configuration.
- INITIALIZATION_REQUEST_CONFIG = 124
Request a configuration.
- INITIALIZATION_CONFIG = 125
Send the configuration for the initialization.
- QIE_REQUEST = 140
Request the start of the Quantum Information Exchange process.
- QIE_READY = 141
Notify that the quantum information is ready to be sent.
- QIE_TRIGGER = 142
Start the quantum information exchange.
- QIE_EMISSION_STARTED = 143
Notify that the emission has started.
- QIE_ACQUISITION_ENDED = 144
Notify that the acquisition has ended.
- QIE_ENDED = 145
End the QIE process.
- PE_SYMBOLS_REQUEST = 160
Request some symbols to Alice.
- PE_SYMBOLS_RESPONSE = 161
Answer to the request of symbols.
- PE_SYMBOLS_ERROR = 162
Answer to the request of symbols if there was an error to to generate the response (i.e. invalid indices).
- PE_NPHOTON_REQUEST = 163
Request the average photon number of Alice.
- PE_NPHOTON_RESPONSE = 164
Response to the request of the average photon number.
- PE_FINISHED = 165
Notify that parameter estimation is finished and send the parameters to Alice.
- PE_DENIED = 167
Deny the estimated parameters and abort.
- FRAME_ENDED = 220
End a frame.
- FRAME_ENDED_ACK = 221
ACK message for a end of frame.
- DISCONNECTION = 222
Notify the other party of a disconnection.
- DISCONNECTION_ACK = 223
ACK for the disconnection message.
- class qosst_core.control_protocol.codes.QOSSTErrorCodes(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Error codes for QOSST.
- SOCKET_DISCONNECTION = -1
Indicate that the other party has disconnected
- FRAME_ERROR = -2
The frame was not well formatted
- AUTHENTICATION_FAILURE = -3
There was an authentication failure (either with the challenge wrong or not present, or on the signed digest)
- UNKOWN_CODE = -4
The sent code is not in the possible QOSST codes.
Sockets
Network sockets for the QOSST control protocol.
- class qosst_core.control_protocol.sockets.QOSSTSocket(host='127.0.0.1', port: int = 8181, authenticator: ~typing.Type[~qosst_core.authentication.base.BaseAuthenticator] = <class 'qosst_core.authentication.base.NoneAuthenticator'>, authentication_params: ~typing.Dict | None = None)
Base QOSST Socket (absract).
Implements the recv and send function.
- Parameters:
host (str, optional) – either the port to connect to or to bind to. Defaults to “127.0.0.1”.
port (int, optional) – either the port to connect to or to bind to. Defaults to DEFAULT_PORT.
authenticator (Type[BaseAuthenticator], optional) – Authenticator to generate and check digests. Defaults to NoneAuthenticator.
authentication_params (Optional[dict], optional) – Parameters to be given to the authentication class. Defaults to {}.
- host: str
Host (to connect or to bind)
- port: int
Port (to connect or to bind)
- socket: socket | None
Socket (making the communication)
- auth: BaseAuthenticator
Signing and verifying digests
- challenge: str
Previous or next challenge
- selector: BaseSelector
Selector for read
- abstract open()
Open socket.
- connect()
Connect socket (connect to server or wait for clients).
- send(code: QOSSTCodes, data: Dict | None = None)
Send a message with code and data.
- Parameters:
code (QOSSTCodes) – the code of the message to send.
data (Dict, optional) – content of the message. Defaults to None.
- recv() Tuple[QOSSTCodes | QOSSTErrorCodes, Dict | None]
Receive a message from the network and return code and data.
- Returns:
the code of the message (or the error code) and the optional content of the message.
- Return type:
Tuple[Union[QOSSTCodes, QOSSTErrorCodes], Optional[Dict]]
- close()
Close socket.
- class qosst_core.control_protocol.sockets.QOSSTClient(host='127.0.0.1', port: int = 8181, authenticator: ~typing.Type[~qosst_core.authentication.base.BaseAuthenticator] = <class 'qosst_core.authentication.base.NoneAuthenticator'>, authentication_params: ~typing.Dict | None = None)
Specific class for the QOSST client.
- Parameters:
host (str, optional) – either the port to connect to or to bind to. Defaults to “127.0.0.1”.
port (int, optional) – either the port to connect to or to bind to. Defaults to DEFAULT_PORT.
authenticator (Type[BaseAuthenticator], optional) – Authenticator to generate and check digests. Defaults to NoneAuthenticator.
authentication_params (Optional[dict], optional) – Parameters to be given to the authentication class. Defaults to {}.
- open() None
Open socket.
- connect() None
Connect to server.
- request(code: QOSSTCodes, data: Dict | None = None) Tuple[QOSSTCodes | QOSSTErrorCodes, Dict | None]
Send a message to the server and wait for a response.
In case of a disconnection, the client will try to reconnect.
- Parameters:
code (QOSSTCodes) – the code of the message to send.
data (Dict, optional) – the content of the message to send. Defaults to None.
- Returns:
Tuple[Union[QOSSTCodes, QOSSTErrorCodes], Optional[Dict]]:: the code and the content of the received message.
- class qosst_core.control_protocol.sockets.QOSSTServer(host='127.0.0.1', port: int = 8181, authenticator: ~typing.Type[~qosst_core.authentication.base.BaseAuthenticator] = <class 'qosst_core.authentication.base.NoneAuthenticator'>, authentication_params: ~typing.Dict | None = None)
Specific class for the QOSST Server.
- Parameters:
host (str, optional) – either the port to connect to or to bind to. Defaults to “127.0.0.1”.
port (int, optional) – either the port to connect to or to bind to. Defaults to DEFAULT_PORT.
authenticator (Type[BaseAuthenticator], optional) – Authenticator to generate and check digests. Defaults to NoneAuthenticator.
authentication_params (Optional[dict], optional) – Parameters to be given to the authentication class. Defaults to {}.
- host_socket: socket
Host socket.
- client_address: str
Address of the client.
- open() None
Open host socket.
- connect() None
Wait for a client to connect.
- recv() Tuple[QOSSTCodes | QOSSTErrorCodes, Dict | None]
Receive a message.
In case of a disconnection, the client socket is closed.
- Returns:
the code of the received message (or the error code) and the optional message.
- Return type:
Tuple[Union[QOSSTCodes, QOSSTErrorCodes], Optional[Dict]]
- close() None
Close the socket. Also close the host socket.