Documentation ¶
Index ¶
- Constants
- Variables
- func Concat(elems ...[]byte) []byte
- func FormSessionKey(remotePublicKey, localPrivateKey *[32]byte, secretKey []byte) *[32]byte
- func GenerateKeyPair() (publicKey, privateKey *[32]byte, err error)
- func GobEncode(items ...interface{}) []byte
- func PosixError(err error) error
- type Config
- type Connection
- type ConnectionAction
- type ConnectionMaker
- func (cm *ConnectionMaker) ConnectionTerminated(address string, err error)
- func (cm *ConnectionMaker) ForgetConnections(peers []string)
- func (cm *ConnectionMaker) InitiateConnections(peers []string, replace bool) []error
- func (cm *ConnectionMaker) Refresh()
- func (cm *ConnectionMaker) Start()
- func (cm *ConnectionMaker) Status() ConnectionMakerStatus
- type ConnectionMakerAction
- type ConnectionMakerStatus
- type ConnectionSet
- type ConnectionSummary
- type ConnectionTieBreak
- type Decryptor
- type EncryptedTCPReceiver
- type EncryptedTCPSender
- type Encryptor
- type EthernetDecoder
- type FieldValidator
- type ForwardedFrame
- type Forwarder
- type ForwarderDF
- type FrameConsumer
- type FrameTooBigError
- type Gossip
- type GossipChannel
- type GossipChannels
- type GossipData
- type GossipSender
- type Gossiper
- type ListOfPeers
- type LocalConnection
- func (conn *LocalConnection) BreakTie(dupConn Connection) ConnectionTieBreak
- func (conn *LocalConnection) Established() bool
- func (conn *LocalConnection) Forward(df bool, frame *ForwardedFrame, dec *EthernetDecoder) error
- func (conn *LocalConnection) ReceivedHeartbeat(remoteUDPAddr *net.UDPAddr, connUID uint64)
- func (conn *LocalConnection) RemoteUDPAddr() *net.UDPAddr
- func (conn *LocalConnection) SendProtocolMsg(m ProtocolMsg)
- func (conn *LocalConnection) SetEstablished()
- func (conn *LocalConnection) Shutdown(err error)
- func (conn *LocalConnection) Start(acceptNewPeer bool)
- type LocalPeer
- func (peer *LocalPeer) AddConnection(conn *LocalConnection) error
- func (peer *LocalPeer) Broadcast(df bool, frame []byte, dec *EthernetDecoder)
- func (peer *LocalPeer) ConnectionEstablished(conn *LocalConnection)
- func (peer *LocalPeer) ConnectionTo(name PeerName) (Connection, bool)
- func (peer *LocalPeer) Connections() ConnectionSet
- func (peer *LocalPeer) ConnectionsTo(names []PeerName) []Connection
- func (peer *LocalPeer) CreateConnection(peerAddr string, acceptNewPeer bool) error
- func (peer *LocalPeer) DeleteConnection(conn *LocalConnection)
- func (peer *LocalPeer) Encode(enc *gob.Encoder)
- func (peer *LocalPeer) Forward(dstPeer *Peer, df bool, frame []byte, dec *EthernetDecoder) error
- func (peer *LocalPeer) Info() string
- func (peer *LocalPeer) Relay(srcPeer, dstPeer *Peer, df bool, frame []byte, dec *EthernetDecoder) error
- func (peer *LocalPeer) RelayBroadcast(srcPeer *Peer, df bool, frame []byte, dec *EthernetDecoder)
- func (peer *LocalPeer) Start()
- type LocalPeerAction
- type LogFrameFunc
- type MacCache
- func (cache *MacCache) Delete(peer *Peer) bool
- func (cache *MacCache) Enter(mac net.HardwareAddr, peer *Peer) bool
- func (cache *MacCache) Lookup(mac net.HardwareAddr) (*Peer, bool)
- func (cache *MacCache) MarshalJSON() ([]byte, error)
- func (cache *MacCache) Start()
- func (cache *MacCache) String() string
- type MacCacheEntry
- type MsgTooBigError
- type NaClDecryptor
- type NaClDecryptorInstance
- type NaClEncryptor
- type NameCollisionError
- type NonDecryptor
- type NonEncryptor
- type PacketDecodingError
- type PacketSink
- type PacketSource
- type PacketSourceSink
- type PcapIO
- type Peer
- func (peer *Peer) Encode(enc *gob.Encoder)
- func (peer *Peer) ForEachConnectedPeer(establishedAndSymmetric bool, exclude map[PeerName]PeerName, f func(*Peer))
- func (peer *Peer) Info() string
- func (peer *Peer) Routes(stopAt *Peer, establishedAndSymmetric bool) (bool, map[PeerName]PeerName)
- func (peer *Peer) String() string
- type PeerName
- type PeerNameSet
- type PeerSummary
- type PeerUID
- type Peers
- func (peers *Peers) ApplyUpdate(update []byte) (PeerNameSet, PeerNameSet, error)
- func (peers *Peers) Dereference(peer *Peer)
- func (peers *Peers) EncodePeers(names PeerNameSet) []byte
- func (peers *Peers) Fetch(name PeerName) (*Peer, bool)
- func (peers *Peers) FetchWithDefault(peer *Peer) *Peer
- func (peers *Peers) ForEach(fun func(*Peer))
- func (peers *Peers) GarbageCollect() []*Peer
- func (peers *Peers) MarshalJSON() ([]byte, error)
- func (peers *Peers) Names() PeerNameSet
- func (peers *Peers) String() string
- type ProtocolMsg
- type ProtocolSender
- type ProtocolTag
- type RawUDPSender
- type RemoteConnection
- func (conn *RemoteConnection) BreakTie(Connection) ConnectionTieBreak
- func (conn *RemoteConnection) Established() bool
- func (conn *RemoteConnection) Local() *Peer
- func (conn *RemoteConnection) Log(args ...interface{})
- func (conn *RemoteConnection) MarshalJSON() ([]byte, error)
- func (conn *RemoteConnection) Outbound() bool
- func (conn *RemoteConnection) Remote() *Peer
- func (conn *RemoteConnection) RemoteTCPAddr() string
- func (conn *RemoteConnection) Shutdown(error)
- func (conn *RemoteConnection) String() string
- type Router
- func (router *Router) Gossip() GossipData
- func (router *Router) NewGossip(channelName string, g Gossiper) Gossip
- func (router *Router) OnGossip(update []byte) (GossipData, error)
- func (router *Router) OnGossipBroadcast(update []byte) (GossipData, error)
- func (router *Router) OnGossipUnicast(sender PeerName, msg []byte) error
- func (router *Router) SendAllGossip()
- func (router *Router) SendAllGossipDown(conn Connection)
- func (router *Router) Start()
- func (router *Router) Status() string
- func (router *Router) StatusJSON(version string) ([]byte, error)
- func (router *Router) Stop() error
- func (router *Router) UsingPassword() bool
- type Routes
- func (routes *Routes) Broadcast(name PeerName) []PeerName
- func (routes *Routes) BroadcastAll(name PeerName) []PeerName
- func (routes *Routes) EnsureRecalculated()
- func (routes *Routes) MarshalJSON() ([]byte, error)
- func (routes *Routes) PeerNames() PeerNameSet
- func (routes *Routes) RandomNeighbours(except PeerName) PeerNameSet
- func (routes *Routes) Recalculate()
- func (routes *Routes) Start()
- func (routes *Routes) String() string
- func (routes *Routes) Unicast(name PeerName) (PeerName, bool)
- func (routes *Routes) UnicastAll(name PeerName) (PeerName, bool)
- type SimpleTCPReceiver
- type SimpleTCPSender
- type SimpleUDPSender
- type SurrogateGossipData
- type SurrogateGossiper
- type TCPCryptoState
- type TCPReceiver
- type TCPSender
- type Target
- type TokenBucket
- type TopologyGossipData
- type UDPSender
- type UnknownPeerError
Constants ¶
const ( InitialInterval = 2 * time.Second MaxInterval = 6 * time.Minute )
const ( EthernetOverhead = 14 UDPOverhead = 28 // 20 bytes for IPv4, 8 bytes for UDP Port = 6783 HTTPPort = Port + 1 DefaultPMTU = 65535 MaxUDPPacketSize = 65535 ChannelSize = 16 FragTestSize = 60001 PMTUDiscoverySize = 60000 TCPHeartbeat = 30 * time.Second FastHeartbeat = 500 * time.Millisecond SlowHeartbeat = 10 * time.Second FragTestInterval = 5 * time.Minute GossipInterval = 30 * time.Second PMTUVerifyAttempts = 8 PMTUVerifyTimeout = 10 * time.Millisecond // gets doubled with every attempt MaxDuration = time.Duration(math.MaxInt64) MaxMissedHeartbeats = 6 HeaderTimeout = 10 * time.Second HeartbeatTimeout = MaxMissedHeartbeats * SlowHeartbeat )
const ( PeerNameFlavour = "mac" NameSize = 6 UnknownPeerName = PeerName(0) )
const ( Protocol = "weave" ProtocolVersion byte = 1 ProtocolMinVersion byte = ProtocolVersion )
const (
WindowSize = 20 // bits
)
Variables ¶
var ( FragTest = make([]byte, FragTestSize) PMTUDiscovery = make([]byte, PMTUDiscoverySize) )
var ( ProtocolBytes = []byte(Protocol) ProtocolLen = len(ProtocolBytes) ProtocolHeader = append(ProtocolBytes, ProtocolMinVersion, ProtocolVersion) ProtocolHeaderLen = len(ProtocolHeader) )
Functions ¶
func FormSessionKey ¶
func GenerateKeyPair ¶
func PosixError ¶
Types ¶
type Connection ¶
type Connection interface { Local() *Peer Remote() *Peer RemoteTCPAddr() string Outbound() bool Established() bool BreakTie(Connection) ConnectionTieBreak Shutdown(error) Log(args ...interface{}) }
type ConnectionAction ¶ added in v0.10.0
type ConnectionAction func() error
type ConnectionMaker ¶
type ConnectionMaker struct {
// contains filtered or unexported fields
}
func NewConnectionMaker ¶ added in v0.9.0
func NewConnectionMaker(ourself *LocalPeer, peers *Peers, port int, discovery bool) *ConnectionMaker
func (*ConnectionMaker) ConnectionTerminated ¶
func (cm *ConnectionMaker) ConnectionTerminated(address string, err error)
func (*ConnectionMaker) ForgetConnections ¶ added in v1.0.0
func (cm *ConnectionMaker) ForgetConnections(peers []string)
func (*ConnectionMaker) InitiateConnections ¶ added in v1.0.0
func (cm *ConnectionMaker) InitiateConnections(peers []string, replace bool) []error
func (*ConnectionMaker) Refresh ¶
func (cm *ConnectionMaker) Refresh()
func (*ConnectionMaker) Start ¶ added in v0.9.0
func (cm *ConnectionMaker) Start()
func (*ConnectionMaker) Status ¶ added in v1.0.0
func (cm *ConnectionMaker) Status() ConnectionMakerStatus
type ConnectionMakerAction ¶ added in v0.10.0
type ConnectionMakerAction func() bool
type ConnectionMakerStatus ¶ added in v1.0.0
func (ConnectionMakerStatus) String ¶ added in v1.0.0
func (status ConnectionMakerStatus) String() string
type ConnectionSet ¶ added in v0.10.0
type ConnectionSet map[Connection]struct{}
type ConnectionSummary ¶ added in v0.11.0
type ConnectionTieBreak ¶ added in v0.9.0
type ConnectionTieBreak int
const ( TieBreakWon ConnectionTieBreak = iota TieBreakLost TieBreakTied )
type Decryptor ¶
type Decryptor interface {
IterateFrames([]byte, FrameConsumer) error
}
type EncryptedTCPReceiver ¶
type EncryptedTCPReceiver struct { SimpleTCPReceiver // contains filtered or unexported fields }
func NewEncryptedTCPReceiver ¶
func NewEncryptedTCPReceiver(sessionKey *[32]byte, outbound bool) *EncryptedTCPReceiver
type EncryptedTCPSender ¶
type EncryptedTCPSender struct { SimpleTCPSender sync.RWMutex // contains filtered or unexported fields }
func NewEncryptedTCPSender ¶
func NewEncryptedTCPSender(encoder *gob.Encoder, sessionKey *[32]byte, outbound bool) *EncryptedTCPSender
func (*EncryptedTCPSender) Send ¶
func (sender *EncryptedTCPSender) Send(msg []byte) error
type EthernetDecoder ¶
type EthernetDecoder struct {
// contains filtered or unexported fields
}
func NewEthernetDecoder ¶
func NewEthernetDecoder() *EthernetDecoder
func (*EthernetDecoder) DecodeLayers ¶
func (dec *EthernetDecoder) DecodeLayers(data []byte) error
func (*EthernetDecoder) DropFrame ¶
func (dec *EthernetDecoder) DropFrame() bool
func (*EthernetDecoder) IsSpecial ¶ added in v0.9.0
func (dec *EthernetDecoder) IsSpecial() bool
type FieldValidator ¶ added in v0.10.0
type FieldValidator struct {
// contains filtered or unexported fields
}
func NewFieldValidator ¶ added in v0.10.0
func NewFieldValidator(fields map[string]string) *FieldValidator
func (*FieldValidator) CheckEqual ¶ added in v0.10.0
func (fv *FieldValidator) CheckEqual(fieldName, expectedValue string) error
func (*FieldValidator) Err ¶ added in v0.10.0
func (fv *FieldValidator) Err() error
type ForwardedFrame ¶
type ForwardedFrame struct {
// contains filtered or unexported fields
}
type Forwarder ¶
type Forwarder struct {
// contains filtered or unexported fields
}
func NewForwarder ¶
func NewForwarder(conn *LocalConnection, enc Encryptor, udpSender UDPSender, pmtu int) *Forwarder
func (*Forwarder) Forward ¶ added in v0.10.0
func (fwd *Forwarder) Forward(frame *ForwardedFrame)
type ForwarderDF ¶ added in v0.10.0
type ForwarderDF struct { Forwarder // contains filtered or unexported fields }
func NewForwarderDF ¶ added in v0.10.0
func NewForwarderDF(conn *LocalConnection, enc Encryptor, udpSender UDPSender, pmtu int) *ForwarderDF
func (*ForwarderDF) PMTUVerified ¶ added in v0.10.0
func (fwd *ForwarderDF) PMTUVerified(pmtu int)
func (*ForwarderDF) Start ¶ added in v0.10.0
func (fwd *ForwarderDF) Start()
type FrameConsumer ¶
type FrameTooBigError ¶
type FrameTooBigError struct {
EPMTU int // effective pmtu, i.e. what we tell packet senders
}
func (FrameTooBigError) Error ¶
func (ftbe FrameTooBigError) Error() string
type Gossip ¶ added in v0.9.0
type Gossip interface { // specific message from one peer to another // intermediate peers relay it using unicast topology. GossipUnicast(dstPeerName PeerName, msg []byte) error // send gossip to every peer, relayed using broadcast topology. GossipBroadcast(update GossipData) error }
type GossipChannel ¶ added in v0.9.0
func NewGossipChannel ¶ added in v1.0.0
func NewGossipChannel(channelName string, ourself *LocalPeer, routes *Routes, g Gossiper) *GossipChannel
func (*GossipChannel) GossipBroadcast ¶ added in v0.9.0
func (c *GossipChannel) GossipBroadcast(update GossipData) error
func (*GossipChannel) GossipUnicast ¶ added in v0.9.0
func (c *GossipChannel) GossipUnicast(dstPeerName PeerName, msg []byte) error
func (*GossipChannel) Send ¶ added in v0.10.0
func (c *GossipChannel) Send(srcName PeerName, data GossipData)
func (*GossipChannel) SendDown ¶ added in v0.10.0
func (c *GossipChannel) SendDown(conn Connection, data GossipData)
type GossipChannels ¶ added in v1.0.0
type GossipChannels map[string]*GossipChannel
type GossipData ¶ added in v0.10.0
type GossipData interface { Encode() [][]byte Merge(GossipData) }
type GossipSender ¶ added in v0.10.0
type GossipSender struct {
// contains filtered or unexported fields
}
Accumulates GossipData that needs to be sent to one destination, and sends it when possible.
func NewGossipSender ¶ added in v0.10.0
func NewGossipSender(send func(GossipData)) *GossipSender
func (*GossipSender) Send ¶ added in v0.10.0
func (sender *GossipSender) Send(data GossipData)
func (*GossipSender) Start ¶ added in v0.10.0
func (sender *GossipSender) Start()
func (*GossipSender) Stop ¶ added in v0.10.0
func (sender *GossipSender) Stop()
type Gossiper ¶ added in v0.9.0
type Gossiper interface { OnGossipUnicast(sender PeerName, msg []byte) error // merge received data into state and return a representation of // the received data, for further propagation OnGossipBroadcast(update []byte) (GossipData, error) // return state of everything we know; gets called periodically Gossip() GossipData // merge received data into state and return "everything new I've // just learnt", or nil if nothing in the received data was new OnGossip(update []byte) (GossipData, error) }
type ListOfPeers ¶
type ListOfPeers []*Peer
func (ListOfPeers) Len ¶
func (lop ListOfPeers) Len() int
func (ListOfPeers) Less ¶
func (lop ListOfPeers) Less(i, j int) bool
func (ListOfPeers) Swap ¶
func (lop ListOfPeers) Swap(i, j int)
type LocalConnection ¶
type LocalConnection struct { sync.RWMutex RemoteConnection TCPConn *net.TCPConn SessionKey *[32]byte Decryptor Decryptor Router *Router // contains filtered or unexported fields }
func NewLocalConnection ¶
func NewLocalConnection(connRemote *RemoteConnection, tcpConn *net.TCPConn, udpAddr *net.UDPAddr, router *Router) *LocalConnection
func (*LocalConnection) BreakTie ¶ added in v0.9.0
func (conn *LocalConnection) BreakTie(dupConn Connection) ConnectionTieBreak
func (*LocalConnection) Established ¶
func (conn *LocalConnection) Established() bool
func (*LocalConnection) Forward ¶
func (conn *LocalConnection) Forward(df bool, frame *ForwardedFrame, dec *EthernetDecoder) error
Called from peer.Relay[Broadcast] which is itself invoked from router (both UDP listener process and sniffer process). Also called from connection's heartbeat process, and from the connection's TCP receiver process.
func (*LocalConnection) ReceivedHeartbeat ¶ added in v0.9.0
func (conn *LocalConnection) ReceivedHeartbeat(remoteUDPAddr *net.UDPAddr, connUID uint64)
Async
Heartbeating serves two purposes: a) keeping NAT paths alive, and b) updating a remote peer's knowledge of our address, in the event it changes (e.g. because NAT paths expired).
func (*LocalConnection) RemoteUDPAddr ¶
func (conn *LocalConnection) RemoteUDPAddr() *net.UDPAddr
Read by the forwarder processes when in the UDP senders
func (*LocalConnection) SendProtocolMsg ¶ added in v0.9.0
func (conn *LocalConnection) SendProtocolMsg(m ProtocolMsg)
Send directly, not via the Actor. If it goes via the Actor we can get a deadlock where LocalConnection is blocked talking to LocalPeer and LocalPeer is blocked trying send a ProtocolMsg via LocalConnection, and the channels are full in both directions so nothing can proceed.
func (*LocalConnection) Start ¶ added in v0.9.0
func (conn *LocalConnection) Start(acceptNewPeer bool)
Async. Does not return anything. If the connection is successful, it will end up in the local peer's connections map.
type LocalPeer ¶
func NewLocalPeer ¶ added in v0.9.0
func (*LocalPeer) AddConnection ¶
func (peer *LocalPeer) AddConnection(conn *LocalConnection) error
Sync.
func (*LocalPeer) Broadcast ¶
func (peer *LocalPeer) Broadcast(df bool, frame []byte, dec *EthernetDecoder)
func (*LocalPeer) ConnectionEstablished ¶
func (peer *LocalPeer) ConnectionEstablished(conn *LocalConnection)
Async.
func (*LocalPeer) ConnectionTo ¶ added in v0.11.0
func (peer *LocalPeer) ConnectionTo(name PeerName) (Connection, bool)
func (*LocalPeer) Connections ¶ added in v0.11.0
func (peer *LocalPeer) Connections() ConnectionSet
func (*LocalPeer) ConnectionsTo ¶ added in v0.10.0
func (peer *LocalPeer) ConnectionsTo(names []PeerName) []Connection
func (*LocalPeer) CreateConnection ¶
func (*LocalPeer) DeleteConnection ¶
func (peer *LocalPeer) DeleteConnection(conn *LocalConnection)
Sync.
func (*LocalPeer) RelayBroadcast ¶
func (peer *LocalPeer) RelayBroadcast(srcPeer *Peer, df bool, frame []byte, dec *EthernetDecoder)
type LocalPeerAction ¶ added in v0.10.0
type LocalPeerAction func()
type MacCacheEntry ¶
type MacCacheEntry struct {
// contains filtered or unexported fields
}
type MsgTooBigError ¶
type MsgTooBigError struct {
PMTU int // actual pmtu, i.e. what the kernel told us
}
func (MsgTooBigError) Error ¶
func (mtbe MsgTooBigError) Error() string
type NaClDecryptor ¶
type NaClDecryptor struct { NonDecryptor // contains filtered or unexported fields }
func NewNaClDecryptor ¶
func NewNaClDecryptor(sessionKey *[32]byte, outbound bool) *NaClDecryptor
func (*NaClDecryptor) IterateFrames ¶
func (nd *NaClDecryptor) IterateFrames(packet []byte, consumer FrameConsumer) error
type NaClDecryptorInstance ¶
type NaClDecryptorInstance struct {
// contains filtered or unexported fields
}
func NewNaClDecryptorInstance ¶ added in v0.11.0
func NewNaClDecryptorInstance(outbound bool) *NaClDecryptorInstance
type NaClEncryptor ¶
type NaClEncryptor struct { NonEncryptor // contains filtered or unexported fields }
func NewNaClEncryptor ¶
func NewNaClEncryptor(prefix []byte, sessionKey *[32]byte, outbound bool, df bool) *NaClEncryptor
func (*NaClEncryptor) Bytes ¶
func (ne *NaClEncryptor) Bytes() ([]byte, error)
func (*NaClEncryptor) PacketOverhead ¶
func (ne *NaClEncryptor) PacketOverhead() int
func (*NaClEncryptor) TotalLen ¶
func (ne *NaClEncryptor) TotalLen() int
type NameCollisionError ¶
type NameCollisionError struct {
Name PeerName
}
func (NameCollisionError) Error ¶
func (nce NameCollisionError) Error() string
type NonDecryptor ¶
type NonDecryptor struct { }
func NewNonDecryptor ¶
func NewNonDecryptor() *NonDecryptor
func (*NonDecryptor) IterateFrames ¶
func (nd *NonDecryptor) IterateFrames(packet []byte, consumer FrameConsumer) error
type NonEncryptor ¶
type NonEncryptor struct {
// contains filtered or unexported fields
}
func NewNonEncryptor ¶
func NewNonEncryptor(prefix []byte) *NonEncryptor
func (*NonEncryptor) AppendFrame ¶
func (ne *NonEncryptor) AppendFrame(src []byte, dst []byte, frame []byte)
func (*NonEncryptor) Bytes ¶
func (ne *NonEncryptor) Bytes() ([]byte, error)
func (*NonEncryptor) FrameOverhead ¶
func (ne *NonEncryptor) FrameOverhead() int
func (*NonEncryptor) IsEmpty ¶
func (ne *NonEncryptor) IsEmpty() bool
func (*NonEncryptor) PacketOverhead ¶
func (ne *NonEncryptor) PacketOverhead() int
func (*NonEncryptor) TotalLen ¶
func (ne *NonEncryptor) TotalLen() int
type PacketDecodingError ¶
type PacketDecodingError struct {
Desc string
}
func (PacketDecodingError) Error ¶
func (pde PacketDecodingError) Error() string
type PacketSink ¶
func NewPcapO ¶
func NewPcapO(ifName string) (po PacketSink, err error)
type PacketSource ¶
type PacketSourceSink ¶
type PacketSourceSink interface { PacketSource PacketSink }
type PcapIO ¶
type PcapIO struct {
// contains filtered or unexported fields
}
func (*PcapIO) ReadPacket ¶
func (*PcapIO) WritePacket ¶
type Peer ¶
type Peer struct { Name PeerName NameByte []byte NickName string UID PeerUID // contains filtered or unexported fields }
func (*Peer) ForEachConnectedPeer ¶ added in v0.11.0
func (*Peer) Routes ¶
Calculate the routing table from this peer to all peers reachable from it, returning a "next hop" map of PeerNameX -> PeerNameY, which says "in order to send a message to X, the peer should send the message to its neighbour Y".
Because currently we do not have weightings on the connections between peers, there is no need to use a minimum spanning tree algorithm. Instead we employ the simpler and cheaper breadth-first widening. The computation is deterministic, which ensures that when it is performed on the same data by different peers, they get the same result. This is important since otherwise we risk message loss or routing cycles.
When the 'establishedAndSymmetric' flag is set, only connections that are marked as 'established' and are symmetric (i.e. where both sides indicate they have a connection to the other) are considered.
When a non-nil stopAt peer is supplied, the widening stops when it reaches that peer. The boolean return indicates whether that has happened.
NB: This function should generally be invoked while holding a read lock on Peers and LocalPeer.
type PeerName ¶
type PeerName uint64
PeerName is used as a map key. Since net.HardwareAddr isn't suitable for that - it's a slice, and slices can't be map keys - we convert that to/from uint64.
func PeerNameFromBin ¶
func PeerNameFromString ¶
func PeerNameFromUserInput ¶
func (PeerName) MarshalJSON ¶ added in v0.10.0
type PeerNameSet ¶ added in v0.10.0
type PeerNameSet map[PeerName]struct{}
type PeerSummary ¶ added in v0.11.0
type Peers ¶
func (*Peers) ApplyUpdate ¶
func (peers *Peers) ApplyUpdate(update []byte) (PeerNameSet, PeerNameSet, error)
Merge an incoming update with our own topology.
We add peers hitherto unknown to us, and update peers for which the update contains a more recent version than known to us. The return value is a) a representation of the received update, and b) an "improved" update containing just these new/updated elements.
func (*Peers) Dereference ¶ added in v0.11.0
func (*Peers) EncodePeers ¶ added in v0.10.0
func (peers *Peers) EncodePeers(names PeerNameSet) []byte
func (*Peers) FetchWithDefault ¶
func (*Peers) GarbageCollect ¶
func (*Peers) MarshalJSON ¶ added in v0.10.0
func (*Peers) Names ¶ added in v0.10.0
func (peers *Peers) Names() PeerNameSet
type ProtocolMsg ¶ added in v0.9.0
type ProtocolMsg struct {
// contains filtered or unexported fields
}
type ProtocolSender ¶ added in v0.9.0
type ProtocolSender interface {
SendProtocolMsg(m ProtocolMsg)
}
type ProtocolTag ¶ added in v0.9.0
type ProtocolTag byte
const ( ProtocolHeartbeat ProtocolTag = iota ProtocolConnectionEstablished ProtocolFragmentationReceived ProtocolPMTUVerified ProtocolGossip ProtocolGossipUnicast ProtocolGossipBroadcast )
type RawUDPSender ¶
type RawUDPSender struct {
// contains filtered or unexported fields
}
func NewRawUDPSender ¶
func NewRawUDPSender(conn *LocalConnection) (*RawUDPSender, error)
func (*RawUDPSender) Send ¶
func (sender *RawUDPSender) Send(msg []byte) error
func (*RawUDPSender) Shutdown ¶
func (sender *RawUDPSender) Shutdown() error
type RemoteConnection ¶
type RemoteConnection struct {
// contains filtered or unexported fields
}
func NewRemoteConnection ¶
func NewRemoteConnection(from, to *Peer, tcpAddr string, outbound bool, established bool) *RemoteConnection
func (*RemoteConnection) BreakTie ¶ added in v0.9.0
func (conn *RemoteConnection) BreakTie(Connection) ConnectionTieBreak
func (*RemoteConnection) Established ¶
func (conn *RemoteConnection) Established() bool
func (*RemoteConnection) Local ¶
func (conn *RemoteConnection) Local() *Peer
func (*RemoteConnection) Log ¶ added in v0.10.0
func (conn *RemoteConnection) Log(args ...interface{})
func (*RemoteConnection) MarshalJSON ¶ added in v0.10.0
func (conn *RemoteConnection) MarshalJSON() ([]byte, error)
func (*RemoteConnection) Outbound ¶ added in v0.10.0
func (conn *RemoteConnection) Outbound() bool
func (*RemoteConnection) Remote ¶
func (conn *RemoteConnection) Remote() *Peer
func (*RemoteConnection) RemoteTCPAddr ¶
func (conn *RemoteConnection) RemoteTCPAddr() string
func (*RemoteConnection) Shutdown ¶
func (conn *RemoteConnection) Shutdown(error)
func (*RemoteConnection) String ¶
func (conn *RemoteConnection) String() string
type Router ¶
type Router struct { Config Ourself *LocalPeer Macs *MacCache Peers *Peers Routes *Routes ConnectionMaker *ConnectionMaker TopologyGossip Gossip UDPListener *net.UDPConn // contains filtered or unexported fields }
func (*Router) Gossip ¶ added in v0.9.0
func (router *Router) Gossip() GossipData
func (*Router) OnGossip ¶ added in v0.9.0
func (router *Router) OnGossip(update []byte) (GossipData, error)
func (*Router) OnGossipBroadcast ¶ added in v0.9.0
func (router *Router) OnGossipBroadcast(update []byte) (GossipData, error)
func (*Router) OnGossipUnicast ¶ added in v0.9.0
func (*Router) SendAllGossip ¶ added in v0.9.0
func (router *Router) SendAllGossip()
func (*Router) SendAllGossipDown ¶ added in v0.9.0
func (router *Router) SendAllGossipDown(conn Connection)
func (*Router) StatusJSON ¶ added in v0.11.0
func (*Router) UsingPassword ¶
type Routes ¶
func (*Routes) BroadcastAll ¶ added in v0.10.0
func (*Routes) EnsureRecalculated ¶ added in v0.10.0
func (routes *Routes) EnsureRecalculated()
Wait for any preceding Recalculate requests to be processed.
func (*Routes) MarshalJSON ¶ added in v0.10.0
func (*Routes) PeerNames ¶ added in v0.10.0
func (routes *Routes) PeerNames() PeerNameSet
func (*Routes) RandomNeighbours ¶ added in v0.10.0
func (routes *Routes) RandomNeighbours(except PeerName) PeerNameSet
Choose min(log2(n_peers), n_neighbouring_peers) neighbours, with a random distribution that is topology-sensitive, favouring neighbours at the end of "bottleneck links". We determine the latter based on the unicast routing table. If a neighbour appears as the value more frequently than others - meaning that we reach a higher proportion of peers via that neighbour than other neighbours - then it is chosen with a higher probability.
Note that we choose log2(n_peers) *neighbours*, not peers. Consequently, on sparsely connected peers this function returns a higher proportion of neighbours than elsewhere. In extremis, on peers with fewer than log2(n_peers) neighbours, all neighbours are returned.
func (*Routes) Recalculate ¶
func (routes *Routes) Recalculate()
Request recalculation of the routing table. This is async but can effectively be made synchronous with a subsequent call to EnsureRecalculated.
type SimpleTCPReceiver ¶
type SimpleTCPReceiver struct { }
func NewSimpleTCPReceiver ¶
func NewSimpleTCPReceiver() *SimpleTCPReceiver
type SimpleTCPSender ¶
type SimpleTCPSender struct {
// contains filtered or unexported fields
}
func NewSimpleTCPSender ¶
func NewSimpleTCPSender(encoder *gob.Encoder) *SimpleTCPSender
func (*SimpleTCPSender) Send ¶
func (sender *SimpleTCPSender) Send(msg []byte) error
type SimpleUDPSender ¶
type SimpleUDPSender struct {
// contains filtered or unexported fields
}
func NewSimpleUDPSender ¶
func NewSimpleUDPSender(conn *LocalConnection) *SimpleUDPSender
func (*SimpleUDPSender) Send ¶
func (sender *SimpleUDPSender) Send(msg []byte) error
func (*SimpleUDPSender) Shutdown ¶
func (sender *SimpleUDPSender) Shutdown() error
type SurrogateGossipData ¶ added in v1.0.0
type SurrogateGossipData struct {
// contains filtered or unexported fields
}
func NewSurrogateGossipData ¶ added in v1.0.0
func NewSurrogateGossipData(msg []byte) *SurrogateGossipData
func (*SurrogateGossipData) Encode ¶ added in v1.0.0
func (d *SurrogateGossipData) Encode() [][]byte
func (*SurrogateGossipData) Merge ¶ added in v1.0.0
func (d *SurrogateGossipData) Merge(other GossipData)
type SurrogateGossiper ¶ added in v1.0.0
type SurrogateGossiper struct{}
func (*SurrogateGossiper) Gossip ¶ added in v1.0.0
func (*SurrogateGossiper) Gossip() GossipData
func (*SurrogateGossiper) OnGossip ¶ added in v1.0.0
func (*SurrogateGossiper) OnGossip(update []byte) (GossipData, error)
func (*SurrogateGossiper) OnGossipBroadcast ¶ added in v1.0.0
func (*SurrogateGossiper) OnGossipBroadcast(update []byte) (GossipData, error)
func (*SurrogateGossiper) OnGossipUnicast ¶ added in v1.0.0
func (*SurrogateGossiper) OnGossipUnicast(sender PeerName, msg []byte) error
type TCPCryptoState ¶ added in v0.11.0
type TCPCryptoState struct {
// contains filtered or unexported fields
}
The lowest 64 bits of the nonce contain the message sequence number. The top most bit indicates the connection polarity at the sender - '1' for outbound; the next indicates protocol type - '1' for TCP. The remaining 126 bits are zero. The polarity is needed so that the two ends of a connection do not use the same nonces; the protocol type so that the TCP and UDP sender nonces are disjoint. This is a requirement of the NaCl Security Model; see http://nacl.cr.yp.to/box.html.
func NewTCPCryptoState ¶ added in v0.11.0
func NewTCPCryptoState(sessionKey *[32]byte, outbound bool) *TCPCryptoState
type TCPReceiver ¶
type Target ¶
type Target struct {
// contains filtered or unexported fields
}
Information about an address where we may find a peer
func (Target) MarshalJSON ¶ added in v1.0.0
type TokenBucket ¶ added in v1.0.2
type TokenBucket struct {
// contains filtered or unexported fields
}
func NewTokenBucket ¶ added in v1.0.2
func NewTokenBucket(capacity int64, tokenInterval time.Duration) *TokenBucket
func (*TokenBucket) Wait ¶ added in v1.0.2
func (tb *TokenBucket) Wait()
type TopologyGossipData ¶ added in v0.10.0
type TopologyGossipData struct {
// contains filtered or unexported fields
}
func NewTopologyGossipData ¶ added in v0.10.0
func NewTopologyGossipData(peers *Peers, update ...*Peer) *TopologyGossipData
func (*TopologyGossipData) Encode ¶ added in v0.10.0
func (d *TopologyGossipData) Encode() [][]byte
func (*TopologyGossipData) Merge ¶ added in v0.10.0
func (d *TopologyGossipData) Merge(other GossipData)
type UnknownPeerError ¶ added in v0.9.0
type UnknownPeerError struct {
Name PeerName
}
func (UnknownPeerError) Error ¶ added in v0.9.0
func (upe UnknownPeerError) Error() string