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
- type Client
- func (c *Client) ClosePeer(target key.Public) error
- func (c *Client) ForwardPacket(srcKey, dstKey key.Public, pkt []byte) (err error)
- func (c *Client) NotePreferred(preferred bool) (err error)
- func (c *Client) Recv() (m ReceivedMessage, err error)
- func (c *Client) Send(dstKey key.Public, pkt []byte) error
- func (c *Client) ServerPublicKey() key.Public
- func (c *Client) WatchConnectionChanges() error
- type ClientOpt
- type Conn
- type PacketForwarder
- type PeerGoneMessage
- type PeerPresentMessage
- type ReceivedMessage
- type ReceivedPacket
- type Server
- func (s *Server) Accept(nc Conn, brw *bufio.ReadWriter, remoteAddr string)
- func (s *Server) AddPacketForwarder(dst key.Public, fwd PacketForwarder)
- func (s *Server) Close() error
- func (s *Server) ConsistencyCheck() error
- func (s *Server) ExpVar() expvar.Var
- func (s *Server) HasMeshKey() bool
- func (s *Server) MeshKey() string
- func (s *Server) PrivateKey() key.Private
- func (s *Server) PublicKey() key.Public
- func (s *Server) RemovePacketForwarder(dst key.Public, fwd PacketForwarder)
- func (s *Server) SetMeshKey(v string)
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
}
Client is a DERP client.
func (*Client) ClosePeer ¶ added in v0.100.0
ClosePeer asks the server to close target's TCP connection. It's a fatal error if the client wasn't created using MeshKey.
func (*Client) ForwardPacket ¶ added in v0.100.0
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() (m ReceivedMessage, err error)
Recv reads a message from the DERP server.
The returned message may alias memory owned by the Client; it should only be accessed until the next call to Client.
Once Recv returns an error, the Client is dead forever.
func (*Client) Send ¶
Send sends a packet to the Tailscale node identified by dstKey.
It is an error if the packet is larger than 64KB.
func (*Client) ServerPublicKey ¶ added in v0.100.0
ServerPublicKey returns the server's public key.
func (*Client) WatchConnectionChanges ¶ added in v0.99.1
WatchConnectionChanges sends a request to subscribe to the peer's connection list. It's a fatal error if the client wasn't created using MeshKey.
type ClientOpt ¶ added in v0.100.0
type ClientOpt interface {
// contains filtered or unexported methods
}
ClientOpt is an option passed to NewClient.
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 PacketForwarder ¶ added in v0.100.0
PacketForwarder is something that can forward packets.
It's mostly an inteface for circular dependency reasons; the typical implementation is derphttp.Client. The other implementation is a multiForwarder, which this package creates as needed if a public key gets more than one PacketForwarder registered for it.
type PeerGoneMessage ¶ added in v0.98.0
PeerGoneMessage is a ReceivedMessage that indicates that the client identified by the underlying public key had previously sent you a packet but has now disconnected from the server.
type PeerPresentMessage ¶ added in v0.99.1
PeerPresentMessage is a ReceivedMessage that indicates that the client is connected to the server. (Only used by trusted mesh clients)
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 { // 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.
func (*Server) AddPacketForwarder ¶ added in v0.100.0
func (s *Server) AddPacketForwarder(dst key.Public, fwd PacketForwarder)
AddPacketForwarder registers fwd as a packet forwarder for dst. fwd must be comparable.
func (*Server) ConsistencyCheck ¶ added in v0.100.0
func (*Server) ExpVar ¶
ExpVar returns an expvar variable suitable for registering with expvar.Publish.
func (*Server) HasMeshKey ¶ added in v0.99.1
HasMeshKey reports whether the server is configured with a mesh key.
func (*Server) PrivateKey ¶ added in v0.100.0
PrivateKey returns the server's private key.
func (*Server) RemovePacketForwarder ¶ added in v0.100.0
func (s *Server) RemovePacketForwarder(dst key.Public, fwd PacketForwarder)
RemovePacketForwarder removes fwd as a packet forwarder for dst. fwd must be comparable.
func (*Server) SetMeshKey ¶ added in v0.99.1
SetMesh sets the pre-shared key that regional DERP servers used to mesh amongst themselves.
It must be called before serving begins.