mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-09 19:32:24 +08:00
rename to dht
This commit is contained in:
38
routing/mock/dht.go
Normal file
38
routing/mock/dht.go
Normal file
@ -0,0 +1,38 @@
|
||||
package mockrouting
|
||||
|
||||
import (
|
||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
|
||||
sync "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
|
||||
mocknet "github.com/jbenet/go-ipfs/net/mock"
|
||||
dht "github.com/jbenet/go-ipfs/routing/dht"
|
||||
"github.com/jbenet/go-ipfs/util/testutil"
|
||||
)
|
||||
|
||||
type mocknetserver struct {
|
||||
mn mocknet.Mocknet
|
||||
}
|
||||
|
||||
func NewDHTNetwork(mn mocknet.Mocknet) Server {
|
||||
return &mocknetserver{
|
||||
mn: mn,
|
||||
}
|
||||
}
|
||||
|
||||
func (rs *mocknetserver) Client(p testutil.Peer) Client {
|
||||
return rs.ClientWithDatastore(context.TODO(), p, ds.NewMapDatastore())
|
||||
}
|
||||
|
||||
func (rs *mocknetserver) ClientWithDatastore(ctx context.Context, p testutil.Peer, ds ds.Datastore) Client {
|
||||
|
||||
// FIXME AddPeer doesn't appear to be idempotent
|
||||
|
||||
net, err := rs.mn.AddPeer(p.PrivateKey(), p.Address())
|
||||
if err != nil {
|
||||
panic("FIXME")
|
||||
// return nil, debugerror.Wrap(err)
|
||||
}
|
||||
return dht.NewDHT(ctx, p.ID(), net, sync.MutexWrap(ds))
|
||||
}
|
||||
|
||||
var _ Server = &mocknetserver{}
|
Reference in New Issue
Block a user