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 MarshalAuthMsg(peerID []byte, authPayload []byte) ([]byte, error)
- func MarshalAuthResponse(address string) ([]byte, error)
- func MarshalCloseMsg() []byte
- func MarshalHealthcheck() []byte
- func MarshalHelloMsg(peerID []byte, additions []byte) ([]byte, error)deprecated
- func MarshalHelloResponse(additionalData []byte) ([]byte, error)deprecated
- func MarshalTransportMsg(peerID []byte, payload []byte) ([]byte, error)
- func UnmarshalAuthMsg(msg []byte) ([]byte, []byte, error)
- func UnmarshalAuthResponse(msg []byte) (string, error)
- func UnmarshalHelloMsg(msg []byte) ([]byte, []byte, error)deprecated
- func UnmarshalHelloResponse(msg []byte) ([]byte, error)deprecated
- 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 MsgType
Constants ¶
const ( MaxHandshakeSize = 212 MaxHandshakeRespSize = 8192 CurrentProtocolVersion = 1 MsgTypeUnknown MsgType = 0 // Deprecated: Use MsgTypeAuth instead. MsgTypeHello MsgType = 1 // Deprecated: Use MsgTypeAuthResponse instead. MsgTypeHelloResponse MsgType = 2 MsgTypeTransport MsgType = 3 MsgTypeClose MsgType = 4 MsgTypeHealthCheck MsgType = 5 MsgTypeAuth = 6 MsgTypeAuthResponse = 7 SizeOfVersionByte = 1 SizeOfMsgType = 1 SizeOfProtoHeader = SizeOfVersionByte + SizeOfMsgType )
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 MarshalAuthMsg ¶ added in v0.29.1
MarshalAuthMsg initial authentication message The Auth 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 MarshalAuthResponse ¶ added in v0.29.1
MarshalAuthResponse creates a response message to the auth. In case of success connection the server response with a AuthResponse 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 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
deprecated
Deprecated: Use MarshalAuthMsg instead. 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
deprecated
Deprecated: Use MarshalAuthResponse instead. 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 UnmarshalAuthMsg ¶ added in v0.29.1
UnmarshalAuthMsg extracts peerID and the auth payload from the message
func UnmarshalAuthResponse ¶ added in v0.29.1
UnmarshalAuthResponse it is a confirmation message to auth success
func UnmarshalHelloMsg
deprecated
func UnmarshalHelloResponse
deprecated
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 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
Directories ¶
Path | Synopsis |
---|---|
Deprecated: This package is deprecated and will be removed in a future release.
|
Deprecated: This package is deprecated and will be removed in a future release. |
Deprecated: This package is deprecated and will be removed in a future release.
|
Deprecated: This package is deprecated and will be removed in a future release. |