tcp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 25 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

ctx.go

Index

Constants

View Source
const (
	DEFAULT_LOG_LEVEL                         = "debug"
	DEFAULT_MAX_PENDING_HANDSHAKES            = 64
	DEFAULT_MAX_PENDING_HANDSHAKES_PER_SOURCE = 32
	DEFAULT_FIRST_MESSAGE_TIMEOUT             = time.Minute
	DEFAULT_HANDSHAKE_TIMEOUT                 = 5 * time.Minute
	DEFAULT_MAX_ROOMS_OPEN                    = 128
	DEFAULT_ROOM_CLEANUP_INTERVAL             = 10 * time.Minute
	DEFAULT_ROOM_TTL                          = 3 * time.Hour
	DEFAULT_SOURCE_JOIN_LIMIT                 = 30
	DEFAULT_ROOM_JOIN_LIMIT                   = 30
	DEFAULT_JOIN_LIMIT_WINDOW                 = time.Minute
)

Variables

View Source
var ErrAdmissionLimited = errors.New("relay admission rate limited")

ErrAdmissionLimited is returned when a relay refuses a room join under its configured per-source or per-room admission policy.

Functions

func ConnectToTCPServer

func ConnectToTCPServer(address, password, room string, timelimit ...time.Duration) (c *comm.Comm, banner string, ipaddr string, err error)

ConnectToTCPServer will initiate a new connection to the specified address, room with optional time limit

func ConnectToTCPServerControl

func ConnectToTCPServerControl(address, password, room string, timelimit ...time.Duration) (c *comm.Comm, banner string, ipaddr string, capability string, err error)

ConnectToTCPServerControl joins a control room and returns an optional fast data-admission capability advertised by an upgraded relay.

func ConnectToTCPServerControlContext

func ConnectToTCPServerControlContext(ctx context.Context, address, password, room string, timelimit ...time.Duration) (c *comm.Comm, banner string, ipaddr string, capability string, err error)

ConnectToTCPServerControlContext joins a control room and closes the connection if the caller cancels during dialing or relay authentication.

func ConnectToTCPServerWithCapability

func ConnectToTCPServerWithCapability(address, password, room, capability string, timelimit ...time.Duration) (c *comm.Comm, banner string, ipaddr string, fast bool, err error)

ConnectToTCPServerWithCapability uses the optional upgraded-relay fast path and transparently reconnects with the legacy PAKE handshake on rejection.

func ConnectToTCPServerWithCapabilityContext

func ConnectToTCPServerWithCapabilityContext(ctx context.Context, address, password, room, capability string, timelimit ...time.Duration) (c *comm.Comm, banner string, ipaddr string, fast bool, err error)

ConnectToTCPServerWithCapabilityContext is ConnectToTCPServerWithCapability with cancellation support.

func HandshakeTCPServer

func HandshakeTCPServer(c *comm.Comm, password, room string) (banner string, ipaddr string, err error)

HandshakeTCPServer authenticates and joins a room over an already-open TCP connection. Keeping raw dialing separate lets callers race address families without admitting the same client to a relay room more than once.

func HandshakeTCPServerCapability

func HandshakeTCPServerCapability(c *comm.Comm, password, room string) (banner string, ipaddr string, capability string, err error)

HandshakeTCPServerCapability is HandshakeTCPServer plus the optional opaque data-port capability advertised by an upgraded relay.

func Ignore

func Ignore(err error) error

Ignore context cancellation error

func MeasureServerLatency

func MeasureServerLatency(address string, timeout time.Duration) (duration time.Duration, err error)

MeasureServerLatency performs a complete croc ping/pong exchange within one overall deadline and returns its elapsed duration.

func MeasureServerLatencyContext

func MeasureServerLatencyContext(ctx context.Context, address string, timeout time.Duration) (duration time.Duration, err error)

MeasureServerLatencyContext performs one relay probe and closes its connection promptly when the caller cancels the probe race.

