Documentation
¶
Index ¶
- type Interface
- func (f *Interface) AddPeer(p *Peer) error
- func (f *Interface) Close() error
- func (f *Interface) GetPeers() []*Peer
- func (f *Interface) RemovePeer(pubkey []byte) error
- func (f *Interface) Run() error
- func (f *Interface) SetPeers(peers []*Peer) error
- func (f *Interface) SetPresharedKey(k []byte) error
- func (f *Interface) SetPrivateKey(k []byte) error
- type InterfaceConfig
- type Peer
- type UDPConn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Interface ¶
type Interface struct {
// contains filtered or unexported fields
}
An Interface communicates encrypted packets with peers.
func NewInterface ¶
func NewInterface(c InterfaceConfig) (*Interface, error)
func (*Interface) AddPeer ¶
AddPeer adds a peer to the interface configuration. If the peer, identified by its public key, already exists, then all configuration will be replaced with the new fields.
func (*Interface) RemovePeer ¶
RemovePeer removes the peer identified with the public key pubkey from the interface configuration.
func (*Interface) SetPeers ¶
SetPeers replaces all of the peers that the interface is configured for with a new list.
func (*Interface) SetPresharedKey ¶
SetPresharedKey changes the pre-shared key for the interface.
func (*Interface) SetPrivateKey ¶
SetPrivateKey changes the private key for the interface. It is safe to call while the interface is running.
type InterfaceConfig ¶
type InterfaceConfig struct {
// Outside is the connection that will be used to send and receive encrypted
// packets with peers. It will be closed if Close is called on the Interface.
Outside UDPConn
// Inside is the interface that will be used to read plaintext packets
// destined for peers and write decrypted packets received from peers. Each
// Read must return a single IP packet to send to a peer, and each Write
// will provide a single received IP packet.
Inside io.ReadWriter
// PrivateKey holds the static Curve25519 private key for the interface. If
// set, it must be exactly 32 random bytes.
PrivateKey []byte
// If set, it must be exactly 32 random bytes.
PresharedKey []byte
// Peers is the initial set of peers that the interface will communicate
// with.
Peers []*Peer
}
An InterfaceConfig is the configuration used to create an interface.
type Peer ¶
type Peer struct {
// PublicKey is the static Curve25519 public key of the peer. It must be
// exactly 32 bytes.
PublicKey []byte
// AllowedIPs is the list of IP networks that will be routed to and accepted
// from the peer.
AllowedIPs []*net.IPNet
// Endpoint is the network address that packets destined for the peer will
// be sent to. If it is nil, packets destined for this peer will not be
// routable until an incoming handshake is received.
Endpoint *net.UDPAddr
// PersistentKeepaliveInterval, if non-zero, is the number of seconds
// between keep-alive packets sent to the peer.
PersistentKeepaliveInterval int
// LastHandshake is the timestamp of the last successful handshake with the
// peer. This field is read-only.
LastHandshake time.Time
// RxBytes is the number of bytes received from the peer. This field is
// read-only.
RxBytes int64
// TxBytes is the number of bytes transmitted to the peer. This field is
// read-only.
TxBytes int64
}
A Peer is a remote endpoint that can be communicated with via an Interface.