Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Snowflake WebExtension
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cecylia Bocovich
Snowflake WebExtension
Commits
3ec9dd19
Commit
3ec9dd19
authored
5 years ago
by
Shane Howearth
Committed by
Cecylia Bocovich
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Handle generated errors in server-webrtc
parent
82e5753b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
client/lib/snowflake.go
+11
-4
11 additions, 4 deletions
client/lib/snowflake.go
server-webrtc/http.go
+9
-2
9 additions, 2 deletions
server-webrtc/http.go
server-webrtc/snowflake.go
+37
-16
37 additions, 16 deletions
server-webrtc/snowflake.go
with
57 additions
and
22 deletions
client/lib/snowflake.go
+
11
−
4
View file @
3ec9dd19
...
...
@@ -13,7 +13,7 @@ const (
SnowflakeTimeout
=
30
)
// When a connection handler starts, +1 is written to this channel; when it
//
HandlerChan -
When a connection handler starts, +1 is written to this channel; when it
// ends, -1 is written.
var
HandlerChan
=
make
(
chan
int
)
...
...
@@ -27,7 +27,10 @@ func Handler(socks SocksConnector, snowflakes SnowflakeCollector) error {
// Obtain an available WebRTC remote. May block.
snowflake
:=
snowflakes
.
Pop
()
if
nil
==
snowflake
{
socks
.
Reject
()
if
err
:=
socks
.
Reject
();
err
!=
nil
{
log
.
Printf
(
"socks.Reject returned error: %v"
,
err
)
}
return
errors
.
New
(
"handler: Received invalid Snowflake"
)
}
defer
socks
.
Close
()
...
...
@@ -57,11 +60,15 @@ func copyLoop(a, b io.ReadWriter) {
var
wg
sync
.
WaitGroup
wg
.
Add
(
2
)
go
func
()
{
io
.
Copy
(
b
,
a
)
if
_
,
err
:=
io
.
Copy
(
ORPort
,
WebRTC
);
err
!=
nil
{
log
.
Printf
(
"copying WebRTC to ORPort resulted in error: %v"
,
err
)
}
wg
.
Done
()
}()
go
func
()
{
io
.
Copy
(
a
,
b
)
if
_
,
err
:=
io
.
Copy
(
WebRTC
,
ORPort
);
err
!=
nil
{
log
.
Printf
(
"copying ORPort to WebRTC resulted in error: %v"
,
err
)
}
wg
.
Done
()
}()
wg
.
Wait
()
...
...
This diff is collapsed.
Click to expand it.
server-webrtc/http.go
+
9
−
2
View file @
3ec9dd19
...
...
@@ -23,11 +23,14 @@ func (h *httpHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
case
"GET"
:
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/plain; charset=utf-8"
)
w
.
WriteHeader
(
http
.
StatusOK
)
w
.
Write
([]
byte
(
`HTTP signaling channel
_
,
err
:=
w
.
Write
([]
byte
(
`HTTP signaling channel
Send a POST request containing an SDP offer. The response will
contain an SDP answer.
`
))
if
err
!=
nil
{
log
.
Printf
(
"GET request write failed with error: %v"
,
err
)
}
return
case
"POST"
:
break
...
...
@@ -57,7 +60,11 @@ contain an SDP answer.
log
.
Println
(
"answering HTTP POST"
)
w
.
WriteHeader
(
http
.
StatusOK
)
w
.
Write
([]
byte
(
pc
.
LocalDescription
()
.
Serialize
()))
_
,
err
=
w
.
Write
([]
byte
(
pc
.
LocalDescription
()
.
Serialize
()))
if
err
!=
nil
{
log
.
Printf
(
"answering HTTP POST write failed with error %v"
,
err
)
}
}
func
receiveSignalsHTTP
(
addr
string
,
config
*
webrtc
.
Configuration
)
error
{
...
...
This diff is collapsed.
Click to expand it.
server-webrtc/snowflake.go
+
37
−
16
View file @
3ec9dd19
...
...
@@ -13,7 +13,7 @@ import (
"syscall"
"time"
"git.torproject.org/pluggable-transports/goptlib.git"
pt
"git.torproject.org/pluggable-transports/goptlib.git"
"github.com/keroserene/go-webrtc"
)
...
...
@@ -25,15 +25,19 @@ var logFile *os.File
// when it ends, -1 is written.
var
handlerChan
=
make
(
chan
int
)
func
copyLoop
(
a
,
b
net
.
Conn
)
{
func
copyLoop
(
WebRTC
,
ORPort
net
.
Conn
)
{
var
wg
sync
.
WaitGroup
wg
.
Add
(
2
)
go
func
()
{
io
.
Copy
(
b
,
a
)
if
_
,
err
:=
io
.
Copy
(
ORPort
,
WebRTC
);
err
!=
nil
{
log
.
Printf
(
"copy WebRTC to ORPort error in copyLoop: %v"
,
err
)
}
wg
.
Done
()
}()
go
func
()
{
io
.
Copy
(
a
,
b
)
if
_
,
err
:=
io
.
Copy
(
WebRTC
,
ORPort
);
err
!=
nil
{
log
.
Printf
(
"copy ORPort to WebRTC error in copyLoop: %v"
,
err
)
}
wg
.
Done
()
}()
wg
.
Wait
()
...
...
@@ -79,14 +83,17 @@ func (c *webRTCConn) RemoteAddr() net.Addr {
}
func
(
c
*
webRTCConn
)
SetDeadline
(
t
time
.
Time
)
error
{
// nolint:golint
return
fmt
.
Errorf
(
"SetDeadline not implemented"
)
}
func
(
c
*
webRTCConn
)
SetReadDeadline
(
t
time
.
Time
)
error
{
// nolint:golint
return
fmt
.
Errorf
(
"SetReadDeadline not implemented"
)
}
func
(
c
*
webRTCConn
)
SetWriteDeadline
(
t
time
.
Time
)
error
{
// nolint:golint
return
fmt
.
Errorf
(
"SetWriteDeadline not implemented"
)
}
...
...
@@ -139,9 +146,12 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
}
dc
.
OnMessage
=
func
(
msg
[]
byte
)
{
log
.
Printf
(
"OnMessage <--- %d bytes"
,
len
(
msg
))
n
,
err
:=
pw
.
Write
(
msg
)
var
n
int
n
,
err
=
pw
.
Write
(
msg
)
if
err
!=
nil
{
pw
.
CloseWithError
(
err
)
if
inerr
:=
pw
.
CloseWithError
(
err
);
inerr
!=
nil
{
log
.
Printf
(
"close with error returned error: %v"
,
inerr
)
}
}
if
n
!=
len
(
msg
)
{
panic
(
"short write"
)
...
...
@@ -153,7 +163,9 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
err
=
pc
.
SetRemoteDescription
(
sdp
)
if
err
!=
nil
{
pc
.
Destroy
()
if
err
=
pc
.
Destroy
();
err
!=
nil
{
log
.
Printf
(
"pc.Destroy returned an error: %v"
,
err
)
}
return
nil
,
fmt
.
Errorf
(
"accept: SetRemoteDescription: %s"
,
err
)
}
log
.
Println
(
"sdp offer successfully received."
)
...
...
@@ -161,18 +173,24 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
log
.
Println
(
"Generating answer..."
)
answer
,
err
:=
pc
.
CreateAnswer
()
if
err
!=
nil
{
pc
.
Destroy
()
if
err
=
pc
.
Destroy
();
err
!=
nil
{
log
.
Printf
(
"pc.Destroy returned an error: %v"
,
err
)
}
return
nil
,
err
}
if
answer
==
nil
{
pc
.
Destroy
()
return
nil
,
fmt
.
Errorf
(
"Failed gathering ICE candidates."
)
if
err
=
pc
.
Destroy
();
err
!=
nil
{
log
.
Printf
(
"pc.Destroy returned an error: %v"
,
err
)
}
return
nil
,
fmt
.
Errorf
(
"failed gathering ICE candidates"
)
}
err
=
pc
.
SetLocalDescription
(
answer
)
if
err
!=
nil
{
pc
.
Destroy
()
if
err
=
pc
.
Destroy
();
err
!=
nil
{
log
.
Printf
(
"pc.Destroy returned an error: %v"
,
err
)
}
return
nil
,
err
}
...
...
@@ -180,7 +198,6 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
}
func
main
()
{
var
err
error
var
httpAddr
string
var
logFilename
string
...
...
@@ -200,7 +217,7 @@ func main() {
log
.
Println
(
"starting"
)
webrtc
.
SetLoggingVerbosity
(
1
)
var
err
error
ptInfo
,
err
=
pt
.
ServerSetup
(
nil
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
...
...
@@ -222,12 +239,14 @@ func main() {
bindaddr
.
Addr
.
Port
=
12345
// lies!!!
pt
.
Smethod
(
bindaddr
.
MethodName
,
bindaddr
.
Addr
)
default
:
pt
.
SmethodError
(
bindaddr
.
MethodName
,
"no such method"
)
if
err
:=
pt
.
SmethodError
(
bindaddr
.
MethodName
,
"no such method"
);
err
!=
nil
{
log
.
Printf
(
"SmethodError returned error: %v"
,
err
)
}
}
}
pt
.
SmethodsDone
()
var
numHandlers
int
=
0
var
numHandlers
int
var
sig
os
.
Signal
sigChan
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
sigChan
,
syscall
.
SIGTERM
)
...
...
@@ -236,7 +255,9 @@ func main() {
// This environment variable means we should treat EOF on stdin
// just like SIGTERM: https://bugs.torproject.org/15435.
go
func
()
{
io
.
Copy
(
ioutil
.
Discard
,
os
.
Stdin
)
if
_
,
err
:=
io
.
Copy
(
ioutil
.
Discard
,
os
.
Stdin
);
err
!=
nil
{
log
.
Printf
(
"error copying os.Stdin to ioutil.Discard: %v"
,
err
)
}
log
.
Printf
(
"synthesizing SIGTERM because of stdin close"
)
sigChan
<-
syscall
.
SIGTERM
}()
...
...
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
register
or
sign in
to comment