relay

package
v1.0.41 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TLSConfig

func TLSConfig(caFile string) (*tls.Config, error)

TLSConfig returns a TLS config for connecting to the relay server. If caFile is provided, it is used as the CA certificate pool. Otherwise, the system root CAs are used.

Types

type Conn

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

Conn wraps a QUIC connection to the relay server.

func Dial

func Dial(ctx context.Context, addr string, user, device string, signer ssh.Signer, tlsCfg *tls.Config) (*Conn, error)

Dial connects to the relay server and authenticates. The handshake:

  1. Client opens a control stream
  2. Client sends: [userLen:1][user][deviceLen:1][device][pubkeyLen:2][pubkey]
  3. Server sends: [challengeLen:1][challenge]
  4. Client signs domainSeparator+challenge with relay key, sends: [sigLen:2][sig]
  5. Server sends: [1] on success, closes stream on failure

func (*Conn) AcceptRawStream

func (c *Conn) AcceptRawStream(ctx context.Context) (*quic.Stream, error)

AcceptRawStream accepts a raw QUIC stream without reading any header.

func (*Conn) AcceptStream

func (c *Conn) AcceptStream(ctx context.Context) (*Stream, error)

AcceptStream accepts an incoming stream from the relay (a routed SSH connection).

func (*Conn) Close

func (c *Conn) Close() error

Close closes the QUIC connection.

func (*Conn) Context added in v1.0.11

func (c *Conn) Context() context.Context

Context returns the QUIC connection's context, which is cancelled when the connection is closed or times out.

func (*Conn) LocalAddr

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

LocalAddr returns the local address of the QUIC connection.

func (*Conn) OpenStream added in v1.0.1

func (c *Conn) OpenStream(ctx context.Context) (*quic.Stream, error)

OpenStream opens a new device-initiated QUIC stream to the relay.

func (*Conn) RemoteAddr

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

RemoteAddr returns the remote address of the QUIC connection.

type PersistentConn

type PersistentConn struct {

	// StreamFunc is called for each accepted SSH stream.
	StreamFunc func(*Stream)

	// UDPFunc is called for each accepted UDP forward stream.
	// The stream has the type byte consumed; next bytes are [targetPort:2][ipLen:2][ipString].
	UDPFunc func(*quic.Stream)

	// ConnectedFunc is called each time a relay connection is established.
	ConnectedFunc func()
	// contains filtered or unexported fields
}

PersistentConn maintains a persistent relay connection with auto-reconnect.

func NewPersistentConn

func NewPersistentConn(addr, user, device string, signer ssh.Signer, tlsCfg *tls.Config, fn func(*Stream)) *PersistentConn

NewPersistentConn creates a new persistent relay connection.

func (*PersistentConn) OpenStream added in v1.0.1

func (p *PersistentConn) OpenStream(ctx context.Context) (*quic.Stream, error)

OpenStream opens a device-initiated QUIC stream on the current connection. Returns an error if not currently connected.

func (*PersistentConn) PushSessions added in v1.0.2

func (p *PersistentConn) PushSessions(data []byte) error

PushSessions sends a session metadata update to the relay. Format: [0x04][len:2][json]

func (*PersistentConn) Start

func (p *PersistentConn) Start()

Start begins the connection loop in a goroutine.

func (*PersistentConn) Stop

func (p *PersistentConn) Stop()

Stop closes the connection and stops reconnecting.

type Stream

type Stream struct {
	*quic.Stream
	// contains filtered or unexported fields
}

Stream wraps a QUIC stream as a net.Conn. The relay sends the original client IP at the start of each stream: [ip_len:2][ip_string].

func WrapStream

func WrapStream(s *quic.Stream, localAddr, quicRemoteAddr net.Addr) (*Stream, error)

WrapStream reads the client IP header and returns a net.Conn. quicRemoteAddr is the actual QUIC connection's remote address; the claimed address from the stream header is stored separately.

func (*Stream) ClaimedAddr

func (s *Stream) ClaimedAddr() net.Addr

func (*Stream) Close

func (s *Stream) Close() error

func (*Stream) LocalAddr

func (s *Stream) LocalAddr() net.Addr

func (*Stream) Read

func (s *Stream) Read(p []byte) (int, error)

func (*Stream) RemoteAddr

func (s *Stream) RemoteAddr() net.Addr

func (*Stream) SetDeadline

func (s *Stream) SetDeadline(t time.Time) error

func (*Stream) SetReadDeadline

func (s *Stream) SetReadDeadline(t time.Time) error

func (*Stream) SetWriteDeadline

func (s *Stream) SetWriteDeadline(t time.Time) error

func (*Stream) Write

func (s *Stream) Write(p []byte) (int, error)

type UDPRelay

type UDPRelay struct {

	// Timeout is the session idle timeout. Zero means 10 minutes.
	Timeout time.Duration
	// contains filtered or unexported fields
}

UDPRelay manages UDP relay sessions for mosh. Each session binds a local UDP port and forwards datagrams to a device via a QUIC stream.

func NewUDPRelay

func NewUDPRelay() *UDPRelay

NewUDPRelay creates a new UDP relay manager.

func (*UDPRelay) CloseSession

func (r *UDPRelay) CloseSession(id string)

CloseSession closes and removes a session.

func (*UDPRelay) CreateSession

func (r *UDPRelay) CreateSession(id string, stream io.ReadWriteCloser) (*UDPSession, error)

CreateSession creates a new UDP relay session. It binds a local UDP port and starts forwarding datagrams between the UDP port and the QUIC stream.

type UDPSession

type UDPSession struct {
	ID        string
	RelayPort int
	// contains filtered or unexported fields
}

UDPSession represents an active mosh UDP relay session.

Jump to

Keyboard shortcuts

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