Merge remote-tracking branch 'origin/1.3'
This commit is contained in:
commit
c2d5cab1b8
6 files changed
+35
-24
No files matched your search
+2
-2
@@ -478,8 +478,8 @@ type ipamGossipData struct {
|
|||||||
alloc *Allocator
|
alloc *Allocator
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ipamGossipData) Merge(other mesh.GossipData) {
|
func (d *ipamGossipData) Merge(other mesh.GossipData) mesh.GossipData {
|
||||||
// no-op
|
return d // no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ipamGossipData) Encode() [][]byte {
|
func (d *ipamGossipData) Encode() [][]byte {
|
||||||
|
|||||||
+2
-3
@@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
type GossipData interface {
|
type GossipData interface {
|
||||||
Encode() [][]byte
|
Encode() [][]byte
|
||||||
Merge(GossipData)
|
Merge(GossipData) GossipData
|
||||||
}
|
}
|
||||||
|
|
||||||
type Gossip interface {
|
type Gossip interface {
|
||||||
@@ -79,8 +79,7 @@ func (sender *GossipSender) Send(data GossipData) {
|
|||||||
// NB: this must not be invoked concurrently
|
// NB: this must not be invoked concurrently
|
||||||
select {
|
select {
|
||||||
case pending := <-sender.cell:
|
case pending := <-sender.cell:
|
||||||
pending.Merge(data)
|
sender.cell <- pending.Merge(data)
|
||||||
sender.cell <- pending
|
|
||||||
default:
|
default:
|
||||||
sender.cell <- data
|
sender.cell <- data
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-8
@@ -127,17 +127,19 @@ func (router *Router) BroadcastTopologyUpdate(update []*Peer) {
|
|||||||
for _, p := range update {
|
for _, p := range update {
|
||||||
names[p.Name] = void
|
names[p.Name] = void
|
||||||
}
|
}
|
||||||
|
router.TopologyGossip.GossipBroadcast(
|
||||||
router.TopologyGossip.GossipBroadcast(&TopologyGossipData{
|
&TopologyGossipData{peers: router.Peers, update: names})
|
||||||
peers: router.Peers,
|
|
||||||
update: names,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *TopologyGossipData) Merge(other GossipData) {
|
func (d *TopologyGossipData) Merge(other GossipData) GossipData {
|
||||||
for name := range other.(*TopologyGossipData).update {
|
names := make(PeerNameSet)
|
||||||
d.update[name] = void
|
for name := range d.update {
|
||||||
|
names[name] = void
|
||||||
}
|
}
|
||||||
|
for name := range other.(*TopologyGossipData).update {
|
||||||
|
names[name] = void
|
||||||
|
}
|
||||||
|
return &TopologyGossipData{peers: d.peers, update: names}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *TopologyGossipData) Encode() [][]byte {
|
func (d *TopologyGossipData) Encode() [][]byte {
|
||||||
|
|||||||
@@ -12,8 +12,12 @@ func (d *SurrogateGossipData) Encode() [][]byte {
|
|||||||
return d.messages
|
return d.messages
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SurrogateGossipData) Merge(other GossipData) {
|
func (d *SurrogateGossipData) Merge(other GossipData) GossipData {
|
||||||
d.messages = append(d.messages, other.(*SurrogateGossipData).messages...)
|
o := other.(*SurrogateGossipData)
|
||||||
|
messages := make([][]byte, 0, len(d.messages)+len(o.messages))
|
||||||
|
messages = append(messages, d.messages...)
|
||||||
|
messages = append(messages, o.messages...)
|
||||||
|
return &SurrogateGossipData{messages: messages}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SurrogateGossiper ignores unicasts and relays broadcasts and gossips.
|
// SurrogateGossiper ignores unicasts and relays broadcasts and gossips.
|
||||||
|
|||||||
+13
-7
@@ -245,12 +245,14 @@ type GossipData struct {
|
|||||||
Entries
|
Entries
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GossipData) Merge(o mesh.GossipData) {
|
func (g *GossipData) Merge(o mesh.GossipData) mesh.GossipData {
|
||||||
other := o.(*GossipData)
|
other := o.(*GossipData)
|
||||||
g.Entries.merge(other.Entries)
|
gossip := g.copy()
|
||||||
if g.Timestamp < other.Timestamp {
|
gossip.Entries.merge(other.Entries)
|
||||||
g.Timestamp = other.Timestamp
|
if gossip.Timestamp < other.Timestamp {
|
||||||
|
gossip.Timestamp = other.Timestamp
|
||||||
}
|
}
|
||||||
|
return gossip
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GossipData) Decode(msg []byte) error {
|
func (g *GossipData) Decode(msg []byte) error {
|
||||||
@@ -264,9 +266,7 @@ func (g *GossipData) Decode(msg []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GossipData) Encode() [][]byte {
|
func (g *GossipData) Encode() [][]byte {
|
||||||
// Make a copy so we can sort: all outgoing data is sent in case-sensitive order
|
g2 := g.copy()
|
||||||
g2 := GossipData{Timestamp: g.Timestamp, Entries: make(Entries, len(g.Entries))}
|
|
||||||
copy(g2.Entries, g.Entries)
|
|
||||||
sort.Sort(CaseSensitive(g2.Entries))
|
sort.Sort(CaseSensitive(g2.Entries))
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
if err := gob.NewEncoder(buf).Encode(g2); err != nil {
|
if err := gob.NewEncoder(buf).Encode(g2); err != nil {
|
||||||
@@ -274,3 +274,9 @@ func (g *GossipData) Encode() [][]byte {
|
|||||||
}
|
}
|
||||||
return [][]byte{buf.Bytes()}
|
return [][]byte{buf.Bytes()}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GossipData) copy() *GossipData {
|
||||||
|
g2 := &GossipData{Timestamp: g.Timestamp, Entries: make(Entries, len(g.Entries))}
|
||||||
|
copy(g2.Entries, g.Entries)
|
||||||
|
return g2
|
||||||
|
}
|
||||||
@@ -117,7 +117,7 @@ func TestGossipDataMerge(t *testing.T) {
|
|||||||
g1 := GossipData{Entries: makeEntries("AcDf")}
|
g1 := GossipData{Entries: makeEntries("AcDf")}
|
||||||
g2 := GossipData{Entries: makeEntries("BEf")}
|
g2 := GossipData{Entries: makeEntries("BEf")}
|
||||||
|
|
||||||
g1.Merge(&g2)
|
g3 := g1.Merge(&g2).(*GossipData)
|
||||||
|
|
||||||
require.Equal(t, GossipData{Entries: makeEntries("ABcDEf")}, g1)
|
require.Equal(t, GossipData{Entries: makeEntries("ABcDEf")}, *g3)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user