relay

package
v0.0.0-...-0db62fc Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 16 Imported by: 0

README

Relay Types

This folder contains types and constants shared between the relay server and toversok library

Documentation

Index

Constants

View Source
const (
	PacketChanLen = 16

	PingInterval = 30 * time.Second
)
View Source
const (
	MaxPacketSize              = 64 << 10
	ServerClientKeepAlive      = 15 * time.Second
	ServerClientWriteTimeout   = 5 * time.Second
	ServerClientSendQueueDepth = 32 // packets buffered for sending
)
View Source
const (
	UpgradeProtocol = "toversok-relay"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a Relay client that lives as long as its conn does

func EstablishClient

func EstablishClient(parentCtx context.Context, mc conn.MetaConn, brw *bufio.ReadWriter, timeout time.Duration, getPriv func() *key.NodePrivate) (*Client, error)

EstablishClient creates a new relay.Client on a given MetaConn with associated bufio.ReadWriter.

It logs in and authenticates the server before returning a Client object. If any error occurs, or no client can be established before timeout, it returns.

func (*Client) Cancel

func (c *Client) Cancel(err error)

func (*Client) Close

func (c *Client) Close()

func (*Client) Closed

func (c *Client) Closed() bool

func (*Client) Done

func (c *Client) Done() <-chan struct{}

func (*Client) Err

func (c *Client) Err() error

func (*Client) Recv

func (c *Client) Recv() <-chan RecvPacket

func (*Client) RelayKey

func (c *Client) RelayKey() key.NodePublic

RelayKey returns the key of the relay we're connected to.

func (*Client) RunReceive

func (c *Client) RunReceive()

func (*Client) RunSend

func (c *Client) RunSend()

func (*Client) Send

func (c *Client) Send() chan<- SendPacket

type ClientInfo

type ClientInfo struct {
	// CanAckPings is whether the client wants to receive keepalives over this connection, default true.
	SendKeepalive bool
}

type FrameType

type FrameType byte

type Information

type Information struct {
	ID int64

	// The key that a client can expect from the relay, always set.
	Key key.NodePublic

	// The domain of the relay, to try to connect to.
	//
	// Can be empty ("") with IPs set.
	Domain string `json:",omitempty"`

	// Common Name on expected TLS certificate
	CertCN *string `json:",omitempty"`

	// Forced IPs to try to connect to, bypasses HostName DNS lookup
	IPs []netip.Addr `json:",omitempty"`

	// Optional STUN port override. (Default 3478)
	STUNPort *uint16 `json:",omitempty"`

	// Optional HTTPS/TLS port override. (Default 443)
	HTTPSPort *uint16 `json:",omitempty"`

	// Optional HTTP port override. (Default 80)
	//
	// Also used for captive portal checks.
	HTTPPort *uint16 `json:",omitempty"`

	// Whether to connect to this relay via plain HTTP or not.
	//
	// Used for tests and development environments.
	IsInsecure bool `json:",omitempty"`

	// Whether to use this relay to detect captive portals.
	IsCaptiveBuster *bool `json:",omitempty"`
}

type PingData

type PingData [8]byte

type ProtocolVersion

type ProtocolVersion byte

type RecvPacket

type RecvPacket struct {
	Src key.NodePublic

	Data []byte
}

type SendPacket

type SendPacket struct {
	Dst key.NodePublic

	Data []byte
}

type Server

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

func NewServer

func NewServer(privKey key.NodePrivate) *Server

func (*Server) Accept

func (s *Server) Accept(ctx context.Context, mc conn.MetaConn, brw *bufio.ReadWriter, remoteAddrPort netip.AddrPort) error

func (*Server) L

func (s *Server) L() *slog.Logger

func (*Server) Logger

func (s *Server) Logger() *slog.Logger

func (*Server) PublicKey

func (s *Server) PublicKey() key.NodePublic

PublicKey returns the server's public key.

type ServerClient

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

ServerClient represents an active client connected to a Server.

func (*ServerClient) Cancel

func (sc *ServerClient) Cancel()

func (*ServerClient) L

func (sc *ServerClient) L() *slog.Logger

func (*ServerClient) Run

func (sc *ServerClient) Run() (err error)

Run will be called by Server.Accept in a blocking fashion.

func (*ServerClient) RunReceiver

func (sc *ServerClient) RunReceiver()

func (*ServerClient) RunSender

func (sc *ServerClient) RunSender()

func (*ServerClient) SendPacket

func (sc *ServerClient) SendPacket(pkt ServerPacket)

SendPacket will be called by other goroutines than the ServerClient-owning Run goroutine.

type ServerInfo

type ServerInfo struct {
	TokenBucketBytesPerSecond int `json:",omitempty"`
	TokenBucketBytesBurst     int `json:",omitempty"`
}

type ServerPacket

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

ServerPacket is a transient packet type handled by the server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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