magicsock

package
v0.98.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2020 License: BSD-3-Clause Imports: 36 Imported by: 16

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

View Source
const DefaultPort = 0

DefaultPort is the default port to listen on. The current default (zero) means to auto-select a random free port.

View Source
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

View Source
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) Addrs

func (a *AddrSet) Addrs() []wgcfg.Endpoint

func (*AddrSet) ClearSrc

func (a *AddrSet) ClearSrc()

func (*AddrSet) DstIP

func (a *AddrSet) DstIP() net.IP

func (*AddrSet) DstToBytes

func (a *AddrSet) DstToBytes() []byte

func (*AddrSet) DstToString

func (a *AddrSet) DstToString() string

func (*AddrSet) SrcIP

func (a *AddrSet) SrcIP() net.IP

func (*AddrSet) SrcToString

func (a *AddrSet) SrcToString() string

func (*AddrSet) String

func (a *AddrSet) String() string

func (*AddrSet) UpdateDst

func (a *AddrSet) UpdateDst(new *net.UDPAddr) error

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/conn.Bind.

func Listen

func Listen(opts Options) (*Conn, error)

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

func (c *Conn) Close() error

Close closes the connection.

Only the first close does anything. Any later closes return nil.

func (*Conn) CreateBind

func (c *Conn) CreateBind(uint16) (conn.Bind, uint16, error)

CreateBind is called by WireGuard to create a UDP binding.

func (*Conn) CreateEndpoint

func (c *Conn) CreateEndpoint(pubKey [32]byte, addrs string) (conn.Endpoint, error)

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) DERPs added in v0.98.0

func (c *Conn) DERPs() int

DERPs reports the number of active DERP connections.

func (*Conn) LastMark

func (c *Conn) LastMark() uint32

func (*Conn) LocalPort

func (c *Conn) LocalPort() uint16

func (*Conn) ReSTUN

func (c *Conn) ReSTUN(why string)

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 (c *Conn) ReceiveIPv4(b []byte) (n int, ep conn.Endpoint, addr *net.UDPAddr, err error)

func (*Conn) ReceiveIPv6

func (c *Conn) ReceiveIPv6(b []byte) (int, conn.Endpoint, *net.UDPAddr, error)

func (*Conn) Send

func (c *Conn) Send(b []byte, ep conn.Endpoint) error

func (*Conn) SetDERPEnabled

func (c *Conn) SetDERPEnabled(wantDerp bool)

SetDERPEnabled controls whether DERP is used. New connections have it enabled by default.

func (*Conn) SetMark

func (c *Conn) SetMark(value uint32) error

func (*Conn) SetNetInfoCallback

func (c *Conn) SetNetInfoCallback(fn func(*tailcfg.NetInfo))

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.

func (*Conn) UpdatePeers added in v0.98.0

func (c *Conn) UpdatePeers(newPeers map[key.Public]struct{})

UpdatePeers is called when the set of WireGuard peers changes. It then removes any state for old peers.

The caller passes ownership of newPeers map to UpdatePeers.

func (*Conn) UpdateStatus added in v0.98.0

func (c *Conn) UpdateStatus(sb *ipnstate.StatusBuilder)

type Options

type Options struct {
	// Logf optionally provides a log function to use.
	// If nil, log.Printf is used.
	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) ReadFrom

func (c *RebindingUDPConn) ReadFrom(b []byte) (int, net.Addr, error)

func (*RebindingUDPConn) Reset

func (c *RebindingUDPConn) Reset(pconn *net.UDPConn)

func (*RebindingUDPConn) SetReadDeadline

func (c *RebindingUDPConn) SetReadDeadline(t time.Time)

func (*RebindingUDPConn) WriteTo

func (c *RebindingUDPConn) WriteTo(b []byte, addr net.Addr) (int, error)

func (*RebindingUDPConn) WriteToUDP

func (c *RebindingUDPConn) WriteToUDP(b []byte, addr *net.UDPAddr) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL