Skip to content

Commit 0526738

Browse files
committed
further simplify
1 parent 1b3ab73 commit 0526738

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

network/wsNetwork.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,14 +1187,16 @@ func (wn *WebsocketNetwork) maybeSendMessagesOfInterest(peer *wsPeer, messagesOf
11871187
peerMessagesOfInterestGeneration := peer.messagesOfInterestGeneration.Load()
11881188
if peerMessagesOfInterestGeneration != messagesOfInterestGeneration {
11891189
peerSupportsStatefulCompression := peer.vpackStatefulCompressionSupported()
1190-
sendEnc := messagesOfInterestEnc
1190+
if messagesOfInterestEnc == nil {
1191+
wn.messagesOfInterestMu.Lock()
1192+
messagesOfInterestEnc = wn.messagesOfInterestEnc
1193+
wn.messagesOfInterestMu.Unlock()
1194+
}
1195+
11911196
var perPeerTags map[protocol.Tag]bool
1192-
if sendEnc == nil || !peerSupportsStatefulCompression {
1197+
if !peerSupportsStatefulCompression {
11931198
wn.messagesOfInterestMu.Lock()
1194-
if sendEnc == nil {
1195-
sendEnc = wn.messagesOfInterestEnc
1196-
}
1197-
if !peerSupportsStatefulCompression && wn.messagesOfInterest[protocol.VotePackedTag] {
1199+
if wn.messagesOfInterest[protocol.VotePackedTag] {
11981200
// Filter VP tag for peers lacking stateful compression support; older nodes (<= v4.3)
11991201
// treat unknown tags as protocol violations and disconnect.
12001202
perPeerTags = make(map[protocol.Tag]bool, len(wn.messagesOfInterest))
@@ -1204,12 +1206,15 @@ func (wn *WebsocketNetwork) maybeSendMessagesOfInterest(peer *wsPeer, messagesOf
12041206
}
12051207
perPeerTags[tag] = flag
12061208
}
1207-
sendEnc = marshallMessageOfInterestMap(perPeerTags)
12081209
}
12091210
wn.messagesOfInterestMu.Unlock()
1211+
1212+
if perPeerTags != nil {
1213+
messagesOfInterestEnc = marshallMessageOfInterestMap(perPeerTags)
1214+
}
12101215
}
1211-
if sendEnc != nil {
1212-
peer.sendMessagesOfInterest(messagesOfInterestGeneration, sendEnc)
1216+
if messagesOfInterestEnc != nil {
1217+
peer.sendMessagesOfInterest(messagesOfInterestGeneration, messagesOfInterestEnc)
12131218
} else {
12141219
wn.log.Infof("msgOfInterest Enc=nil, MOIGen=%d", messagesOfInterestGeneration)
12151220
}

0 commit comments

Comments
 (0)