protocol

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: May 18, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Ping      = MessageVariant(1)
	Pong      = MessageVariant(2)
	Cast      = MessageVariant(3)
	Multicast = MessageVariant(4)
	Broadcast = MessageVariant(5)
)
View Source
const (
	V1 = MessageVersion(1)
)

Variables

View Source
var (
	ErrInvalidGroupID = errors.New("invalid group id")

	ErrInvalidMessageLength = errors.New("invalid message length")
)
View Source
var NilGroupID = GroupID{}

NilGroupID is a reserved GroupID and usually represents all known PeerIDs.

Functions

func NewErrMessageLengthIsTooLow added in v0.3.0

func NewErrMessageLengthIsTooLow(length MessageLength) error

NewErrMessageLengthIsTooLow creates a new error which is returned when the message length if lower than required.

func NewErrMessageVariantIsNotSupported added in v0.2.3

func NewErrMessageVariantIsNotSupported(variant MessageVariant) error

NewErrMessageVariantIsNotSupported creates a new error which is returned when the given message variant is not supported.

func NewErrMessageVersionIsNotSupported added in v0.3.0

func NewErrMessageVersionIsNotSupported(version MessageVersion) error

NewErrMessageVersionIsNotSupported creates a new error which is returned when the given message version is not supported.

func ParForAllAddresses added in v0.3.0

func ParForAllAddresses(addrs PeerAddresses, numWorkers int, f func(PeerAddress))

Spawn multiple goroutine workers to process the peer addresses in the queue one-by-one.

func ValidateGroupID added in v0.3.3

func ValidateGroupID(groupID GroupID, variant MessageVariant) error

ValidateGroupID checks if the GroupID is valid under the given message variant

func ValidateMessageLength added in v0.3.0

func ValidateMessageLength(length MessageLength, variant MessageVariant) error

ValidateMessageLength checks if the length is valid.

func ValidateMessageVariant added in v0.3.0

func ValidateMessageVariant(variant MessageVariant) error

ValidateMessageVariant checks if the given variant is supported.

func ValidateMessageVersion added in v0.3.0

func ValidateMessageVersion(version MessageVersion) error

ValidateMessageVersion checks if the given version is supported.

Types

type Client added in v0.3.0

type Client interface {
	Run(context.Context, MessageReceiver)
}

Client reads message from the MessageReceiver and sends the message to the target Peer.

type ErrMessageLengthIsTooLow

type ErrMessageLengthIsTooLow struct {
	Length MessageLength
	// contains filtered or unexported fields
}

type ErrMessageVariantIsNotSupported

type ErrMessageVariantIsNotSupported struct {
	Variant MessageVariant
	// contains filtered or unexported fields
}

type ErrMessageVersionIsNotSupported

type ErrMessageVersionIsNotSupported struct {
	Version MessageVersion
	// contains filtered or unexported fields
}

type Event

type Event interface {
	IsEvent()
}

Event is used to notify user when something happens.

type EventMessageReceived

type EventMessageReceived struct {
	Time    time.Time
	Message MessageBody
	From    PeerID
}

EventMessageReceived is triggered when we receive an AW message.

func (EventMessageReceived) IsEvent

func (EventMessageReceived) IsEvent()

EventMessageReceived implements the Event interface.

type EventPeerChanged

type EventPeerChanged struct {
	Time        time.Time
	PeerAddress PeerAddress
}

EventPeerChanged is triggered when we detect an address change of a Peer.

func (EventPeerChanged) IsEvent

func (EventPeerChanged) IsEvent()

EventPeerChanged implements the Event interface.

type EventReceiver

type EventReceiver <-chan Event

EventReceiver is used for reading Event.

type EventSender

type EventSender chan<- Event

EventSender is used for sending Event.

type GroupID added in v0.3.3

type GroupID [32]byte

GroupID uniquely identifies a group of PeerIDs.

func (GroupID) Equal added in v0.3.3

func (id GroupID) Equal(another GroupID) bool

Equal compares two groupIDs and return if they are same.

type Message

type Message struct {
	Length  MessageLength
	Version MessageVersion
	Variant MessageVariant
	GroupID GroupID
	Body    MessageBody
}

Message is the object used for communicating in the network.

