Przeglądaj źródła

Merge branch 'packet-tunnel' of https://github.com/rod-hynes/psiphon-tunnel-core into packet-tunnel

Rod Hynes 8 lat temu
rodzic
commit
68f93dc980
2 zmienionych plików z 13 dodań i 8 usunięć
  1. 6 6
      psiphon/common/tun/tun.go
  2. 7 2
      psiphon/packetTunnelTransport.go

+ 6 - 6
psiphon/common/tun/tun.go

@@ -1417,9 +1417,9 @@ func (client *Client) Start() {
 			if err != nil {
 				client.config.Logger.WithContextFields(
 					common.LogFields{"error": err}).Info("write channel packets failed")
-				// Only this goroutine exits and no alarm is raised. It's assumed
-				// that if the channel fails, the outer client will know about it.
-				return
+				// May be temporary error condition, such as reconnecting the tunnel;
+				// keep working. The packets are most likely dropped.
+				continue
 			}
 		}
 	}()
@@ -1440,9 +1440,9 @@ func (client *Client) Start() {
 			if err != nil {
 				client.config.Logger.WithContextFields(
 					common.LogFields{"error": err}).Info("read channel packet failed")
-				// Only this goroutine exits and no alarm is raised. It's assumed
-				// that if the channel fails, the outer client will know about it.
-				return
+				// May be temporary error condition, such as reconnecting the tunnel;
+				// keep working.
+				continue
 			}
 
 			if !processPacket(

+ 7 - 2
psiphon/packetTunnelTransport.go

@@ -111,7 +111,7 @@ func (p *PacketTunnelTransport) Read(data []byte) (int, error) {
 		p.failedChannel(channelConn, channelTunnel)
 	}
 
-	return n, err
+	return n, common.ContextError(err)
 }
 
 // Write implements the io.Writer interface. It uses the current transport channel
@@ -146,7 +146,7 @@ func (p *PacketTunnelTransport) Write(data []byte) (int, error) {
 		p.failedChannel(channelConn, channelTunnel)
 	}
 
-	return n, err
+	return n, common.ContextError(err)
 }
 
 // Close implements the io.Closer interface. Any underlying transport channel is
@@ -216,6 +216,11 @@ func (p *PacketTunnelTransport) setChannel(
 	default:
 	}
 
+	// Interrupt Read/Write calls blocking on any previous channel.
+	if p.channelConn != nil {
+		p.channelConn.Close()
+	}
+
 	p.channelConn = channelConn
 	p.channelTunnel = channelTunnel