Client
SusClient
This class is responsible for managing the client.
Source code in sus/client/client.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
connected
property
True if the client is connected to the server.
__init__(addr, ppks, protocol_id)
Initializes the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
addr |
tuple[str, int]
|
Server address |
required |
ppks |
str
|
Server public key |
required |
protocol_id |
bytes
|
Protocol ID (any bytestring) |
required |
Source code in sus/client/client.py
__key_exchange(epks_ns_port, wallet)
This function is responsible for performing the key exchange.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epks_ns_port |
bytes
|
received (epks, ns, port) from server |
required |
wallet |
Wallet
|
wallet containing the client's keys |
required |
Returns:
| Type | Description |
|---|---|
Wallet
|
wallet containing the shared secret |
Source code in sus/client/client.py
connect()
async
This coroutine is responsible for connecting to the server. Performs the key exchange and starts the handshake.
Source code in sus/client/client.py
disconnect()
Disconnects from the server.
Source code in sus/client/client.py
keep_alive()
async
Convenience coroutine that waits until the client is disconnected.
Source code in sus/client/client.py
send(data)
Sends a message to the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
bytes
|
message to send as bytes |
required |
start(handlers=None)
async
This coroutine is responsible for starting the client. Blocks until the client is connected. It also registers message handlers, called when a message is received.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handlers |
Iterable[MessageHandler]
|
|
None
|
Returns:
| Type | Description |
|---|---|
|
|
Source code in sus/client/client.py
Protocol
Bases: DatagramProtocol
This class is responsible for handling the UDP protocol.
Source code in sus/client/protocol.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
__encrypt_and_tag(data, token)
This function is responsible for encrypting and tagging a message. Uses the ChaCha20-Poly1305 AEAD to encrypt and authenticate the message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
bytes
|
data to encrypt |
required |
token |
bytes
|
optional token to include in the first packet |
required |
Returns:
| Type | Description |
|---|---|
list[bytes]
|
packets containing the encrypted and tagged message to send to the server |
Source code in sus/client/protocol.py
__init__(wallet, protcol_id, handlers=None)
Initializes the client protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wallet |
Wallet
|
wallet containing the client's keys |
required |
protcol_id |
bytes
|
protocol ID (any bytestring) |
required |
handlers |
Optional[Iterable[MessageHandler]]
|
message handlers, called when a message is received |
None
|
Source code in sus/client/protocol.py
__split_message(data)
This function is responsible for splitting a message into packets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
bytes
|
data to split |
required |
Returns:
| Type | Description |
|---|---|
list[bytes]
|
list of packets |
Source code in sus/client/protocol.py
__verify_and_decrypt(data)
This function is responsible for verifying the packet and decrypting it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
bytes
|
data to verify and decrypt |
required |
Returns:
| Type | Description |
|---|---|
tuple[None, None] | tuple[int, bytes]
|
packet ID and message, or None if the packet is invalid |
Source code in sus/client/protocol.py
connection_lost(exc)
Called when the connection is lost. Sets the disconnection event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc |
exception raised, if any |
required |
Source code in sus/client/protocol.py
connection_made(transport)
This function is called when the connection is established.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transport |
DatagramTransport
|
transport object, used to send and receive packets |
required |
Source code in sus/client/protocol.py
datagram_received(data, _addr)
This function is called when a packet is received.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
bytes
|
packet data |
required |
_addr |
tuple[str, int]
|
originating address (always the server, unused) |
required |
Source code in sus/client/protocol.py
disconnect()
handle_message(pid, message)
Calls all message handlers asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pid |
int
|
packet ID |
required |
message |
bytes
|
message bytes |
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in sus/client/protocol.py
send(data, token=b'')
This function is responsible for sending a message to the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
bytes
|
data to send |
required |
token |
bytes
|
token to include in the first packet. DO NOT INCLUDE THE TOKEN IN SUBSEQUENT PACKETS -- a MalformedPacket error will be raised! |
b''
|
Raises:
| Type | Description |
|---|---|
MalformedPacket
|
if the token is included in a subsequent packet |