Commit b26c7a7a authored by Shane Howearth's avatar Shane Howearth Committed by Cecylia Bocovich
Browse files

Handle generated errors in client

parent 78a37844
......@@ -56,18 +56,18 @@ func Handler(socks SocksConnector, snowflakes SnowflakeCollector) error {
// Exchanges bytes between two ReadWriters.
// (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
wg.Add(2)
go func() {
if _, err := io.Copy(ORPort, WebRTC); err != nil {
log.Printf("copying WebRTC to ORPort resulted in error: %v", err)
if _, err := io.Copy(SOCKS, WebRTC); err != nil {
log.Printf("copying WebRTC to SOCKS resulted in error: %v", err)
}
wg.Done()
}()
go func() {
if _, err := io.Copy(WebRTC, ORPort); err != nil {
log.Printf("copying ORPort to WebRTC resulted in error: %v", err)
if _, err := io.Copy(WebRTC, SOCKS); err != nil {
log.Printf("copying SOCKS to WebRTC resulted in error: %v", err)
}
wg.Done()
}()
......
......@@ -138,7 +138,8 @@ func (c *WebRTCPeer) Connect() error {
}
err = c.establishDataChannel()
if err != nil {
return errors.New("WebRTC: Could not establish DataChannel.")
// nolint: golint
return errors.New("WebRTC: Could not establish DataChannel")
}
err = c.exchangeSDP()
if err != nil {
......@@ -151,7 +152,9 @@ func (c *WebRTCPeer) Connect() error {
// Create and prepare callbacks on a new WebRTC PeerConnection.
func (c *WebRTCPeer) preparePeerConnection() error {
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
}
......@@ -267,7 +270,9 @@ func (c *WebRTCPeer) establishDataChannel() error {
if err != nil {
// TODO: Maybe shouldn't actually close.
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) {
log.Println("Error: short write")
......
......@@ -45,7 +45,7 @@ func ConnectLoop(snowflakes sf.SnowflakeCollector) {
}
// 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()
log.Println("Started SOCKS listener.")
for {
......@@ -55,7 +55,8 @@ func socksAcceptLoop(ln *pt.SocksListener, snowflakes sf.SnowflakeCollector) err
if e, ok := err.(net.Error); ok && e.Temporary() {
continue
}
return err
log.Printf("SOCKS accept error: %s", err)
break
}
log.Println("SOCKS accepted: ", conn.Req)
err = sf.Handler(conn, snowflakes)
......@@ -155,7 +156,9 @@ func main() {
log.Fatal(err)
}
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)
}
listeners := make([]net.Listener, 0)
......@@ -165,14 +168,18 @@ func main() {
// TODO: Be able to recover when SOCKS dies.
ln, err := pt.ListenSocks("tcp", "127.0.0.1:0")
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
}
go socksAcceptLoop(ln, snowflakes)
pt.Cmethod(methodName, ln.Version(), ln.Addr())
listeners = append(listeners, ln)
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()
......@@ -186,7 +193,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("calling io.Copy(ioutil.Discard, os.Stdin) returned error: %v", err)
}
log.Printf("synthesizing SIGTERM because of stdin close")
sigChan <- syscall.SIGTERM
}()
......
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