github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/routing/mock/interface.go (about) 1 // Package mock provides a virtual routing server. To use it, create a virtual 2 // routing server and use the Client() method to get a routing client 3 // (IpfsRouting). The server quacks like a DHT but is really a local in-memory 4 // hash table. 5 package mockrouting 6 7 import ( 8 ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore" 9 context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context" 10 key "github.com/ipfs/go-ipfs/blocks/key" 11 peer "github.com/ipfs/go-ipfs/p2p/peer" 12 routing "github.com/ipfs/go-ipfs/routing" 13 delay "github.com/ipfs/go-ipfs/thirdparty/delay" 14 "github.com/ipfs/go-ipfs/util/testutil" 15 ) 16 17 // Server provides mockrouting Clients 18 type Server interface { 19 Client(p testutil.Identity) Client 20 ClientWithDatastore(context.Context, testutil.Identity, ds.Datastore) Client 21 } 22 23 // Client implements IpfsRouting 24 type Client interface { 25 FindProviders(context.Context, key.Key) ([]peer.PeerInfo, error) 26 routing.IpfsRouting 27 } 28 29 // NewServer returns a mockrouting Server 30 func NewServer() Server { 31 return NewServerWithDelay(DelayConfig{ 32 ValueVisibility: delay.Fixed(0), 33 Query: delay.Fixed(0), 34 }) 35 } 36 37 // NewServerWithDelay returns a mockrouting Server with a delay! 38 func NewServerWithDelay(conf DelayConfig) Server { 39 return &s{ 40 providers: make(map[key.Key]map[peer.ID]providerRecord), 41 delayConf: conf, 42 } 43 } 44 45 type DelayConfig struct { 46 // ValueVisibility is the time it takes for a value to be visible in the network 47 // FIXME there _must_ be a better term for this 48 ValueVisibility delay.D 49 50 // Query is the time it takes to receive a response from a routing query 51 Query delay.D 52 }