Commit ee2fb42d authored by David Fifield's avatar David Fifield
Browse files

Immediately and unconditionally grant new SOCKS connections.

parent e9b218a6
......@@ -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.
......
......@@ -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
}
}()
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment