Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
e32e9cd0
Commit
e32e9cd0
authored
Apr 11, 2016
by
Ian Preston
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented byte decoder for onion addresses. Corrected onion bit size.
parent
f3dff105
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
3 deletions
+10
-3
codec.go
codec.go
+6
-0
multiaddr_test.go
multiaddr_test.go
+2
-1
protocols.csv
protocols.csv
+1
-1
protocols.go
protocols.go
+1
-1
No files found.
codec.go
View file @
e32e9cd0
...
...
@@ -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"
)
}
...
...
multiaddr_test.go
View file @
e32e9cd0
...
...
@@ -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
)
{
...
...
protocols.csv
View file @
e32e9cd0
...
...
@@ -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
protocols.go
View file @
e32e9cd0
...
...
@@ -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
)},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment