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()
|
presharedKey := GenerateJSONKey()
|
||||||
publicKey := privateKey.PublicKey()
|
publicKey := privateKey.PublicKey()
|
||||||
|
|
||||||
IP, err := conf.ChooseIP()
|
IP := conf.MustChooseIP()
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
peer := PeerConfig{
|
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
|
// choose a free IP for a new Peer
|
||||||
// TODO MustChooseIP? -- failure means we give up anyway
|
func (conf DsnetConfig) MustChooseIP() net.IP {
|
||||||
func (conf DsnetConfig) ChooseIP() (net.IP, error) {
|
|
||||||
network := conf.Network.IPNet
|
network := conf.Network.IPNet
|
||||||
ones, bits := network.Mask.Size()
|
ones, bits := network.Mask.Size()
|
||||||
zeros := bits - ones
|
zeros := bits - ones
|
||||||
@ -127,11 +126,13 @@ func (conf DsnetConfig) ChooseIP() (net.IP, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ! conf.IPAllocated(IP) {
|
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 {
|
type Dsnet struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user