func PingServer

func PingServer(address string) (err error)

func Run

func Run(debugLevel, host, port, password string, banner ...string) (err error)

Run starts a tcp listener, run async

func RunCtx

func RunCtx(ctx context.Context, debugLevel, host, port, password string, banner ...string) error

func RunWithListener

func RunWithListener(listener net.Listener, password string, opts ...serverOptsFunc) error

RunWithListener serves an already-bound TCP listener until it stops or its configured context is cancelled. It takes ownership of listener, including closing it if configuration fails.

func RunWithOptionsAsync

func RunWithOptionsAsync(host, port, password string, opts ...serverOptsFunc) error

RunWithOptionsAsync asynchronously starts a TCP listener.

func WithAdmissionLimits

func WithAdmissionLimits(sourceLimit, roomLimit int, window time.Duration) serverOptsFunc

WithAdmissionLimits sets sliding-window room admission limits per source IP and per room on this relay port.

func WithBanner

func WithBanner(banner ...string) serverOptsFunc

func WithCtx

func WithCtx(ctx context.Context) serverOptsFunc

func WithFastAdmission

func WithFastAdmission(capabilities *RelayCapabilitySet) serverOptsFunc

WithFastAdmission shares one capability key and replay set across every advertised port of a relay process.

func WithFirstMessageTimeout

func WithFirstMessageTimeout(timeout time.Duration) serverOptsFunc

WithFirstMessageTimeout sets the absolute time from acceptance to receive the first complete protocol frame. The overall handshake timeout still applies.

func WithHandshakeTimeout

func WithHandshakeTimeout(timeout time.Duration) serverOptsFunc

WithHandshakeTimeout sets the absolute time allowed for the initial relay handshake to complete.

func WithLogLevel

func WithLogLevel(level string) serverOptsFunc

func WithMaxPendingHandshakes

func WithMaxPendingHandshakes(maxPendingHandshakes int) serverOptsFunc

WithMaxPendingHandshakes sets the maximum number of connections that may be performing the initial relay handshake at the same time.

func WithMaxPendingHandshakesPerSource

func WithMaxPendingHandshakesPerSource(limit int) serverOptsFunc

WithMaxPendingHandshakesPerSource limits incomplete handshakes from one source IP on this relay port. The total pending limit still applies.

func WithMaxRoomsOpen

func WithMaxRoomsOpen(maxRoomsOpen int) serverOptsFunc

WithMaxRoomsOpen sets the maximum number of single-occupant rooms that may wait for a peer at the same time.

func WithRoomCleanupInterval

func WithRoomCleanupInterval(interval time.Duration) serverOptsFunc

func WithRoomPairedCallback

func WithRoomPairedCallback(callback func()) serverOptsFunc

WithRoomPairedCallback sets a callback invoked after a room's second peer has joined and received confirmation. The callback must not block.

func WithRoomProtocolCallback

func WithRoomProtocolCallback(callback func(RoomProtocol)) serverOptsFunc

WithRoomProtocolCallback sets a callback invoked once when a paired room advertises a recognized application protocol. The callback must not block.

func WithRoomTTL

func WithRoomTTL(ttl time.Duration) serverOptsFunc

Types

type RelayCapabilitySet

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

RelayCapabilitySet is shared by every port in one relay process. Its key and replay state never cross the relay's trust boundary.

func NewRelayCapabilitySet

func NewRelayCapabilitySet(maxStreams int) (*RelayCapabilitySet, error)

NewRelayCapabilitySet creates a capability group for one control port and maxStreams advertised data ports.

type RoomProtocol

type RoomProtocol string

RoomProtocol identifies an application protocol that a relay can recognize from fixed metadata without inspecting encrypted application data.

const (
	// RoomProtocolSSH is croc's shared SSH terminal rendezvous protocol.
	RoomProtocolSSH RoomProtocol = "ssh"
)

Jump to

Keyboard shortcuts

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