From 4b15a3c0b21caf6d4dc728f72c5a4c5a1c55a941 Mon Sep 17 00:00:00 2001 From: Ivan Schasny Date: Thu, 15 Sep 2022 10:51:20 +0100 Subject: [PATCH] Fixed serialisation issue with multiadds --- client/provide.go | 4 ++-- test/provide_test.go | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/client/provide.go b/client/provide.go index 3137d03..e92d8cd 100644 --- a/client/provide.go +++ b/client/provide.go @@ -139,8 +139,8 @@ func bytesToMA(b []byte) (interface{}, error) { return multiaddr.NewMultiaddrBytes(b) } func maToBytes(iface interface{}) ([]byte, error) { - if ma, ok := iface.(multiaddr.Multiaddr); ok { - return ma.Bytes(), nil + if ma, ok := iface.(*multiaddr.Multiaddr); ok { + return (*ma).Bytes(), nil } return nil, fmt.Errorf("did not get expected MA type") } diff --git a/test/provide_test.go b/test/provide_test.go index 8006687..1a09ed1 100644 --- a/test/provide_test.go +++ b/test/provide_test.go @@ -11,6 +11,7 @@ import ( "github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/peer" multiaddr "github.com/multiformats/go-multiaddr" + "github.com/multiformats/go-multicodec" "github.com/multiformats/go-multihash" ) @@ -34,12 +35,17 @@ func TestProvideRoundtrip(t *testing.T) { t.Fatal("should get sync error on unsigned provide request.") } + ma, err := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/4001") + if err != nil { + t.Fatal(err) + } + c, s := createClientAndServer(t, testDelegatedRoutingService{}, &client.Provider{ Peer: peer.AddrInfo{ ID: pID, - Addrs: []multiaddr.Multiaddr{}, + Addrs: []multiaddr.Multiaddr{ma}, }, - ProviderProto: []client.TransferProtocol{}, + ProviderProto: []client.TransferProtocol{{Codec: multicodec.TransportBitswap}}, }, priv) defer s.Close()