feat: add TLS protocol

This commit is contained in:
Pavel Karpy 2021-05-26 16:04:06 +03:00
parent 32974f6a47
commit 99477a348c
2 changed files with 19 additions and 7 deletions

View File

@ -140,6 +140,7 @@ func TestConstructSucceeds(t *testing.T) {
"/udp/1234/udt", "/udp/1234/udt",
"/udp/1234/utp", "/udp/1234/utp",
"/tcp/1234/http", "/tcp/1234/http",
"/tcp/1234/http/tls",
"/tcp/1234/https", "/tcp/1234/https",
"/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234", "/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234",
"/ipfs/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7/tcp/1234", "/ipfs/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7/tcp/1234",
@ -168,6 +169,7 @@ func TestConstructSucceeds(t *testing.T) {
"/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct", "/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct",
"/ip4/127.0.0.1/tcp/127/ws", "/ip4/127.0.0.1/tcp/127/ws",
"/ip4/127.0.0.1/tcp/127/ws", "/ip4/127.0.0.1/tcp/127/ws",
"/ip4/127.0.0.1/tcp/127/ws/tls",
"/ip4/127.0.0.1/tcp/127/wss", "/ip4/127.0.0.1/tcp/127/wss",
"/ip4/127.0.0.1/tcp/127/wss", "/ip4/127.0.0.1/tcp/127/wss",
} }
@ -425,9 +427,10 @@ func assertValueForProto(t *testing.T, a Multiaddr, p int, exp string) {
} }
func TestGetValue(t *testing.T) { func TestGetValue(t *testing.T) {
a := newMultiaddr(t, "/ip4/127.0.0.1/utp/tcp/5555/udp/1234/utp/ipfs/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP") a := newMultiaddr(t, "/ip4/127.0.0.1/utp/tcp/5555/udp/1234/tls/utp/ipfs/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP")
assertValueForProto(t, a, P_IP4, "127.0.0.1") assertValueForProto(t, a, P_IP4, "127.0.0.1")
assertValueForProto(t, a, P_UTP, "") assertValueForProto(t, a, P_UTP, "")
assertValueForProto(t, a, P_TLS, "")
assertValueForProto(t, a, P_TCP, "5555") assertValueForProto(t, a, P_TCP, "5555")
assertValueForProto(t, a, P_UDP, "1234") assertValueForProto(t, a, P_UDP, "1234")
assertValueForProto(t, a, P_IPFS, "QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP") assertValueForProto(t, a, P_IPFS, "QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP")
@ -528,6 +531,7 @@ func TestRoundTrip(t *testing.T) {
"/unix/a/b/c/d", "/unix/a/b/c/d",
"/ip6/::ffff:127.0.0.1/tcp/111", "/ip6/::ffff:127.0.0.1/tcp/111",
"/ip4/127.0.0.1/tcp/123", "/ip4/127.0.0.1/tcp/123",
"/ip4/127.0.0.1/tcp/123/tls",
"/ip4/127.0.0.1/udp/123", "/ip4/127.0.0.1/udp/123",
"/ip4/127.0.0.1/udp/123/ip6/::", "/ip4/127.0.0.1/udp/123/ip6/::",
"/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP", "/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP",
@ -630,7 +634,7 @@ func TestZone(t *testing.T) {
} }
func TestBinaryMarshaler(t *testing.T) { func TestBinaryMarshaler(t *testing.T) {
addr := newMultiaddr(t, "/ip4/0.0.0.0/tcp/4001") addr := newMultiaddr(t, "/ip4/0.0.0.0/tcp/4001/tls")
b, err := addr.MarshalBinary() b, err := addr.MarshalBinary()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -646,7 +650,7 @@ func TestBinaryMarshaler(t *testing.T) {
} }
func TestTextMarshaler(t *testing.T) { func TestTextMarshaler(t *testing.T) {
addr := newMultiaddr(t, "/ip4/0.0.0.0/tcp/4001") addr := newMultiaddr(t, "/ip4/0.0.0.0/tcp/4001/tls")
b, err := addr.MarshalText() b, err := addr.MarshalText()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -662,7 +666,7 @@ func TestTextMarshaler(t *testing.T) {
} }
func TestJSONMarshaler(t *testing.T) { func TestJSONMarshaler(t *testing.T) {
addr := newMultiaddr(t, "/ip4/0.0.0.0/tcp/4001") addr := newMultiaddr(t, "/ip4/0.0.0.0/tcp/4001/tls")
b, err := addr.MarshalJSON() b, err := addr.MarshalJSON()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -20,16 +20,17 @@ const (
P_UTP = 0x012E P_UTP = 0x012E
P_UNIX = 0x0190 P_UNIX = 0x0190
P_P2P = 0x01A5 P_P2P = 0x01A5
P_IPFS = 0x01A5 // alias for backwards compatability P_IPFS = 0x01A5 // alias for backwards compatibility
P_HTTP = 0x01E0 P_HTTP = 0x01E0
P_HTTPS = 0x01BB P_HTTPS = 0x01BB // deprecated alias for /tls/http
P_ONION = 0x01BC // also for backwards compatibility P_ONION = 0x01BC // also for backwards compatibility
P_ONION3 = 0x01BD P_ONION3 = 0x01BD
P_GARLIC64 = 0x01BE P_GARLIC64 = 0x01BE
P_GARLIC32 = 0x01BF P_GARLIC32 = 0x01BF
P_P2P_WEBRTC_DIRECT = 0x0114 P_P2P_WEBRTC_DIRECT = 0x0114
P_TLS = 0x01c0
P_WS = 0x01DD P_WS = 0x01DD
P_WSS = 0x01DE P_WSS = 0x01DE // deprecated alias for /tls/ws
) )
var ( var (
@ -197,6 +198,12 @@ var (
Code: P_P2P_WEBRTC_DIRECT, Code: P_P2P_WEBRTC_DIRECT,
VCode: CodeToVarint(P_P2P_WEBRTC_DIRECT), VCode: CodeToVarint(P_P2P_WEBRTC_DIRECT),
} }
protoTLS = Protocol{
Name: "tls",
Code: P_TLS,
VCode: CodeToVarint(P_TLS),
Size: 0,
}
protoWS = Protocol{ protoWS = Protocol{
Name: "ws", Name: "ws",
Code: P_WS, Code: P_WS,
@ -235,6 +242,7 @@ func init() {
protoP2P, protoP2P,
protoUNIX, protoUNIX,
protoP2P_WEBRTC_DIRECT, protoP2P_WEBRTC_DIRECT,
protoTLS,
protoWS, protoWS,
protoWSS, protoWSS,
} { } {