Documentation ¶
Index ¶
- Constants
- Variables
- func HasPrefix(x []byte, prefix []byte, nbits int) bool
- func IsErrClosed(err error) bool
- func IsErrPublicKeyNotFound(err error) bool
- func IsErrUnreachable(err error) bool
- func MarshalPublicKey(pubKey PublicKey) []byte
- func NewPacketConn(n Node) net.PacketConn
- func Receive(ctx context.Context, n Node, msg *Message) error
- type Addr
- type ErrAddrUnreachable
- type ID
- type Message
- type Node
- type NodeConfig
- type NodeOption
- type PrivateKey
- type PublicKey
- type ReceiveFunc
- type Service
Constants ¶
const ( // MinMTU is the minimum MTU a network can provide to any address. // Applications should be designed to operate correctly if they can only send messages up to this size. MinMTU = 1 << 15 // MaxMTU is the size of largest message that a network will ever receive from any address. // Applications should be prepared to receieve this much data at a time or they may encounter io.ErrShortBuffer MaxMTU = 1 << 16 )
Variables ¶
var ( ErrPublicKeyNotFound = p2p.ErrPublicKeyNotFound ErrNoAddrWithPrefix = errors.New("no address with prefix") ErrClosed = net.ErrClosed )
Functions ¶
func IsErrClosed ¶
func IsErrPublicKeyNotFound ¶ added in v0.0.3
func IsErrUnreachable ¶ added in v0.0.3
func MarshalPublicKey ¶
func NewPacketConn ¶
func NewPacketConn(n Node) net.PacketConn
NewPacketConn wraps a node with the net.PacketConn interface
Types ¶
type Addr ¶
type Addr [32]byte
Addr is an address in an INET256 Network. It uniquely identifies a Node.
func AddrFromBytes ¶
AddrFromBytes creates a new address by reading up to 32 bytes from x Note that these bytes are not interpretted as a public key, they are interpretted as the raw address. To derive an address from a PublicKey use NewAddr
func ParseAddrB64 ¶ added in v0.0.2
ParseAddrB64 attempts to parse a base64 encoded INET256 address from data
func (Addr) MarshalText ¶
func (*Addr) UnmarshalText ¶
type ErrAddrUnreachable ¶
type ErrAddrUnreachable struct {
Addr Addr
}
func (ErrAddrUnreachable) Error ¶
func (e ErrAddrUnreachable) Error() string
type Message ¶
Message is the essential information carried by Tell and Receive provided as a struct for use in queues or other APIs
type Node ¶
type Node interface { // Tell sends a message containing data to the node at addr. // The message will be delivered at most once. Send(ctx context.Context, addr Addr, data []byte) error // Receive calls fn with a message sent to this node. // The message fields, and payload must not be accessed outside fn. Receive(ctx context.Context, fn ReceiveFunc) error // MTU finds the maximum message size that can be sent to addr. // If the context expires, a reasonable default (normally a significant underestimate) will be returned. MTU(ctx context.Context, addr Addr) int // LookupPublicKey attempts to find the public key corresponding to addr. // If it can't find it, ErrPublicKeyNotFound is returned. LookupPublicKey(ctx context.Context, addr Addr) (PublicKey, error) // FindAddr looks for an address with nbits leading bits in common with prefix. FindAddr(ctx context.Context, prefix []byte, nbits int) (Addr, error) // LocalAddr returns this Node's address LocalAddr() Addr // PublicKey returns this Node's public key PublicKey() PublicKey // Close indicates no more messages should be sent or received from this node // and releases any resources allocated for this node. Close() error }
Node is a single host in an INET256 network. Nodes send and receive messages to and from other nodes in the network. Nodes are usually created and managed by a Service. Nodes have an single ID or address corresponding to their public key.
This interface is compatible with the INET256 specification.
type NodeConfig ¶ added in v0.0.3
type NodeConfig struct { }
NodeConfig is an aggregate of applied NodeOptions Not all implementations will support all the options.
func CollectNodeOptions ¶ added in v0.0.3
func CollectNodeOptions(opts []NodeOption) (cfg NodeConfig)
CollectNodeOptions applyies each option in opts to a NodeOptions and returns the result.
type NodeOption ¶ added in v0.0.3
type NodeOption = func(*NodeConfig)
NodeOption is the type of functions which configure a Node.
type PrivateKey ¶
type PrivateKey = p2p.PrivateKey
type ReceiveFunc ¶
type ReceiveFunc = func(Message)
ReceiveFunc is passed as a callback to Node.Receive
type Service ¶
type Service interface { Open(ctx context.Context, privKey p2p.PrivateKey, opts ...NodeOption) (Node, error) Delete(ctx context.Context, privKey p2p.PrivateKey) error }
Service is the top level INET256 object. It manages a set of nodes which can be created and deleted.
This interface is compatible with the INET256 specification.