-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GossipSub: IDontWant #934
GossipSub: IDontWant #934
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,6 +263,7 @@ proc handleControl(g: GossipSub, peer: PubSubPeer, control: ControlMessage) = | |
g.handlePrune(peer, control.prune) | ||
|
||
var respControl: ControlMessage | ||
g.handleIDontWant(peer, control.idontwant) | ||
let iwant = g.handleIHave(peer, control.ihave) | ||
if iwant.messageIds.len > 0: | ||
respControl.iwant.add(iwant) | ||
|
@@ -332,11 +333,25 @@ proc validateAndRelay(g: GossipSub, | |
g.floodsub.withValue(t, peers): toSendPeers.incl(peers[]) | ||
g.mesh.withValue(t, peers): toSendPeers.incl(peers[]) | ||
|
||
|
||
# Don't send it to source peer, or peers that | ||
# sent it during validation | ||
toSendPeers.excl(peer) | ||
toSendPeers.excl(seenPeers) | ||
|
||
if msg.data.len > msgId.len * 10: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this condition more descriptive - like making it a proc or adding a comment with the reasoning? |
||
g.broadcast(toSendPeers, RPCMsg(control: some(ControlMessage( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should only broadcast this to peers that haven't themselves sent us an idontwant for the given hash, ie this should be moved below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is true in this version of IDontWant, because as soon as we sent the IDontWant, we also send the full message, so it's too late to "choke" us So in these future versions, receiving a IDontWant won't mean it's too late to send ours. Sending the IDontWant to everyone is "forward-compatibility" at the cost of a few bytes |
||
idontwant: @[ControlIWant(messageIds: @[msgId])] | ||
)))) | ||
|
||
for peer in toSendPeers: | ||
for heDontWant in peer.heDontWants: | ||
if msgId in heDontWant: | ||
seenPeers.incl(peer) | ||
break | ||
toSendPeers.excl(seenPeers) | ||
|
||
|
||
# In theory, if topics are the same in all messages, we could batch - we'd | ||
# also have to be careful to only include validated messages | ||
g.broadcast(toSendPeers, RPCMsg(messages: @[msg])) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -262,6 +262,15 @@ proc handleIHave*(g: GossipSub, | |
g.rng.shuffle(res.messageIds) | ||
return res | ||
|
||
proc handleIDontWant*(g: GossipSub, | ||
peer: PubSubPeer, | ||
iDontWants: seq[ControlIWant]) = | ||
for dontWant in iDontWants: | ||
for message in dontWant.messageIds: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if peer.heDontWants[^1].len > 1000: break | ||
if message.len > 100: break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it be a |
||
peer.heDontWants[^1].incl(message) | ||
|
||
proc handleIWant*(g: GossipSub, | ||
peer: PubSubPeer, | ||
iwants: seq[ControlIWant]): seq[Message] {.raises: [].} = | ||
|
@@ -629,6 +638,9 @@ proc onHeartbeat(g: GossipSub) {.raises: [].} = | |
peer.sentIHaves.addFirst(default(HashSet[MessageId])) | ||
if peer.sentIHaves.len > g.parameters.historyLength: | ||
discard peer.sentIHaves.popLast() | ||
peer.heDontWants.addFirst(default(HashSet[MessageId])) | ||
if peer.heDontWants.len > g.parameters.historyLength: | ||
discard peer.heDontWants.popLast() | ||
peer.iHaveBudget = IHavePeerBudget | ||
peer.pingBudget = PingsPeerBudget | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ import rpc/[messages, message, protobuf], | |
../../protobuf/minprotobuf, | ||
../../utility | ||
|
||
export peerid, connection | ||
export peerid, connection, deques | ||
|
||
logScope: | ||
topics = "libp2p pubsubpeer" | ||
|
@@ -60,6 +60,7 @@ type | |
|
||
score*: float64 | ||
sentIHaves*: Deque[HashSet[MessageId]] | ||
heDontWants*: Deque[HashSet[MessageId]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the list of "iDontWant" he sent, so I think "heDontWants" or "receivedDontWants" is more descriptive There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just |
||
iHaveBudget*: int | ||
pingBudget*: int | ||
maxMessageSize: int | ||
|
@@ -317,3 +318,4 @@ proc new*( | |
maxMessageSize: maxMessageSize | ||
) | ||
result.sentIHaves.addFirst(default(HashSet[MessageId])) | ||
result.heDontWants.addFirst(default(HashSet[MessageId])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary?