allocate IP to peer

This commit is contained in:
Callan Bryant 2020-03-02 19:13:47 +00:00
parent faf0e59887
commit af7484c84b
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA

14
add.go
View File

@ -1,5 +1,9 @@
package dsnet
import (
"net"
)
func Add(hostname string, owner string, description string) { //, publicKey string) {
conf := MustLoadDsnetConfig()
@ -8,7 +12,6 @@ func Add(hostname string, owner string, description string) { //, publicKey stri
publicKey := privateKey.PublicKey()
IP, err := conf.ChooseIP()
check(err)
peer := PeerConfig{
@ -18,7 +21,14 @@ func Add(hostname string, owner string, description string) { //, publicKey stri
PublicKey: publicKey,
PresharedKey: presharedKey,
// TODO Endpoint:
// TODO pick an available IP AllowedIPs
AllowedIPs: []JSONIPNet{
JSONIPNet {
IPNet: net.IPNet{
IP: IP,
Mask: conf.Network.IPNet.Mask,
},
},
},
}
conf.MustAddPeer(peer)