Merge pull request #3732 from weaveworks/mesh-0-4
Update Weave Mesh library to 0.4
This commit is contained in:
10 files changed
+55
-45
No files matched your search
Generated
+3
-4
@@ -686,12 +686,12 @@
|
|||||||
revision = "6b0aa22550d9325eb8f43418185859e13dc0de1d"
|
revision = "6b0aa22550d9325eb8f43418185859e13dc0de1d"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:ef8d0a1f90a33a968984ba2159a02304c591bbe964ad13e6408bf361975b3a58"
|
digest = "1:dfa8458da99855b0f0e13f580e6107b46311db15dc7f76cb80c131b937f7f8aa"
|
||||||
name = "github.com/weaveworks/mesh"
|
name = "github.com/weaveworks/mesh"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "8889a805f7f6fe19a40dd175575d7f5efb7eda79"
|
revision = "58dbcc3e8e63eed7dd77f3a6286855ae8c8876c1"
|
||||||
version = "v0.3"
|
version = "v0.4"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@@ -1108,7 +1108,6 @@
|
|||||||
"github.com/weaveworks/mesh",
|
"github.com/weaveworks/mesh",
|
||||||
"golang.org/x/crypto/hkdf",
|
"golang.org/x/crypto/hkdf",
|
||||||
"golang.org/x/crypto/nacl/secretbox",
|
"golang.org/x/crypto/nacl/secretbox",
|
||||||
"golang.org/x/net/context",
|
|
||||||
"golang.org/x/sys/unix",
|
"golang.org/x/sys/unix",
|
||||||
"golang.org/x/tools/cover",
|
"golang.org/x/tools/cover",
|
||||||
"k8s.io/api/core/v1",
|
"k8s.io/api/core/v1",
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ func (m *mockGossipComms) GossipBroadcast(update mesh.GossipData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mockGossipComms) GossipNeighbourSubset(update mesh.GossipData) {
|
||||||
|
m.GossipBroadcast(update)
|
||||||
|
}
|
||||||
func equalByteBuffer(a, b []byte) bool {
|
func equalByteBuffer(a, b []byte) bool {
|
||||||
if len(a) != len(b) {
|
if len(a) != len(b) {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -199,3 +199,7 @@ func (client TestRouterClient) GossipUnicast(dstPeerName mesh.PeerName, buf []by
|
|||||||
func (client TestRouterClient) GossipBroadcast(update mesh.GossipData) {
|
func (client TestRouterClient) GossipBroadcast(update mesh.GossipData) {
|
||||||
client.router.gossipBroadcast(client.sender, update)
|
client.router.gossipBroadcast(client.sender, update)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (client TestRouterClient) GossipNeighbourSubset(update mesh.GossipData) {
|
||||||
|
client.router.gossip(client.sender, update)
|
||||||
|
}
|
||||||
-4
@@ -1,4 +0,0 @@
|
|||||||
test:
|
|
||||||
pre:
|
|
||||||
- ./lint
|
|
||||||
|
|
||||||
+3
@@ -22,6 +22,9 @@ type Gossip interface {
|
|||||||
//
|
//
|
||||||
// TODO(pb): rename to Broadcast?
|
// TODO(pb): rename to Broadcast?
|
||||||
GossipBroadcast(update GossipData)
|
GossipBroadcast(update GossipData)
|
||||||
|
|
||||||
|
// GossipNeighbourSubset emits a message to subset of neighbour peers in the mesh.
|
||||||
|
GossipNeighbourSubset(update GossipData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gossiper is the receiving interface.
|
// Gossiper is the receiving interface.
|
||||||
|
|||||||
+6
@@ -83,6 +83,12 @@ func (c *gossipChannel) GossipBroadcast(update GossipData) {
|
|||||||
c.relayBroadcast(c.ourself.Name, update)
|
c.relayBroadcast(c.ourself.Name, update)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GossipNeighbourSubset implements Gossip, relaying update to subset of members of the
|
||||||
|
// channel.
|
||||||
|
func (c *gossipChannel) GossipNeighbourSubset(update GossipData) {
|
||||||
|
c.relay(c.ourself.Name, update)
|
||||||
|
}
|
||||||
|
|
||||||
// Send relays data into the channel topology via random neighbours.
|
// Send relays data into the channel topology via random neighbours.
|
||||||
func (c *gossipChannel) Send(data GossipData) {
|
func (c *gossipChannel) Send(data GossipData) {
|
||||||
c.relay(c.ourself.Name, data)
|
c.relay(c.ourself.Name, data)
|
||||||
|
|||||||
+4
-13
@@ -4,19 +4,10 @@ set -o errexit
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
if [ ! $(command -v gometalinter) ]
|
if [ ! $(command -v golangci-lint) ]
|
||||||
then
|
then
|
||||||
go get github.com/alecthomas/gometalinter
|
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.20.0
|
||||||
gometalinter --install --vendor
|
golangci-lint --version
|
||||||
fi
|
fi
|
||||||
|
|
||||||
gometalinter \
|
golangci-lint run
|
||||||
--exclude='error return value not checked.*(Close|Log|Print).*\(errcheck\)$' \
|
|
||||||
--exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$' \
|
|
||||||
--exclude='duplicate of.*_test.go.*\(dupl\)$' \
|
|
||||||
--disable=aligncheck \
|
|
||||||
--disable=gotype \
|
|
||||||
--disable=gas \
|
|
||||||
--cyclo-over=20 \
|
|
||||||
--tests \
|
|
||||||
--deadline=20s
|
|
||||||
+5
-8
@@ -350,14 +350,11 @@ func (peers *Peers) forEach(fun func(*Peer)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (peers *Peers) actorLoop() {
|
func (peers *Peers) actorLoop() {
|
||||||
for {
|
for range peers.timer.C {
|
||||||
select {
|
peers.GarbageCollect()
|
||||||
case <-peers.timer.C:
|
peers.Lock()
|
||||||
peers.GarbageCollect()
|
peers.pendingGC = false
|
||||||
peers.Lock()
|
peers.Unlock()
|
||||||
peers.pendingGC = false
|
|
||||||
peers.Unlock()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -24,8 +24,8 @@ var (
|
|||||||
const (
|
const (
|
||||||
tcpHeartbeat = 30 * time.Second
|
tcpHeartbeat = 30 * time.Second
|
||||||
maxDuration = time.Duration(math.MaxInt64)
|
maxDuration = time.Duration(math.MaxInt64)
|
||||||
acceptMaxTokens = 100
|
acceptMaxTokens = 20
|
||||||
acceptTokenDelay = 100 * time.Millisecond // [2]
|
acceptTokenDelay = 50 * time.Millisecond
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config defines dimensions of configuration for the router.
|
// Config defines dimensions of configuration for the router.
|
||||||
@@ -233,7 +233,7 @@ func (router *Router) sendPendingGossip() bool {
|
|||||||
// topology, and broadcasts the new set of peers to the mesh.
|
// topology, and broadcasts the new set of peers to the mesh.
|
||||||
func (router *Router) broadcastTopologyUpdate(update peerNameSet) {
|
func (router *Router) broadcastTopologyUpdate(update peerNameSet) {
|
||||||
gossipData := &topologyGossipData{peers: router.Peers, update: update}
|
gossipData := &topologyGossipData{peers: router.Peers, update: update}
|
||||||
router.topologyGossip.GossipBroadcast(gossipData)
|
router.topologyGossip.GossipNeighbourSubset(gossipData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnGossipUnicast implements Gossiper, but always returns an error, as a
|
// OnGossipUnicast implements Gossiper, but always returns an error, as a
|
||||||
|
|||||||
+24
-13
@@ -2,6 +2,7 @@ package mesh
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
|
"math/rand"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -127,7 +128,7 @@ func (r *routes) lookupOrCalculate(name PeerName, broadcast *broadcastRoutes, es
|
|||||||
return <-res
|
return <-res
|
||||||
}
|
}
|
||||||
|
|
||||||
// RandomNeighbours chooses min(log2(n_peers), n_neighbouring_peers)
|
// RandomNeighbours chooses min(2 log2(n_peers), n_neighbouring_peers)
|
||||||
// neighbours, with a random distribution that is topology-sensitive,
|
// neighbours, with a random distribution that is topology-sensitive,
|
||||||
// favouring neighbours at the end of "bottleneck links". We determine the
|
// favouring neighbours at the end of "bottleneck links". We determine the
|
||||||
// latter based on the unicast routing table. If a neighbour appears as the
|
// latter based on the unicast routing table. If a neighbour appears as the
|
||||||
@@ -135,29 +136,39 @@ func (r *routes) lookupOrCalculate(name PeerName, broadcast *broadcastRoutes, es
|
|||||||
// proportion of peers via that neighbour than other neighbours - then it is
|
// proportion of peers via that neighbour than other neighbours - then it is
|
||||||
// chosen with a higher probability.
|
// chosen with a higher probability.
|
||||||
//
|
//
|
||||||
// Note that we choose log2(n_peers) *neighbours*, not peers. Consequently, on
|
// Note that we choose 2log2(n_peers) *neighbours*, not peers. Consequently, on
|
||||||
// sparsely connected peers this function returns a higher proportion of
|
// sparsely connected peers this function returns a higher proportion of
|
||||||
// neighbours than elsewhere. In extremis, on peers with fewer than
|
// neighbours than elsewhere. In extremis, on peers with fewer than
|
||||||
// log2(n_peers) neighbours, all neighbours are returned.
|
// log2(n_peers) neighbours, all neighbours are returned.
|
||||||
func (r *routes) randomNeighbours(except PeerName) []PeerName {
|
func (r *routes) randomNeighbours(except PeerName) []PeerName {
|
||||||
destinations := make(peerNameSet)
|
|
||||||
r.RLock()
|
r.RLock()
|
||||||
defer r.RUnlock()
|
defer r.RUnlock()
|
||||||
count := int(math.Log2(float64(len(r.unicastAll))))
|
var total int64 = 0
|
||||||
// depends on go's random map iteration
|
weights := make(map[PeerName]int64)
|
||||||
|
// First iterate the whole set, counting how often each neighbour appears
|
||||||
for _, dst := range r.unicastAll {
|
for _, dst := range r.unicastAll {
|
||||||
if dst != UnknownPeerName && dst != except {
|
if dst != UnknownPeerName && dst != except {
|
||||||
destinations[dst] = struct{}{}
|
total++
|
||||||
if len(destinations) >= count {
|
weights[dst]++
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res := make([]PeerName, 0, len(destinations))
|
needed := int(math.Min(2*math.Log2(float64(len(r.unicastAll))), float64(len(weights))))
|
||||||
for dst := range destinations {
|
destinations := make([]PeerName, 0, needed)
|
||||||
res = append(res, dst)
|
for len(destinations) < needed {
|
||||||
|
// Pick a random point on the distribution and linear search for it
|
||||||
|
rnd := rand.Int63n(total)
|
||||||
|
for dst, count := range weights {
|
||||||
|
if rnd < count {
|
||||||
|
destinations = append(destinations, dst)
|
||||||
|
// Remove the one we selected from consideration
|
||||||
|
delete(weights, dst)
|
||||||
|
total -= count
|
||||||
|
break
|
||||||
|
}
|
||||||
|
rnd -= count
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res
|
return destinations
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recalculate requests recalculation of the routing table. This is async but
|
// Recalculate requests recalculation of the routing table. This is async but
|
||||||
|
|||||||
Reference in new issue
Block a user