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
312b9db3
Unverified
Commit
312b9db3
authored
Dec 18, 2018
by
Steven Allen
Committed by
GitHub
Dec 18, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #87 from RTradeLtd/master
onionv3 and i2p base64 addresses
parents
f8a18bb2
f60a1c99
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
148 additions
and
23 deletions
+148
-23
codec.go
codec.go
+2
-2
multiaddr_test.go
multiaddr_test.go
+32
-3
protocols.go
protocols.go
+36
-18
transcoders.go
transcoders.go
+78
-0
No files found.
codec.go
View file @
312b9db3
...
...
@@ -83,7 +83,7 @@ func validateBytes(b []byte) (err error) {
b
=
b
[
n
:
]
if
len
(
b
)
<
size
||
size
<
0
{
return
fmt
.
Errorf
(
"invalid value for size
"
)
return
fmt
.
Errorf
(
"invalid value for size
%d"
,
len
(
b
)
)
}
err
=
p
.
Transcoder
.
ValidateBytes
(
b
[
:
size
])
...
...
@@ -126,7 +126,7 @@ func readComponent(b []byte) (int, Component, error) {
offset
+=
n
if
len
(
b
[
offset
:
])
<
size
||
size
<
0
{
return
0
,
Component
{},
fmt
.
Errorf
(
"invalid value for size
"
)
return
0
,
Component
{},
fmt
.
Errorf
(
"invalid value for size
%d"
,
len
(
b
[
offset
:
])
)
}
return
offset
+
size
,
Component
{
...
...
multiaddr_test.go
View file @
312b9db3
...
...
@@ -38,6 +38,22 @@ func TestConstructFails(t *testing.T) {
"/onion/timaq4ygg2iegci7:-1"
,
"/onion/timaq4ygg2iegci7"
,
"/onion/timaq4ygg2iegci@:666"
,
"/onion3/9ww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:80"
,
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd7:80"
,
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:0"
,
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:-1"
,
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd"
,
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyy@:666"
,
"/garlic64/jT~IyXaoauTni6N4517EG8mrFUKpy0IlgZh-EY9csMAk82Odatmzr~YTZy8Hv7u~wvkg75EFNOyqb~nAPg-khyp2TS~ObUz8WlqYAM2VlEzJ7wJB91P-cUlKF18zSzVoJFmsrcQHZCirSbWoOknS6iNmsGRh5KVZsBEfp1Dg3gwTipTRIx7Vl5Vy~1OSKQVjYiGZS9q8RL0MF~7xFiKxZDLbPxk0AK9TzGGqm~wMTI2HS0Gm4Ycy8LYPVmLvGonIBYndg2bJC7WLuF6tVjVquiokSVDKFwq70BCUU5AU-EvdOD5KEOAM7mPfw-gJUG4tm1TtvcobrObqoRnmhXPTBTN5H7qDD12AvlwFGnfAlBXjuP4xOUAISL5SRLiulrsMSiT4GcugSI80mF6sdB0zWRgL1yyvoVWeTBn1TqjO27alr95DGTluuSqrNAxgpQzCKEWAyzrQkBfo2avGAmmz2NaHaAvYbOg0QSJz1PLjv2jdPW~ofiQmrGWM1cd~1cCqAAAA7:80"
,
"/garlic64/jT~IyXaoauTni6N4517EG8mrFUKpy0IlgZh-EY9csMAk82Odatmzr~YTZy8Hv7u~wvkg75EFNOyqb~nAPg-khyp2TS~ObUz8WlqYAM2VlEzJ7wJB91P-cUlKF18zSzVoJFmsrcQHZCirSbWoOknS6iNmsGRh5KVZsBEfp1Dg3gwTipTRIx7Vl5Vy~1OSKQVjYiGZS9q8RL0MF~7xFiKxZDLbPxk0AK9TzGGqm~wMTI2HS0Gm4Ycy8LYPVmLvGonIBYndg2bJC7WLuF6tVjVquiokSVDKFw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TN5H7qDD12AvlwFGnfAlBXjuP4xOUAISL5SRLiulrsMSiT4GcugSI80mF6sdB0zWRgL1yyvoVWeTBn1TqjO27alr95DGTluuSqrNAxgpQzCKEWAyzrQkBfo2avGAmmz2NaHaAvYbOg0QSJz1PLjv2jdPW~ofiQmrGWM1cd~1cCqAAAA@:666"
,
"/udp/1234/sctp"
,
"/udp/1234/udt/1234"
,
"/udp/1234/utp/1234"
,
...
...
@@ -74,6 +90,12 @@ func TestConstructSucceeds(t *testing.T) {
"/ip6zone/x/ip6/fe80::1/udp/1234/quic"
,
"/onion/timaq4ygg2iegci7:1234"
,
"/onion/timaq4ygg2iegci7:80/http"
,
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234"
,
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:80/http"
,
"/garlic64/jT~IyXaoauTni6N4517EG8mrFUKpy0IlgZh-EY9csMAk82Odatmzr~YTZy8Hv7u~wvkg75EFNOyqb~nAPg-khyp2TS~ObUz8WlqYAM2VlEzJ7wJB91P-cUlKF18zSzVoJFmsrcQHZCirSbWoOknS6iNmsGRh5KVZsBEfp1Dg3gwTipTRIx7Vl5Vy~1OSKQVjYiGZS9q8RL0MF~7xFiKxZDLbPxk0AK9TzGGqm~wMTI2HS0Gm4Ycy8LYPVmLvGonIBYndg2bJC7WLuF6tVjVquiokSVDKFwq70BCUU5AU-EvdOD5KEOAM7mPfw-gJUG4tm1TtvcobrObqoRnmhXPTBTN5H7qDD12AvlwFGnfAlBXjuP4xOUAISL5SRLiulrsMSiT4GcugSI80mF6sdB0zWRgL1yyvoVWeTBn1TqjO27alr95DGTluuSqrNAxgpQzCKEWAyzrQkBfo2avGAmmz2NaHaAvYbOg0QSJz1PLjv2jdPW~ofiQmrGWM1cd~1cCqAAAA"
,
"/garlic64/jT~IyXaoauTni6N4517EG8mrFUKpy0IlgZh-EY9csMAk82Odatmzr~YTZy8H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FNOyqb~nAPg-khyp2TS~ObUz8WlqYAM2VlEzJ7wJB91P-cUlKF18zSzVoJFmsrcQHZCirSbWoOknS6iNmsGRh5KVZsBEfp1Dg3gwTipTRIx7Vl5Vy~1OSKQVjYiGZS9q8RL0MF~7xFiKxZDLbPxk0AK9TzGGqm~wMTI2HS0Gm4Ycy8LYPVmLvGonIBYndg2bJC7WLuF6tVjVquiokSVDKFwq70BCUU5AU-EvdOD5KEOAM7mPfw-gJUG4tm1TtvcobrObqoRnmhXPTBTN5H7qDD12AvlwFGnfAlBXjuP4xOUAISL5SRLiulrsMSiT4GcugSI80mF6sdB0zWRgL1yyvoVWeTBn1TqjO27alr95DGTluuSqrNAxgpQzCKEWAyzrQkBfo2avGAmmz2NaHaAvYbOg0QSJz1PLjv2jdPW~ofiQmrGWM1cd~1cCqAAAA/tcp/8080"
,
"/udp/0"
,
"/tcp/0"
,
"/sctp/0"
,
...
...
@@ -159,21 +181,25 @@ func TestStringToBytes(t *testing.T) {
b2
,
err
:=
stringToBytes
(
s
)
if
err
!=
nil
{
t
.
Error
(
"failed to convert"
,
s
)
t
.
Error
(
"failed to convert"
,
s
,
err
)
}
if
!
bytes
.
Equal
(
b1
,
b2
)
{
t
.
Error
(
"failed to convert"
,
s
,
"to"
,
b1
,
"got"
,
b2
)
t
.
Error
(
"failed to convert
\n
"
,
s
,
"to
\n
"
,
b1
,
"got
\n
"
,
b2
)
}
if
err
:=
validateBytes
(
b2
);
err
!=
nil
{
t
.
Error
(
err
)
t
.
Error
(
err
,
"len:"
,
len
(
b2
)
)
}
}
testString
(
"/ip4/127.0.0.1/udp/1234"
,
"047f000001910204d2"
)
testString
(
"/ip4/127.0.0.1/tcp/4321"
,
"047f0000010610e1"
)
testString
(
"/ip4/127.0.0.1/udp/1234/ip4/127.0.0.1/tcp/4321"
,
"047f000001910204d2047f0000010610e1"
)
testString
(
"/onion/aaimaq4ygg2iegci:80"
,
"bc030010c0439831b48218480050"
)
testString
(
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234"
,
"bd03adadec040be047f9658668b11a504f3155001f231a37f54c4476c07fb4cc139ed7e30304d2"
)
testString
(
"/garlic64/jT~IyXaoauTni6N4517EG8mrFUKpy0IlgZh-EY9csMAk82Odatmzr~YTZy8Hv7u~wvkg75EFNOyqb~nAPg-khyp2TS~ObUz8WlqYAM2VlEzJ7wJB91P-cUlKF18zSzVoJFmsrcQHZCirSbWoOknS6iNmsGRh5KVZsBEfp1Dg3gwTipTRIx7Vl5Vy~1OSKQVjYiGZS9q8RL0MF~7xFiKxZDLbPxk0AK9TzGGqm~wMTI2HS0Gm4Ycy8LYPVmLvGonIBYndg2bJC7WLuF6tVjVquiokSVDKFwq70BCUU5AU-EvdOD5KEOAM7mPfw-gJUG4tm1TtvcobrObqoRnmhXPTBTN5H7qDD12AvlwFGnfAlBXjuP4xOUAISL5SRLiulrsMSiT4GcugSI80mF6sdB0zWRgL1yyvoVWeTBn1TqjO27alr95DGTluuSqrNAxgpQzCKEWAyzrQkBfo2avGAmmz2NaHaAvYbOg0QSJz1PLjv2jdPW~ofiQmrGWM1cd~1cCqAAAA"
,
"ca0383038d3fc8c976a86ae4e78ba378e75ec41bc9ab1542a9cb422581987e118f5cb0c024f3639d6ad9b3aff613672f07bfbbbfc2f920ef910534ecaa6ff9c03e0fa4872a764d2fce6d4cfc5a5a9800cd95944cc9ef0241f753fe71494a175f334b35682459acadc4076428ab49b5a83a49d2ea2366b06461e4a559b0111fa750e0de0c138a94d1231ed5979572ff53922905636221994bdabc44bd0c17fef11622b16432db3f193400af53cc61aa9bfc0c4c8d874b41a6e18732f0b60f5662ef1a89c80589dd8366c90bb58bb85ead56356aba2a244950ca170abbd01094539014f84bdd383e4a10e00cee63dfc3e809506e2d9b54edbdca1bace6eaa119e68573d30533791fba830f5d80be5c051a77c09415e3b8fe3139400848be5244b8ae96bb0c4a24f819cba0488f34985eac741d3359180bd72cafa1559e4c19f54ea8cedbb6a5afde4319396eb92aab340c60a50cc2284580cb3ad09017e8d9abc60269b3d8d687680bd86ce834412273d4f2e3bf68dd3d6fe87e2426ac658cd5c77fd5c0aa000000"
)
}
func
TestBytesToString
(
t
*
testing
.
T
)
{
...
...
@@ -203,6 +229,9 @@ func TestBytesToString(t *testing.T) {
testString
(
"/ip4/127.0.0.1/tcp/4321"
,
"047f0000010610e1"
)
testString
(
"/ip4/127.0.0.1/udp/1234/ip4/127.0.0.1/tcp/4321"
,
"047f000001910204d2047f0000010610e1"
)
testString
(
"/onion/aaimaq4ygg2iegci:80"
,
"bc030010c0439831b48218480050"
)
testString
(
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234"
,
"bd03adadec040be047f9658668b11a504f3155001f231a37f54c4476c07fb4cc139ed7e30304d2"
)
testString
(
"/garlic64/jT~IyXaoauTni6N4517EG8mrFUKpy0IlgZh-EY9csMAk82Odatmzr~YTZy8Hv7u~wvkg75EFNOyqb~nAPg-khyp2TS~ObUz8WlqYAM2VlEzJ7wJB91P-cUlKF18zSzVoJFmsrcQHZCirSbWoOknS6iNmsGRh5KVZsBEfp1Dg3gwTipTRIx7Vl5Vy~1OSKQVjYiGZS9q8RL0MF~7xFiKxZDLbPxk0AK9TzGGqm~wMTI2HS0Gm4Ycy8LYPVmLvGonIBYndg2bJC7WLuF6tVjVquiokSVDKFwq70BCUU5AU-EvdOD5KEOAM7mPfw-gJUG4tm1TtvcobrObqoRnmhXPTBTN5H7qDD12AvlwFGnfAlBXjuP4xOUAISL5SRLiulrsMSiT4GcugSI80mF6sdB0zWRgL1yyvoVWeTBn1TqjO27alr95DGTluuSqrNAxgpQzCKEWAyzrQkBfo2avGAmmz2NaHaAvYbOg0QSJz1PLjv2jdPW~ofiQmrGWM1cd~1cCqAAAA"
,
"ca0383038d3fc8c976a86ae4e78ba378e75ec41bc9ab1542a9cb422581987e118f5cb0c024f3639d6ad9b3aff613672f07bfbbbfc2f920ef910534ecaa6ff9c03e0fa4872a764d2fce6d4cfc5a5a9800cd95944cc9ef0241f753fe71494a175f334b35682459acadc4076428ab49b5a83a49d2ea2366b06461e4a559b0111fa750e0de0c138a94d1231ed5979572ff53922905636221994bdabc44bd0c17fef11622b16432db3f193400af53cc61aa9bfc0c4c8d874b41a6e18732f0b60f5662ef1a89c80589dd8366c90bb58bb85ead56356aba2a244950ca170abbd01094539014f84bdd383e4a10e00cee63dfc3e809506e2d9b54edbdca1bace6eaa119e68573d30533791fba830f5d80be5c051a77c09415e3b8fe3139400848be5244b8ae96bb0c4a24f819cba0488f34985eac741d3359180bd72cafa1559e4c19f54ea8cedbb6a5afde4319396eb92aab340c60a50cc2284580cb3ad09017e8d9abc60269b3d8d687680bd86ce834412273d4f2e3bf68dd3d6fe87e2426ac658cd5c77fd5c0aa000000"
)
}
func
TestBytesSplitAndJoin
(
t
*
testing
.
T
)
{
...
...
protocols.go
View file @
312b9db3
...
...
@@ -6,22 +6,24 @@ package multiaddr
// TODO: Use a single source of truth for all multicodecs instead of
// distributing them like this...
const
(
P_IP4
=
0x0004
P_TCP
=
0x0006
P_UDP
=
0x0111
P_DCCP
=
0x0021
P_IP6
=
0x0029
P_IP6ZONE
=
0x002A
P_QUIC
=
0x01CC
P_SCTP
=
0x0084
P_UDT
=
0x012D
P_UTP
=
0x012E
P_UNIX
=
0x0190
P_P2P
=
0x01A5
P_IPFS
=
0x01A5
// alias for backwards compatability
P_HTTP
=
0x01E0
P_HTTPS
=
0x01BB
P_ONION
=
0x01BC
P_IP4
=
0x0004
P_TCP
=
0x0006
P_UDP
=
0x0111
P_DCCP
=
0x0021
P_IP6
=
0x0029
P_IP6ZONE
=
0x002A
P_QUIC
=
0x01CC
P_SCTP
=
0x0084
P_UDT
=
0x012D
P_UTP
=
0x012E
P_UNIX
=
0x0190
P_P2P
=
0x01A5
P_IPFS
=
0x01A5
// alias for backwards compatability
P_HTTP
=
0x01E0
P_HTTPS
=
0x01BB
P_ONION
=
0x01BC
// also for backwards compatibility
P_ONION3
=
0x01BD
P_GARLIC64
=
0x01CA
)
var
(
...
...
@@ -80,13 +82,27 @@ var (
Size
:
16
,
Transcoder
:
TranscoderPort
,
}
protoONION
=
Protocol
{
protoONION
2
=
Protocol
{
Name
:
"onion"
,
Code
:
P_ONION
,
VCode
:
CodeToVarint
(
P_ONION
),
Size
:
96
,
Transcoder
:
TranscoderOnion
,
}
protoONION3
=
Protocol
{
Name
:
"onion3"
,
Code
:
P_ONION3
,
VCode
:
CodeToVarint
(
P_ONION3
),
Size
:
296
,
Transcoder
:
TranscoderOnion3
,
}
protoGARLIC64
=
Protocol
{
Name
:
"garlic64"
,
Code
:
P_GARLIC64
,
VCode
:
CodeToVarint
(
P_GARLIC64
),
Size
:
LengthPrefixedVarSize
,
Transcoder
:
TranscoderGarlic64
,
}
protoUTP
=
Protocol
{
Name
:
"utp"
,
Code
:
P_UTP
,
...
...
@@ -138,7 +154,9 @@ func init() {
protoIP6
,
protoIP6ZONE
,
protoSCTP
,
protoONION
,
protoONION2
,
protoONION3
,
protoGARLIC64
,
protoUTP
,
protoUDT
,
protoQUIC
,
...
...
transcoders.go
View file @
312b9db3
...
...
@@ -3,6 +3,7 @@ package multiaddr
import
(
"bytes"
"encoding/base32"
"encoding/base64"
"encoding/binary"
"fmt"
"net"
...
...
@@ -167,6 +168,83 @@ func onionBtS(b []byte) (string, error) {
return
addr
+
":"
+
strconv
.
Itoa
(
int
(
port
)),
nil
}
var
TranscoderOnion3
=
NewTranscoderFromFunctions
(
onion3StB
,
onion3BtS
,
nil
)
func
onion3StB
(
s
string
)
([]
byte
,
error
)
{
addr
:=
strings
.
Split
(
s
,
":"
)
if
len
(
addr
)
!=
2
{
return
nil
,
fmt
.
Errorf
(
"failed to parse onion addr: %s does not contain a port number."
,
s
)
}
// onion address without the ".onion" substring
if
len
(
addr
[
0
])
!=
56
{
return
nil
,
fmt
.
Errorf
(
"failed to parse onion addr: %s not a Tor onionv3 address. len == %d"
,
s
,
len
(
addr
[
0
]))
}
onionHostBytes
,
err
:=
base32
.
StdEncoding
.
DecodeString
(
strings
.
ToUpper
(
addr
[
0
]))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to decode base32 onion addr: %s %s"
,
s
,
err
)
}
// onion port number
i
,
err
:=
strconv
.
Atoi
(
addr
[
1
])
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to parse onion addr: %s"
,
err
)
}
if
i
>=
65536
{
return
nil
,
fmt
.
Errorf
(
"failed to parse onion addr: %s"
,
"port greater than 65536"
)
}
if
i
<
1
{
return
nil
,
fmt
.
Errorf
(
"failed to parse onion addr: %s"
,
"port less than 1"
)
}
onionPortBytes
:=
make
([]
byte
,
2
)
binary
.
BigEndian
.
PutUint16
(
onionPortBytes
,
uint16
(
i
))
bytes
:=
[]
byte
{}
bytes
=
append
(
bytes
,
onionHostBytes
[
0
:
35
]
...
)
bytes
=
append
(
bytes
,
onionPortBytes
...
)
return
bytes
,
nil
}
func
onion3BtS
(
b
[]
byte
)
(
string
,
error
)
{
addr
:=
strings
.
ToLower
(
base32
.
StdEncoding
.
EncodeToString
(
b
[
0
:
35
]))
port
:=
binary
.
BigEndian
.
Uint16
(
b
[
35
:
37
])
str
:=
addr
+
":"
+
strconv
.
Itoa
(
int
(
port
))
return
str
,
nil
}
var
TranscoderGarlic64
=
NewTranscoderFromFunctions
(
garlic64StB
,
garlic64BtS
,
garlicValidate
)
// i2p uses an alternate character set for base64 addresses. This returns an appropriate encoder.
var
garlicBase64Encoding
=
base64
.
NewEncoding
(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-~"
)
func
garlic64StB
(
s
string
)
([]
byte
,
error
)
{
// i2p base64 address
if
len
(
s
)
<
516
||
len
(
s
)
>
616
{
return
nil
,
fmt
.
Errorf
(
"failed to parse garlic addr: %s not an i2p base64 address. len: %d
\n
"
,
s
,
len
(
s
))
}
garlicHostBytes
,
err
:=
garlicBase64Encoding
.
DecodeString
(
s
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to decode base64 i2p addr: %s %s"
,
s
,
err
)
}
return
garlicHostBytes
,
nil
}
func
garlic64BtS
(
b
[]
byte
)
(
string
,
error
)
{
if
len
(
b
)
<
386
{
return
""
,
fmt
.
Errorf
(
"failed to validate garlic addr: %s not an i2p base64 address. len: %d
\n
"
,
b
,
len
(
b
))
}
addr
:=
garlicBase64Encoding
.
EncodeToString
(
b
)
return
addr
,
nil
}
func
garlicValidate
(
b
[]
byte
)
error
{
if
len
(
b
)
<
386
{
return
fmt
.
Errorf
(
"failed to validate garlic addr: %s not an i2p base64 address. len: %d
\n
"
,
b
,
len
(
b
))
}
return
nil
}
var
TranscoderP2P
=
NewTranscoderFromFunctions
(
p2pStB
,
p2pBtS
,
p2pVal
)
func
p2pStB
(
s
string
)
([]
byte
,
error
)
{
...
...
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