Skip to content

Commit

Permalink
Correct the requestByNumber topic
Browse files Browse the repository at this point in the history
  • Loading branch information
Djadih committed May 16, 2024
1 parent 4141ac5 commit e8d6196
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions p2p/node/peerManager/peerManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"maps"
"net"
"reflect"
"runtime/debug"
"strings"
"sync"
Expand Down Expand Up @@ -343,19 +344,25 @@ func (pm *BasicPeerManager) GetPeers(location common.Location, data interface{},

func (pm *BasicPeerManager) queryDHT(location common.Location, data interface{}, peerList map[p2p.PeerID]struct{}, peerCount int) map[p2p.PeerID]struct{} {
// create a Cid from the slice location
topicName, _ := pubsubManager.TopicName(pm.genesis, location, data)
topicName, err := pubsubManager.TopicName(pm.genesis, location, data)
if err != nil {
log.Global.WithFields(log.Fields{
"location": location,
"dataType": reflect.TypeOf(data),
}).Error("Unable to find topic for requested data")
}
topicCid := pubsubManager.TopicToCid(topicName)

// Internal list of peers from the dht
dhtPeers := make(map[p2p.PeerID]struct{})
log.Global.Infof("Querying DHT for slice Cid %s", topicCid)
log.Global.WithField("topic", topicName).Infof("Querying DHT for topic")
// query the DHT for peers in the slice
for peer := range pm.dht.FindProvidersAsync(pm.ctx, topicCid, peerCount) {
if peer.ID != pm.selfID {
dhtPeers[peer.ID] = struct{}{}
}
}
log.Global.Warn("Found the following peers from the DHT: ", dhtPeers)
log.Global.Info("Found the following peers from the DHT: ", dhtPeers)
maps.Copy(peerList, dhtPeers)
return peerList
}
Expand Down
8 changes: 4 additions & 4 deletions p2p/node/pubsubManager/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pubsubManager

import (
"errors"
"math/big"
"strings"

"github.com/dominant-strategies/go-quai/common"
Expand All @@ -17,18 +18,17 @@ const (
C_workObjectType = "blocks"
C_transactionType = "transactions"
C_headerType = "headers"
C_hashType = "hash"
C_workObjectHeaderType = "woHeaders"
)

// gets the name of the topic for the given type of data
func TopicName(genesis common.Hash, location common.Location, data interface{}) (string, error) {
baseTopic := strings.Join([]string{genesis.String(), location.Name()}, "/")
switch data.(type) {
case *types.WorkObject:
case *types.WorkObject, *big.Int, common.Hash:
return strings.Join([]string{baseTopic, C_workObjectType}, "/"), nil
case common.Hash:
return strings.Join([]string{baseTopic, C_hashType}, "/"), nil
case *types.Transaction:
return strings.Join([]string{baseTopic, C_transactionType}, "/"), nil
case *types.Transactions:
return strings.Join([]string{baseTopic, C_transactionType}, "/"), nil
case *types.WorkObjectHeader:
Expand Down

0 comments on commit e8d6196

Please sign in to comment.