commit ee2fb42d33ea105995adfc84d2be47a9d6dfc97f
Author: David Fifield <david(a)bamsoftware.com>
Date: Thu Jan 30 23:49:41 2020 -0700
Immediately and unconditionally grant new SOCKS connections.
---
client/lib/snowflake.go | 10 +---------
client/snowflake.go | 8 ++++++++
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/client/lib/snowflake.go b/client/lib/snowflake.go
index 2065f73..199f8a4 100644
--- a/client/lib/snowflake.go
+++ b/client/lib/snowflake.go
@@ -16,22 +16,14 @@ const (
// Given an accepted SOCKS connection, establish a WebRTC connection to the
// remote peer and exchange traffic.
-func Handler(socks SocksConnector, snowflakes SnowflakeCollector) error {
+func Handler(socks net.Conn, snowflakes SnowflakeCollector) error {
// Obtain an available WebRTC remote. May block.
snowflake := snowflakes.Pop()
if nil == snowflake {
- if err := socks.Reject(); err != nil {
- log.Printf("socks.Reject returned error: %v", err)
- }
-
return errors.New("handler: Received invalid Snowflake")
}
defer snowflake.Close()
log.Println("---- Handler: snowflake assigned ----")
- err := socks.Grant(&net.TCPAddr{IP: net.IPv4zero, Port: 0})
- if err != nil {
- return err
- }
go func() {
// When WebRTC resets, close the SOCKS connection too.
diff --git a/client/snowflake.go b/client/snowflake.go
index af8447c..dda59ae 100644
--- a/client/snowflake.go
+++ b/client/snowflake.go
@@ -59,9 +59,17 @@ func socksAcceptLoop(ln *pt.SocksListener, snowflakes sf.SnowflakeCollector) {
log.Printf("SOCKS accepted: %v", conn.Req)
go func() {
defer conn.Close()
+
+ err := conn.Grant(&net.TCPAddr{IP: net.IPv4zero, Port: 0})
+ if err != nil {
+ log.Printf("conn.Grant error: %s", err)
+ return
+ }
+
err = sf.Handler(conn, snowflakes)
if err != nil {
log.Printf("handler error: %s", err)
+ return
}
}()
}