mesh

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2016 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InitialInterval = 2 * time.Second
	MaxInterval     = 6 * time.Minute
	ResetAfter      = 1 * time.Minute
)
View Source
const (
	PeerNameFlavour = "mac"
	NameSize        = 6
	UnknownPeerName = PeerName(0)
)
View Source
const (
	Protocol           = "weave"
	ProtocolMinVersion = 1
	ProtocolMaxVersion = 2
)
View Source
const (
	ProtocolHeartbeat = iota
	ProtocolReserved1 // legacy overlay control messages
	ProtocolReserved2 //
	ProtocolReserved3 //
	ProtocolGossip
	ProtocolGossipUnicast
	ProtocolGossipBroadcast
	ProtocolOverlayControlMsg
)
View Source
const (
	Port           = 6783
	ChannelSize    = 16
	TCPHeartbeat   = 30 * time.Second
	GossipInterval = 30 * time.Second
	MaxDuration    = time.Duration(math.MaxInt64)
)
View Source
const MaxTCPMsgSize = 10 * 1024 * 1024
View Source
const PeerShortIDBits = 12

Variables

View Source
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")
)
View Source
var ErrConnectToSelf = fmt.Errorf("Cannot connect to ourself")

Functions

func FormSessionKey

func FormSessionKey(remotePublicKey, localPrivateKey *[32]byte, secretKey []byte) *[32]byte

func GenerateKeyPair

func GenerateKeyPair() (publicKey, privateKey *[32]byte, err error)

func GobEncode

func GobEncode(items ...interface{}) []byte

func NewTargetSlice

func NewTargetSlice(cm *ConnectionMaker) []string

func NewTrustedSubnetsSlice added in v1.4.0

func NewTrustedSubnetsSlice(trustedSubnets []*net.IPNet) []string

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

type BroadcastRouteStatus struct {
	Source string
	Via    []string
}

func NewBroadcastRouteStatusSlice

func NewBroadcastRouteStatusSlice(routes *Routes) []BroadcastRouteStatus

type Config

type Config struct {
	Port               int
	ProtocolMinVersion byte
	Password           []byte
	ConnLimit          int
	PeerDiscovery      bool
	TrustedSubnets     []*net.IPNet
}

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 ConnectionStatus struct {
	Name        string
	NickName    string
	Address     string
	Outbound    bool
	Established bool
}

type ConnectionSummary

type ConnectionSummary struct {
	NameByte      []byte
	RemoteTCPAddr string
	Outbound      bool
	Established   bool
}

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

type EncryptedTCPSender struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

type GossipChannel struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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) Shutdown

func (conn *LocalConnection) Shutdown(err error)

Non-blocking.

func (*LocalConnection) Untrusted added in v1.4.0

func (conn *LocalConnection) Untrusted() bool

type LocalConnectionStatus

type LocalConnectionStatus struct {
	Address  string
	Outbound bool
	State    string
	Info     string
}

func NewLocalConnectionStatusSlice

func NewLocalConnectionStatusSlice(cm *ConnectionMaker) []LocalConnectionStatus

type LocalPeer

type LocalPeer struct {
	sync.RWMutex
	*Peer
	// contains filtered or unexported fields
}

func NewLocalPeer

func NewLocalPeer(name PeerName, nickName string, router *Router) *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 (peer *LocalPeer) CreateConnection(peerAddr string, acceptNewPeer bool) error

func (*LocalPeer) DeleteConnection

func (peer *LocalPeer) DeleteConnection(conn *LocalConnection)

Sync.

func (*LocalPeer) Encode

func (peer *LocalPeer) Encode(enc *gob.Encoder)

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) 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 NewPeer

func NewPeer(name PeerName, nickName string, uid PeerUID, version uint64, shortID PeerShortID) *Peer

func NewPeerFrom

func NewPeerFrom(peer *Peer) *Peer

func NewPeerFromSummary

func NewPeerFromSummary(summary PeerSummary) *Peer

func NewPeerPlaceholder added in v1.4.0

func NewPeerPlaceholder(name PeerName) *Peer

func (*Peer) Encode

func (peer *Peer) Encode(enc *gob.Encoder)

func (*Peer) ForEachConnectedPeer

func (peer *Peer) ForEachConnectedPeer(establishedAndSymmetric bool, exclude map[PeerName]PeerName, f func(*Peer))

func (*Peer) Routes

