@@ -47,6 +47,7 @@ type ProtocolMatchFn = func(protocol.ID) func(protocol.ID) bool
4747
4848type peerTopicState struct {
4949 requestsPartial bool
50+ supportsPartial bool
5051}
5152
5253type peerOutgoingStream struct {
@@ -1197,15 +1198,18 @@ func (p *PubSub) handleRemoveRelay(topic string) {
11971198// Only called from processLoop.
11981199func (p * PubSub ) announce (topic string , sub bool ) {
11991200 var requestPartialMessages bool
1201+ var supportsPartialMessages bool
12001202 if sub {
12011203 if t , ok := p .myTopics [topic ]; ok {
12021204 requestPartialMessages = t .requestPartialMessages
1205+ supportsPartialMessages = t .supportsPartialMessages
12031206 }
12041207 }
12051208 subopt := & pb.RPC_SubOpts {
1206- Topicid : & topic ,
1207- Subscribe : & sub ,
1208- Partial : & requestPartialMessages ,
1209+ Topicid : & topic ,
1210+ Subscribe : & sub ,
1211+ RequestsPartial : & requestPartialMessages ,
1212+ SupportsPartial : & supportsPartialMessages ,
12091213 }
12101214
12111215 out := rpcWithSubs (subopt )
@@ -1248,15 +1252,18 @@ func (p *PubSub) doAnnounceRetry(pid peer.ID, topic string, sub bool) {
12481252 }
12491253
12501254 var requestPartialMessages bool
1255+ var supportsPartialMessages bool
12511256 if sub {
12521257 if t , ok := p .myTopics [topic ]; ok {
12531258 requestPartialMessages = t .requestPartialMessages
1259+ supportsPartialMessages = t .supportsPartialMessages
12541260 }
12551261 }
12561262 subopt := & pb.RPC_SubOpts {
1257- Topicid : & topic ,
1258- Subscribe : & sub ,
1259- Partial : & requestPartialMessages ,
1263+ Topicid : & topic ,
1264+ Subscribe : & sub ,
1265+ RequestsPartial : & requestPartialMessages ,
1266+ SupportsPartial : & supportsPartialMessages ,
12601267 }
12611268
12621269 out := rpcWithSubs (subopt )
@@ -1360,16 +1367,19 @@ func (p *PubSub) handleIncomingRPC(rpc *RPC) {
13601367 p .topics [t ] = tmap
13611368 }
13621369
1363- if _ , ok = tmap [rpc .from ]; ! ok {
1364- tmap [rpc .from ] = peerTopicState {requestsPartial : subopt .GetPartial ()}
1370+ pts := peerTopicState {
1371+ requestsPartial : subopt .GetRequestsPartial (),
1372+ // If they peer requested partial, they support it by default
1373+ supportsPartial : subopt .GetRequestsPartial () || subopt .GetSupportsPartial (),
1374+ }
1375+ _ , seenBefore := tmap [rpc .from ]
1376+ tmap [rpc .from ] = pts
1377+ if ! seenBefore {
1378+ tmap [rpc .from ] = pts
13651379 if topic , ok := p .myTopics [t ]; ok {
13661380 peer := rpc .from
13671381 topic .sendNotification (PeerEvent {PeerJoin , peer })
13681382 }
1369- } else {
1370- s := tmap [rpc .from ]
1371- s .requestsPartial = subopt .GetPartial ()
1372- tmap [rpc .from ] = s
13731383 }
13741384 } else {
13751385 tmap , ok := p .topics [t ]
@@ -1565,6 +1575,22 @@ func RequestPartialMessages() TopicOpt {
15651575 return errors .New ("partial messages are not enabled" )
15661576 }
15671577 t .requestPartialMessages = true
1578+ t .supportsPartialMessages = true
1579+ return nil
1580+ }
1581+ }
1582+
1583+ func SupportsPartialMessages () TopicOpt {
1584+ return func (t * Topic ) error {
1585+ gs , ok := t .p .rt .(* GossipSubRouter )
1586+ if ! ok {
1587+ return errors .New ("partial messages only supported by gossipsub" )
1588+ }
1589+
1590+ if ! gs .extensions .myExtensions .PartialMessages {
1591+ return errors .New ("partial messages are not enabled" )
1592+ }
1593+ t .supportsPartialMessages = true
15681594 return nil
15691595 }
15701596}
0 commit comments