Merge pull request #376 from rade/372_udp_connectivity_check
LGTM. Fixes #372
This commit is contained in:
commit
d354f4bea4
2 files changed
+34
-24
No files matched your search
+33
-24
@@ -38,26 +38,27 @@ type RemoteConnection struct {
|
|||||||
type LocalConnection struct {
|
type LocalConnection struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
RemoteConnection
|
RemoteConnection
|
||||||
TCPConn *net.TCPConn
|
TCPConn *net.TCPConn
|
||||||
tcpSender TCPSender
|
tcpSender TCPSender
|
||||||
remoteUDPAddr *net.UDPAddr
|
remoteUDPAddr *net.UDPAddr
|
||||||
established bool
|
established bool
|
||||||
receivedHeartbeat bool
|
receivedHeartbeat bool
|
||||||
stackFrag bool
|
stackFrag bool
|
||||||
effectivePMTU int
|
effectivePMTU int
|
||||||
SessionKey *[32]byte
|
SessionKey *[32]byte
|
||||||
heartbeatFrame *ForwardedFrame
|
establishedTimeout *time.Timer
|
||||||
heartbeat *time.Ticker
|
heartbeatFrame *ForwardedFrame
|
||||||
fragTest *time.Ticker
|
heartbeat *time.Ticker
|
||||||
forwardChan chan<- *ForwardedFrame
|
fragTest *time.Ticker
|
||||||
forwardChanDF chan<- *ForwardedFrame
|
forwardChan chan<- *ForwardedFrame
|
||||||
stopForward chan<- interface{}
|
forwardChanDF chan<- *ForwardedFrame
|
||||||
stopForwardDF chan<- interface{}
|
stopForward chan<- interface{}
|
||||||
verifyPMTU chan<- int
|
stopForwardDF chan<- interface{}
|
||||||
Decryptor Decryptor
|
verifyPMTU chan<- int
|
||||||
Router *Router
|
Decryptor Decryptor
|
||||||
uid uint64
|
Router *Router
|
||||||
queryChan chan<- *ConnectionInteraction
|
uid uint64
|
||||||
|
queryChan chan<- *ConnectionInteraction
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConnectionInteraction struct {
|
type ConnectionInteraction struct {
|
||||||
@@ -253,10 +254,9 @@ func (conn *LocalConnection) run(queryChan <-chan *ConnectionInteraction, accept
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := conn.queryLoop(queryChan)
|
conn.establishedTimeout = time.NewTimer(EstablishedTimeout)
|
||||||
if netErr, ok := err.(net.Error); ok && netErr.Timeout() && !conn.established {
|
|
||||||
conn.log("connection shutting down due to timeout; possibly caused by blocked UDP connectivity")
|
if err := conn.queryLoop(queryChan); err != nil {
|
||||||
} else if err != nil {
|
|
||||||
conn.log("connection shutting down due to error:", err)
|
conn.log("connection shutting down due to error:", err)
|
||||||
} else {
|
} else {
|
||||||
conn.log("connection shutting down")
|
conn.log("connection shutting down")
|
||||||
@@ -278,10 +278,15 @@ func (conn *LocalConnection) queryLoop(queryChan <-chan *ConnectionInteraction)
|
|||||||
case CReceivedHeartbeat:
|
case CReceivedHeartbeat:
|
||||||
err = conn.handleReceivedHeartbeat(query.payload.(*net.UDPAddr))
|
err = conn.handleReceivedHeartbeat(query.payload.(*net.UDPAddr))
|
||||||
case CSetEstablished:
|
case CSetEstablished:
|
||||||
|
conn.establishedTimeout.Stop()
|
||||||
err = conn.handleSetEstablished()
|
err = conn.handleSetEstablished()
|
||||||
case CSendProtocolMsg:
|
case CSendProtocolMsg:
|
||||||
err = conn.handleSendProtocolMsg(query.payload.(ProtocolMsg))
|
err = conn.handleSendProtocolMsg(query.payload.(ProtocolMsg))
|
||||||
}
|
}
|
||||||
|
case <-conn.establishedTimeout.C:
|
||||||
|
if !conn.established {
|
||||||
|
err = fmt.Errorf("failed to establish UDP connectivity")
|
||||||
|
}
|
||||||
case <-tickerChan(conn.heartbeat):
|
case <-tickerChan(conn.heartbeat):
|
||||||
conn.Forward(true, conn.heartbeatFrame, nil)
|
conn.Forward(true, conn.heartbeatFrame, nil)
|
||||||
case <-tickerChan(conn.fragTest):
|
case <-tickerChan(conn.fragTest):
|
||||||
@@ -368,6 +373,10 @@ func (conn *LocalConnection) handleShutdown() {
|
|||||||
conn.Router.Ourself.DeleteConnection(conn)
|
conn.Router.Ourself.DeleteConnection(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conn.establishedTimeout != nil {
|
||||||
|
conn.establishedTimeout.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
stopTicker(conn.heartbeat)
|
stopTicker(conn.heartbeat)
|
||||||
stopTicker(conn.fragTest)
|
stopTicker(conn.fragTest)
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const (
|
|||||||
FastHeartbeat = 500 * time.Millisecond
|
FastHeartbeat = 500 * time.Millisecond
|
||||||
SlowHeartbeat = 10 * time.Second
|
SlowHeartbeat = 10 * time.Second
|
||||||
FragTestInterval = 5 * time.Minute
|
FragTestInterval = 5 * time.Minute
|
||||||
|
EstablishedTimeout = 30 * time.Second
|
||||||
ReadTimeout = 1 * time.Minute
|
ReadTimeout = 1 * time.Minute
|
||||||
PMTUVerifyAttempts = 8
|
PMTUVerifyAttempts = 8
|
||||||
PMTUVerifyTimeout = 10 * time.Millisecond // gets doubled with every attempt
|
PMTUVerifyTimeout = 10 * time.Millisecond // gets doubled with every attempt
|
||||||
|
|||||||
Reference in new issue
Block a user