@cryptotaxi247 / kubo / commits / 9ec3c1aac

clean up unused dht methods

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Jul 13, 2015 at 15:53 UTC 9ec3c1aac1ea5871b3b3dd964ff464ea293e0746
2 files changed +6 -60
routing/dht/dht.go
-57
@@ -4,7 +4,6 @@ package dht
4
5 import (
6 "bytes"
7 - "crypto/rand"
7 "errors"
8 "fmt"
9 "sync"
@@ -33,8 +32,6 @@ var log = eventlog.Logger("dht")
32
33 var ProtocolDHT protocol.ID = "/ipfs/dht"
34
36 -const doPinging = false
37 -
35 // NumBootstrapQueries defines the number of random dht queries to do to
36 // collect members of the routing table.
37 const NumBootstrapQueries = 5
@@ -92,11 +89,6 @@ func NewDHT(ctx context.Context, h host.Host, dstore ds.ThreadSafeDatastore) *Ip
89 dht.Validator = make(record.Validator)
90 dht.Validator["pk"] = record.PublicKeyValidator
91
95 - if doPinging {
96 - dht.proc.Go(func(p goprocess.Process) {
97 - dht.PingRoutine(time.Second * 10)
98 - })
99 - }
92 return dht
93 }
94
@@ -110,23 +102,6 @@ func (dht *IpfsDHT) log() eventlog.EventLogger {
102 return log // TODO rm
103 }
104
113 -// Connect to a new peer at the given address, ping and add to the routing table
114 -func (dht *IpfsDHT) Connect(ctx context.Context, npeer peer.ID) error {
115 - // TODO: change interface to accept a PeerInfo as well.
116 - if err := dht.host.Connect(ctx, peer.PeerInfo{ID: npeer}); err != nil {
117 - return err
118 - }
119 -
120 - // Ping new peer to register in their routing table
121 - // NOTE: this should be done better...
122 - if _, err := dht.Ping(ctx, npeer); err != nil {
123 - return fmt.Errorf("failed to ping newly connected peer: %s", err)
124 - }
125 - log.Event(ctx, "connect", dht.self, npeer)
126 - dht.Update(ctx, npeer)
127 - return nil
128 -}
129 -
105 // putValueToPeer stores the given key/value pair at the peer 'p'
106 func (dht *IpfsDHT) putValueToPeer(ctx context.Context, p peer.ID,
107 key key.Key, rec *pb.Record) error {
@@ -343,38 +318,6 @@ func (dht *IpfsDHT) betterPeersToQuery(pmes *pb.Message, p peer.ID, count int) [
318 return filtered
319 }
320
346 -func (dht *IpfsDHT) ensureConnectedToPeer(ctx context.Context, p peer.ID) error {
347 - if p == dht.self {
348 - return errors.New("attempting to ensure connection to self")
349 - }
350 -
351 - // dial connection
352 - return dht.host.Connect(ctx, peer.PeerInfo{ID: p})
353 -}
354 -
355 -// PingRoutine periodically pings nearest neighbors.
356 -func (dht *IpfsDHT) PingRoutine(t time.Duration) {
357 - tick := time.Tick(t)
358 - for {
359 - select {
360 - case <-tick:
361 - id := make([]byte, 16)
362 - rand.Read(id)
363 - peers := dht.routingTable.NearestPeers(kb.ConvertKey(key.Key(id)), 5)
364 - for _, p := range peers {
365 - ctx, cancel := context.WithTimeout(dht.Context(), time.Second*5)
366 - _, err := dht.Ping(ctx, p)
367 - if err != nil {
368 - log.Debugf("Ping error: %s", err)
369 - }
370 - cancel()
371 - }
372 - case <-dht.proc.Closing():
373 - return
374 - }
375 - }
376 -}
377 -
321 // Context return dht's context
322 func (dht *IpfsDHT) Context() context.Context {
323 return dht.ctx
routing/dht/dht_test.go
+6 -3
@@ -74,7 +74,8 @@ func connect(t *testing.T, ctx context.Context, a, b *IpfsDHT) {
74 }
75
76 a.peerstore.AddAddrs(idB, addrB, peer.TempAddrTTL)
77 - if err := a.Connect(ctx, idB); err != nil {
77 + pi := peer.PeerInfo{ID: idB}
78 + if err := a.host.Connect(ctx, pi); err != nil {
79 t.Fatal(err)
80 }
81 }
@@ -789,12 +790,14 @@ func TestConnectCollision(t *testing.T) {
790 errs := make(chan error)
791 go func() {
792 dhtA.peerstore.AddAddr(peerB, addrB, peer.TempAddrTTL)
792 - err := dhtA.Connect(ctx, peerB)
793 + pi := peer.PeerInfo{ID: peerB}
794 + err := dhtA.host.Connect(ctx, pi)
795 errs <- err
796 }()
797 go func() {
798 dhtB.peerstore.AddAddr(peerA, addrA, peer.TempAddrTTL)
797 - err := dhtB.Connect(ctx, peerA)
799 + pi := peer.PeerInfo{ID: peerA}
800 + err := dhtB.host.Connect(ctx, pi)
801 errs <- err
802 }()
803