ChooseIP -> MustChooseIP
This commit is contained in:
parent
6700a47a75
commit
e0f753d3d0
2
add.go
2
add.go
@ -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{
|
||||
|
9
types.go
9
types.go
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user