Documentation
¶
Index ¶
- Constants
- Variables
- func NewErrMessageLengthIsTooLow(length MessageLength) error
- func NewErrMessageVariantIsNotSupported(variant MessageVariant) error
- func NewErrMessageVersionIsNotSupported(version MessageVersion) error
- func ParForAllAddresses(addrs PeerAddresses, numWorkers int, f func(PeerAddress))
- func ValidateGroupID(groupID GroupID, variant MessageVariant) error
- func ValidateMessageLength(length MessageLength, variant MessageVariant) error
- func ValidateMessageVariant(variant MessageVariant) error
- func ValidateMessageVersion(version MessageVersion) error
- type Client
- type ErrMessageLengthIsTooLow
- type ErrMessageVariantIsNotSupported
- type ErrMessageVersionIsNotSupported
- type Event
- type EventMessageReceived
- type EventPeerChanged
- type EventReceiver
- type EventSender
- type GroupID
- type Message
- type MessageBody
- type MessageLength
- type MessageOnTheWire
- type MessageReceiver
- type MessageSender
- type MessageVariant
- type MessageVersion
- type PeerAddress
- type PeerAddressCodec
- type PeerAddresses
- type PeerID
- type PeerIDCodec
- type PeerIDs
- type Server
- type Session
- type SessionManager
- type SignVerifier
Constants ¶
const ( Ping = MessageVariant(1) Pong = MessageVariant(2) Cast = MessageVariant(3) Multicast = MessageVariant(4) Broadcast = MessageVariant(5) )
const (
V1 = MessageVersion(1)
)
Variables ¶
var ( ErrInvalidGroupID = errors.New("invalid group id") ErrInvalidMessageLength = errors.New("invalid message length") )
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 GroupID ¶ added in v0.3.3
type GroupID [32]byte
GroupID uniquely identifies a group of PeerIDs.
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) MarshalBinary ¶ added in v0.3.0
MarshalBinary implements `BinaryMarshaler` interface.
func (*Message) UnmarshalBinary ¶ added in v0.3.0
UnmarshalBinary implements `BinaryUnmarshaler` interface.
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 PeerID ¶
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
PeerIDCodec can encode and decode between PeerID and bytes.
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.