mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
They have been moved to their own repositories: * github.com/ipfs/go-ipfs-delay * github.com/ipfs/go-ipfs-flags History has been preserved. They have been published with gx'ed. Imports have been updated and re-ordered accordingly. License: MIT Signed-off-by: Hector Sanjuan <hector@protocol.ai>
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
// Package mockrouting 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"
|
|
|
|
ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
|
|
delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
|
|
routing "gx/ipfs/QmTiWLZ6Fo5j4KcTVutZJ5KWRRJrbxzmxA4td8NfEdrPh7/go-libp2p-routing"
|
|
"gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
|
|
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
|
|
)
|
|
|
|
// Server provides mockrouting Clients
|
|
type Server interface {
|
|
Client(p testutil.Identity) Client
|
|
ClientWithDatastore(context.Context, testutil.Identity, ds.Datastore) Client
|
|
}
|
|
|
|
// Client implements IpfsRouting
|
|
type Client interface {
|
|
routing.IpfsRouting
|
|
}
|
|
|
|
// NewServer returns a mockrouting Server
|
|
func NewServer() Server {
|
|
return NewServerWithDelay(DelayConfig{
|
|
ValueVisibility: delay.Fixed(0),
|
|
Query: delay.Fixed(0),
|
|
})
|
|
}
|
|
|
|
// NewServerWithDelay returns a mockrouting Server with a delay!
|
|
func NewServerWithDelay(conf DelayConfig) Server {
|
|
return &s{
|
|
providers: make(map[string]map[peer.ID]providerRecord),
|
|
delayConf: conf,
|
|
}
|
|
}
|
|
|
|
// DelayConfig can be used to configured the fake delays of a mock server.
|
|
// Use with NewServerWithDelay().
|
|
type DelayConfig struct {
|
|
// ValueVisibility is the time it takes for a value to be visible in the network
|
|
// FIXME there _must_ be a better term for this
|
|
ValueVisibility delay.D
|
|
|
|
// Query is the time it takes to receive a response from a routing query
|
|
Query delay.D
|
|
}
|