peer

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPeerSendFailed = errors.New("peer send queue full")

ErrPeerSendFailed is returned when the peer send queue is full.

Functions

func NewPeer

func NewPeer(addr string, cfg *config.Config, mgr *Manager) *peerImpl

NewPeer creates a new Peer instance.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is responsible for establishing and maintaining connections to all peer Nexus nodes and managing the global routing table.

func NewManager

func NewManager(cfg *config.Config, hub iface.Hub, tlsBase *tls.Config) *Manager

NewManager creates a new peer manager.

func (*Manager) AnnounceLocalRoutes

func (m *Manager) AnnounceLocalRoutes()

AnnounceLocalRoutes calculates the current local routes, increments the state version, and broadcasts the new state to all connected peers.

func (*Manager) ClearRoutesForPeer

func (m *Manager) ClearRoutesForPeer(p *peerImpl)

ClearRoutesForPeer is called when a peer disconnects, to purge its routes.

func (*Manager) Done

func (m *Manager) Done() <-chan struct{}

Done returns a channel that is closed when the manager is shutting down. Used by peers for graceful shutdown during bandwidth waits.

func (*Manager) ForwardUDP

func (m *Manager) ForwardUDP(routeKey string, dstPort int, pc net.PacketConn, clientAddr *net.UDPAddr, payload []byte) error

func (*Manager) GetBandwidthScheduler

func (m *Manager) GetBandwidthScheduler() *bandwidth.Scheduler

GetBandwidthScheduler returns the bandwidth scheduler from the hub. Used by peers for bandwidth limiting during tunneling.

func (*Manager) GetPeerForHostname

func (m *Manager) GetPeerForHostname(hostname string) (iface.Peer, bool)

GetPeerForHostname checks the routing table for a peer that can service a given hostname.

func (*Manager) HandleInboundPeer

func (m *Manager) HandleInboundPeer(conn *websocket.Conn)

HandleInboundPeer manages a new connection initiated by another peer.

func (*Manager) HandleOutboundUDPClose

func (m *Manager) HandleOutboundUDPClose(flowID uuid.UUID) bool

func (*Manager) HandleOutboundUDPData

func (m *Manager) HandleOutboundUDPData(flowID uuid.UUID, payload []byte) bool

func (*Manager) HandleTunnelClose

func (m *Manager) HandleTunnelClose(clientID uuid.UUID)

HandleTunnelClose cleans up a tunnel when a peer signals it has closed.

func (*Manager) HandleTunnelData

func (m *Manager) HandleTunnelData(clientID uuid.UUID, payload []byte)

HandleTunnelData forwards data received from a peer to the correct tunneled connection.

func (*Manager) HandleTunnelRequest

func (m *Manager) HandleTunnelRequest(p iface.Peer, hostname string, clientID uuid.UUID, clientIP string, connPort int, isTLS bool)

HandleTunnelRequest is called by a peer's read pump when it receives a request to establish a tunnel for a client. It selects a local backend and starts the proxying.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

Run starts the manager, which will attempt to connect to all configured peers.

func (*Manager) Stop

func (m *Manager) Stop()

Stop signals all peer connections to terminate.

func (*Manager) UpdatePeerRoutes

func (m *Manager) UpdatePeerRoutes(p *peerImpl, version uint64, hostnames []string)

UpdatePeerRoutes is called by a Peer when it receives an announcement.

type TunneledConn

type TunneledConn struct {
	// contains filtered or unexported fields
}

TunneledConn implements the net.Conn interface for a client connection that is being tunneled from another peer.

func NewTunneledConn

func NewTunneledConn(clientID uuid.UUID, peer iface.Peer, clientIp string, connPort int) *TunneledConn

NewTunneledConn creates a new virtual connection for a tunneled client. clientIp is parsed eagerly into a *net.TCPAddr using numeric-only parsing (no DNS resolution). If parsing fails, a warning is logged and a zero-value fallback is stored.

func (*TunneledConn) Close

func (c *TunneledConn) Close() error

Close signals to the peer that this end of the tunnel is closed. Safe to call multiple times - only sends close message once.

func (*TunneledConn) IsPaused

func (c *TunneledConn) IsPaused() bool

IsPaused returns the current pause state.

func (*TunneledConn) LocalAddr

func (c *TunneledConn) LocalAddr() net.Addr

LocalAddr, RemoteAddr, SetDeadline, etc., are part of the net.Conn interface.

func (*TunneledConn) Pause

func (c *TunneledConn) Pause()

Pause propagates pause to the origin peer where actual backpressure occurs. The local paused flag tracks state but does NOT block Read() locally. Local state is only updated if the peer message is successfully queued.

func (*TunneledConn) Read

func (c *TunneledConn) Read(b []byte) (n int, err error)

Read reads from the pipe. This method does NOT block when paused because: 1. io.Pipe is unbuffered - blocking here would deadlock the shared readPump 2. The actual backpressure happens at the origin peer's PausableConn 3. Any in-flight data when pause is requested will still be delivered

func (*TunneledConn) RemoteAddr

func (c *TunneledConn) RemoteAddr() net.Addr

func (*TunneledConn) Resume

func (c *TunneledConn) Resume()

Resume propagates resume to the origin peer to restore data flow. Local state is only updated if the peer message is successfully queued.

func (*TunneledConn) SetDeadline

func (c *TunneledConn) SetDeadline(t time.Time) error

func (*TunneledConn) SetReadDeadline

func (c *TunneledConn) SetReadDeadline(t time.Time) error

func (*TunneledConn) SetWriteDeadline

func (c *TunneledConn) SetWriteDeadline(t time.Time) error

func (*TunneledConn) Write

func (c *TunneledConn) Write(b []byte) (n int, err error)

Write writes data back to the originating peer. Returns ErrPeerSendFailed if the peer send queue is full.

func (*TunneledConn) WriteToPipe

func (c *TunneledConn) WriteToPipe(b []byte) (n int, err error)

WriteToPipe writes data received from a peer into the tunnel's read pipe. Called by the peer's readPump - must never block indefinitely.

Jump to

Keyboard shortcuts

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