refactor: extract nameserver GossipData.copy
and remove a self-evident comment
This commit is contained in:
1 parent
3cd199e852
commit
1500b1dc00
1 file changed
+8
-8
+8
-8
@@ -247,11 +247,7 @@ type GossipData struct {
|
|||||||
|
|
||||||
func (g *GossipData) Merge(o mesh.GossipData) mesh.GossipData {
|
func (g *GossipData) Merge(o mesh.GossipData) mesh.GossipData {
|
||||||
other := o.(*GossipData)
|
other := o.(*GossipData)
|
||||||
gossip := &GossipData{
|
gossip := g.copy()
|
||||||
Entries: make(Entries, len(g.Entries)),
|
|
||||||
Timestamp: g.Timestamp,
|
|
||||||
}
|
|
||||||
copy(gossip.Entries, g.Entries)
|
|
||||||
gossip.Entries.merge(other.Entries)
|
gossip.Entries.merge(other.Entries)
|
||||||
if gossip.Timestamp < other.Timestamp {
|
if gossip.Timestamp < other.Timestamp {
|
||||||
gossip.Timestamp = other.Timestamp
|
gossip.Timestamp = other.Timestamp
|
||||||
@@ -270,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 {
|
||||||
@@ -280,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
|
||||||
|
}
|
||||||
Reference in new issue
Block a user