Documentation
¶
Overview ¶
Package messages provides the message types that are used to communicate between the relay and the client. This package is used to determine the type of message that is being sent and received between the relay and the client.
Index ¶
- Constants
- Variables
- func HashID(peerID string) ([]byte, string)
- func HashIDToString(idHash []byte) string
- func MarshalCloseMsg() []byte
- func MarshalHealthcheck() []byte
- func MarshalHelloMsg(peerID []byte, additions []byte) ([]byte, error)
- func MarshalHelloResponse(additionalData []byte) ([]byte, error)
- func MarshalTransportMsg(peerID []byte, payload []byte) ([]byte, error)
- func UnmarshalHelloMsg(msg []byte) ([]byte, []byte, error)
- func UnmarshalHelloResponse(msg []byte) ([]byte, error)
- func UnmarshalTransportID(buf []byte) ([]byte, error)
- func UnmarshalTransportMsg(buf []byte) ([]byte, []byte, error)
- func UpdateTransportMsg(msg []byte, peerID []byte) error
- func ValidateVersion(msg []byte) (int, error)
- type HelloResponse
- type MsgType
Constants ¶
const ( MsgTypeUnknown MsgType = 0 MsgTypeHello MsgType = 1 MsgTypeHelloResponse MsgType = 2 MsgTypeTransport MsgType = 3 MsgTypeClose MsgType = 4 MsgTypeHealthCheck MsgType = 5 SizeOfVersionByte = 1 SizeOfMsgType = 1 SizeOfProtoHeader = SizeOfVersionByte + SizeOfMsgType MaxHandshakeSize = 8192 CurrentProtocolVersion = 1 )
const (
IDSize = prefixLength + sha256.Size
)
Variables ¶
var ( ErrInvalidMessageLength = errors.New("invalid message length") ErrUnsupportedVersion = errors.New("unsupported version") )
Functions ¶
func HashID ¶
HashID generates a sha256 hash from the peerID and returns the hash and the human-readable string
func HashIDToString ¶
HashIDToString converts a hash to a human-readable string
func MarshalCloseMsg ¶
func MarshalCloseMsg() []byte
MarshalCloseMsg creates a close message. The close message is used to close the connection gracefully between the client and the server. The server and the client can send this message. After receiving this message, the server or client will close the connection.
func MarshalHealthcheck ¶
func MarshalHealthcheck() []byte
MarshalHealthcheck creates a health check message. Health check message is sent by the server periodically. The client will respond with a health check response message. If the client does not respond to the health check message, the server will close the connection.
func MarshalHelloMsg ¶
MarshalHelloMsg initial hello message The Hello message is the first message sent by a client after establishing a connection with the Relay server. This message is used to authenticate the client with the server. The authentication is done using an HMAC method. The protocol does not limit to use HMAC, it can be any other method. If the authentication failed the server will close the network connection without any response.
func MarshalHelloResponse ¶
MarshalHelloResponse creates a response message to the hello message. In case of success connection the server response with a Hello Response message. This message contains the server's instance URL. This URL will be used by choose the common Relay server in case if the peers are in different Relay servers.
func MarshalTransportMsg ¶
MarshalTransportMsg creates a transport message. The transport message is used to exchange data between peers. The message contains the data to be exchanged and the destination peer hashed ID.
func UnmarshalHelloMsg ¶
UnmarshalHelloMsg extracts peerID and the additional data from the hello message. The Additional data is used to authenticate the client with the server.
func UnmarshalHelloResponse ¶
UnmarshalHelloResponse extracts the additional data from the hello response message.
func UnmarshalTransportID ¶
UnmarshalTransportID extracts the peerID from the transport message.
func UnmarshalTransportMsg ¶
UnmarshalTransportMsg extracts the peerID and the payload from the transport message.
func UpdateTransportMsg ¶
UpdateTransportMsg updates the peerID in the transport message. With this function the server can reuse the given byte slice to update the peerID in the transport message. So do need to allocate a new byte slice.
func ValidateVersion ¶
ValidateVersion checks if the given version is supported by the protocol
Types ¶
type HelloResponse ¶
type HelloResponse struct {
InstanceAddress string
}
type MsgType ¶
type MsgType byte
func DetermineClientMessageType ¶
DetermineClientMessageType determines the message type from the first the message
func DetermineServerMessageType ¶
DetermineServerMessageType determines the message type from the first the message