Documentation
¶
Overview ¶
Package relay contains all code necessary to establish a connection with a relay server, create a relay server, and communicate with one.
This package is largely transport-agnostic, for a specific implementation, see relayhttp.
Index ¶
- Constants
- type Client
- type ClientInfo
- type FrameType
- type HTTPClient
- func (c *HTTPClient) Cancel(err error)
- func (c *HTTPClient) Close()
- func (c *HTTPClient) Closed() bool
- func (c *HTTPClient) Done() <-chan struct{}
- func (c *HTTPClient) Err() error
- func (c *HTTPClient) Recv() <-chan RecvPacket
- func (c *HTTPClient) RelayKey() key.NodePublic
- func (c *HTTPClient) Run()
- func (c *HTTPClient) RunReceive()
- func (c *HTTPClient) RunSend()
- func (c *HTTPClient) Send() chan<- SendPacket
- type Information
- type PingData
- type ProtocolVersion
- type RecvPacket
- type SendPacket
- type Server
- type ServerClient
- type ServerInfo
- type ServerPacket
Constants ¶
const ( PacketChanLen = 16 PingInterval = 30 * time.Second )
const ( MaxPacketSize = 64 << 10 ServerClientKeepAlive = 15 * time.Second ServerClientWriteTimeout = 5 * time.Second ServerClientSendQueueDepth = 32 // packets buffered for sending )
const (
UpgradeProtocol = "toversok-relay"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { Run() RelayKey() key.NodePublic Send() chan<- SendPacket Recv() <-chan RecvPacket Done() <-chan struct{} Err() error Close() }
type ClientInfo ¶
type ClientInfo struct { // CanAckPings is whether the client wants to receive keepalives over this connection, default true. SendKeepalive bool }
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient is a Relay client that lives as long as its conn does
func EstablishClient ¶
func EstablishClient(parentCtx context.Context, mc types.MetaConn, brw *bufio.ReadWriter, timeout time.Duration, getPriv func() *key.NodePrivate) (*HTTPClient, error)
EstablishClient creates a new relay.HTTPClient on a given MetaConn with associated bufio.ReadWriter.
It logs in and authenticates the server before returning a HTTPClient object. If any error occurs, or no client can be established before timeout, it returns.
func (*HTTPClient) Cancel ¶
func (c *HTTPClient) Cancel(err error)
func (*HTTPClient) Close ¶
func (c *HTTPClient) Close()
func (*HTTPClient) Closed ¶
func (c *HTTPClient) Closed() bool
func (*HTTPClient) Done ¶
func (c *HTTPClient) Done() <-chan struct{}
func (*HTTPClient) Err ¶
func (c *HTTPClient) Err() error
func (*HTTPClient) Recv ¶
func (c *HTTPClient) Recv() <-chan RecvPacket
func (*HTTPClient) RelayKey ¶
func (c *HTTPClient) RelayKey() key.NodePublic
RelayKey returns the key of the relay we're connected to.
func (*HTTPClient) Run ¶
func (c *HTTPClient) Run()
func (*HTTPClient) RunReceive ¶
func (c *HTTPClient) RunReceive()
func (*HTTPClient) RunSend ¶
func (c *HTTPClient) RunSend()
func (*HTTPClient) Send ¶
func (c *HTTPClient) Send() chan<- SendPacket
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"` IsSTUNOnly *bool `json:",omitempty"` }
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) 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 ServerPacket ¶
type ServerPacket struct {
// contains filtered or unexported fields
}
ServerPacket is a transient packet type handled by the server