diff --git a/codec.go b/codec.go index 554ed4e..2068b84 100644 --- a/codec.go +++ b/codec.go @@ -276,6 +276,12 @@ func addressBytesToString(p Protocol, b []byte) (string, error) { return "", err } return m.B58String(), nil + + case P_ONION: + addr := strings.ToLower(base32.StdEncoding.EncodeToString(b[0:10])) + port := binary.BigEndian.Uint16(b[10:12]) + return addr + ":"+ strconv.Itoa(int(port)), nil + default: return "", fmt.Errorf("unknown protocol") } diff --git a/multiaddr_test.go b/multiaddr_test.go index 6c7d772..3d5a835 100644 --- a/multiaddr_test.go +++ b/multiaddr_test.go @@ -166,7 +166,7 @@ func TestBytesToString(t *testing.T) { s2, err := bytesToString(b) if err != nil { - t.Error("failed to convert", b) + t.Error("failed to convert", b, err) } if s1 != s2 { @@ -177,6 +177,7 @@ func TestBytesToString(t *testing.T) { testString("/ip4/127.0.0.1/udp/1234", "047f0000011104d2") testString("/ip4/127.0.0.1/tcp/4321", "047f0000010610e1") testString("/ip4/127.0.0.1/udp/1234/ip4/127.0.0.1/tcp/4321", "047f0000011104d2047f0000010610e1") + testString("/onion/aaimaq4ygg2iegci:80", "bc030010c0439831b48218480050") } func TestBytesSplitAndJoin(t *testing.T) { diff --git a/protocols.csv b/protocols.csv index fa27ba3..4072980 100644 --- a/protocols.csv +++ b/protocols.csv @@ -10,4 +10,4 @@ code size name 421 V ipfs 480 0 http 443 0 https -444 10 onion \ No newline at end of file +444 96 onion \ No newline at end of file diff --git a/protocols.go b/protocols.go index 7454590..3fe0e58 100644 --- a/protocols.go +++ b/protocols.go @@ -47,7 +47,7 @@ var Protocols = []Protocol{ Protocol{P_IP6, 128, "ip6", CodeToVarint(P_IP6)}, // these require varint: Protocol{P_SCTP, 16, "sctp", CodeToVarint(P_SCTP)}, - Protocol{P_ONION, 80, "onion", CodeToVarint(P_ONION)}, + Protocol{P_ONION, 96, "onion", CodeToVarint(P_ONION)}, Protocol{P_UTP, 0, "utp", CodeToVarint(P_UTP)}, Protocol{P_UDT, 0, "udt", CodeToVarint(P_UDT)}, Protocol{P_HTTP, 0, "http", CodeToVarint(P_HTTP)},