Documentation ¶
Index ¶
- Constants
- type Client
- func (c *Client) Cancel(err error)
- func (c *Client) Close()
- func (c *Client) Closed() bool
- func (c *Client) Done() <-chan struct{}
- func (c *Client) Err() error
- func (c *Client) Recv() <-chan RecvPacket
- func (c *Client) RelayKey() key.NodePublic
- func (c *Client) RunReceive()
- func (c *Client) RunSend()
- func (c *Client) Send() chan<- SendPacket
- type ClientInfo
- type FrameType
- 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 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) 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) 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 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 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