Documentation ¶
Overview ¶
Package magicsock implements a socket that can change its communication path while in use, actively searching for the best way to communicate.
Index ¶
- Constants
- Variables
- type AddrSet
- func (a *AddrSet) Addrs() []wgcfg.Endpoint
- func (a *AddrSet) ClearSrc()
- func (a *AddrSet) DstIP() net.IP
- func (a *AddrSet) DstToBytes() []byte
- func (a *AddrSet) DstToString() string
- func (a *AddrSet) SrcIP() net.IP
- func (a *AddrSet) SrcToString() string
- func (a *AddrSet) String() string
- func (a *AddrSet) UpdateDst(new *net.UDPAddr) error
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) CreateBind(uint16) (conn.Bind, uint16, error)
- func (c *Conn) CreateEndpoint(key [32]byte, addrs string) (conn.Endpoint, error)
- func (c *Conn) LastMark() uint32
- func (c *Conn) LocalPort() uint16
- func (c *Conn) ReSTUN(why string)
- func (c *Conn) Rebind()
- func (c *Conn) ReceiveIPv4(b []byte) (n int, ep conn.Endpoint, addr *net.UDPAddr, err error)
- func (c *Conn) ReceiveIPv6(buff []byte) (int, conn.Endpoint, *net.UDPAddr, error)
- func (c *Conn) Send(b []byte, ep conn.Endpoint) error
- func (c *Conn) SetDERPEnabled(wantDerp bool)
- func (c *Conn) SetMark(value uint32) error
- func (c *Conn) SetNetInfoCallback(fn func(*tailcfg.NetInfo))
- func (c *Conn) SetPrivateKey(privateKey wgcfg.PrivateKey) error
- type Options
- type RebindingUDPConn
- func (c *RebindingUDPConn) Close() error
- func (c *RebindingUDPConn) LocalAddr() *net.UDPAddr
- func (c *RebindingUDPConn) ReadFrom(b []byte) (int, net.Addr, error)
- func (c *RebindingUDPConn) Reset(pconn *net.UDPConn)
- func (c *RebindingUDPConn) SetReadDeadline(t time.Time)
- func (c *RebindingUDPConn) WriteTo(b []byte, addr net.Addr) (int, error)
- func (c *RebindingUDPConn) WriteToUDP(b []byte, addr *net.UDPAddr) (int, error)
Constants ¶
const DefaultPort = 0
DefaultPort is the default port to listen on. The current default (zero) means to auto-select a random free port.
const DerpMagicIP = "127.3.3.40"
DerpMagicIP is a fake WireGuard endpoint IP address that means to use DERP. When used, the port number of the WireGuard endpoint is the DERP server number to use.
Mnemonic: 3.3.40 are numbers above the keys D, E, R, P.
Variables ¶
var DisableSTUNForTesting bool
Functions ¶
This section is empty.
Types ¶
type AddrSet ¶
type AddrSet struct { Logf logger.Logf // Logf, if non-nil, is used instead of log.Printf // contains filtered or unexported fields }
AddrSet is a set of UDP addresses that implements wireguard/conn.Endpoint.
func (*AddrSet) DstToBytes ¶
func (*AddrSet) DstToString ¶
func (*AddrSet) SrcToString ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
A Conn routes UDP packets and actively manages a list of its endpoints. It implements wireguard/device.Bind.
func Listen ¶
Listen creates a magic Conn listening on opts.Port. As the set of possible endpoints for a Conn changes, the callback opts.EndpointsFunc is called.
func (*Conn) Close ¶
Close closes the connection.
Only the first close does anything. Any later closes return nil.
func (*Conn) CreateBind ¶
CreateBind is called by WireGuard to create a UDP binding.
func (*Conn) CreateEndpoint ¶
CreateEndpoint is called by WireGuard to connect to an endpoint. The key is the public key of the peer and addrs is a comma-separated list of UDP ip:ports.
func (*Conn) ReSTUN ¶
ReSTUN triggers an address discovery. The provided why string is for debug logging only.
func (*Conn) Rebind ¶
func (c *Conn) Rebind()
Rebind closes and re-binds the UDP sockets. It should be followed by a call to ReSTUN.
func (*Conn) ReceiveIPv4 ¶
func (*Conn) ReceiveIPv6 ¶
func (*Conn) SetDERPEnabled ¶
SetDERPEnabled controls whether DERP is used. New connections have it enabled by default.
func (*Conn) SetNetInfoCallback ¶
func (*Conn) SetPrivateKey ¶
func (c *Conn) SetPrivateKey(privateKey wgcfg.PrivateKey) error
SetPrivateKey sets the connection's private key.
This is only used to be able prove our identity when connecting to DERP servers.
If the private key changes, any DERP connections are torn down & recreated when needed.
type Options ¶
type Options struct { Logf logger.Logf // Port is the port to listen on. // Zero means to pick one automatically. Port uint16 // DERPs, if non-nil, is used instead of derpmap.Prod. DERPs *derpmap.World // EndpointsFunc optionally provides a func to be called when // endpoints change. The called func does not own the slice. EndpointsFunc func(endpoint []string) // contains filtered or unexported fields }
Options contains options for Listen.
type RebindingUDPConn ¶
type RebindingUDPConn struct {
// contains filtered or unexported fields
}
RebindingUDPConn is a UDP socket that can be re-bound. Unix has no notion of re-binding a socket, so we swap it out for a new one.
func (*RebindingUDPConn) Close ¶
func (c *RebindingUDPConn) Close() error
func (*RebindingUDPConn) LocalAddr ¶
func (c *RebindingUDPConn) LocalAddr() *net.UDPAddr
func (*RebindingUDPConn) Reset ¶
func (c *RebindingUDPConn) Reset(pconn *net.UDPConn)
func (*RebindingUDPConn) SetReadDeadline ¶
func (c *RebindingUDPConn) SetReadDeadline(t time.Time)