Commit 2c1700b4 authored by Brian Tiger Chow's avatar Brian Tiger Chow

refactor(dht) remove extraneous return value

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 5e61ef67
...@@ -97,32 +97,23 @@ func NewDHT(ctx context.Context, p peer.Peer, ps peer.Peerstore, dialer inet.Dia ...@@ -97,32 +97,23 @@ func NewDHT(ctx context.Context, p peer.Peer, ps peer.Peerstore, dialer inet.Dia
} }
// Connect to a new peer at the given address, ping and add to the routing table // Connect to a new peer at the given address, ping and add to the routing table
func (dht *IpfsDHT) Connect(ctx context.Context, npeer peer.Peer) (peer.Peer, error) { func (dht *IpfsDHT) Connect(ctx context.Context, npeer peer.Peer) error {
// TODO(jbenet,whyrusleeping)
//
// Connect should take in a Peer (with ID). In a sense, we shouldn't be
// allowing connections to random multiaddrs without knowing who we're
// speaking to (i.e. peer.ID). In terms of moving around simple addresses
// -- instead of an (ID, Addr) pair -- we can use:
//
// /ip4/10.20.30.40/tcp/1234/ipfs/Qxhxxchxzcncxnzcnxzcxzm
//
err := dht.dialer.DialPeer(ctx, npeer) err := dht.dialer.DialPeer(ctx, npeer)
if err != nil { if err != nil {
return nil, err return err
} }
// Ping new peer to register in their routing table // Ping new peer to register in their routing table
// NOTE: this should be done better... // NOTE: this should be done better...
err = dht.Ping(ctx, npeer) err = dht.Ping(ctx, npeer)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to ping newly connected peer: %s\n", err) return fmt.Errorf("failed to ping newly connected peer: %s\n", err)
} }
log.Event(ctx, "connect", dht.self, npeer) log.Event(ctx, "connect", dht.self, npeer)
dht.Update(ctx, npeer) dht.Update(ctx, npeer)
return npeer, nil return nil
} }
// HandleMessage implements the inet.Handler interface. // HandleMessage implements the inet.Handler interface.
......
...@@ -101,7 +101,7 @@ func TestPing(t *testing.T) { ...@@ -101,7 +101,7 @@ func TestPing(t *testing.T) {
defer dhtA.dialer.(inet.Network).Close() defer dhtA.dialer.(inet.Network).Close()
defer dhtB.dialer.(inet.Network).Close() defer dhtB.dialer.(inet.Network).Close()
_, err = dhtA.Connect(ctx, peerB) err = dhtA.Connect(ctx, peerB)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -151,7 +151,7 @@ func TestValueGetSet(t *testing.T) { ...@@ -151,7 +151,7 @@ func TestValueGetSet(t *testing.T) {
defer dhtA.dialer.(inet.Network).Close() defer dhtA.dialer.(inet.Network).Close()
defer dhtB.dialer.(inet.Network).Close() defer dhtB.dialer.(inet.Network).Close()
_, err = dhtA.Connect(ctx, peerB) err = dhtA.Connect(ctx, peerB)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -194,17 +194,17 @@ func TestProvides(t *testing.T) { ...@@ -194,17 +194,17 @@ func TestProvides(t *testing.T) {
} }
}() }()
_, err := dhts[0].Connect(ctx, peers[1]) err := dhts[0].Connect(ctx, peers[1])
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = dhts[1].Connect(ctx, peers[2]) err = dhts[1].Connect(ctx, peers[2])
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = dhts[1].Connect(ctx, peers[3]) err = dhts[1].Connect(ctx, peers[3])
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -256,17 +256,17 @@ func TestProvidesAsync(t *testing.T) { ...@@ -256,17 +256,17 @@ func TestProvidesAsync(t *testing.T) {
} }
}() }()
_, err := dhts[0].Connect(ctx, peers[1]) err := dhts[0].Connect(ctx, peers[1])
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = dhts[1].Connect(ctx, peers[2]) err = dhts[1].Connect(ctx, peers[2])
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = dhts[1].Connect(ctx, peers[3]) err = dhts[1].Connect(ctx, peers[3])
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -321,17 +321,17 @@ func TestLayeredGet(t *testing.T) { ...@@ -321,17 +321,17 @@ func TestLayeredGet(t *testing.T) {
} }
}() }()
_, err := dhts[0].Connect(ctx, peers[1]) err := dhts[0].Connect(ctx, peers[1])
if err != nil { if err != nil {
t.Fatalf("Failed to connect: %s", err) t.Fatalf("Failed to connect: %s", err)
} }
_, err = dhts[1].Connect(ctx, peers[2]) err = dhts[1].Connect(ctx, peers[2])
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = dhts[1].Connect(ctx, peers[3]) err = dhts[1].Connect(ctx, peers[3])
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -376,17 +376,17 @@ func TestFindPeer(t *testing.T) { ...@@ -376,17 +376,17 @@ func TestFindPeer(t *testing.T) {
} }
}() }()
_, err := dhts[0].Connect(ctx, peers[1]) err := dhts[0].Connect(ctx, peers[1])
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = dhts[1].Connect(ctx, peers[2]) err = dhts[1].Connect(ctx, peers[2])
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = dhts[1].Connect(ctx, peers[3]) err = dhts[1].Connect(ctx, peers[3])
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -435,14 +435,14 @@ func TestConnectCollision(t *testing.T) { ...@@ -435,14 +435,14 @@ func TestConnectCollision(t *testing.T) {
done := make(chan struct{}) done := make(chan struct{})
go func() { go func() {
_, err := dhtA.Connect(ctx, peerB) err := dhtA.Connect(ctx, peerB)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
done <- struct{}{} done <- struct{}{}
}() }()
go func() { go func() {
_, err := dhtB.Connect(ctx, peerA) err := dhtB.Connect(ctx, peerA)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment