Skip to content
Snippets Groups Projects
Commit b26c7a7a authored by Shane Howearth's avatar Shane Howearth Committed by Cecylia Bocovich
Browse files

Handle generated errors in client

parent 78a37844
No related branches found
No related tags found
No related merge requests found
...@@ -56,18 +56,18 @@ func Handler(socks SocksConnector, snowflakes SnowflakeCollector) error { ...@@ -56,18 +56,18 @@ func Handler(socks SocksConnector, snowflakes SnowflakeCollector) error {
// Exchanges bytes between two ReadWriters. // Exchanges bytes between two ReadWriters.
// (In this case, between a SOCKS and WebRTC connection.) // (In this case, between a SOCKS and WebRTC connection.)
func copyLoop(a, b io.ReadWriter) { func copyLoop(WebRTC, SOCKS io.ReadWriter) {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(2) wg.Add(2)
go func() { go func() {
if _, err := io.Copy(ORPort, WebRTC); err != nil { if _, err := io.Copy(SOCKS, WebRTC); err != nil {
log.Printf("copying WebRTC to ORPort resulted in error: %v", err) log.Printf("copying WebRTC to SOCKS resulted in error: %v", err)
} }
wg.Done() wg.Done()
}() }()
go func() { go func() {
if _, err := io.Copy(WebRTC, ORPort); err != nil { if _, err := io.Copy(WebRTC, SOCKS); err != nil {
log.Printf("copying ORPort to WebRTC resulted in error: %v", err) log.Printf("copying SOCKS to WebRTC resulted in error: %v", err)
} }
wg.Done() wg.Done()
}() }()
......
...@@ -138,7 +138,8 @@ func (c *WebRTCPeer) Connect() error { ...@@ -138,7 +138,8 @@ func (c *WebRTCPeer) Connect() error {
} }
err = c.establishDataChannel() err = c.establishDataChannel()
if err != nil { if err != nil {
return errors.New("WebRTC: Could not establish DataChannel.") // nolint: golint
return errors.New("WebRTC: Could not establish DataChannel")
} }
err = c.exchangeSDP() err = c.exchangeSDP()
if err != nil { if err != nil {
...@@ -151,7 +152,9 @@ func (c *WebRTCPeer) Connect() error { ...@@ -151,7 +152,9 @@ func (c *WebRTCPeer) Connect() error {
// Create and prepare callbacks on a new WebRTC PeerConnection. // Create and prepare callbacks on a new WebRTC PeerConnection.
func (c *WebRTCPeer) preparePeerConnection() error { func (c *WebRTCPeer) preparePeerConnection() error {
if nil != c.pc { if nil != c.pc {
c.pc.Close() if err := c.pc.Close(); err != nil {
log.Printf("c.pc.Close returned error: %v", err)
}
c.pc = nil c.pc = nil
} }
...@@ -267,7 +270,9 @@ func (c *WebRTCPeer) establishDataChannel() error { ...@@ -267,7 +270,9 @@ func (c *WebRTCPeer) establishDataChannel() error {
if err != nil { if err != nil {
// TODO: Maybe shouldn't actually close. // TODO: Maybe shouldn't actually close.
log.Println("Error writing to SOCKS pipe") log.Println("Error writing to SOCKS pipe")
c.writePipe.CloseWithError(err) if inerr := c.writePipe.CloseWithError(err); inerr != nil {
log.Printf("c.writePipe.CloseWithError returned error: %v", inerr)
}
} }
if n != len(msg.Data) { if n != len(msg.Data) {
log.Println("Error: short write") log.Println("Error: short write")
......
...@@ -45,7 +45,7 @@ func ConnectLoop(snowflakes sf.SnowflakeCollector) { ...@@ -45,7 +45,7 @@ func ConnectLoop(snowflakes sf.SnowflakeCollector) {
} }
// Accept local SOCKS connections and pass them to the handler. // Accept local SOCKS connections and pass them to the handler.
func socksAcceptLoop(ln *pt.SocksListener, snowflakes sf.SnowflakeCollector) error { func socksAcceptLoop(ln *pt.SocksListener, snowflakes sf.SnowflakeCollector) {
defer ln.Close() defer ln.Close()
log.Println("Started SOCKS listener.") log.Println("Started SOCKS listener.")
for { for {
...@@ -55,7 +55,8 @@ func socksAcceptLoop(ln *pt.SocksListener, snowflakes sf.SnowflakeCollector) err ...@@ -55,7 +55,8 @@ func socksAcceptLoop(ln *pt.SocksListener, snowflakes sf.SnowflakeCollector) err
if e, ok := err.(net.Error); ok && e.Temporary() { if e, ok := err.(net.Error); ok && e.Temporary() {
continue continue
} }
return err log.Printf("SOCKS accept error: %s", err)
break
} }
log.Println("SOCKS accepted: ", conn.Req) log.Println("SOCKS accepted: ", conn.Req)
err = sf.Handler(conn, snowflakes) err = sf.Handler(conn, snowflakes)
...@@ -155,7 +156,9 @@ func main() { ...@@ -155,7 +156,9 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
if ptInfo.ProxyURL != nil { if ptInfo.ProxyURL != nil {
pt.ProxyError("proxy is not supported") if err := pt.ProxyError("proxy is not supported"); err != nil {
log.Printf("call to pt.ProxyError generated error: %v", err)
}
os.Exit(1) os.Exit(1)
} }
listeners := make([]net.Listener, 0) listeners := make([]net.Listener, 0)
...@@ -165,14 +168,18 @@ func main() { ...@@ -165,14 +168,18 @@ func main() {
// TODO: Be able to recover when SOCKS dies. // TODO: Be able to recover when SOCKS dies.
ln, err := pt.ListenSocks("tcp", "127.0.0.1:0") ln, err := pt.ListenSocks("tcp", "127.0.0.1:0")
if err != nil { if err != nil {
pt.CmethodError(methodName, err.Error()) if inerr := pt.CmethodError(methodName, err.Error()); inerr != nil {
log.Printf("handling error generated by pt.ListenSocks with pt.CmethodError generated error: %v", inerr)
}
break break
} }
go socksAcceptLoop(ln, snowflakes) go socksAcceptLoop(ln, snowflakes)
pt.Cmethod(methodName, ln.Version(), ln.Addr()) pt.Cmethod(methodName, ln.Version(), ln.Addr())
listeners = append(listeners, ln) listeners = append(listeners, ln)
default: default:
pt.CmethodError(methodName, "no such method") if err := pt.CmethodError(methodName, "no such method"); err != nil {
log.Printf("calling pt.CmethodError generated error: %v", err)
}
} }
} }
pt.CmethodsDone() pt.CmethodsDone()
...@@ -186,7 +193,9 @@ func main() { ...@@ -186,7 +193,9 @@ func main() {
// This environment variable means we should treat EOF on stdin // This environment variable means we should treat EOF on stdin
// just like SIGTERM: https://bugs.torproject.org/15435. // just like SIGTERM: https://bugs.torproject.org/15435.
go func() { go func() {
io.Copy(ioutil.Discard, os.Stdin) if _, err := io.Copy(ioutil.Discard, os.Stdin); err != nil {
log.Printf("calling io.Copy(ioutil.Discard, os.Stdin) returned error: %v", err)
}
log.Printf("synthesizing SIGTERM because of stdin close") log.Printf("synthesizing SIGTERM because of stdin close")
sigChan <- syscall.SIGTERM sigChan <- syscall.SIGTERM
}() }()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment