Handle generated errors in client

This commit is contained in:
Shane Howearth 2019-09-24 09:00:13 +10:00 committed by Cecylia Bocovich
parent 78a37844b2
commit b26c7a7a73
3 changed files with 28 additions and 14 deletions

View file

@ -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()
}()

View file

@ -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")