From 8cf611b73103e562c7aea9c2ef725e154258d05e Mon Sep 17 00:00:00 2001 From: Chinmay Kousik Date: Fri, 1 Jul 2022 23:05:36 +0530 Subject: [PATCH 1/5] Add x-webrtc --- protocols.go | 8 ++++++++ transcoders.go | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/protocols.go b/protocols.go index 28b3959..c814198 100644 --- a/protocols.go +++ b/protocols.go @@ -36,6 +36,7 @@ const ( P_WS = 0x01DD P_WSS = 0x01DE // deprecated alias for /tls/ws P_PLAINTEXTV2 = 0x706c61 + P_XWEBRTC = 0x115 ) var ( @@ -247,6 +248,13 @@ var ( Code: P_WSS, VCode: CodeToVarint(P_WSS), } + protoXWebRTC = Protocol { + Name: "x-webrtc", + Code: P_XWEBRTC, + VCode: CodeToVarint(P_XWEBRTC), + Size: 256, + Transcoder: TranscoderXWebRTC, + } ) func init() { diff --git a/transcoders.go b/transcoders.go index 764bb29..fddb318 100644 --- a/transcoders.go +++ b/transcoders.go @@ -5,6 +5,7 @@ import ( "encoding/base32" "encoding/base64" "encoding/binary" + "encoding/hex" "fmt" "net" "strconv" @@ -391,3 +392,21 @@ func certHashStB(s string) ([]byte, error) { func certHashBtS(b []byte) (string, error) { return multibase.Encode(multibase.Base64url, b) } + +func xwebrtcVal(b []byte) error { + if len(b) != 32 { + return fmt.Errorf("fingerprint should be 32 bytes, found: %d", len(b)) + } + return nil +} + +func xwebrtcStB(s string) ([]byte, error) { + return hex.DecodeString(s) +} + +func xwebrtcBtS(b []byte) (string, error) { + return hex.EncodeToString(b), nil +} + +var TranscoderXWebRTC = NewTranscoderFromFunctions(xwebrtcStB, xwebrtcBtS, xwebrtcVal) + From 97a059cf90203c4f5198bb763a105d7da125f887 Mon Sep 17 00:00:00 2001 From: Chinmay Kousik Date: Tue, 12 Jul 2022 19:27:02 +0530 Subject: [PATCH 2/5] update webrtc protocol --- protocols.go | 10 ++++------ transcoders.go | 18 ------------------ 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/protocols.go b/protocols.go index c814198..a8edbd4 100644 --- a/protocols.go +++ b/protocols.go @@ -36,7 +36,7 @@ const ( P_WS = 0x01DD P_WSS = 0x01DE // deprecated alias for /tls/ws P_PLAINTEXTV2 = 0x706c61 - P_XWEBRTC = 0x115 + P_WEBRTC = 0x115 ) var ( @@ -249,11 +249,9 @@ var ( VCode: CodeToVarint(P_WSS), } protoXWebRTC = Protocol { - Name: "x-webrtc", - Code: P_XWEBRTC, - VCode: CodeToVarint(P_XWEBRTC), - Size: 256, - Transcoder: TranscoderXWebRTC, + Name: "webrtc", + Code: P_WEBRTC, + VCode: CodeToVarint(P_WEBRTC), } ) diff --git a/transcoders.go b/transcoders.go index fddb318..11a61a8 100644 --- a/transcoders.go +++ b/transcoders.go @@ -5,7 +5,6 @@ import ( "encoding/base32" "encoding/base64" "encoding/binary" - "encoding/hex" "fmt" "net" "strconv" @@ -393,20 +392,3 @@ func certHashBtS(b []byte) (string, error) { return multibase.Encode(multibase.Base64url, b) } -func xwebrtcVal(b []byte) error { - if len(b) != 32 { - return fmt.Errorf("fingerprint should be 32 bytes, found: %d", len(b)) - } - return nil -} - -func xwebrtcStB(s string) ([]byte, error) { - return hex.DecodeString(s) -} - -func xwebrtcBtS(b []byte) (string, error) { - return hex.EncodeToString(b), nil -} - -var TranscoderXWebRTC = NewTranscoderFromFunctions(xwebrtcStB, xwebrtcBtS, xwebrtcVal) - From f599ce1750f05172276b9ce83df9456c4090d054 Mon Sep 17 00:00:00 2001 From: Chinmay Kousik Date: Tue, 12 Jul 2022 19:45:50 +0530 Subject: [PATCH 3/5] address review comments --- protocols.go | 3 ++- transcoders.go | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/protocols.go b/protocols.go index a8edbd4..7b9cf86 100644 --- a/protocols.go +++ b/protocols.go @@ -248,7 +248,7 @@ var ( Code: P_WSS, VCode: CodeToVarint(P_WSS), } - protoXWebRTC = Protocol { + protoWebRTC = Protocol { Name: "webrtc", Code: P_WEBRTC, VCode: CodeToVarint(P_WEBRTC), @@ -289,6 +289,7 @@ func init() { protoWS, protoWSS, protoPlaintextV2, + protoWebRTC, } { if err := AddProtocol(p); err != nil { panic(err) diff --git a/transcoders.go b/transcoders.go index 11a61a8..764bb29 100644 --- a/transcoders.go +++ b/transcoders.go @@ -391,4 +391,3 @@ func certHashStB(s string) ([]byte, error) { func certHashBtS(b []byte) (string, error) { return multibase.Encode(multibase.Base64url, b) } - From 898e22258104aee61ccf74d2fe8f4c142972237e Mon Sep 17 00:00:00 2001 From: Chinmay Kousik Date: Tue, 12 Jul 2022 20:41:42 +0530 Subject: [PATCH 4/5] fix fmt --- protocols.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/protocols.go b/protocols.go index 7b9cf86..2dcbb07 100644 --- a/protocols.go +++ b/protocols.go @@ -36,7 +36,7 @@ const ( P_WS = 0x01DD P_WSS = 0x01DE // deprecated alias for /tls/ws P_PLAINTEXTV2 = 0x706c61 - P_WEBRTC = 0x115 + P_WEBRTC = 0x115 ) var ( @@ -248,9 +248,9 @@ var ( Code: P_WSS, VCode: CodeToVarint(P_WSS), } - protoWebRTC = Protocol { - Name: "webrtc", - Code: P_WEBRTC, + protoWebRTC = Protocol{ + Name: "webrtc", + Code: P_WEBRTC, VCode: CodeToVarint(P_WEBRTC), } ) From 0d17db1dafe809ba1f7779ce94828247eabd49a9 Mon Sep 17 00:00:00 2001 From: Chinmay Kousik Date: Tue, 12 Jul 2022 22:56:02 +0530 Subject: [PATCH 5/5] update code to 0x118 --- protocols.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocols.go b/protocols.go index 2dcbb07..fc97ab3 100644 --- a/protocols.go +++ b/protocols.go @@ -36,7 +36,7 @@ const ( P_WS = 0x01DD P_WSS = 0x01DE // deprecated alias for /tls/ws P_PLAINTEXTV2 = 0x706c61 - P_WEBRTC = 0x115 + P_WEBRTC = 0x118 ) var (