mirror of
https://github.com/logos-messaging/go-multiaddr.git
synced 2026-01-08 16:03:06 +00:00
Merge pull request #21 from ianopolous/master
Implemented byte decoder for onion addresses. Corrected onion bit size.
This commit is contained in:
commit
1eaad7f248
6
codec.go
6
codec.go
@ -276,6 +276,12 @@ func addressBytesToString(p Protocol, b []byte) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return m.B58String(), nil
|
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:
|
default:
|
||||||
return "", fmt.Errorf("unknown protocol")
|
return "", fmt.Errorf("unknown protocol")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -166,7 +166,7 @@ func TestBytesToString(t *testing.T) {
|
|||||||
|
|
||||||
s2, err := bytesToString(b)
|
s2, err := bytesToString(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("failed to convert", b)
|
t.Error("failed to convert", b, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s1 != s2 {
|
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/udp/1234", "047f0000011104d2")
|
||||||
testString("/ip4/127.0.0.1/tcp/4321", "047f0000010610e1")
|
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("/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) {
|
func TestBytesSplitAndJoin(t *testing.T) {
|
||||||
|
|||||||
@ -10,4 +10,4 @@ code size name
|
|||||||
421 V ipfs
|
421 V ipfs
|
||||||
480 0 http
|
480 0 http
|
||||||
443 0 https
|
443 0 https
|
||||||
444 10 onion
|
444 96 onion
|
||||||
|
@ -47,7 +47,7 @@ var Protocols = []Protocol{
|
|||||||
Protocol{P_IP6, 128, "ip6", CodeToVarint(P_IP6)},
|
Protocol{P_IP6, 128, "ip6", CodeToVarint(P_IP6)},
|
||||||
// these require varint:
|
// these require varint:
|
||||||
Protocol{P_SCTP, 16, "sctp", CodeToVarint(P_SCTP)},
|
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_UTP, 0, "utp", CodeToVarint(P_UTP)},
|
||||||
Protocol{P_UDT, 0, "udt", CodeToVarint(P_UDT)},
|
Protocol{P_UDT, 0, "udt", CodeToVarint(P_UDT)},
|
||||||
Protocol{P_HTTP, 0, "http", CodeToVarint(P_HTTP)},
|
Protocol{P_HTTP, 0, "http", CodeToVarint(P_HTTP)},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user