Documentation ¶
Overview ¶
Package derp implements DERP, the Detour Encrypted Routing Protocol.
DERP routes packets to clients using curve25519 keys as addresses.
DERP is used by Tailscale nodes to proxy encrypted WireGuard packets through the Tailscale cloud servers when a direct path cannot be found or opened. DERP is a last resort. Both sides between very aggressive NATs, firewalls, no IPv6, etc? Well, DERP.
Index ¶
Constants ¶
const MaxPacketSize = 64 << 10
MaxPacketSize is the maximum size of a packet sent over DERP. (This only includes the data bytes visible to magicsock, not including its on-wire framing overhead)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) NotePreferred ¶
NotePreferred sends a packet that tells the server whether this client is the user's preferred server. This is only used in the server for stats.
func (*Client) Recv ¶
func (c *Client) Recv(b []byte) (m ReceivedMessage, err error)
Recv reads a message from the DERP server. The provided buffer must be large enough to receive a complete packet, which in practice are are 1.5-4 KB, but can be up to 64 KB. Once Recv returns an error, the Client is dead forever.
type Conn ¶
type Conn interface { io.Closer SetDeadline(time.Time) error SetReadDeadline(time.Time) error SetWriteDeadline(time.Time) error }
Conn is the subset of the underlying net.Conn the DERP Server needs. It is a defined type so that non-net connections can be used.
type ReceivedMessage ¶
type ReceivedMessage interface {
// contains filtered or unexported methods
}
ReceivedMessage represents a type returned by Client.Recv. Unless otherwise documented, the returned message aliases the byte slice provided to Recv and thus the message is only as good as that buffer, which is up to the caller.
type ReceivedPacket ¶
type ReceivedPacket struct { Source key.Public // Data is the received packet bytes. It aliases the memory // passed to Client.Recv. Data []byte }
ReceivedPacket is a ReceivedMessage representing an incoming packet.
type Server ¶
type Server struct { // BytesPerSecond, if non-zero, specifies how many bytes per // second to cap per-client reads at. BytesPerSecond int // WriteTimeout, if non-zero, specifies how long to wait // before failing when writing to a client. WriteTimeout time.Duration // contains filtered or unexported fields }
Server is a DERP server.
func NewServer ¶
NewServer returns a new DERP server. It doesn't listen on its own. Connections are given to it via Server.Accept.
func (*Server) Accept ¶
func (s *Server) Accept(nc Conn, brw *bufio.ReadWriter, remoteAddr string)
Accept adds a new connection to the server and serves it.
The provided bufio ReadWriter must be already connected to nc. Accept blocks until the Server is closed or the connection closes on its own.
Accept closes nc.