Versions in this module Expand all Collapse all v1 v1.1.5 Jul 30, 2020 v1.1.4 Jul 30, 2020 Changes in this version + const SizePrivateKey + const SizePublicKey + const SizeSignature + var ErrMessageTooLarge = errors.New("msg from peer is too large") + var ZeroPrivateKey PrivateKey + var ZeroPublicKey PublicKey + var ZeroSignature Signature + func ECDH(ourPrivateKey PrivateKey, peerPublicKey PublicKey) ([]byte, error) + func GenerateKeys(rand io.Reader) (publicKey PublicKey, privateKey PrivateKey, err error) + func ResolveAddress(address string) (string, error) + type Client struct + func (c *Client) Close() + func (c *Client) Error() error + func (c *Client) ID() ID + func (c *Client) Logger() *zap.Logger + func (c *Client) SetLogger(logger *zap.Logger) + func (c *Client) WaitUntilClosed() + func (c *Client) WaitUntilReady() + type Handler func(ctx HandlerContext) error + type HandlerContext struct + func (ctx *HandlerContext) Data() []byte + func (ctx *HandlerContext) DecodeMessage() (Serializable, error) + func (ctx *HandlerContext) ID() ID + func (ctx *HandlerContext) IsRequest() bool + func (ctx *HandlerContext) Logger() *zap.Logger + func (ctx *HandlerContext) Send(data []byte) error + func (ctx *HandlerContext) SendMessage(msg Serializable) error + type ID struct + Address string + Host net.IP + ID PublicKey + Port uint16 + func NewID(id PublicKey, host net.IP, port uint16) ID + func UnmarshalID(buf []byte) (ID, error) + func (e ID) Marshal() []byte + func (e ID) Size() int + func (e ID) String() string + type Node struct + func NewNode(opts ...NodeOption) (*Node, error) + func (n *Node) Addr() string + func (n *Node) Bind(protocols ...Protocol) + func (n *Node) Close() error + func (n *Node) DecodeMessage(data []byte) (Serializable, error) + func (n *Node) EncodeMessage(msg Serializable) ([]byte, error) + func (n *Node) Handle(handlers ...Handler) + func (n *Node) ID() ID + func (n *Node) Inbound() []*Client + func (n *Node) Listen() error + func (n *Node) Logger() *zap.Logger + func (n *Node) Outbound() []*Client + func (n *Node) Ping(ctx context.Context, addr string) (*Client, error) + func (n *Node) RegisterMessage(ser Serializable, de interface{}) uint16 + func (n *Node) Request(ctx context.Context, addr string, data []byte) ([]byte, error) + func (n *Node) RequestMessage(ctx context.Context, addr string, req Serializable) (Serializable, error) + func (n *Node) Send(ctx context.Context, addr string, data []byte) error + func (n *Node) SendMessage(ctx context.Context, addr string, msg Serializable) error + func (n *Node) Sign(data []byte) Signature + type NodeOption func(n *Node) + func WithNodeAddress(addr string) NodeOption + func WithNodeBindHost(host net.IP) NodeOption + func WithNodeBindPort(port uint16) NodeOption + func WithNodeID(id ID) NodeOption + func WithNodeIdleTimeout(idleTimeout time.Duration) NodeOption + func WithNodeLogger(logger *zap.Logger) NodeOption + func WithNodeMaxDialAttempts(maxDialAttempts uint) NodeOption + func WithNodeMaxInboundConnections(maxInboundConnections uint) NodeOption + func WithNodeMaxOutboundConnections(maxOutboundConnections uint) NodeOption + func WithNodeMaxRecvMessageSize(maxRecvMessageSize uint32) NodeOption + func WithNodeNumWorkers(numWorkers uint) NodeOption + func WithNodePrivateKey(privateKey PrivateKey) NodeOption + type PrivateKey [SizePrivateKey]byte + func LoadKeysFromHex(secretHex string) (PrivateKey, error) + func (k PrivateKey) MarshalJSON() ([]byte, error) + func (k PrivateKey) Public() PublicKey + func (k PrivateKey) Sign(data []byte) Signature + func (k PrivateKey) String() string + type Protocol struct + Bind func(node *Node) error + OnMessageRecv func(client *Client) + OnMessageSent func(client *Client) + OnPeerConnected func(client *Client) + OnPeerDisconnected func(client *Client) + OnPingFailed func(addr string, err error) + VersionMajor uint + VersionMinor uint + VersionPatch uint + type PublicKey [SizePublicKey]byte + func (k PublicKey) MarshalJSON() ([]byte, error) + func (k PublicKey) String() string + func (k PublicKey) Verify(data []byte, signature Signature) bool + type Serializable interface + Marshal func() []byte + type Signature [SizeSignature]byte + func UnmarshalSignature(data []byte) Signature + func (s Signature) MarshalJSON() ([]byte, error) + func (s Signature) String() string