mirror of
https://github.com/ipfs/kubo.git
synced 2025-05-20 08:27:29 +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>
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package supernode
|
|
|
|
import (
|
|
"testing"
|
|
|
|
dhtpb "gx/ipfs/QmWHiyk5y2EKgxHogFJ4Zt1xTqKeVsBc4zcBke8ie9C2Bn/go-libp2p-kad-dht/pb"
|
|
key "gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
|
|
datastore "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore"
|
|
)
|
|
|
|
func TestPutProviderDoesntResultInDuplicates(t *testing.T) {
|
|
routingBackend := datastore.NewMapDatastore()
|
|
k := key.Key("foo")
|
|
put := []*dhtpb.Message_Peer{
|
|
convPeer("bob", "127.0.0.1/tcp/4001"),
|
|
convPeer("alice", "10.0.0.10/tcp/4001"),
|
|
}
|
|
if err := putRoutingProviders(routingBackend, k, put); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := putRoutingProviders(routingBackend, k, put); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
got, err := getRoutingProviders(routingBackend, k)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(got) != 2 {
|
|
t.Fatal("should be 2 values, but there are", len(got))
|
|
}
|
|
}
|
|
|
|
func convPeer(name string, addrs ...string) *dhtpb.Message_Peer {
|
|
var rawAddrs [][]byte
|
|
for _, addr := range addrs {
|
|
rawAddrs = append(rawAddrs, []byte(addr))
|
|
}
|
|
return &dhtpb.Message_Peer{Id: &name, Addrs: rawAddrs}
|
|
}
|