ChooseIP -> MustChooseIP

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

2
add.go
View File

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

View File

@ -108,8 +108,7 @@ func (conf DsnetConfig) IPAllocated(IP net.IP) bool {
}
// choose a free IP for a new Peer
// TODO MustChooseIP? -- failure means we give up anyway
func (conf DsnetConfig) ChooseIP() (net.IP, error) {
func (conf DsnetConfig) MustChooseIP() net.IP {
network := conf.Network.IPNet
ones, bits := network.Mask.Size()
zeros := bits - ones
@ -127,11 +126,13 @@ func (conf DsnetConfig) ChooseIP() (net.IP, error) {
}
if ! conf.IPAllocated(IP) {
return IP, nil
return IP
}
}
return net.IP{}, errors.New("IP range exhausted")
ExitFail("IP range exhausted")
return net.IP{}
}
type Dsnet struct {