transport

package
v1.3.112 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package transport pkg/cxo/node/transport/connection.go c2-net-cxo

Package transport pkg/cxo/node/transport/dmsg.go c2-net-cxo dmsg.go implements a CXO transport factory over DMSG connections, allowing CXO nodes to communicate via skywire's DMSG network instead of raw TCP.

Package transport pkg/cxo/node/transport/noise_tcp.go c2-net-cxo

Package transport pkg/cxo/node/transport/tcp.go c2-net-cxo

Package transport pkg/cxo/node/transport/udp.go c2-net-cxo

Index

Constants

View Source
const DefaultCXOPort = skyenv.DmsgCXOPort

DefaultCXOPort is the default DMSG port for CXO connections. Sourced from skyenv so the port allocation is visible in the same table as DmsgHypervisorPort (46), DmsgTransportSetupPort (47), etc.

Was previously the literal 46, which clashed with DmsgHypervisorPort: whichever module called dmsgC.Listen first won, and on a hypervisor- enabled visor the CXO publisher's Listen typically fired before the hypervisor's, so hypervisor-RPC-over-DMSG silently failed with "port already occupied" and remote visors stopped showing up.

Variables

View Source
var ErrInterrupted = errors.New("cxo transport: read interrupted")

ErrInterrupted is returned by ReadFrame after Interrupt or Close.

View Source
var ErrSendStopped = errors.New("cxo transport: send stopped")

ErrSendStopped is returned by SendFrame when its stop channel closes.

View Source
var ErrSendTimeout = errors.New("cxo transport: send queue full")

ErrSendTimeout is returned by SendFrame when the queue stays full.

Functions

This section is empty.

Types

type Connection

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

Connection wraps a net.Conn with length-prefixed (4 bytes, big-endian) message I/O. The owner reads frames with ReadFrame. Outbound frames go through a queue that a writer goroutine drains only while it is non-empty, so an idle connection holds no goroutine of its own.

func (*Connection) Close

func (c *Connection) Close()

Close closes the connection.

func (*Connection) Closed

func (c *Connection) Closed() bool

Closed returns true if the connection has been closed.

func (*Connection) GetRemoteAddr

func (c *Connection) GetRemoteAddr() net.Addr

GetRemoteAddr returns the remote address of the connection.

func (*Connection) Interrupt

func (c *Connection) Interrupt()

Interrupt makes a blocked or later ReadFrame return ErrInterrupted. Frames already queued are written first, then the connection closes, since some carriers (a VStream over skywire transports) ignore read deadlines.

func (*Connection) QueueFrame

func (c *Connection) QueueFrame(f Frame) bool

QueueFrame queues f unless sendQueueLen frames are already waiting, and starts the writer unless one is running. It never blocks.

func (*Connection) ReadFrame

func (c *Connection) ReadFrame(timeout time.Duration) ([]byte, error)

ReadFrame reads one frame. A timeout above zero bounds the read and returns an error satisfying os.IsTimeout when it passes. A failed read closes the connection, since a partly read frame leaves the stream unusable, except after Interrupt, which leaves writes to the owner.

func (*Connection) SendFrame

func (c *Connection) SendFrame(f Frame, stop <-chan struct{}, timeout time.Duration) error

SendFrame queues f, waiting up to timeout while the queue is full. It returns ErrSendTimeout when the wait runs out and ErrSendStopped when stop closes first.

func (*Connection) TCP

func (c *Connection) TCP() bool

TCP returns true if this is a TCP connection.

type DMSGFactory

type DMSGFactory struct {
	AcceptedCallback func(conn *Connection)

	// MaxPendingAccepts caps in-flight AcceptedCallback invocations.
	// Zero (default) leaves accepts unbounded for backwards compatibility;
	// set it from the Node's MaxPendingConnections to apply backpressure
	// to the dmsg listener queue when handshake processing falls behind.
	MaxPendingAccepts int

	// Dial, when set, replaces the dmsg dial in Connect: a visor sets it to
	// reach a deployment service over skynet through its host first.
	Dial func(ctx context.Context, addr dmsg.Addr) (net.Conn, error)
	// contains filtered or unexported fields
}

DMSGFactory creates and manages CXO connections over DMSG. It implements the same interface as TCPFactory but uses DMSG streams as the underlying transport.

func NewDMSGFactory

