Documentation
¶
Overview ¶
ctx.go
Index ¶
- Constants
- Variables
- func ConnectToTCPServer(address, password, room string, timelimit ...time.Duration) (c *comm.Comm, banner string, ipaddr string, err error)
- func ConnectToTCPServerControl(address, password, room string, timelimit ...time.Duration) (c *comm.Comm, banner string, ipaddr string, capability string, err error)
- func ConnectToTCPServerControlContext(ctx context.Context, address, password, room string, ...) (c *comm.Comm, banner string, ipaddr string, capability string, err error)
- func ConnectToTCPServerWithCapability(address, password, room, capability string, timelimit ...time.Duration) (c *comm.Comm, banner string, ipaddr string, fast bool, err error)
- func ConnectToTCPServerWithCapabilityContext(ctx context.Context, address, password, room, capability string, ...) (c *comm.Comm, banner string, ipaddr string, fast bool, err error)
- func HandshakeTCPServer(c *comm.Comm, password, room string) (banner string, ipaddr string, err error)
- func HandshakeTCPServerCapability(c *comm.Comm, password, room string) (banner string, ipaddr string, capability string, err error)
- func Ignore(err error) error
- func MeasureServerLatency(address string, timeout time.Duration) (duration time.Duration, err error)
- func MeasureServerLatencyContext(ctx context.Context, address string, timeout time.Duration) (duration time.Duration, err error)
- func PingServer(address string) (err error)
- func Run(debugLevel, host, port, password string, banner ...string) (err error)
- func RunCtx(ctx context.Context, debugLevel, host, port, password string, banner ...string) error
- func RunWithListener(listener net.Listener, password string, opts ...serverOptsFunc) error
- func RunWithOptionsAsync(host, port, password string, opts ...serverOptsFunc) error
- func WithAdmissionLimits(sourceLimit, roomLimit int, window time.Duration) serverOptsFunc
- func WithBanner(banner ...string) serverOptsFunc
- func WithCtx(ctx context.Context) serverOptsFunc
- func WithFastAdmission(capabilities *RelayCapabilitySet) serverOptsFunc
- func WithFirstMessageTimeout(timeout time.Duration) serverOptsFunc
- func WithHandshakeTimeout(timeout time.Duration) serverOptsFunc
- func WithLogLevel(level string) serverOptsFunc
- func WithMaxPendingHandshakes(maxPendingHandshakes int) serverOptsFunc
- func WithMaxPendingHandshakesPerSource(limit int) serverOptsFunc
- func WithMaxRoomsOpen(maxRoomsOpen int) serverOptsFunc
- func WithRoomCleanupInterval(interval time.Duration) serverOptsFunc
- func WithRoomPairedCallback(callback func()) serverOptsFunc
- func WithRoomProtocolCallback(callback func(RoomProtocol)) serverOptsFunc
- func WithRoomTTL(ttl time.Duration) serverOptsFunc
- type RelayCapabilitySet
- type RoomProtocol
Constants ¶
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 ¶
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 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 RunWithListener ¶
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 ¶
RunWithOptionsAsync asynchronously starts a TCP listener.
func WithAdmissionLimits ¶
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 WithFastAdmission ¶
func WithFastAdmission(capabilities *RelayCapabilitySet) serverOptsFunc
WithFastAdmission shares one capability key and replay set across every advertised port of a relay process.
func WithFirstMessageTimeout ¶
WithFirstMessageTimeout sets the absolute time from acceptance to receive the first complete protocol frame. The overall handshake timeout still applies.
func WithHandshakeTimeout ¶
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 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 ¶
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" )