Merge pull request #825 from milosgajdos83/net-chan-nodes

Recover net channel Accept() errors. Init tunnel nodes before tunnel.Connect()
This commit is contained in:
Asim Aslam 2019-10-07 20:29:45 +01:00 committed by GitHub
commit 89d71417f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -213,6 +213,9 @@ func (n *network) handleNetConn(sess tunnel.Session, msg chan *transport.Message
m := new(transport.Message) m := new(transport.Message)
if err := sess.Recv(m); err != nil { if err := sess.Recv(m); err != nil {
log.Debugf("Network tunnel [%s] receive error: %v", NetworkChannel, err) log.Debugf("Network tunnel [%s] receive error: %v", NetworkChannel, err)
if sessErr := sess.Close(); sessErr != nil {
log.Debugf("Network tunnel [%s] closing connection error: %v", sessErr)
}
return return
} }
@ -230,9 +233,7 @@ func (n *network) acceptNetConn(l tunnel.Listener, recv chan *transport.Message)
// accept a connection // accept a connection
conn, err := l.Accept() conn, err := l.Accept()
if err != nil { if err != nil {
// TODO: handle this
log.Debugf("Network tunnel [%s] accept error: %v", NetworkChannel, err) log.Debugf("Network tunnel [%s] accept error: %v", NetworkChannel, err)
return
} }
select { select {
@ -730,6 +731,11 @@ func (n *network) Connect() error {
log.Debugf("Network failed to resolve nodes: %v", err) log.Debugf("Network failed to resolve nodes: %v", err)
} }
// initialize the tunnel to resolved nodes
n.tunnel.Init(
tunnel.Nodes(nodes...),
)
// connect network tunnel // connect network tunnel
if err := n.tunnel.Connect(); err != nil { if err := n.tunnel.Connect(); err != nil {
n.Unlock() n.Unlock()
@ -742,11 +748,6 @@ func (n *network) Connect() error {
n.server.Init(server.Advertise(n.tunnel.Address())) n.server.Init(server.Advertise(n.tunnel.Address()))
} }
// initialize the tunnel to resolved nodes
n.tunnel.Init(
tunnel.Nodes(nodes...),
)
// dial into ControlChannel to send route adverts // dial into ControlChannel to send route adverts
ctrlClient, err := n.tunnel.Dial(ControlChannel, tunnel.DialMulticast()) ctrlClient, err := n.tunnel.Dial(ControlChannel, tunnel.DialMulticast())
if err != nil { if err != nil {