1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-30 09:59:13 +08:00

change back to using Client method

This commit is contained in:
Jeromy
2014-09-23 11:45:02 -07:00
committed by Brian Tiger Chow
parent c45cc8c448
commit 414ff34194
4 changed files with 18 additions and 13 deletions

View File

@ -281,8 +281,7 @@ func session(net tn.Network, rs mock.RoutingServer, id peer.ID) instance {
p := &peer.Peer{ID: id} p := &peer.Peer{ID: id}
adapter := net.Adapter(p) adapter := net.Adapter(p)
htc := mock.NewMockRouter(p, nil) htc := rs.Client(p)
htc.SetRoutingServer(rs)
blockstore := bstore.NewBlockstore(ds.NewMapDatastore()) blockstore := bstore.NewBlockstore(ds.NewMapDatastore())
const alwaysSendToPeer = true const alwaysSendToPeer = true

View File

@ -1 +0,0 @@
package bitswap

View File

@ -43,12 +43,10 @@ func TestSetAndGet(t *testing.T) {
} }
func TestClientFindProviders(t *testing.T) { func TestClientFindProviders(t *testing.T) {
peer := &peer.Peer{ peer := &peer.Peer{ID: []byte("42")}
ID: []byte("42"),
}
rs := mock.VirtualRoutingServer() rs := mock.VirtualRoutingServer()
client := mock.NewMockRouter(peer, nil) client := rs.Client(peer)
client.SetRoutingServer(rs)
k := u.Key("hello") k := u.Key("hello")
err := client.Provide(context.Background(), k) err := client.Provide(context.Background(), k)
if err != nil { if err != nil {
@ -99,8 +97,9 @@ func TestClientOverMax(t *testing.T) {
} }
max := 10 max := 10
client := mock.NewMockRouter(&peer.Peer{ID: []byte("TODO")}, nil) peer := &peer.Peer{ID: []byte("TODO")}
client.SetRoutingServer(rs) client := rs.Client(peer)
providersFromClient := client.FindProvidersAsync(context.Background(), k, max) providersFromClient := client.FindProvidersAsync(context.Background(), k, max)
i := 0 i := 0
for _ = range providersFromClient { for _ = range providersFromClient {
@ -132,8 +131,7 @@ func TestCanceledContext(t *testing.T) {
}() }()
local := &peer.Peer{ID: []byte("peer id doesn't matter")} local := &peer.Peer{ID: []byte("peer id doesn't matter")}
client := mock.NewMockRouter(local, nil) client := rs.Client(local)
client.SetRoutingServer(rs)
t.Log("warning: max is finite so this test is non-deterministic") t.Log("warning: max is finite so this test is non-deterministic")
t.Log("context cancellation could simply take lower priority") t.Log("context cancellation could simply take lower priority")

View File

@ -20,7 +20,7 @@ type MockRouter struct {
peer *peer.Peer peer *peer.Peer
} }
func NewMockRouter(local *peer.Peer, dstore ds.Datastore) *MockRouter { func NewMockRouter(local *peer.Peer, dstore ds.Datastore) routing.IpfsRouting {
return &MockRouter{ return &MockRouter{
datastore: dstore, datastore: dstore,
peer: local, peer: local,
@ -84,6 +84,8 @@ type RoutingServer interface {
Announce(*peer.Peer, u.Key) error Announce(*peer.Peer, u.Key) error
Providers(u.Key) []*peer.Peer Providers(u.Key) []*peer.Peer
Client(p *peer.Peer) routing.IpfsRouting
} }
func VirtualRoutingServer() RoutingServer { func VirtualRoutingServer() RoutingServer {
@ -128,3 +130,10 @@ func (rs *hashTable) Providers(k u.Key) []*peer.Peer {
return ret return ret
} }
func (rs *hashTable) Client(p *peer.Peer) routing.IpfsRouting {
return &MockRouter{
peer: p,
hashTable: rs,
}
}