1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 14:34:24 +08:00

refactor(mockrouting) misc

License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
This commit is contained in:
Brian Tiger Chow
2014-12-12 22:56:36 -08:00
parent 193004a061
commit 3ecdec985f
10 changed files with 228 additions and 197 deletions

40
routing/mock/interface.go Normal file
View File

@ -0,0 +1,40 @@
// Package mock provides a virtual routing server. To use it, create a virtual
// routing server and use the Client() method to get a routing client
// (IpfsRouting). The server quacks like a DHT but is really a local in-memory
// hash table.
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"
peer "github.com/jbenet/go-ipfs/peer"
routing "github.com/jbenet/go-ipfs/routing"
u "github.com/jbenet/go-ipfs/util"
delay "github.com/jbenet/go-ipfs/util/delay"
)
// Server provides mockrouting Clients
type Server interface {
Client(p peer.Peer) Client
ClientWithDatastore(peer.Peer, ds.Datastore) Client
}
// Client implements IpfsRouting
type Client interface {
FindProviders(context.Context, u.Key) ([]peer.Peer, error)
routing.IpfsRouting
}
// NewServer returns a mockrouting Server
func NewServer() Server {
return NewServerWithDelay(delay.Fixed(0))
}
// NewServerWithDelay returns a mockrouting Server with a delay!
func NewServerWithDelay(d delay.D) Server {
return &s{
providers: make(map[u.Key]peer.Map),
delay: d,
}
}