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) ExitFail("Could not find peer with hostname %s", hostname)
} }
// remove peer from slice (by moving the last element to peerIndex, and // remove peer from slice, retaining order
// truncating) copy(conf.Peers[peerIndex:], conf.Peers[peerIndex+1:]) // shift left
conf.Peers[peerIndex] = conf.Peers[len(conf.Peers)-1] conf.Peers = conf.Peers[:len(conf.Peers)-1] // truncate
conf.Peers = conf.Peers[:len(conf.Peers)-1]
} }
func (conf DsnetConfig) IPAllocated(IP net.IP) bool { func (conf DsnetConfig) IPAllocated(IP net.IP) bool {