@@ -168,9 +168,9 @@ func (m *PeerManager) NumTopicPeers(topic string) int {
168168 return len (m .pubsub .ListPeers (topic ))
169169}
170170
171- // RegisterProtocol starts tracking and managing peers that support the given protocol.
171+ // TrackProtocolPeers starts tracking and managing peers that support the given protocol.
172172// If the protocol is already registered, its values are updated.
173- func (m * PeerManager ) RegisterProtocol (p core.ProtocolID , minPeers int , totalPeers int ) {
173+ func (m * PeerManager ) TrackProtocolPeers (p core.ProtocolID , minPeers int , totalPeers int ) {
174174 m .mu .Lock ()
175175 defer m .mu .Unlock ()
176176
@@ -188,18 +188,16 @@ func (m *PeerManager) RegisterProtocol(p core.ProtocolID, minPeers int, totalPee
188188 }
189189
190190 m .protocols [p ] = & watermark {minPeers , totalPeers }
191- m .discovery .startAdvertising (string (p ))
192-
193191 m .logger .Debug ("protocol registered" ,
194192 "protocol" , p ,
195193 "min_peers" , minPeers ,
196194 "total_peers" , totalPeers ,
197195 )
198196}
199197
200- // RegisterTopic starts tracking and managing peers that support the given topic.
198+ // TrackTopicPeers starts tracking and managing peers that support the given topic.
201199// If the topic is already registered, its values are updated.
202- func (m * PeerManager ) RegisterTopic (topic string , minPeers int , totalPeers int ) {
200+ func (m * PeerManager ) TrackTopicPeers (topic string , minPeers int , totalPeers int ) {
203201 m .mu .Lock ()
204202 defer m .mu .Unlock ()
205203
@@ -217,7 +215,6 @@ func (m *PeerManager) RegisterTopic(topic string, minPeers int, totalPeers int)
217215 }
218216
219217 m .topics [topic ] = & watermark {minPeers , totalPeers }
220- m .discovery .startAdvertising (topic )
221218
222219 m .logger .Debug ("topic registered" ,
223220 "topic" , topic ,
@@ -226,9 +223,23 @@ func (m *PeerManager) RegisterTopic(topic string, minPeers int, totalPeers int)
226223 )
227224}
228225
229- // UnregisterProtocol stops managing peers that support the given protocol.
226+ // AdvertiseProtocol starts advertising readiness to serve the specified protocol.
227+ //
228+ // This enables remote peers without existing connection to find the host node.
229+ func (m * PeerManager ) AdvertiseProtocol (p core.ProtocolID ) {
230+ m .discovery .startAdvertising (string (p ))
231+ }
232+
233+ // AdvertiseTopic starts advertising readiness to serve the specified topic.
234+ //
235+ // This enables remote peers without existing connection to find the host node.
236+ func (m * PeerManager ) AdvertiseTopic (topic string ) {
237+ m .discovery .startAdvertising (topic )
238+ }
239+
240+ // StopTrackingProtocolPeers stops managing peers that support the given protocol.
230241// If the protocol is not registered, this is a noop operation.
231- func (m * PeerManager ) UnregisterProtocol (p core.ProtocolID ) {
242+ func (m * PeerManager ) StopTrackingProtocolPeers (p core.ProtocolID ) {
232243 m .mu .Lock ()
233244 defer m .mu .Unlock ()
234245
@@ -237,16 +248,15 @@ func (m *PeerManager) UnregisterProtocol(p core.ProtocolID) {
237248 }
238249
239250 delete (m .protocols , p )
240- m .discovery .stopAdvertising (string (p ))
241251
242252 m .logger .Debug ("protocol unregistered" ,
243253 "protocol" , p ,
244254 )
245255}
246256
247- // UnregisterTopic stops managing peers that support the given topic.
257+ // StopTrackingTopicPeers stops managing peers that support the given topic.
248258// If the topic is not registered, this is a noop operation.
249- func (m * PeerManager ) UnregisterTopic (topic string ) {
259+ func (m * PeerManager ) StopTrackingTopicPeers (topic string ) {
250260 m .mu .Lock ()
251261 defer m .mu .Unlock ()
252262
@@ -255,13 +265,22 @@ func (m *PeerManager) UnregisterTopic(topic string) {
255265 }
256266
257267 delete (m .topics , topic )
258- m .discovery .stopAdvertising (topic )
259268
260269 m .logger .Debug ("topic unregistered" ,
261270 "topic" , topic ,
262271 )
263272}
264273
274+ // StopAdvertisingProtocol stops advertising readiness to serve the specified protocol.
275+ func (m * PeerManager ) StopAdvertisingProtocol (p core.ProtocolID ) {
276+ m .discovery .stopAdvertising (string (p ))
277+ }
278+
279+ // StopAdvertisingTopic stops advertising readiness to serve the specified protocol.
280+ func (m * PeerManager ) StopAdvertisingTopic (topic string ) {
281+ m .discovery .stopAdvertising (topic )
282+ }
283+
265284func (m * PeerManager ) run (ctx context.Context ) {
266285 // Start background services.
267286 m .backup .start ()
0 commit comments