messages

package
v0.32.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

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

View Source
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
)
View Source
const (
	IDSize = prefixLength + sha256.Size
)

Variables

View Source
var (
	ErrInvalidMessageLength = errors.New("invalid message length")
	ErrUnsupportedVersion   = errors.New("unsupported version")
)

Functions

func HashID

func HashID(peerID string) ([]byte, string)

HashID generates a sha256 hash from the peerID and returns the hash and the human-readable string

func HashIDToString

func HashIDToString(idHash []byte) string

HashIDToString converts a hash to a human-readable string

func MarshalAuthMsg added in v0.29.1

func MarshalAuthMsg(peerID []byte, authPayload []byte) ([]byte, error)

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

func MarshalAuthResponse(address string) ([]byte, error)

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

func MarshalHelloMsg(peerID []byte, additions []byte) ([]byte, error)

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

func MarshalHelloResponse(additionalData []byte) ([]byte, error)

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

func MarshalTransportMsg(peerID []byte, payload []byte) ([]byte, error)

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

func UnmarshalAuthMsg(msg []byte) ([]byte, []byte, error)

UnmarshalAuthMsg extracts peerID and the auth payload from the message

func UnmarshalAuthResponse added in v0.29.1

func UnmarshalAuthResponse(msg []byte) (string, error)

UnmarshalAuthResponse it is a confirmation message to auth success

func UnmarshalHelloMsg deprecated

func UnmarshalHelloMsg(msg []byte) ([]byte, []byte, error)

Deprecated: Use UnmarshalAuthMsg instead. 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 deprecated

func UnmarshalHelloResponse(msg []byte) ([]byte, error)

Deprecated: Use UnmarshalAuthResponse instead. UnmarshalHelloResponse extracts the additional data from the hello response message.

func UnmarshalTransportID

func UnmarshalTransportID(buf []byte) ([]byte, error)

UnmarshalTransportID extracts the peerID from the transport message.

func UnmarshalTransportMsg

func UnmarshalTransportMsg(buf []byte) ([]byte, []byte, error)

UnmarshalTransportMsg extracts the peerID and the payload from the transport message.

func UpdateTransportMsg

func UpdateTransportMsg(msg []byte, peerID []byte) error

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

func ValidateVersion(msg []byte) (int, error)

ValidateVersion checks if the given version is supported by the protocol

Types

type MsgType

type MsgType byte

func DetermineClientMessageType

func DetermineClientMessageType(msg []byte) (MsgType, error)

DetermineClientMessageType determines the message type from the first the message

func DetermineServerMessageType

func DetermineServerMessageType(msg []byte) (MsgType, error)

DetermineServerMessageType determines the message type from the first the message

func (MsgType) String

func (m MsgType) String() string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL