Skip to content

Commit c66cef0

Browse files
committed
Add documentation for the RequestPartialMessages topic option
and fix a bug where we would skip sending them full messages if they requested partial messages and we disabled partial messages.
1 parent a0a57bb commit c66cef0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

gossipsub.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ func (gs *GossipSubRouter) rpcs(msg *Message) iter.Seq2[peer.ID, *RPC] {
13751375
if pid == from || pid == peer.ID(msg.GetFrom()) {
13761376
continue
13771377
}
1378-
if peerStates, ok := gs.p.topics[topic]; ok && peerStates[pid].requestsPartial {
1378+
if gs.peerWantsPartial(pid, topic) {
13791379
// The peer requested partial messages. We'll skip sending them full messages
13801380
continue
13811381
}
@@ -1387,6 +1387,11 @@ func (gs *GossipSubRouter) rpcs(msg *Message) iter.Seq2[peer.ID, *RPC] {
13871387
}
13881388
}
13891389

1390+
func (gs *GossipSubRouter) peerWantsPartial(p peer.ID, topic string) bool {
1391+
peerStates, ok := gs.p.topics[topic]
1392+
return ok && gs.extensions.myExtensions.PartialMessages && peerStates[p].requestsPartial
1393+
}
1394+
13901395
func (gs *GossipSubRouter) Join(topic string) {
13911396
gmap, ok := gs.mesh[topic]
13921397
if ok {

pubsub.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,8 +1543,21 @@ type TopicOptions struct {
15431543

15441544
// RequestPartialMessages requests that peers, if they support it, send us
15451545
// partial messages on this topic.
1546+
//
1547+
// If a peer does not support partial messages, this has no effect, and the peer
1548+
// will continue sending us full messages
1549+
//
1550+
// It is an error to use this option if partial messages are not enabled
15461551
func RequestPartialMessages() TopicOpt {
15471552
return func(t *Topic) error {
1553+
gs, ok := t.p.rt.(*GossipSubRouter)
1554+
if !ok {
1555+
return errors.New("partial messages only supported by gossipsub")
1556+
}
1557+
1558+
if !gs.extensions.myExtensions.PartialMessages {
1559+
return errors.New("partial messages are not enabled")
1560+
}
15481561
t.requestPartialMessages = true
15491562
return nil
15501563
}

0 commit comments

Comments
 (0)