mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-04-24 22:32:13 +00:00
net: add Connectedness var.
This commit is contained in:
parent
58f4c4c16d
commit
1b96fd5f6a
36
ext_test.go
36
ext_test.go
@ -8,6 +8,7 @@ import (
|
||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
|
||||
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
|
||||
inet "github.com/jbenet/go-ipfs/net"
|
||||
msg "github.com/jbenet/go-ipfs/net/message"
|
||||
mux "github.com/jbenet/go-ipfs/net/mux"
|
||||
peer "github.com/jbenet/go-ipfs/peer"
|
||||
@ -79,6 +80,7 @@ func (f *fauxSender) SendMessage(ctx context.Context, m msg.NetMessage) error {
|
||||
// fauxNet is a standin for a swarm.Network in order to more easily recreate
|
||||
// different testing scenarios
|
||||
type fauxNet struct {
|
||||
local peer.Peer
|
||||
}
|
||||
|
||||
// DialPeer attempts to establish a connection to a given peer
|
||||
@ -86,6 +88,10 @@ func (f *fauxNet) DialPeer(context.Context, peer.Peer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fauxNet) LocalPeer() peer.Peer {
|
||||
return f.local
|
||||
}
|
||||
|
||||
// ClosePeer connection to peer
|
||||
func (f *fauxNet) ClosePeer(peer.Peer) error {
|
||||
return nil
|
||||
@ -96,6 +102,11 @@ func (f *fauxNet) IsConnected(peer.Peer) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Connectedness returns whether a connection to given peer exists.
|
||||
func (f *fauxNet) Connectedness(peer.Peer) inet.Connectedness {
|
||||
return inet.Connected
|
||||
}
|
||||
|
||||
// GetProtocols returns the protocols registered in the network.
|
||||
func (f *fauxNet) GetProtocols() *mux.ProtocolMap { return nil }
|
||||
|
||||
@ -120,13 +131,13 @@ func TestGetFailures(t *testing.T) {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
fn := &fauxNet{}
|
||||
fs := &fauxSender{}
|
||||
|
||||
peerstore := peer.NewPeerstore()
|
||||
local := makePeerString(t, "")
|
||||
|
||||
ctx := context.Background()
|
||||
fn := &fauxNet{local}
|
||||
fs := &fauxSender{}
|
||||
|
||||
d := NewDHT(ctx, local, peerstore, fn, fs, ds.NewMapDatastore())
|
||||
other := makePeerString(t, "")
|
||||
d.Update(ctx, other)
|
||||
@ -219,14 +230,14 @@ func TestNotFound(t *testing.T) {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
fn := &fauxNet{}
|
||||
fs := &fauxSender{}
|
||||
|
||||
local := makePeerString(t, "")
|
||||
peerstore := peer.NewPeerstore()
|
||||
peerstore.Add(local)
|
||||
|
||||
ctx := context.Background()
|
||||
fn := &fauxNet{local}
|
||||
fs := &fauxSender{}
|
||||
|
||||
d := NewDHT(ctx, local, peerstore, fn, fs, ds.NewMapDatastore())
|
||||
|
||||
var ps []peer.Peer
|
||||
@ -285,14 +296,15 @@ func TestNotFound(t *testing.T) {
|
||||
func TestLessThanKResponses(t *testing.T) {
|
||||
// t.Skip("skipping test because it makes a lot of output")
|
||||
|
||||
ctx := context.Background()
|
||||
u.Debug = false
|
||||
fn := &fauxNet{}
|
||||
fs := &fauxSender{}
|
||||
local := makePeerString(t, "")
|
||||
peerstore := peer.NewPeerstore()
|
||||
peerstore.Add(local)
|
||||
|
||||
ctx := context.Background()
|
||||
u.Debug = false
|
||||
fn := &fauxNet{local}
|
||||
fs := &fauxSender{}
|
||||
|
||||
d := NewDHT(ctx, local, peerstore, fn, fs, ds.NewMapDatastore())
|
||||
|
||||
var ps []peer.Peer
|
||||
|
Loading…
x
Reference in New Issue
Block a user