Documentation ¶
Index ¶
- Constants
- Variables
- func NewConnectedPipeStacks() (Protocol, Protocol)
- type EventPeering
- type EventState
- type Link
- type LinkBase
- func (link *LinkBase) AddMeasuredLatency(latency time.Duration)
- func (link *LinkBase) BytesIn() uint64
- func (link *LinkBase) BytesOut() uint64
- func (link *LinkBase) Close(log func())
- func (link *LinkBase) FlowControlIndicator() frame.FlowControlFlag
- func (link *LinkBase) GeoMark() string
- func (link *LinkBase) IsClosing() bool
- func (link *LinkBase) Latency() uint16
- func (link *LinkBase) Lite() bool
- func (link *LinkBase) LocalAddr() net.Addr
- func (link *LinkBase) Outgoing() bool
- func (link *LinkBase) Peer() netip.Addr
- func (link *LinkBase) PeeringURL() *m.PeeringURL
- func (link *LinkBase) RemoteAddr() net.Addr
- func (link *LinkBase) Send(f frame.Frame) error
- func (link *LinkBase) SendPriority(f frame.Frame) error
- func (link *LinkBase) Started() time.Time
- func (link *LinkBase) String() string
- func (link *LinkBase) SwitchLabel() m.SwitchLabel
- func (link *LinkBase) Uptime() time.Duration
- type LinkFrame
- func (f LinkFrame) Length() uint16
- func (f LinkFrame) LinkData() []byte
- func (f LinkFrame) LinkDataWithAuth() []byte
- func (f LinkFrame) Nonce() []byte
- func (f LinkFrame) RecvRate() uint8
- func (f LinkFrame) Seal(encrypt *state.EncryptionSession) error
- func (f LinkFrame) SequenceAck() uint32
- func (f LinkFrame) SequenceNum() uint32
- func (f LinkFrame) SetLength(n uint16)
- func (f LinkFrame) SetRecvRate(percent uint8)
- func (f LinkFrame) SetSequenceAck(n uint32)
- func (f LinkFrame) SetSequenceNum(n uint32)
- func (f LinkFrame) SetVersion(v uint8)
- func (f LinkFrame) Unseal(encrypt *state.EncryptionSession) error
- func (f LinkFrame) Version() uint8
- type Listener
- type ListenerBase
- type Peering
- func (p *Peering) AddLink(link Link) error
- func (p *Peering) AddListener(id string, listener Listener)
- func (p *Peering) AddProtocol(id string, prot Protocol)
- func (p *Peering) CloseLink(ip netip.Addr)
- func (p *Peering) CloseListener(id string)
- func (p *Peering) GetLink(ip netip.Addr) Link
- func (p *Peering) GetLinkByLabel(label m.SwitchLabel) Link
- func (p *Peering) GetLinkByRemoteHost(peeringHost string) Link
- func (p *Peering) GetLinks() []Link
- func (p *Peering) GetListener(id string) Listener
- func (p *Peering) GetProtocol(id string) Protocol
- func (p *Peering) LinkCnt() int
- func (p *Peering) PeerWith(peeringURL *m.PeeringURL, ip netip.Addr) (Link, error)
- func (p *Peering) RemoveLink(link Link)
- func (p *Peering) RemoveListener(id string)
- func (p *Peering) Start(m *mgr.Manager) error
- func (p *Peering) StartListener(peeringURL *m.PeeringURL, ip netip.Addr) (Listener, error)
- func (p *Peering) Stop(mgr *mgr.Manager) error
- func (p *Peering) TriggerPeering()
- type Protocol
- type ProtocolFunctions
Constants ¶
const ( EventStateUp = "up" EventStateDown = "down" )
Peering Event States.
const ( FrameOffset = 12 FrameOverhead = 16 )
Required Frame Margins.
Variables ¶
var ( ErrUnsupportedVersion = errors.New("unsupported version") ErrRemoteDeniedPeering = errors.New("remote denied peering") )
Peering Errors.
var ( ErrNetworkReadError = errors.New("read i/o error") ErrNetworkWriteError = errors.New("write i/o error") )
Errors.
var ProtocolTCP = NewProtocol(
"tcp",
tcpPeerWith,
tcpStartListener,
)
ProtocolTCP uses plain TCP.
Functions ¶
func NewConnectedPipeStacks ¶
NewConnectedPipeStacks returns a new set of net.Pipe based connectivity stacks for testing.
Types ¶
type EventPeering ¶ added in v0.4.0
type EventPeering struct { Peer netip.Addr State EventState }
EventPeering is a peering event.
type EventState ¶ added in v0.4.0
type EventState string
EventState describes a peering event state.
type Link ¶
type Link interface { String() string // Peer returns the ID of the connected peer. Peer() netip.Addr // SwitchLabel returns the switch label of the link. SwitchLabel() m.SwitchLabel // GeoMark returns geo location of the peer, based on the router address. GeoMark() string // PeeringURL returns the used peering URL. PeeringURL() *m.PeeringURL // Outgoing returns whether the connection was initiated by this router. Outgoing() bool // Lite returns whether the connected router is in lite mode. Lite() bool // SendPriority sends a priority frame to the peer. SendPriority(f frame.Frame) error // Send sends a frame to the peer. Send(f frame.Frame) error // LocalAddr returns the underlying local net.Addr of the connection. LocalAddr() net.Addr // RemoteAddr returns the underlying remote net.Addr of the connection. RemoteAddr() net.Addr // Started returns when the link was created. Started() time.Time // Uptime returns how long the link has been up. Uptime() time.Duration // Latency returns the latency of the link in milliseconds. Latency() uint16 // AddMeasuredLatency adds the given latency to the measured latencies and // calculates and sets the new average. AddMeasuredLatency(latency time.Duration) // BytesIn returns the total amount of bytes received via the link. BytesIn() uint64 // BytesOut returns the total amount of bytes sent via the link. BytesOut() uint64 // FlowControlIndicator returns a flow control flag that indicates the // pressure on the sending queue of this link. FlowControlIndicator() frame.FlowControlFlag // IsClosing returns whether the link is closing or has closed. IsClosing() bool // Close closes the link. Close(log func()) }
Link represents a network connection to another router.
type LinkBase ¶
type LinkBase struct {
// contains filtered or unexported fields
}
LinkBase implements common functions to comply with the Link interface.
func (*LinkBase) AddMeasuredLatency ¶ added in v0.3.0
AddMeasuredLatency adds the given latency to the measured latencies and calculates and sets the new average.
func (*LinkBase) BytesIn ¶ added in v0.4.0
BytesIn returns the total amount of bytes received via the link.
func (*LinkBase) BytesOut ¶ added in v0.4.0
BytesOut returns the total amount of bytes sent via the link.
func (*LinkBase) FlowControlIndicator ¶
func (link *LinkBase) FlowControlIndicator() frame.FlowControlFlag
FlowControlIndicator returns a flow control flag that indicates the pressure on the sending queue of this link.
func (*LinkBase) GeoMark ¶ added in v0.3.0
GeoMark returns geo location of the peer, based on the router address.
func (*LinkBase) PeeringURL ¶
func (link *LinkBase) PeeringURL() *m.PeeringURL
PeeringURL returns the used peering URL.
func (*LinkBase) RemoteAddr ¶
RemoteAddr returns the underlying remote net.Addr of the connection.
func (*LinkBase) SendPriority ¶
SendPriority sends a priority frame to the peer.
func (*LinkBase) SwitchLabel ¶
func (link *LinkBase) SwitchLabel() m.SwitchLabel
SwitchLabel returns the switch label of the link.
type LinkFrame ¶
type LinkFrame []byte
LinkFrame is a minimal frame used to protect links.
func (LinkFrame) LinkDataWithAuth ¶
LinkDataWithAuth the link data and the authentication data.
func (LinkFrame) Seal ¶
func (f LinkFrame) Seal(encrypt *state.EncryptionSession) error
Seal sets the link frame metadata and encrypts everything.
func (LinkFrame) SequenceAck ¶
SequenceAck returns the acknowledge sequence number.
func (LinkFrame) SequenceNum ¶
SequenceNum returns the sequence number.
func (LinkFrame) SetRecvRate ¶
SetRecvRate sets the recv rate.
func (LinkFrame) SetSequenceAck ¶
SetSequenceAck sets the acknowledge sequence number.
func (LinkFrame) SetSequenceNum ¶
SetSequenceNum sets the sequence number.
func (LinkFrame) SetVersion ¶
SetVersion sets the frame version.
type Listener ¶
type Listener interface { // ID returns the listener ID. ID() string // PeeringURL returns the used peering URL. PeeringURL() *m.PeeringURL // ListenAddress returns the used listen address. ListenAddress() net.Addr // Close closes the underlying listener and cleans up any related resources. Close(log func()) }
Listener represents a network connection listener.
type ListenerBase ¶
type ListenerBase struct {
// contains filtered or unexported fields
}
ListenerBase implements common functions to comply with the Listener interface.
func (*ListenerBase) ListenAddress ¶
func (ln *ListenerBase) ListenAddress() net.Addr
ListenAddress returns the listen address.
func (*ListenerBase) PeeringURL ¶
func (ln *ListenerBase) PeeringURL() *m.PeeringURL
PeeringURL returns the used peering URL.
type Peering ¶
type Peering struct { PeeringEvents *mgr.EventMgr[*EventPeering] // contains filtered or unexported fields }
Peering is a peering manager.
func (*Peering) AddListener ¶
AddListener adds the listener to the listener list.
func (*Peering) AddProtocol ¶
AddProtocol adds a new protocol.
func (*Peering) CloseListener ¶
CloseListener closes the listener with the given ID.
func (*Peering) GetLinkByLabel ¶
func (p *Peering) GetLinkByLabel(label m.SwitchLabel) Link
GetLinkByLabel returns the link to the given peer by switch label, if available.
func (*Peering) GetLinkByRemoteHost ¶ added in v0.2.0
GetLinkByRemoteHost returns the link with the given peering host.
func (*Peering) GetListener ¶
GetListener returns the listener with the given ID.
func (*Peering) GetProtocol ¶
GetProtocol adds a new protocol.
func (*Peering) PeerWith ¶
PeerWith establishes a connection with the given peering URL. The IP address is optional, but may be required by different protocols. If the peering URL has no IP defined, the IP address is required.
func (*Peering) RemoveLink ¶
RemoveLink removes the link from the peering list. The link is not closed by this function!
func (*Peering) RemoveListener ¶
RemoveListener removes the listener from the listener list.
func (*Peering) Start ¶
Start starts the peering manager. It: - Starts configured listeners. - Connects to configured peers.
func (*Peering) StartListener ¶
StartListener starts a new listener with the given peering URL. The IP address is optional, but may be required by different protocols.
func (*Peering) TriggerPeering ¶ added in v0.4.0
func (p *Peering) TriggerPeering()
TriggerPeering triggers checking peers and connecting to new peers if needed.
type Protocol ¶
type Protocol interface { // Name returns the protocol name/scheme. Name() string // PeerWith connects to the given router. PeerWith(peering *Peering, peeringURL *m.PeeringURL, ip netip.Addr) (Link, error) // StartListener starts a listener for peering requests. StartListener(peering *Peering, peeringURL *m.PeeringURL, ip netip.Addr) (Listener, error) }
Protocol defines how to create a listener or connect to a peer using a certain protocol.
type ProtocolFunctions ¶
type ProtocolFunctions struct {
// contains filtered or unexported fields
}
ProtocolFunctions implements Protocol with saved functions.
func NewProtocol ¶
func NewProtocol( name string, peerWith func(peering *Peering, peeringURL *m.PeeringURL, ip netip.Addr) (Link, error), startListener func(peering *Peering, peeringURL *m.PeeringURL, ip netip.Addr) (Listener, error), ) *ProtocolFunctions
NewProtocol returns a new protocol using the given functions.
func (*ProtocolFunctions) Name ¶
func (p *ProtocolFunctions) Name() string
Name returns the protocol name/scheme.
func (*ProtocolFunctions) PeerWith ¶
func (p *ProtocolFunctions) PeerWith(peering *Peering, peeringURL *m.PeeringURL, ip netip.Addr) (Link, error)
PeerWith connects to the given router.
func (*ProtocolFunctions) StartListener ¶
func (p *ProtocolFunctions) StartListener(peering *Peering, peeringURL *m.PeeringURL, ip netip.Addr) (Listener, error)
StartListener starts a listener for peering requests.