fix preservation of order on remove

This commit is contained in:
Callan Bryant 2020-04-04 09:22:09 +01:00
parent fb9cc3d4e3
commit 2d7447c32c
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA

View File

@ -125,10 +125,9 @@ func (conf *DsnetConfig) MustRemovePeer(hostname string) {
ExitFail("Could not find peer with hostname %s", hostname)
}
// remove peer from slice (by moving the last element to peerIndex, and
// truncating)
conf.Peers[peerIndex] = conf.Peers[len(conf.Peers)-1]
conf.Peers = conf.Peers[:len(conf.Peers)-1]
// remove peer from slice, retaining order
copy(conf.Peers[peerIndex:], conf.Peers[peerIndex+1:]) // shift left
conf.Peers = conf.Peers[:len(conf.Peers)-1] // truncate
}
func (conf DsnetConfig) IPAllocated(IP net.IP) bool {