correct IPAllocated()

This commit is contained in:
Callan Bryant 2020-03-02 19:31:29 +00:00
parent e0f753d3d0
commit cf93b219a1
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
2 changed files with 3 additions and 5 deletions

1
add.go
View File

@ -12,7 +12,6 @@ func Add(hostname string, owner string, description string) { //, publicKey stri
publicKey := privateKey.PublicKey()
IP := conf.MustChooseIP()
check(err)
peer := PeerConfig{
Owner: owner,

View File

@ -2,7 +2,6 @@ package dsnet
import (
"encoding/json"
"errors"
"io/ioutil"
"net"
"strings"
@ -88,7 +87,7 @@ func (conf *DsnetConfig) MustAddPeer(peer PeerConfig) {
for _, peerIPNet := range peer.AllowedIPs {
if conf.IPAllocated(peerIPNet.IPNet.IP) {
ExitFail("%s is not unique", peerIPNet)
ExitFail("%s is already allocated", peerIPNet)
}
}
@ -99,12 +98,12 @@ func (conf DsnetConfig) IPAllocated(IP net.IP) bool {
for _, peer := range conf.Peers {
for _, peerIPNet := range peer.AllowedIPs {
if IP.Equal(peerIPNet.IPNet.IP) {
return false
return true
}
}
}
return true
return false
}
// choose a free IP for a new Peer