Remove handler correctly

This commit is contained in:
StephenButtolph 2020-05-18 00:54:06 -04:00
parent b4306585a4
commit 9c9b5bf51d
1 changed files with 6 additions and 2 deletions

View File

@ -434,7 +434,9 @@ func (n *network) connected(p *peer) {
for i := 0; i < len(n.handlers); {
if n.handlers[i].Connected(p.id) {
n.handlers[i] = n.handlers[len(n.handlers)-1] // remove the current handler
newLen := len(n.handlers) - 1
n.handlers[i] = n.handlers[newLen] // remove the current handler
n.handlers = n.handlers[:newLen]
} else {
i++
}
@ -459,7 +461,9 @@ func (n *network) disconnected(p *peer) {
if p.connected {
for i := 0; i < len(n.handlers); {
if n.handlers[i].Disconnected(p.id) {
n.handlers[i] = n.handlers[len(n.handlers)-1] // remove the current handler
newLen := len(n.handlers) - 1
n.handlers[i] = n.handlers[newLen] // remove the current handler
n.handlers = n.handlers[:newLen]
} else {
i++
}