Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Patch multiaddr codec to handle alternative serializations
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacia committed Feb 4, 2019
1 parent e72c46f commit 762e661
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions net/retriever/retriever_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net

import (
"fmt"
"github.com/OpenBazaar/openbazaar-go/pb"
"gx/ipfs/QmT4U94DnD8FRfqr21obWY32HLM5VExccPKMjQHofeYqr9/go-multiaddr"
"testing"
)

Expand Down Expand Up @@ -36,3 +38,8 @@ func TestEnsureNoOmissionsInMessageProcessingOrder(t *testing.T) {
t.Errorf("found %d unexpected message types which are not considered in MessageProcessingOrder: %v", l, messages)
}
}

func TestMessageRetriever_Run(t *testing.T) {
addr, _ := multiaddr.NewMultiaddr("/ipfs/QmWWQ2Txc2c6tqjsBpzg5Ar652cHPGNsQQp2SejkNmkUMb")
fmt.Println(addr.String())
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func stringToBytes(s string) ([]byte, error) {
return nil, fmt.Errorf("failed to parse %s: %s %s", p.Name, sp[0], err)
}
if p.Size < 0 { // varint size.
_, _ = b.Write(CodeToVarint(len(a)))
if p.Code != P_P2P { // OpenBazaar: for backwards compatibility we will avoid writing len here until more nodes upgrade
_, _ = b.Write(CodeToVarint(len(a)))
}
}
b.Write(a)
sp = sp[1:]
Expand Down Expand Up @@ -157,13 +159,15 @@ func sizeForAddr(p Protocol, b []byte) (skip, size int, err error) {
case p.Size == 0:
return 0, 0, nil
case p.Code == P_P2P:
// OpenBazaar: this has to be patched to handle cids in this field
// until most nodes on the network upgrade and we do not need this
// anymore.
// OpenBazaar: this has to be patched to handle cids and multiaddrs
// serialized in both the new and old format until enough nodes
// upgrade that this isn't needed any more.
if b[0] == 0x01 {
return 0, len(b), nil
} else if len(b) == 37 {
return 3, 34, nil
} else if len(b) == 35 {
return 1, 34, nil
} else {
return 2, 34, nil
}
Expand Down

0 comments on commit 762e661

Please sign in to comment.