Merge pull request #829 from milosgajdos83/limit-net-connections
Limit the number of outbound connections to MaxConnections
This commit is contained in:
commit
44473f954f
@ -29,6 +29,8 @@ var (
|
|||||||
ControlChannel = "control"
|
ControlChannel = "control"
|
||||||
// DefaultLink is default network link
|
// DefaultLink is default network link
|
||||||
DefaultLink = "network"
|
DefaultLink = "network"
|
||||||
|
// MaxConnections is the max number of network client connections
|
||||||
|
MaxConnections = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -169,9 +171,16 @@ func (n *network) resolveNodes() ([]string, error) {
|
|||||||
|
|
||||||
// collect network node addresses
|
// collect network node addresses
|
||||||
var nodes []string
|
var nodes []string
|
||||||
|
|
||||||
|
i := 0
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
nodes = append(nodes, record.Address)
|
nodes = append(nodes, record.Address)
|
||||||
nodeMap[record.Address] = true
|
nodeMap[record.Address] = true
|
||||||
|
i++
|
||||||
|
// break once MaxConnection nodes has been reached
|
||||||
|
if i == MaxConnections {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use the dns resolver to expand peers
|
// use the dns resolver to expand peers
|
||||||
@ -497,7 +506,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 +524,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…
Reference in New Issue
Block a user