@@ -18,7 +18,6 @@ import (
1818 "github.com/pastelnetwork/gonode/common/storage"
1919 "github.com/pastelnetwork/gonode/common/storage/memory"
2020 "github.com/pastelnetwork/gonode/common/utils"
21- "github.com/pastelnetwork/gonode/p2p/kademlia/domain"
2221 "github.com/pastelnetwork/gonode/pastel"
2322 "golang.org/x/crypto/sha3"
2423)
@@ -36,20 +35,19 @@ const maxIterations = 5
3635
3736// DHT represents the state of the local node in the distributed hash table
3837type DHT struct {
39- ht * HashTable // the hashtable for routing
40- options * Options // the options of DHT
41- network * Network // the network of DHT
42- store Store // the storage of DHT
43- metaStore MetaStore // the meta storage of DHT
44- done chan struct {} // distributed hash table is done
45- cache storage.KeyValue // store bad bootstrap addresses
46- pastelClient pastel.Client
47- externalIP string
48- mtx sync.Mutex
49- authHelper * AuthHelper
50- ignorelist * BanList
51- nodeReplicationTimes map [string ]domain.NodeReplicationInfo
52- replicationMtx sync.RWMutex
38+ ht * HashTable // the hashtable for routing
39+ options * Options // the options of DHT
40+ network * Network // the network of DHT
41+ store Store // the storage of DHT
42+ metaStore MetaStore // the meta storage of DHT
43+ done chan struct {} // distributed hash table is done
44+ cache storage.KeyValue // store bad bootstrap addresses
45+ pastelClient pastel.Client
46+ externalIP string
47+ mtx sync.Mutex
48+ authHelper * AuthHelper
49+ ignorelist * BanList
50+ replicationMtx sync.RWMutex
5351}
5452
5553// Options contains configuration options for the local node
@@ -84,26 +82,16 @@ func NewDHT(ctx context.Context, store Store, metaStore MetaStore, pc pastel.Cli
8482 if options .Port <= 0 {
8583 options .Port = defaultNetworkPort
8684 }
87- info , err := store .GetAllReplicationInfo (ctx )
88- if err != nil {
89- log .P2P ().WithContext (ctx ).WithError (err ).Errorf ("get all replicationInfo failed" )
90- }
91-
92- replicationMap := make (map [string ]domain.NodeReplicationInfo )
93- for _ , v := range info {
94- replicationMap [string (v .ID )] = v
95- }
9685
9786 s := & DHT {
98- metaStore : metaStore ,
99- store : store ,
100- options : options ,
101- pastelClient : pc ,
102- done : make (chan struct {}),
103- cache : memory .NewKeyValue (),
104- ignorelist : NewBanList (ctx ),
105- nodeReplicationTimes : replicationMap ,
106- replicationMtx : sync.RWMutex {},
87+ metaStore : metaStore ,
88+ store : store ,
89+ options : options ,
90+ pastelClient : pc ,
91+ done : make (chan struct {}),
92+ cache : memory .NewKeyValue (),
93+ ignorelist : NewBanList (ctx ),
94+ replicationMtx : sync.RWMutex {},
10795 }
10896
10997 if options .ExternalIP != "" {
@@ -482,7 +470,7 @@ func (s *DHT) iterate(ctx context.Context, iterativeType int, target []byte, dat
482470
483471 igList := s .ignorelist .ToNodeList ()
484472 // find the closest contacts for the target node from local route tables
485- nl := s .ht .closestContacts (Alpha , target , igList )
473+ nl , _ := s .ht .closestContacts (Alpha , target , igList )
486474 if len (igList ) > 0 {
487475 log .P2P ().WithContext (ctx ).WithField ("nodes" , nl .String ()).WithField ("ignored" , s .ignorelist .String ()).Info ("closest contacts" )
488476 }
@@ -633,7 +621,7 @@ func (s *DHT) iterateFindValue(ctx context.Context, iterativeType int, target []
633621 igList := s .ignorelist .ToNodeList ()
634622
635623 // nl will have the closest nodes to the target value, it will ignore the nodes in igList
636- nl := s .ht .closestContacts (Alpha , target , igList )
624+ nl , _ := s .ht .closestContacts (Alpha , target , igList )
637625 if len (igList ) > 0 {
638626 log .P2P ().WithContext (ctx ).WithField ("nodes" , nl .String ()).WithField ("ignored" , s .ignorelist .String ()).Info ("closest contacts" )
639627 }
@@ -785,7 +773,7 @@ func (s *DHT) addNode(ctx context.Context, node *Node) *Node {
785773func (s * DHT ) NClosestNodes (_ context.Context , n int , key string , ignores ... * Node ) []* Node {
786774 list := s .ignorelist .ToNodeList ()
787775 ignores = append (ignores , list ... )
788- nodeList := s .ht .closestContacts (n , base58 .Decode (key ), ignores )
776+ nodeList , _ := s .ht .closestContacts (n , base58 .Decode (key ), ignores )
789777
790778 return nodeList .Nodes
791779}
0 commit comments