Common functions for manipulating Ixian protocol message. More...
Static Public Member Functions | |
static byte | getHeaderChecksum (byte[] header) |
Calculates a single-byte checksum from the given header. More... | |
static byte [] | prepareProtocolMessage (ProtocolMessageCode code, byte[] data, byte[] checksum=null) |
Prepares (serializes) a protocol message from the given Ixian message code and appropriate data. Checksum can be supplied, but if it isn't, this function will calculate it using the default method. More... | |
static void | sendBye (RemoteEndpoint endpoint, ProtocolByeCode code, string message, string data, bool removeAddressEntry=true) |
Prepares and sends the disconnect message to the specified remote endpoint. More... | |
static void | readProtocolMessage (byte[] recv_buffer, RemoteEndpoint endpoint) |
Reads a protocol message from the specified byte-field and calls appropriate methods to process this message. More... | |
static bool | processHelloMessage (RemoteEndpoint endpoint, BinaryReader reader) |
Processes a Hello Ixian protocol message and updates the PresenceList as appropriate. More... | |
static void | sendHelloMessage (RemoteEndpoint endpoint, bool sendHelloData, byte[] challenge_response) |
Prepares and sends an Ixian protocol 'Hello' message to the specified remote endpoint. More... | |
static bool | broadcastProtocolMessage (char[] types, ProtocolMessageCode code, byte[] data, byte[] helper_data, RemoteEndpoint skipEndpoint=null) |
Prepares and broadcasts an Ixian protocol message to all connected nodes, filtered by types . More... | |
static bool | broadcastEventDataMessage (NetworkEvents.Type type, byte[] address, ProtocolMessageCode code, byte[] data, byte[] helper_data, RemoteEndpoint skipEndpoint=null) |
Broadcasts an event message to all clients who are subscribed to receive the specific event type and wallet address. More... | |
static bool | broadcastProtocolMessageToSingleRandomNode (char[] types, ProtocolMessageCode code, byte[] data, ulong block_num, RemoteEndpoint skipEndpoint=null) |
Sends the specified protocol message to one of the connected remote endpoints, chosen randomly. More... | |
static bool | checkNodeConnectivity (RemoteEndpoint endpoint) |
Verifies that the given remote endpoint is reachable by connecting to it and sending a short message. More... | |
Common functions for manipulating Ixian protocol message.
Definition at line 14 of file CoreNetworkProtocol.cs.
|
static |
Broadcasts an event message to all clients who are subscribed to receive the specific event type and wallet address.
Events are filtered by type and address. A client must subscribe to the specifif type for specific addresses in order to receive this data. The payload data
should be properly formatted for the given code
- this function will not ensure that this is so and the caller must provide a valid message to this function. The skipEndpoint
parameter is useful when re-broadcasting a message received from a specific endpoint and do not wish to echo the same data back to the sender.
type | Type of the event message - used to filter subscribers |
address | Address, which triggered the event. |
code | Ixian protocol code. |
data | Payload data. |
helper_data | Optional additional data, as required by code . |
skipEndpoint | Endpoint to skip when broadcasting. |
Definition at line 571 of file CoreNetworkProtocol.cs.
|
static |
Prepares and broadcasts an Ixian protocol message to all connected nodes, filtered by types
.
The payload data
should be properly formatted for the given code
- this function will not ensure that this is so and the caller must provide a valid message to this function. The skipEndpoint
parameter is useful when re-broadcasting a message received from a specific endpoint and do not wish to echo the same data back to the sender.
types | Types of nodes to send this message to. |
code | Protocol code. |
data | Message payload |
helper_data | Additional information, as required by the protocol message |
skipEndpoint | Remote endpoint which should be skipped (data should not be sent to it). |
Definition at line 535 of file CoreNetworkProtocol.cs.
|
static |
Sends the specified protocol message to one of the connected remote endpoints, chosen randomly.
The payload data
should be properly formatted for the given code
- this function will not ensure that this is so and the caller must provide a valid message to this function. The skipEndpoint
parameter is useful when re-broadcasting a message received from a specific endpoint and do not wish to echo the same data back to the sender. The block_num
parameter is used to filter the remote endpoints based on their latest known block height.
types | Types of the nodes where the message should be sent. |
code | Ixian protocol code. |
data | Payload data. |
block_num | Block which should be searched for the endpoint addresses. |
skipEndpoint | Minimum block height for endpoints which should receive this message. |
Definition at line 596 of file CoreNetworkProtocol.cs.
|
static |
Verifies that the given remote endpoint is reachable by connecting to it and sending a short message.
This function is used to ensure that the remote endpoing has listed the correct IP and port information for their PresenceList
entry.
endpoint | Target endpoint to verify for connectivity. |
Definition at line 702 of file CoreNetworkProtocol.cs.
|
static |
Calculates a single-byte checksum from the given header.
A single byte of checksum is not extremely robust, but it is simple and fast.
header | Message header. |
Definition at line 24 of file CoreNetworkProtocol.cs.
|
static |
Prepares (serializes) a protocol message from the given Ixian message code and appropriate data. Checksum can be supplied, but if it isn't, this function will calculate it using the default method.
This function can be used from the server and client side. Please note: This function does not validate that the payload data
conforms to the expected message for code
. It is the caller's job to ensure that.
code | Message code. |
data | Payload for the message. |
checksum | Optional checksum. If not supplied, or if null, this function will calculate it with the default method. |
Definition at line 47 of file CoreNetworkProtocol.cs.
|
static |
Processes a Hello Ixian protocol message and updates the PresenceList
as appropriate.
This function should normally be called from NetworkProtocol.parseProtocolMessage()
endpoint | Remote endpoint from which the message was received. |
reader | Reader object placed at the beginning of the hello message data. |
Definition at line 228 of file CoreNetworkProtocol.cs.
|
static |
Reads a protocol message from the specified byte-field and calls appropriate methods to process this message.
This function checks all applicable checksums and validates that the message is complete before calling one of the specialized methods to handle actual decoding and processing.
recv_buffer | Byte-field with an Ixian protocol message. |
endpoint | Remote endpoint from where the message was received. |
Definition at line 141 of file CoreNetworkProtocol.cs.
|
static |
Prepares and sends the disconnect message to the specified remote endpoint.
endpoint | Remote client. |
code | Disconnection reason. |
message | Optional text message for the user of the remote client. |
data | Optional payload to further explain the disconnection reason. |
removeAddressEntry | If true, the remote address will be removed from the PresenceList . |
Definition at line 104 of file CoreNetworkProtocol.cs.
|
static |
Prepares and sends an Ixian protocol 'Hello' message to the specified remote endpoint.
A valid Ixian 'Hello' message includes certain Node data, verified by a public-key signature, which this function prepares using the primary wallet's keypair. If this message is a reply to the other endpoint's hello message, then
endpoint | Remote endpoint to send the message to. |
sendHelloData | True if the message is the first hello sent to the remote node, false if it is a reply to the challenge. |
challenge_response | Response byte-field to the other node's hello challenge |
Definition at line 415 of file CoreNetworkProtocol.cs.