func NewDMSGFactory(dmsgC *dmsg.Client, port uint16) *DMSGFactory

NewDMSGFactory creates a new DMSGFactory using the given DMSG client. The port parameter specifies the DMSG port to listen on and dial to.

func (*DMSGFactory) Address

func (f *DMSGFactory) Address() string

Address returns a string representation of the listening address (PK:port).

func (*DMSGFactory) Close

func (f *DMSGFactory) Close()

Close stops the factory and closes the listener.

func (*DMSGFactory) Connect

func (f *DMSGFactory) Connect(ctx context.Context, remotePK cipher.PubKey) (*Connection, error)

Connect dials a remote CXO node over DMSG by public key. ctx is passed straight to dmsg.Client.Dial — a canceled or expired ctx aborts the dial and returns ctx.Err() (wrapped). Callers that don't need cancellation can pass context.Background(); the (*DMSG).ConnectPK wrapper threads its caller's ctx through here.

func (*DMSGFactory) Listen

func (f *DMSGFactory) Listen() error

Listen starts listening on the DMSG port for incoming CXO connections.

type Frame

type Frame struct {
	Head []byte
	Body []byte
}

Frame is one outbound message split into a small per-message Head (the 8-byte seq/rseq the CXO Conn prepends) and a Body (the encoded message). Splitting them lets a broadcast encode the (potentially large) Body ONCE and share that immutable []byte across every subscriber connection — each conn supplies only its own tiny Head. On the wire the frame is identical to the old single-buffer form: [4-byte length][Head][Body]. Sharing the Body is what turns a fan-out of an N-MB feed to M subscribers from O(N*M) memory + encode CPU (one encoded+buffered copy per conn) into O(N + M). See docs — the transport-discovery CXO node ballooned to multi-GB RSS re-encoding the all-transports feed once per subscriber.

type TCPFactory

type TCPFactory struct {
	AcceptedCallback func(conn *Connection)

	// MaxPendingAccepts caps in-flight AcceptedCallback invocations.
	// Zero (default) leaves accepts unbounded for backwards compatibility;
	// set it from the Node's MaxPendingConnections to apply backpressure
	// to the listener queue when handshake processing falls behind.
	MaxPendingAccepts int
	// contains filtered or unexported fields
}

TCPFactory creates and manages TCP connections. Every connection (dial + accept) is Noise_XX-encrypted via wrapNoiseXX using the factory's identity, so CXO-TCP is no longer a plaintext transport.

func NewTCPFactory

func NewTCPFactory(localPK cipher.PubKey, localSK cipher.SecKey) *TCPFactory

NewTCPFactory creates a new TCPFactory bound to the given identity, used for the Noise XX handshake on every TCP connection.

func (*TCPFactory) Close

func (f *TCPFactory) Close()

Close stops the factory and closes the listener.

func (*TCPFactory) Connect

func (f *TCPFactory) Connect(address string) (*Connection, error)

Connect dials a TCP address and returns a Connection.

func (*TCPFactory) Listen

func (f *TCPFactory) Listen(address string) error

Listen starts listening on the given address for incoming TCP connections.

func (*TCPFactory) ListenerAddress

func (f *TCPFactory) ListenerAddress() string

ListenerAddress returns the actual address the listener is bound to. Useful when listening on ":0" to get the OS-assigned port.

type UDPFactory

type UDPFactory struct {
	AcceptedCallback func(conn *Connection)

	// MaxPendingAccepts caps in-flight AcceptedCallback invocations.
	// Zero (default) leaves accepts unbounded for backwards compatibility;
	// set it from the Node's MaxPendingConnections to apply backpressure
	// to the listener queue when handshake processing falls behind.
	MaxPendingAccepts int
	// contains filtered or unexported fields
}

UDPFactory creates and manages UDP connections. Currently implemented over TCP for reliable delivery. A future version may use a true reliable UDP protocol.

func NewUDPFactory

func NewUDPFactory() *UDPFactory

NewUDPFactory creates a new UDPFactory.

func (*UDPFactory) Close

func (f *UDPFactory) Close()

Close stops the factory and closes the listener.

func (*UDPFactory) Connect

func (f *UDPFactory) Connect(address string) (*Connection, error)

Connect dials the given address and returns a Connection.

func (*UDPFactory) Listen

func (f *UDPFactory) Listen(address string) error

Listen starts listening on the given address.

Jump to

Keyboard shortcuts

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