Documentation ¶
Index ¶
- Constants
- Variables
- func FormSessionKey(remotePublicKey, localPrivateKey *[32]byte, secretKey []byte) *[32]byte
- func GenerateKeyPair() (publicKey, privateKey *[32]byte, err error)
- func GobEncode(items ...interface{}) []byte
- func NewTargetSlice(cm *ConnectionMaker) []string
- func NewTrustedSubnetsSlice(trustedSubnets []*net.IPNet) []string
- func StartLocalConnection(connRemote *RemoteConnection, tcpConn *net.TCPConn, router *Router, ...)
- type BroadcastRouteStatus
- type Config
- type Connection
- type ConnectionAction
- type ConnectionMaker
- func (cm *ConnectionMaker) ConnectionAborted(address string, err error)
- func (cm *ConnectionMaker) ConnectionCreated(conn Connection)
- func (cm *ConnectionMaker) ConnectionTerminated(conn Connection, err error)
- func (cm *ConnectionMaker) ForgetConnections(peers []string)
- func (cm *ConnectionMaker) InitiateConnections(peers []string, replace bool) []error
- func (cm *ConnectionMaker) Refresh()
- type ConnectionMakerAction
- type ConnectionSet
- type ConnectionStatus
- type ConnectionSummary
- type ConnectionTieBreak
- type EncryptedTCPReceiver
- type EncryptedTCPSender
- type GobTCPReceiver
- type GobTCPSender
- type Gossip
- type GossipChannel
- type GossipChannels
- type GossipData
- type GossipSender
- type Gossiper
- type LengthPrefixTCPReceiver
- type LengthPrefixTCPSender
- type ListOfPeers
- type LocalConnection
- type LocalConnectionStatus
- type LocalPeer
- func (peer *LocalPeer) AddConnection(conn *LocalConnection) error
- 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)
- type LocalPeerAction
- type NullOverlay
- func (NullOverlay) AddFeaturesTo(map[string]string)
- func (NullOverlay) Confirm()
- func (NullOverlay) ControlMessage(byte, []byte)
- func (NullOverlay) Diagnostics() interface{}
- func (NullOverlay) DisplayName() string
- func (NullOverlay) ErrorChannel() <-chan error
- func (NullOverlay) EstablishedChannel() <-chan struct{}
- func (NullOverlay) PrepareConnection(OverlayConnectionParams) (OverlayConnection, error)
- func (NullOverlay) Stop()
- type Overlay
- type OverlayConnection
- type OverlayConnectionParams
- type Peer
- type PeerName
- type PeerNameSet
- type PeerShortID
- type PeerStatus
- 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
- func (peers *Peers) FetchAndAddRef(name PeerName) *Peer
- func (peers *Peers) FetchByShortID(shortID PeerShortID) *Peer
- func (peers *Peers) FetchWithDefault(peer *Peer) *Peer
- func (peers *Peers) ForEach(fun func(*Peer))
- func (peers *Peers) GarbageCollect()
- func (peers *Peers) Names() PeerNameSet
- func (peers *Peers) OnGC(callback func(*Peer))
- func (peers *Peers) OnInvalidateShortIDs(callback func())
- type PeersPendingNotifications
- type ProtocolIntroConn
- type ProtocolIntroParams
- type ProtocolIntroResults
- type ProtocolMsg
- type ProtocolSender
- type ProtocolTag
- type RemoteConnection
- func (conn *RemoteConnection) BreakTie(Connection) ConnectionTieBreak
- func (conn *RemoteConnection) ErrorLog(args ...interface{})
- func (conn *RemoteConnection) Established() bool
- func (conn *RemoteConnection) Local() *Peer
- func (conn *RemoteConnection) Log(args ...interface{})
- func (conn *RemoteConnection) Outbound() bool
- func (conn *RemoteConnection) Remote() *Peer
- func (conn *RemoteConnection) RemoteTCPAddr() string
- func (conn *RemoteConnection) Shutdown(error)
- type Router
- func (router *Router) BroadcastTopologyUpdate(update []*Peer)
- 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(_ PeerName, 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) Stop() error
- func (router *Router) Trusts(remote *RemoteConnection) bool
- 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) OnChange(callback func())
- func (routes *Routes) PeerNames() PeerNameSet
- func (routes *Routes) RandomNeighbours(except PeerName) []PeerName
- func (routes *Routes) Recalculate()
- func (routes *Routes) Unicast(name PeerName) (PeerName, bool)
- func (routes *Routes) UnicastAll(name PeerName) (PeerName, bool)
- type ShortIDPeers
- type Status
- type SurrogateGossipData
- type SurrogateGossiper
- type TCPCryptoState
- type TCPReceiver
- type TCPSender
- type Target
- type TargetState
- type TokenBucket
- type TopologyGossipData
- type UnicastRouteStatus
Constants ¶
const ( InitialInterval = 2 * time.Second MaxInterval = 6 * time.Minute ResetAfter = 1 * time.Minute )
const ( PeerNameFlavour = "mac" NameSize = 6 UnknownPeerName = PeerName(0) )
const ( Protocol = "weave" ProtocolMinVersion = 1 ProtocolMaxVersion = 2 )
const ( ProtocolHeartbeat = iota ProtocolReserved1 // legacy overlay control messages ProtocolReserved2 // ProtocolReserved3 // ProtocolGossip ProtocolGossipUnicast ProtocolGossipBroadcast ProtocolOverlayControlMsg )
const ( Port = 6783 ChannelSize = 16 TCPHeartbeat = 30 * time.Second GossipInterval = 30 * time.Second MaxDuration = time.Duration(math.MaxInt64) )
const MaxTCPMsgSize = 10 * 1024 * 1024
const PeerShortIDBits = 12
Variables ¶
var ( ProtocolBytes = []byte(Protocol) HeaderTimeout = 10 * time.Second ProtocolV1Features = []string{ "ConnID", "Name", "NickName", "PeerNameFlavour", "UID", } ErrExpectedCrypto = fmt.Errorf("Password specified, but peer requested an unencrypted connection") ErrExpectedNoCrypto = fmt.Errorf("No password specificed, but peer requested an encrypted connection") )
var ErrConnectToSelf = fmt.Errorf("Cannot connect to ourself")
Functions ¶
func FormSessionKey ¶
func GenerateKeyPair ¶
func NewTargetSlice ¶
func NewTargetSlice(cm *ConnectionMaker) []string
func NewTrustedSubnetsSlice ¶ added in v1.4.0
func StartLocalConnection ¶
func StartLocalConnection(connRemote *RemoteConnection, tcpConn *net.TCPConn, router *Router, acceptNewPeer bool)
Does not return anything. If the connection is successful, it will end up in the local peer's connections map.
Types ¶
type BroadcastRouteStatus ¶
func NewBroadcastRouteStatusSlice ¶
func NewBroadcastRouteStatusSlice(routes *Routes) []BroadcastRouteStatus
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 ¶
type ConnectionAction func() error
type ConnectionMaker ¶
type ConnectionMaker struct {
// contains filtered or unexported fields
}
func NewConnectionMaker ¶
func NewConnectionMaker(ourself *LocalPeer, peers *Peers, port int, discovery bool) *ConnectionMaker
func (*ConnectionMaker) ConnectionAborted ¶
func (cm *ConnectionMaker) ConnectionAborted(address string, err error)
func (*ConnectionMaker) ConnectionCreated ¶
func (cm *ConnectionMaker) ConnectionCreated(conn Connection)
func (*ConnectionMaker) ConnectionTerminated ¶
func (cm *ConnectionMaker) ConnectionTerminated(conn Connection, err error)
func (*ConnectionMaker) ForgetConnections ¶
func (cm *ConnectionMaker) ForgetConnections(peers []string)
func (*ConnectionMaker) InitiateConnections ¶
func (cm *ConnectionMaker) InitiateConnections(peers []string, replace bool) []error
func (*ConnectionMaker) Refresh ¶
func (cm *ConnectionMaker) Refresh()
type ConnectionMakerAction ¶
type ConnectionMakerAction func() bool
type ConnectionSet ¶
type ConnectionSet map[Connection]struct{}
type ConnectionStatus ¶
type ConnectionSummary ¶
type ConnectionTieBreak ¶
type ConnectionTieBreak int
const ( TieBreakWon ConnectionTieBreak = iota TieBreakLost TieBreakTied )
type EncryptedTCPReceiver ¶
type EncryptedTCPReceiver struct {
// contains filtered or unexported fields
}
func NewEncryptedTCPReceiver ¶
func NewEncryptedTCPReceiver(receiver TCPReceiver, sessionKey *[32]byte, outbound bool) *EncryptedTCPReceiver
func (*EncryptedTCPReceiver) Receive ¶
func (receiver *EncryptedTCPReceiver) Receive() ([]byte, error)
type EncryptedTCPSender ¶
func NewEncryptedTCPSender ¶
func NewEncryptedTCPSender(sender TCPSender, sessionKey *[32]byte, outbound bool) *EncryptedTCPSender
func (*EncryptedTCPSender) Send ¶
func (sender *EncryptedTCPSender) Send(msg []byte) error
type GobTCPReceiver ¶
type GobTCPReceiver struct {
// contains filtered or unexported fields
}
func NewGobTCPReceiver ¶
func NewGobTCPReceiver(decoder *gob.Decoder) *GobTCPReceiver
func (*GobTCPReceiver) Receive ¶
func (receiver *GobTCPReceiver) Receive() ([]byte, error)
type GobTCPSender ¶
type GobTCPSender struct {
// contains filtered or unexported fields
}
func NewGobTCPSender ¶
func NewGobTCPSender(encoder *gob.Encoder) *GobTCPSender
func (*GobTCPSender) Send ¶
func (sender *GobTCPSender) Send(msg []byte) error
type Gossip ¶
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 ¶
func NewGossipChannel ¶
func NewGossipChannel(channelName string, ourself *LocalPeer, routes *Routes, g Gossiper) *GossipChannel
func (*GossipChannel) GossipBroadcast ¶
func (c *GossipChannel) GossipBroadcast(update GossipData) error
func (*GossipChannel) GossipUnicast ¶
func (c *GossipChannel) GossipUnicast(dstPeerName PeerName, msg []byte) error
func (*GossipChannel) Send ¶
func (c *GossipChannel) Send(srcName PeerName, data GossipData)
func (*GossipChannel) SendDown ¶
func (c *GossipChannel) SendDown(conn Connection, data GossipData)
type GossipChannels ¶
type GossipChannels map[string]*GossipChannel
type GossipData ¶
type GossipData interface { Encode() [][]byte Merge(GossipData) GossipData }
type GossipSender ¶
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 ¶
func NewGossipSender(send func(GossipData)) *GossipSender
func (*GossipSender) Send ¶
func (sender *GossipSender) Send(data GossipData)
func (*GossipSender) Stop ¶
func (sender *GossipSender) Stop()
type Gossiper ¶
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(sender PeerName, 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 LengthPrefixTCPReceiver ¶
type LengthPrefixTCPReceiver struct {
// contains filtered or unexported fields
}
func NewLengthPrefixTCPReceiver ¶
func NewLengthPrefixTCPReceiver(reader io.Reader) *LengthPrefixTCPReceiver
func (*LengthPrefixTCPReceiver) Receive ¶
func (receiver *LengthPrefixTCPReceiver) Receive() ([]byte, error)
type LengthPrefixTCPSender ¶
type LengthPrefixTCPSender struct {
// contains filtered or unexported fields
}
func NewLengthPrefixTCPSender ¶
func NewLengthPrefixTCPSender(writer io.Writer) *LengthPrefixTCPSender
func (*LengthPrefixTCPSender) Send ¶
func (sender *LengthPrefixTCPSender) Send(msg []byte) 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 TrustRemote bool // is remote on a trusted subnet? TrustedByRemote bool // does remote trust us? SessionKey *[32]byte Router *Router OverlayConn OverlayConnection // contains filtered or unexported fields }
func (*LocalConnection) BreakTie ¶
func (conn *LocalConnection) BreakTie(dupConn Connection) ConnectionTieBreak
func (*LocalConnection) Established ¶
func (conn *LocalConnection) Established() bool
func (*LocalConnection) SendProtocolMsg ¶
func (conn *LocalConnection) SendProtocolMsg(m ProtocolMsg)
func (*LocalConnection) Untrusted ¶ added in v1.4.0
func (conn *LocalConnection) Untrusted() bool
type LocalConnectionStatus ¶
func NewLocalConnectionStatusSlice ¶
func NewLocalConnectionStatusSlice(cm *ConnectionMaker) []LocalConnectionStatus
type LocalPeer ¶
func (*LocalPeer) AddConnection ¶
func (peer *LocalPeer) AddConnection(conn *LocalConnection) error
Sync.
func (*LocalPeer) ConnectionEstablished ¶
func (peer *LocalPeer) ConnectionEstablished(conn *LocalConnection)
Async.
func (*LocalPeer) ConnectionTo ¶
func (peer *LocalPeer) ConnectionTo(name PeerName) (Connection, bool)
func (*LocalPeer) Connections ¶
func (peer *LocalPeer) Connections() ConnectionSet
func (*LocalPeer) ConnectionsTo ¶
func (peer *LocalPeer) ConnectionsTo(names []PeerName) []Connection
func (*LocalPeer) CreateConnection ¶
func (*LocalPeer) DeleteConnection ¶
func (peer *LocalPeer) DeleteConnection(conn *LocalConnection)
Sync.
type LocalPeerAction ¶
type LocalPeerAction func()
type NullOverlay ¶
type NullOverlay struct{}
func (NullOverlay) AddFeaturesTo ¶
func (NullOverlay) AddFeaturesTo(map[string]string)
func (NullOverlay) Confirm ¶
func (NullOverlay) Confirm()
func (NullOverlay) ControlMessage ¶
func (NullOverlay) ControlMessage(byte, []byte)
func (NullOverlay) Diagnostics ¶
func (NullOverlay) Diagnostics() interface{}
func (NullOverlay) DisplayName ¶
func (NullOverlay) DisplayName() string
func (NullOverlay) ErrorChannel ¶
func (NullOverlay) ErrorChannel() <-chan error
func (NullOverlay) EstablishedChannel ¶
func (NullOverlay) EstablishedChannel() <-chan struct{}
func (NullOverlay) PrepareConnection ¶
func (NullOverlay) PrepareConnection(OverlayConnectionParams) (OverlayConnection, error)
func (NullOverlay) Stop ¶
func (NullOverlay) Stop()
type Overlay ¶
type Overlay interface { // Enhance a features map with overlay-related features AddFeaturesTo(map[string]string) // Prepare on overlay connection. The connection should remain // passive until it has been Confirm()ed. PrepareConnection(OverlayConnectionParams) (OverlayConnection, error) // Obtain diagnostic information specific to the overlay Diagnostics() interface{} }
type OverlayConnection ¶
type OverlayConnection interface { // Confirm that the connection is really wanted, and so the // Overlay should begin heartbeats etc. to verify the operation of // the overlay connection. Confirm() // A channel indicating that the overlay connection is // established, i.e. its operation has been confirmed. EstablishedChannel() <-chan struct{} // A channel indicating an error from the overlay connection. The // overlay connection is not expected to be operational after the // first error, so the channel only needs to buffer a single // error. ErrorChannel() <-chan error Stop() // Handle a message from the peer. 'tag' exists for // compatibility, and should always be // ProtocolOverlayControlMessage for non-sleeve overlays. ControlMessage(tag byte, msg []byte) // User facing overlay name DisplayName() string }
All of the machinery to manage overlay connectivity to a particular peer
type OverlayConnectionParams ¶
type OverlayConnectionParams struct { RemotePeer *Peer // The local address of the corresponding TCP connection. Used to // derive the local IP address for sending. May differ for // different overlay connections. LocalAddr *net.TCPAddr // The remote address of the corresponding TCP connection. Used to // determine the address to send to, but only if the TCP // connection is outbound. Otherwise the Overlay needs to discover // it (e.g. from incoming datagrams). RemoteAddr *net.TCPAddr // Is the corresponding TCP connection outbound? Outbound bool // Unique identifier for this connection ConnUID uint64 // Session key, if connection is encrypted; nil otherwise. // // NB: overlay connections must take care not to use nonces which // may collide with those of the main connection. These nonces are // 192 bits, with the top most bit unspecified, the next bit set // to 1, followed by 126 zero bits, and a message sequence number // in the lowest 64 bits. SessionKey *[32]byte // Function to send a control message to the counterpart // overlay connection. SendControlMessage func(tag byte, msg []byte) error // Features passed at connection initiation Features map[string]string }
type Peer ¶
type Peer struct { Name PeerName PeerSummary // contains filtered or unexported fields }
func NewPeerFrom ¶
func NewPeerFromSummary ¶
func NewPeerFromSummary(summary PeerSummary) *Peer
func NewPeerPlaceholder ¶ added in v1.4.0
func (*Peer) ForEachConnectedPeer ¶
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 ¶
type PeerNameSet ¶
type PeerNameSet map[PeerName]struct{}
type PeerShortID ¶
type PeerShortID uint16
Short IDs exist for the sake of fast datapath. They are 12 bits, randomly assigned, but we detect and recover from collisions. This does limit us to 4096 peers, but that should be sufficient for a while.
type PeerStatus ¶
type PeerStatus struct { Name string NickName string UID PeerUID ShortID PeerShortID Version uint64 Connections []ConnectionStatus }
func NewPeerStatusSlice ¶
func NewPeerStatusSlice(peers *Peers) []PeerStatus
type PeerSummary ¶
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 ¶
func (*Peers) EncodePeers ¶
func (peers *Peers) EncodePeers(names PeerNameSet) []byte
func (*Peers) FetchAndAddRef ¶
func (*Peers) FetchByShortID ¶
func (peers *Peers) FetchByShortID(shortID PeerShortID) *Peer
func (*Peers) FetchWithDefault ¶
func (*Peers) GarbageCollect ¶
func (peers *Peers) GarbageCollect()
func (*Peers) Names ¶
func (peers *Peers) Names() PeerNameSet
func (*Peers) OnInvalidateShortIDs ¶
func (peers *Peers) OnInvalidateShortIDs(callback func())
type PeersPendingNotifications ¶
type PeersPendingNotifications struct {
// contains filtered or unexported fields
}
Pending notifications due to changes to Peers that need to be sent out once the Peers is unlocked.
type ProtocolIntroConn ¶
type ProtocolIntroConn interface { // io.Reader Read(b []byte) (n int, err error) // io.Writer Write(b []byte) (n int, err error) // net.Conn's deadline methods SetDeadline(t time.Time) error SetReadDeadline(t time.Time) error SetWriteDeadline(t time.Time) error }
We don't need the full net.TCPConn to do the protocol intro. This interface contains just the parts we do need, to support testing
type ProtocolIntroParams ¶
type ProtocolIntroParams struct { MinVersion byte MaxVersion byte Features map[string]string Conn ProtocolIntroConn Password []byte Outbound bool }
func (ProtocolIntroParams) DoIntro ¶
func (params ProtocolIntroParams) DoIntro() (res ProtocolIntroResults, err error)
type ProtocolIntroResults ¶
type ProtocolMsg ¶
type ProtocolMsg struct {
// contains filtered or unexported fields
}
type ProtocolSender ¶
type ProtocolSender interface {
SendProtocolMsg(m ProtocolMsg)
}
type ProtocolTag ¶
type ProtocolTag byte
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 ¶
func (conn *RemoteConnection) BreakTie(Connection) ConnectionTieBreak
func (*RemoteConnection) ErrorLog ¶
func (conn *RemoteConnection) ErrorLog(args ...interface{})
func (*RemoteConnection) Established ¶
func (conn *RemoteConnection) Established() bool
func (*RemoteConnection) Local ¶
func (conn *RemoteConnection) Local() *Peer
func (*RemoteConnection) Log ¶
func (conn *RemoteConnection) Log(args ...interface{})
func (*RemoteConnection) Outbound ¶
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)
type Router ¶
type Router struct { Config Overlay Overlay Ourself *LocalPeer Peers *Peers Routes *Routes ConnectionMaker *ConnectionMaker TopologyGossip Gossip // contains filtered or unexported fields }
func (*Router) BroadcastTopologyUpdate ¶
func (*Router) Gossip ¶
func (router *Router) Gossip() GossipData
func (*Router) OnGossipBroadcast ¶
func (router *Router) OnGossipBroadcast(_ PeerName, update []byte) (GossipData, error)
func (*Router) OnGossipUnicast ¶
func (*Router) SendAllGossip ¶
func (router *Router) SendAllGossip()
func (*Router) SendAllGossipDown ¶
func (router *Router) SendAllGossipDown(conn Connection)
func (*Router) Start ¶
func (router *Router) Start()
Start listening for TCP connections. This is separate from NewRouter so that gossipers can register before we start forming connections.
func (*Router) Trusts ¶ added in v1.4.0
func (router *Router) Trusts(remote *RemoteConnection) bool
func (*Router) UsingPassword ¶
type Routes ¶
func (*Routes) BroadcastAll ¶
func (*Routes) EnsureRecalculated ¶
func (routes *Routes) EnsureRecalculated()
Wait for any preceding Recalculate requests to be processed.
func (*Routes) PeerNames ¶
func (routes *Routes) PeerNames() PeerNameSet
func (*Routes) RandomNeighbours ¶
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 ShortIDPeers ¶
type ShortIDPeers struct {
// contains filtered or unexported fields
}
type Status ¶
type Status struct { Protocol string ProtocolMinVersion int ProtocolMaxVersion int Encryption bool PeerDiscovery bool Name string NickName string Port int Peers []PeerStatus UnicastRoutes []UnicastRouteStatus BroadcastRoutes []BroadcastRouteStatus Connections []LocalConnectionStatus Targets []string OverlayDiagnostics interface{} TrustedSubnets []string }
type SurrogateGossipData ¶
type SurrogateGossipData struct {
// contains filtered or unexported fields
}
func NewSurrogateGossipData ¶
func NewSurrogateGossipData(msg []byte) *SurrogateGossipData
func (*SurrogateGossipData) Encode ¶
func (d *SurrogateGossipData) Encode() [][]byte
func (*SurrogateGossipData) Merge ¶
func (d *SurrogateGossipData) Merge(other GossipData) GossipData
type SurrogateGossiper ¶
type SurrogateGossiper struct{}
func (*SurrogateGossiper) Gossip ¶
func (*SurrogateGossiper) Gossip() GossipData
func (*SurrogateGossiper) OnGossip ¶
func (*SurrogateGossiper) OnGossip(update []byte) (GossipData, error)
func (*SurrogateGossiper) OnGossipBroadcast ¶
func (*SurrogateGossiper) OnGossipBroadcast(_ PeerName, update []byte) (GossipData, error)
func (*SurrogateGossiper) OnGossipUnicast ¶
func (*SurrogateGossiper) OnGossipUnicast(sender PeerName, msg []byte) error
type TCPCryptoState ¶
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 connection nonces are distinct from nonces used by overlay connections, if they share the session key. This is a requirement of the NaCl Security Model; see http://nacl.cr.yp.to/box.html.
func NewTCPCryptoState ¶
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
type TargetState ¶
type TargetState int
const ( TargetWaiting TargetState = iota // we are waiting to connect there TargetAttempting // we are attempting to connect there TargetConnected // we are connected to there )
type TokenBucket ¶
type TokenBucket struct {
// contains filtered or unexported fields
}
func NewTokenBucket ¶
func NewTokenBucket(capacity int64, tokenInterval time.Duration) *TokenBucket
func (*TokenBucket) Wait ¶
func (tb *TokenBucket) Wait()
type TopologyGossipData ¶
type TopologyGossipData struct {
// contains filtered or unexported fields
}
func (*TopologyGossipData) Encode ¶
func (d *TopologyGossipData) Encode() [][]byte
func (*TopologyGossipData) Merge ¶
func (d *TopologyGossipData) Merge(other GossipData) GossipData
type UnicastRouteStatus ¶
type UnicastRouteStatus struct {
Dest, Via string
}
func NewUnicastRouteStatusSlice ¶
func NewUnicastRouteStatusSlice(routes *Routes) []UnicastRouteStatus