Skip to content

Commit 152990b

Browse files
authored
Merge pull request #93 from backkem/p2p-webrtc-direct
Add p2p-webrtc-direct protocol
2 parents 312b9db + 6b421ea commit 152990b

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

multiaddr_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func TestConstructFails(t *testing.T) {
6868
"/ip4/127.0.0.1/p2p/tcp",
6969
"/unix",
7070
"/ip4/1.2.3.4/tcp/80/unix",
71+
"/ip4/127.0.0.1/tcp/9090/http/p2p-webcrt-direct",
7172
}
7273

7374
for _, a := range cases {
@@ -127,6 +128,7 @@ func TestConstructSucceeds(t *testing.T) {
127128
"/ip4/1.2.3.4/tcp/80/unix/a/b/c/d/e/f",
128129
"/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234/unix/stdio",
129130
"/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234/unix/stdio",
131+
"/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct",
130132
}
131133

132134
for _, a := range cases {

protocols.go

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@ package multiaddr
66
// TODO: Use a single source of truth for all multicodecs instead of
77
// distributing them like this...
88
const (
9-
P_IP4 = 0x0004
10-
P_TCP = 0x0006
11-
P_UDP = 0x0111
12-
P_DCCP = 0x0021
13-
P_IP6 = 0x0029
14-
P_IP6ZONE = 0x002A
15-
P_QUIC = 0x01CC
16-
P_SCTP = 0x0084
17-
P_UDT = 0x012D
18-
P_UTP = 0x012E
19-
P_UNIX = 0x0190
20-
P_P2P = 0x01A5
21-
P_IPFS = 0x01A5 // alias for backwards compatability
22-
P_HTTP = 0x01E0
23-
P_HTTPS = 0x01BB
24-
P_ONION = 0x01BC // also for backwards compatibility
25-
P_ONION3 = 0x01BD
26-
P_GARLIC64 = 0x01CA
9+
P_IP4 = 0x0004
10+
P_TCP = 0x0006
11+
P_UDP = 0x0111
12+
P_DCCP = 0x0021
13+
P_IP6 = 0x0029
14+
P_IP6ZONE = 0x002A
15+
P_QUIC = 0x01CC
16+
P_SCTP = 0x0084
17+
P_UDT = 0x012D
18+
P_UTP = 0x012E
19+
P_UNIX = 0x0190
20+
P_P2P = 0x01A5
21+
P_IPFS = 0x01A5 // alias for backwards compatability
22+
P_HTTP = 0x01E0
23+
P_HTTPS = 0x01BB
24+
P_ONION = 0x01BC // also for backwards compatibility
25+
P_ONION3 = 0x01BD
26+
P_GARLIC64 = 0x01CA
27+
P_P2P_WEBRTC_DIRECT = 0x0114
2728
)
2829

2930
var (
@@ -143,6 +144,11 @@ var (
143144
Path: true,
144145
Transcoder: TranscoderUnix,
145146
}
147+
protoP2P_WEBRTC_DIRECT = Protocol{
148+
Name: "p2p-webrtc-direct",
149+
Code: P_P2P_WEBRTC_DIRECT,
150+
VCode: CodeToVarint(P_P2P_WEBRTC_DIRECT),
151+
}
146152
)
147153

148154
func init() {
@@ -164,6 +170,7 @@ func init() {
164170
protoHTTPS,
165171
protoP2P,
166172
protoUNIX,
173+
protoP2P_WEBRTC_DIRECT,
167174
} {
168175
if err := AddProtocol(p); err != nil {
169176
panic(err)

transcoders.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func garlic64StB(s string) ([]byte, error) {
231231
}
232232

233233
func garlic64BtS(b []byte) (string, error) {
234-
if len(b) < 386 {
234+
if len(b) < 386 {
235235
return "", fmt.Errorf("failed to validate garlic addr: %s not an i2p base64 address. len: %d\n", b, len(b))
236236
}
237237
addr := garlicBase64Encoding.EncodeToString(b)

0 commit comments

Comments
 (0)