mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-16 04:02:05 +08:00

We now consider debugerrors harmful: we've run into cases where debugerror.Wrap() hid valuable error information (err == io.EOF?). I've removed them from the main code, but left them in some tests. Go errors are lacking, but unfortunately, this isn't the solution. It is possible that debugerros.New or debugerrors.Errorf should remain still (i.e. only remove debugerrors.Wrap) but we don't use these errors often enough to keep.
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package mockrouting
|
|
|
|
import (
|
|
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
|
|
sync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
|
|
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
|
mocknet "github.com/ipfs/go-ipfs/p2p/net/mock"
|
|
dht "github.com/ipfs/go-ipfs/routing/dht"
|
|
"github.com/ipfs/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.Identity) Client {
|
|
return rs.ClientWithDatastore(context.TODO(), p, ds.NewMapDatastore())
|
|
}
|
|
|
|
func (rs *mocknetserver) ClientWithDatastore(ctx context.Context, p testutil.Identity, ds ds.Datastore) Client {
|
|
|
|
// FIXME AddPeer doesn't appear to be idempotent
|
|
|
|
host, err := rs.mn.AddPeer(p.PrivateKey(), p.Address())
|
|
if err != nil {
|
|
panic("FIXME")
|
|
}
|
|
return dht.NewDHT(ctx, host, sync.MutexWrap(ds))
|
|
}
|
|
|
|
var _ Server = &mocknetserver{}
|