Limit the number of outbound connections to MaxConnections
This commit also fixes control channel shenanigans: - recover error in control channel accept
This commit is contained in:
parent
b886dd4b8f
commit
ec2fbde979
@ -29,6 +29,8 @@ var (
|
|||||||
ControlChannel = "control"
|
ControlChannel = "control"
|
||||||
// DefaultLink is default network link
|
// DefaultLink is default network link
|
||||||
DefaultLink = "network"
|
DefaultLink = "network"
|
||||||
|
// MaxCconnections is the max number of network client connections
|
||||||
|
MaxCconnections = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -193,6 +195,15 @@ func (n *network) resolveNodes() ([]string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only return MaxCconnections nodes
|
||||||
|
if len(nodes) > MaxCconnections {
|
||||||
|
resNodes := make([]string, MaxCconnections)
|
||||||
|
for i, _ := range resNodes {
|
||||||
|
resNodes[i] = nodes[i]
|
||||||
|
}
|
||||||
|
return resNodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
return nodes, nil
|
return nodes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,7 +508,6 @@ func (n *network) handleCtrlConn(sess tunnel.Session, msg chan *transport.Messag
|
|||||||
for {
|
for {
|
||||||
m := new(transport.Message)
|
m := new(transport.Message)
|
||||||
if err := sess.Recv(m); err != nil {
|
if err := sess.Recv(m); err != nil {
|
||||||
// TODO: should we bail here?
|
|
||||||
log.Debugf("Network tunnel advert receive error: %v", err)
|
log.Debugf("Network tunnel advert receive error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -516,9 +526,7 @@ func (n *network) acceptCtrlConn(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", ControlChannel, err)
|
log.Debugf("Network tunnel [%s] accept error: %v", ControlChannel, err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user