@@ -2,6 +2,7 @@ package pubsub
2
2
3
3
import (
4
4
"context"
5
+ "crypto/sha256"
5
6
"fmt"
6
7
"math/rand"
7
8
"sort"
64
65
GossipSubIDontWantMessageTTL = 3 // 3 heartbeats
65
66
)
66
67
68
+ type checksum [32 ]byte
69
+
67
70
// GossipSubParams defines all the gossipsub specific parameters.
68
71
type GossipSubParams struct {
69
72
// overlay parameters.
@@ -243,7 +246,7 @@ func DefaultGossipSubRouter(h host.Host) *GossipSubRouter {
243
246
backoff : make (map [string ]map [peer.ID ]time.Time ),
244
247
peerhave : make (map [peer.ID ]int ),
245
248
peerdontwant : make (map [peer.ID ]int ),
246
- unwanted : make (map [peer.ID ]map [string ]int ),
249
+ unwanted : make (map [peer.ID ]map [checksum ]int ),
247
250
iasked : make (map [peer.ID ]int ),
248
251
outbound : make (map [peer.ID ]bool ),
249
252
connect : make (chan connectInfo , params .MaxPendingConnections ),
@@ -448,7 +451,7 @@ type GossipSubRouter struct {
448
451
control map [peer.ID ]* pb.ControlMessage // pending control messages
449
452
peerhave map [peer.ID ]int // number of IHAVEs received from peer in the last heartbeat
450
453
peerdontwant map [peer.ID ]int // number of IDONTWANTs received from peer in the last heartbeat
451
- unwanted map [peer.ID ]map [string ]int // TTL of the message ids peers don't want
454
+ unwanted map [peer.ID ]map [checksum ]int // TTL of the message ids peers don't want
452
455
iasked map [peer.ID ]int // number of messages we have asked from peer in the last heartbeat
453
456
outbound map [peer.ID ]bool // connection direction cache, marks peers with outbound connections
454
457
backoff map [string ]map [peer.ID ]time.Time // prune backoff
@@ -966,7 +969,7 @@ func (gs *GossipSubRouter) handlePrune(p peer.ID, ctl *pb.ControlMessage) {
966
969
967
970
func (gs * GossipSubRouter ) handleIDontWant (p peer.ID , ctl * pb.ControlMessage ) {
968
971
if gs .unwanted [p ] == nil {
969
- gs .unwanted [p ] = make (map [string ]int )
972
+ gs .unwanted [p ] = make (map [checksum ]int )
970
973
}
971
974
972
975
// IDONTWANT flood protection
@@ -979,7 +982,8 @@ func (gs *GossipSubRouter) handleIDontWant(p peer.ID, ctl *pb.ControlMessage) {
979
982
// Remember all the unwanted message ids
980
983
for _ , idontwant := range ctl .GetIdontwant () {
981
984
for _ , mid := range idontwant .GetMessageIDs () {
982
- gs.unwanted [p ][mid ] = gs .params .IDontWantMessageTTL
985
+ hashed := sha256 .Sum256 ([]byte (mid ))
986
+ gs.unwanted [p ][hashed ] = gs .params .IDontWantMessageTTL
983
987
}
984
988
}
985
989
}
@@ -1145,9 +1149,10 @@ func (gs *GossipSubRouter) Publish(msg *Message) {
1145
1149
1146
1150
for p := range gmap {
1147
1151
mid := gs .p .idGen .ID (msg )
1152
+ hashed := sha256 .Sum256 ([]byte (mid ))
1148
1153
// Check if it has already received an IDONTWANT for the message.
1149
1154
// If so, don't send it to the peer
1150
- if _ , ok := gs.unwanted [p ][mid ]; ok {
1155
+ if _ , ok := gs.unwanted [p ][hashed ]; ok {
1151
1156
continue
1152
1157
}
1153
1158
tosend [p ] = struct {}{}
0 commit comments