Skip to content

Commit

Permalink
Announce to the DHT that we are providing a topic when we subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
Djadih committed Apr 23, 2024
1 parent c07c1e7 commit a484ac4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion p2p/node/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ func (p *P2PNode) Start() error {
}

func (p *P2PNode) Subscribe(location common.Location, datatype interface{}) error {
return p.pubsub.Subscribe(location, datatype)
err := p.pubsub.Subscribe(location, datatype)
if err != nil {
return err
}

return p.peerManager.Provide(p.ctx, location, datatype)
}

func (p *P2PNode) Broadcast(location common.Location, data interface{}) error {
Expand Down
7 changes: 7 additions & 0 deletions p2p/peerManager/peerManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ type PeerManager interface {
// Sets the DHT provided from the Host interface
SetDHT(*dual.DHT)

// Announces to the DHT that we are providing this data
Provide(context.Context, common.Location, interface{}) error

// Manages stream lifecycles
streamManager.StreamManager

Expand Down Expand Up @@ -253,6 +256,10 @@ func (pm *BasicPeerManager) CloseStream(peerID p2p.PeerID) error {
return pm.streamManager.CloseStream(peerID)
}

func (pm *BasicPeerManager) Provide(ctx context.Context, location common.Location, data interface{}) error {
return pm.dht.Provide(ctx, pubsubManager.LocationToCid(location), true)
}

func (pm *BasicPeerManager) SetP2PBackend(p2pBackend quaiprotocol.QuaiP2PNode) {
pm.streamManager.SetP2PBackend(p2pBackend)
}
Expand Down

0 comments on commit a484ac4

Please sign in to comment.