func (peer *Peer) Routes(stopAt *Peer, establishedAndSymmetric bool) (bool, map[PeerName]PeerName)

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.

func (*Peer) String

func (peer *Peer) String() string

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 PeerNameFromBin(nameByte []byte) PeerName

func PeerNameFromString

func PeerNameFromString(nameStr string) (PeerName, error)

func PeerNameFromUserInput

func PeerNameFromUserInput(userInput string) (PeerName, error)

func (PeerName) Bin

func (name PeerName) Bin() []byte

func (PeerName) String

func (name PeerName) String() string

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 PeerSummary struct {
	NameByte   []byte
	NickName   string
	UID        PeerUID
	Version    uint64
	ShortID    PeerShortID
	HasShortID bool
}

type PeerUID

type PeerUID uint64

func ParsePeerUID

func ParsePeerUID(s string) (PeerUID, error)

type Peers

type Peers struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewPeers

func NewPeers(ourself *LocalPeer) *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 *Peers) Dereference(peer *Peer)

func (*Peers) EncodePeers

func (peers *Peers) EncodePeers(names PeerNameSet) []byte

func (*Peers) Fetch

func (peers *Peers) Fetch(name PeerName) *Peer

func (*Peers) FetchAndAddRef

func (peers *Peers) FetchAndAddRef(name PeerName) *Peer

func (*Peers) FetchByShortID

func (peers *Peers) FetchByShortID(shortID PeerShortID) *Peer

func (*Peers) FetchWithDefault

func (peers *Peers) FetchWithDefault(peer *Peer) *Peer

func (*Peers) ForEach

func (peers *Peers) ForEach(fun func(*Peer))

func (*Peers) GarbageCollect

func (peers *Peers) GarbageCollect()

func (*Peers) Names

func (peers *Peers) Names() PeerNameSet

func (*Peers) OnGC

func (peers *Peers) OnGC(callback func(*Peer))

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 ProtocolIntroResults struct {
	Features   map[string]string
	Receiver   TCPReceiver
	Sender     TCPSender
	SessionKey *[32]byte
	Version    byte
}

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 (*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 NewRouter

func NewRouter(config Config, name PeerName, nickName string, overlay Overlay) *Router

func (*Router) BroadcastTopologyUpdate

func (router *Router) BroadcastTopologyUpdate(update []*Peer)

func (*Router) Gossip

func (router *Router) Gossip() GossipData

func (*Router) NewGossip

func (router *Router) NewGossip(channelName string, g Gossiper) Gossip

func (*Router) OnGossip

func (router *Router) OnGossip(update []byte) (GossipData, error)

func (*Router) OnGossipBroadcast

func (router *Router) OnGossipBroadcast(_ PeerName, update []byte) (GossipData, error)

func (*Router) OnGossipUnicast

func (router *Router) OnGossipUnicast(sender PeerName, msg []byte) error

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) Stop

func (router *Router) Stop() error

func (*Router) Trusts added in v1.4.0

func (router *Router) Trusts(remote *RemoteConnection) bool

func (*Router) UsingPassword

func (router *Router) UsingPassword() bool

type Routes

type Routes struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRoutes

func NewRoutes(ourself *LocalPeer, peers *Peers) *Routes

func (*Routes) Broadcast

func (routes *Routes) Broadcast(name PeerName) []PeerName

func (*Routes) BroadcastAll

func (routes *Routes) BroadcastAll(name PeerName) []PeerName

func (*Routes) EnsureRecalculated

func (routes *Routes) EnsureRecalculated()

Wait for any preceding Recalculate requests to be processed.

func (*Routes) OnChange

func (routes *Routes) OnChange(callback func())

func (*Routes) PeerNames

func (routes *Routes) PeerNames() PeerNameSet

func (*Routes) RandomNeighbours

func (routes *Routes) RandomNeighbours(except PeerName) []PeerName

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.

func (*Routes) Unicast

func (routes *Routes) Unicast(name PeerName) (PeerName, bool)

func (*Routes) UnicastAll

func (routes *Routes) UnicastAll(name PeerName) (PeerName, bool)

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
}

func NewStatus

func NewStatus(router *Router) *Status

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 TCPReceiver interface {
	Receive() ([]byte, error)
}

type TCPSender

type TCPSender interface {
	Send([]byte) error
}

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

Jump to

Keyboard shortcuts

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