func NewMessage

func NewMessage(version MessageVersion, variant MessageVariant, groupID GroupID, body MessageBody) Message

NewMessage returns a new message with given version, variant and body.

func (Message) Hash

func (message Message) Hash() id.Hash

Hash returns the hash of the message.

func (Message) MarshalBinary added in v0.3.0

func (message Message) MarshalBinary() ([]byte, error)

MarshalBinary implements `BinaryMarshaler` interface.

func (*Message) UnmarshalBinary added in v0.3.0

func (message *Message) UnmarshalBinary(data []byte) error

UnmarshalBinary implements `BinaryUnmarshaler` interface.

func (*Message) UnmarshalReader added in v0.3.0

func (message *Message) UnmarshalReader(reader io.Reader) error

UnmarshalReader reads bytes from an `io.Reader` and unmarshals them into itself.

type MessageBody

type MessageBody []byte

MessageBody contains the content of the message.

func (MessageBody) String

func (body MessageBody) String() string

String implements the `Stringer` interface.

type MessageLength

type MessageLength uint32

MessageLength indicates the length of the entire message.

type MessageOnTheWire

type MessageOnTheWire struct {
	To      PeerAddress
	From    PeerID
	Message Message
}

Message we trying to send on the wire.

type MessageReceiver

type MessageReceiver <-chan MessageOnTheWire

MessageReceiver is used for reading MessageOnTheWire.

type MessageSender

type MessageSender chan<- MessageOnTheWire

MessageSender is used for sending MessageOnTheWire.

type MessageVariant

type MessageVariant uint16

MessageVariant represents the type of message.

func (MessageVariant) NonBodyLength added in v0.3.0

func (variant MessageVariant) NonBodyLength() int

Returns the message length (ex-messageBody) which equals to len(MessageLength) + len(MessageVersion) + len(MessageVariant) + len(GroupID)

func (MessageVariant) String

func (variant MessageVariant) String() string

type MessageVersion

type MessageVersion uint16

MessageVersion indicates the version of the message.

func (MessageVersion) String

func (version MessageVersion) String() string

type PeerAddress

type PeerAddress interface {
	String() string
	Equal(PeerAddress) bool
	PeerID() PeerID
	NetworkAddress() net.Addr
	IsNewer(PeerAddress) bool
}

PeerAddress stores information about the network address of a peer in the network.

type PeerAddressCodec

type PeerAddressCodec interface {
	Encode(PeerAddress) ([]byte, error)
	Decode([]byte) (PeerAddress, error)
}

PeerAddressCodec can encode and decode between PeerAddress and bytes.

type PeerAddresses

type PeerAddresses []PeerAddress

PeerAddresses is a list of PeerAddress.

type PeerID

type PeerID interface {
	String() string
	Equal(PeerID) bool
}

PeerID uniquely identifies a peer in the network, but it does not provide information about the network address of the peer.

type PeerIDCodec added in v0.3.0

type PeerIDCodec interface {
	Encode(PeerID) ([]byte, error)
	Decode([]byte) (PeerID, error)
}

PeerIDCodec can encode and decode between PeerID and bytes.

type PeerIDs

type PeerIDs []PeerID

PeerIDs is a list of PeerID.

type Server added in v0.3.0

type Server interface {
	Run(context.Context, MessageSender)
}

Server listens for messages sent by other Peers and pipes it to the message handler through the provided MessageSender

type Session added in v0.3.0

type Session interface {
	ReadMessageOnTheWire(io.Reader) (MessageOnTheWire, error)
	WriteMessage(io.Writer, Message) error
}

Session is a secure connection between two Peers which allow them send and receive AW messages through the same io.ReadWriter.

type SessionManager added in v0.3.0

type SessionManager interface {
	NewSession(peerID PeerID, key []byte) Session
	NewSessionKey() []byte
}

SessionManager is able to establish new Session with a Peer.

type SignVerifier

type SignVerifier interface {
	Sign(digest []byte) ([]byte, error)
	Verify(digest, sig []byte) (PeerID, error)
	Hash(data []byte) []byte
	SigLength() uint64
}

SignVerifier is used for authentication by using cryptography.

Jump to

Keyboard shortcuts

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