Skip to content

Commit 0fcbe89

Browse files
Merge pull request #153 from carpawell/feature/add-TLS-protocol
Add TLS protocol
2 parents 7cb054e + 33b3c2d commit 0fcbe89

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

multiaddr_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func TestConstructSucceeds(t *testing.T) {
140140
"/udp/1234/udt",
141141
"/udp/1234/utp",
142142
"/tcp/1234/http",
143+
"/tcp/1234/tls/http",
143144
"/tcp/1234/https",
144145
"/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234",
145146
"/ipfs/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7/tcp/1234",
@@ -168,6 +169,7 @@ func TestConstructSucceeds(t *testing.T) {
168169
"/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct",
169170
"/ip4/127.0.0.1/tcp/127/ws",
170171
"/ip4/127.0.0.1/tcp/127/ws",
172+
"/ip4/127.0.0.1/tcp/127/tls/ws",
171173
"/ip4/127.0.0.1/tcp/127/wss",
172174
"/ip4/127.0.0.1/tcp/127/wss",
173175
}
@@ -425,9 +427,10 @@ func assertValueForProto(t *testing.T, a Multiaddr, p int, exp string) {
425427
}
426428

427429
func TestGetValue(t *testing.T) {
428-
a := newMultiaddr(t, "/ip4/127.0.0.1/utp/tcp/5555/udp/1234/utp/ipfs/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP")
430+
a := newMultiaddr(t, "/ip4/127.0.0.1/utp/tcp/5555/udp/1234/tls/utp/ipfs/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP")
429431
assertValueForProto(t, a, P_IP4, "127.0.0.1")
430432
assertValueForProto(t, a, P_UTP, "")
433+
assertValueForProto(t, a, P_TLS, "")
431434
assertValueForProto(t, a, P_TCP, "5555")
432435
assertValueForProto(t, a, P_UDP, "1234")
433436
assertValueForProto(t, a, P_IPFS, "QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP")
@@ -528,6 +531,7 @@ func TestRoundTrip(t *testing.T) {
528531
"/unix/a/b/c/d",
529532
"/ip6/::ffff:127.0.0.1/tcp/111",
530533
"/ip4/127.0.0.1/tcp/123",
534+
"/ip4/127.0.0.1/tcp/123/tls",
531535
"/ip4/127.0.0.1/udp/123",
532536
"/ip4/127.0.0.1/udp/123/ip6/::",
533537
"/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP",
@@ -630,7 +634,7 @@ func TestZone(t *testing.T) {
630634
}
631635

632636
func TestBinaryMarshaler(t *testing.T) {
633-
addr := newMultiaddr(t, "/ip4/0.0.0.0/tcp/4001")
637+
addr := newMultiaddr(t, "/ip4/0.0.0.0/tcp/4001/tls")
634638
b, err := addr.MarshalBinary()
635639
if err != nil {
636640
t.Fatal(err)
@@ -646,7 +650,7 @@ func TestBinaryMarshaler(t *testing.T) {
646650
}
647651

648652
func TestTextMarshaler(t *testing.T) {
649-
addr := newMultiaddr(t, "/ip4/0.0.0.0/tcp/4001")
653+
addr := newMultiaddr(t, "/ip4/0.0.0.0/tcp/4001/tls")
650654
b, err := addr.MarshalText()
651655
if err != nil {
652656
t.Fatal(err)
@@ -662,7 +666,7 @@ func TestTextMarshaler(t *testing.T) {
662666
}
663667

664668
func TestJSONMarshaler(t *testing.T) {
665-
addr := newMultiaddr(t, "/ip4/0.0.0.0/tcp/4001")
669+
addr := newMultiaddr(t, "/ip4/0.0.0.0/tcp/4001/tls")
666670
b, err := addr.MarshalJSON()
667671
if err != nil {
668672
t.Fatal(err)

protocols.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ const (
2020
P_UTP = 0x012E
2121
P_UNIX = 0x0190
2222
P_P2P = 0x01A5
23-
P_IPFS = 0x01A5 // alias for backwards compatability
23+
P_IPFS = 0x01A5 // alias for backwards compatibility
2424
P_HTTP = 0x01E0
25-
P_HTTPS = 0x01BB
25+
P_HTTPS = 0x01BB // deprecated alias for /tls/http
2626
P_ONION = 0x01BC // also for backwards compatibility
2727
P_ONION3 = 0x01BD
2828
P_GARLIC64 = 0x01BE
2929
P_GARLIC32 = 0x01BF
3030
P_P2P_WEBRTC_DIRECT = 0x0114
31+
P_TLS = 0x01c0
3132
P_WS = 0x01DD
32-
P_WSS = 0x01DE
33+
P_WSS = 0x01DE // deprecated alias for /tls/ws
3334
)
3435

3536
var (
@@ -197,6 +198,12 @@ var (
197198
Code: P_P2P_WEBRTC_DIRECT,
198199
VCode: CodeToVarint(P_P2P_WEBRTC_DIRECT),
199200
}
201+
protoTLS = Protocol{
202+
Name: "tls",
203+
Code: P_TLS,
204+
VCode: CodeToVarint(P_TLS),
205+
Size: 0,
206+
}
200207
protoWS = Protocol{
201208
Name: "ws",
202209
Code: P_WS,
@@ -235,6 +242,7 @@ func init() {
235242
protoP2P,
236243
protoUNIX,
237244
protoP2P_WEBRTC_DIRECT,
245+
protoTLS,
238246
protoWS,
239247
protoWSS,
240248
} {

0 commit comments

Comments
 (0)