Hold all entries sorted case-insensitively until just before sending, when we re-sort case-sensitively in Encode()
This commit is contained in:
1 parent
64f7953423
commit
f485b729bc
2 files changed
+7
-5
No files matched your search
+7
-4
@@ -233,8 +233,8 @@ type GossipData struct {
|
||||
}
|
||||
|
||||
func (g *GossipData) Merge(o router.GossipData) {
|
||||
checkAndPanic(CaseSensitive(g.Entries))
|
||||
defer func() { checkAndPanic(CaseSensitive(g.Entries)) }()
|
||||
checkAndPanic(CaseInsensitive(g.Entries))
|
||||
defer func() { checkAndPanic(CaseInsensitive(g.Entries)) }()
|
||||
other := o.(*GossipData)
|
||||
g.Entries.merge(other.Entries)
|
||||
if g.Timestamp < other.Timestamp {
|
||||
@@ -243,9 +243,12 @@ func (g *GossipData) Merge(o router.GossipData) {
|
||||
}
|
||||
|
||||
func (g *GossipData) Encode() [][]byte {
|
||||
checkAndPanic(CaseSensitive(g.Entries))
|
||||
// Make a copy so we can sort: all outgoing data is sent in case-sensitive order
|
||||
g2 := GossipData{Timestamp: g.Timestamp, Entries: make(Entries, len(g.Entries))}
|
||||
copy(g2.Entries, g.Entries)
|
||||
sort.Sort(CaseSensitive(g2.Entries))
|
||||
buf := &bytes.Buffer{}
|
||||
if err := gob.NewEncoder(buf).Encode(g); err != nil {
|
||||
if err := gob.NewEncoder(buf).Encode(g2); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return [][]byte{buf.Bytes()}
|
||||
|
||||
@@ -196,7 +196,6 @@ func (n *Nameserver) Gossip() router.GossipData {
|
||||
Timestamp: now(),
|
||||
}
|
||||
copy(gossip.Entries, n.entries)
|
||||
sort.Sort(CaseSensitive(gossip.Entries))
|
||||
return gossip
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user