node

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2023 License: Unlicense Imports: 10 Imported by: 0

Documentation

Overview

Package node maintains information about peers on the network and associated connection sessions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	nonce.ID
	Addr          string
	AddrPort      *netip.AddrPort
	IdentityPub   *pub.Key
	IdentityBytes pub.Bytes
	IdentityPrv   *prv.Key
	PingCount     int
	LastSeen      time.Time
	Services
	ifc.Transport
}

Node is a representation of a messaging counterparty. The netip.AddrPort can be nil for the case of a client node that is not in a direct open connection. For this reason all nodes are assigned an ID and will normally be handled by this except when the netip.AddrPort is known via the packet sender address.

func New

func New(addr *netip.AddrPort, hdr *pub.Key, hdrPrv *prv.Key,
	tpt ifc.Transport) (n *Node, id nonce.ID)

New creates a new Node. netip.AddrPort is optional if the counterparty is not in direct connection.

func (*Node) ReceiveFrom

func (n *Node) ReceiveFrom(port uint16) (b <-chan slice.Bytes)

ReceiveFrom returns the channel that receives messages for a given port.

func (*Node) SendTo

func (n *Node) SendTo(port uint16, b slice.Bytes) (e error)

SendTo delivers a message to a service identified by its port.

type Nodes

type Nodes []*Node

func NewNodes

func NewNodes() (n Nodes)

NewNodes creates an empty Nodes

func (Nodes) Add

func (n Nodes) Add(nn *Node) Nodes

Add a Node to a Nodes.

func (Nodes) DeleteByAddrPort

func (n Nodes) DeleteByAddrPort(ip *netip.AddrPort) (nn Nodes, e error)

DeleteByAddrPort deletes a node identified by a netip.AddrPort.

func (Nodes) DeleteByID

func (n Nodes) DeleteByID(ii nonce.ID) (nn Nodes, e error)

DeleteByID deletes a node identified by an ID.

func (Nodes) FindByAddrPort

func (n Nodes) FindByAddrPort(id *netip.AddrPort) (no *Node)

FindByAddrPort searches for a Node by netip.AddrPort.

func (Nodes) FindByID

func (n Nodes) FindByID(i nonce.ID) (no *Node)

FindByID searches for a Node by ID.

func (Nodes) Len

func (n Nodes) Len() int

Len returns the length of a Nodes.

type Service

type Service struct {
	Port uint16
	ifc.Transport
}

type Services

type Services []*Service

Jump to

Keyboard shortcuts

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