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
ed310561
Commit
ed310561
authored
Aug 29, 2015
by
David Stainton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Tor .onion address support and unit test cases
parent
c13f11bb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
0 deletions
+19
-0
codec.go
codec.go
+11
-0
multiaddr_test.go
multiaddr_test.go
+5
-0
protocols.csv
protocols.csv
+1
-0
protocols.go
protocols.go
+2
-0
No files found.
codec.go
View file @
ed310561
package
multiaddr
import
(
"encoding/base32"
"encoding/binary"
"errors"
"fmt"
...
...
@@ -165,6 +166,16 @@ func addressStringToBytes(p Protocol, s string) ([]byte, error) {
binary
.
BigEndian
.
PutUint16
(
b
,
uint16
(
i
))
return
b
,
nil
case
P_TOR
:
fields
:=
strings
.
Split
(
s
,
".onion"
)
if
len
(
fields
)
!=
2
{
return
nil
,
fmt
.
Errorf
(
"failed to parse ipfs addr: %s not a Tor .onion address."
,
s
)
}
b
,
err
:=
base32
.
StdEncoding
.
DecodeString
(
strings
.
ToUpper
(
fields
[
0
]))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to parse ipfs addr: %s %s"
,
s
,
err
)
}
return
b
,
nil
case
P_IPFS
:
// ipfs
// the address is a varint prefixed multihash string representation
m
,
err
:=
mh
.
FromB58String
(
s
)
...
...
multiaddr_test.go
View file @
ed310561
...
...
@@ -25,6 +25,8 @@ func TestConstructFails(t *testing.T) {
"/sctp"
,
"/udp/65536"
,
"/tcp/65536"
,
"/tor/9imaq4ygg2iegci7.onion"
,
"/tor/aaimaq4ygg2iegci7.onion"
,
"/udp/1234/sctp"
,
"/udp/1234/udt/1234"
,
"/udp/1234/utp/1234"
,
...
...
@@ -49,6 +51,9 @@ func TestConstructSucceeds(t *testing.T) {
"/ip4/0.0.0.0"
,
"/ip6/::1"
,
"/ip6/2601:9:4f81:9700:803e:ca65:66e8:c21"
,
"/tor/timaq4ygg2iegci7.onion"
,
"/tor/timaq4ygg2iegci7.onion/tcp/1234"
,
"/tor/timaq4ygg2iegci7.onion/tcp/80/http"
,
"/udp/0"
,
"/tcp/0"
,
"/sctp/0"
,
...
...
protocols.csv
View file @
ed310561
...
...
@@ -5,6 +5,7 @@ code size name
33 16 dccp
41 128 ip6
132 16 sctp
133 10 tor
301 0 udt
302 0 utp
421 V ipfs
...
...
protocols.go
View file @
ed310561
...
...
@@ -25,6 +25,7 @@ const (
P_DCCP
=
33
P_IP6
=
41
P_SCTP
=
132
P_TOR
=
133
P_UTP
=
301
P_UDT
=
302
P_IPFS
=
421
...
...
@@ -46,6 +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_TOR
,
10
,
"tor"
,
CodeToVarint
(
P_TOR
)},
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