Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Snowflake
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Automate
Agent sessions
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Fifield
Snowflake
Commits
b48fb781
Commit
b48fb781
authored
Apr 28, 2020
by
David Fifield
Browse files
Options
Downloads
Patches
Plain Diff
Have util.{Serialize,Deserialize}SessionDescription return an error
https://bugs.torproject.org/33897#comment:4
parent
76732155
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
client/lib/lib_test.go
+8
-3
8 additions, 3 deletions
client/lib/lib_test.go
client/lib/rendezvous.go
+6
-3
6 additions, 3 deletions
client/lib/rendezvous.go
common/util/util.go
+12
-21
12 additions, 21 deletions
common/util/util.go
with
26 additions
and
27 deletions
client/lib/lib_test.go
+
8
−
3
View file @
b48fb781
...
...
@@ -231,7 +231,8 @@ func TestSnowflakeClient(t *testing.T) {
So
(
err
,
ShouldBeNil
)
c
.
offerChannel
<-
nil
answer
:=
util
.
DeserializeSessionDescription
(
sampleAnswer
)
answer
,
err
:=
util
.
DeserializeSessionDescription
(
sampleAnswer
)
So
(
err
,
ShouldBeNil
)
So
(
answer
,
ShouldNotBeNil
)
c
.
answerChannel
<-
answer
err
=
c
.
exchangeSDP
()
...
...
@@ -256,7 +257,8 @@ func TestSnowflakeClient(t *testing.T) {
ctx
.
So
(
err
,
ShouldBeNil
)
wg
.
Done
()
}()
answer
:=
util
.
DeserializeSessionDescription
(
sampleAnswer
)
answer
,
err
:=
util
.
DeserializeSessionDescription
(
sampleAnswer
)
So
(
err
,
ShouldBeNil
)
c
.
answerChannel
<-
answer
wg
.
Wait
()
})
...
...
@@ -286,7 +288,10 @@ func TestSnowflakeClient(t *testing.T) {
http
.
StatusOK
,
[]
byte
(
`{"type":"answer","sdp":"fake"}`
),
}
fakeOffer
:=
util
.
DeserializeSessionDescription
(
`{"type":"offer","sdp":"test"}`
)
fakeOffer
,
err
:=
util
.
DeserializeSessionDescription
(
`{"type":"offer","sdp":"test"}`
)
if
err
!=
nil
{
panic
(
err
)
}
Convey
(
"Construct BrokerChannel with no front domain"
,
func
()
{
b
,
err
:=
NewBrokerChannel
(
"test.broker"
,
""
,
transport
,
false
)
...
...
This diff is collapsed.
Click to expand it.
client/lib/rendezvous.go
+
6
−
3
View file @
b48fb781
...
...
@@ -96,7 +96,11 @@ func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
SDP
:
util
.
StripLocalAddresses
(
offer
.
SDP
),
}
}
data
:=
bytes
.
NewReader
([]
byte
(
util
.
SerializeSessionDescription
(
offer
)))
offerSDP
,
err
:=
util
.
SerializeSessionDescription
(
offer
)
if
err
!=
nil
{
return
nil
,
err
}
data
:=
bytes
.
NewReader
([]
byte
(
offerSDP
))
// Suffix with broker's client registration handler.
clientURL
:=
bc
.
url
.
ResolveReference
(
&
url
.
URL
{
Path
:
"client"
})
request
,
err
:=
http
.
NewRequest
(
"POST"
,
clientURL
.
String
(),
data
)
...
...
@@ -119,8 +123,7 @@ func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
if
nil
!=
err
{
return
nil
,
err
}
answer
:=
util
.
DeserializeSessionDescription
(
string
(
body
))
return
answer
,
nil
return
util
.
DeserializeSessionDescription
(
string
(
body
))
case
http
.
StatusServiceUnavailable
:
return
nil
,
errors
.
New
(
BrokerError503
)
case
http
.
StatusBadRequest
:
...
...
This diff is collapsed.
Click to expand it.
common/util/util.go
+
12
−
21
View file @
b48fb781
...
...
@@ -2,43 +2,38 @@ package util
import
(
"encoding/json"
"
log
"
"
errors
"
"net"
"github.com/pion/sdp/v2"
"github.com/pion/webrtc/v2"
)
func
SerializeSessionDescription
(
desc
*
webrtc
.
SessionDescription
)
string
{
func
SerializeSessionDescription
(
desc
*
webrtc
.
SessionDescription
)
(
string
,
error
)
{
bytes
,
err
:=
json
.
Marshal
(
*
desc
)
if
nil
!=
err
{
log
.
Println
(
err
)
return
""
if
err
!=
nil
{
return
""
,
err
}
return
string
(
bytes
)
return
string
(
bytes
)
,
nil
}
func
DeserializeSessionDescription
(
msg
string
)
*
webrtc
.
SessionDescription
{
func
DeserializeSessionDescription
(
msg
string
)
(
*
webrtc
.
SessionDescription
,
error
)
{
var
parsed
map
[
string
]
interface
{}
err
:=
json
.
Unmarshal
([]
byte
(
msg
),
&
parsed
)
if
nil
!=
err
{
log
.
Println
(
err
)
return
nil
if
err
!=
nil
{
return
nil
,
err
}
if
_
,
ok
:=
parsed
[
"type"
];
!
ok
{
log
.
Println
(
"Cannot deserialize SessionDescription without type field."
)
return
nil
return
nil
,
errors
.
New
(
"cannot deserialize SessionDescription without type field"
)
}
if
_
,
ok
:=
parsed
[
"sdp"
];
!
ok
{
log
.
Println
(
"Cannot deserialize SessionDescription without sdp field."
)
return
nil
return
nil
,
errors
.
New
(
"cannot deserialize SessionDescription without sdp field"
)
}
var
stype
webrtc
.
SDPType
switch
parsed
[
"type"
]
.
(
string
)
{
default
:
log
.
Println
(
"Unknown SDP type"
)
return
nil
return
nil
,
errors
.
New
(
"Unknown SDP type"
)
case
"offer"
:
stype
=
webrtc
.
SDPTypeOffer
case
"pranswer"
:
...
...
@@ -49,14 +44,10 @@ func DeserializeSessionDescription(msg string) *webrtc.SessionDescription {
stype
=
webrtc
.
SDPTypeRollback
}
if
err
!=
nil
{
log
.
Println
(
err
)
return
nil
}
return
&
webrtc
.
SessionDescription
{
Type
:
stype
,
SDP
:
parsed
[
"sdp"
]
.
(
string
),
}
}
,
nil
}
// Stolen from https://github.com/golang/go/pull/30278
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment