add remove cmd
This commit is contained in:
parent
b6bd2d33e1
commit
0380753104
@ -31,6 +31,9 @@ func main() {
|
||||
case "report":
|
||||
dsnet.Report()
|
||||
|
||||
case "remove":
|
||||
dsnet.Remove()
|
||||
|
||||
case "down":
|
||||
dsnet.Down()
|
||||
|
||||
|
@ -110,6 +110,26 @@ func (conf *DsnetConfig) MustAddPeer(peer PeerConfig) {
|
||||
conf.Peers = append(conf.Peers, peer)
|
||||
}
|
||||
|
||||
func (conf *DsnetConfig) MustRemovePeer(hostname string) {
|
||||
peerIndex := -1;
|
||||
|
||||
for i, peer := range conf.Peers {
|
||||
if peer.Hostname == hostname {
|
||||
peerIndex = i
|
||||
}
|
||||
}
|
||||
|
||||
if peerIndex == -1 {
|
||||
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]
|
||||
}
|
||||
|
||||
|
||||
func (conf DsnetConfig) IPAllocated(IP net.IP) bool {
|
||||
if IP.Equal(conf.IP) {
|
||||
return true
|
||||
|
Loading…
Reference in New Issue
Block a user