mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-07 09:17:49 +08:00
This change adds the /ipfs/bitswap/1.1.0 protocol. The new protocol adds a 'payload' field to the protobuf message and deprecates the existing 'blocks' field. The 'payload' field is an array of pairs of cid prefixes and block data. The cid prefixes are used to ensure the correct codecs and hash functions are used to handle the block on the receiving end. License: MIT Signed-off-by: Jeromy <why@ipfs.io>
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
// 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"
|
|
|
|
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
|
|
"github.com/ipfs/go-ipfs/thirdparty/testutil"
|
|
|
|
routing "gx/ipfs/QmNUgVQTYnXQVrGT2rajZYsuKV8GYdiL91cdZSQDKNPNgE/go-libp2p-routing"
|
|
cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
|
|
pstore "gx/ipfs/QmXXCcQ7CLg5a81Ui9TTR35QcR4y7ZyihxwfjqaHfUVcVo/go-libp2p-peerstore"
|
|
ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore"
|
|
peer "gx/ipfs/QmfMmLGoKzCHDN7cGgk64PJr4iipzidDRME8HABSJqvmhC/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 {
|
|
FindProviders(context.Context, *cid.Cid) ([]pstore.PeerInfo, error)
|
|
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,
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|