dsnet/add.go

37 lines
661 B
Go
Raw Normal View History

2020-03-02 01:45:14 +01:00
package dsnet
2020-03-02 20:13:47 +01:00
import (
"net"
)
2020-03-02 20:03:00 +01:00
func Add(hostname string, owner string, description string) { //, publicKey string) {
conf := MustLoadDsnetConfig()
privateKey := GenerateJSONPrivateKey()
presharedKey := GenerateJSONKey()
publicKey := privateKey.PublicKey()
2020-03-02 20:02:09 +01:00
IP, err := conf.ChooseIP()
check(err)
2020-03-02 19:44:19 +01:00
peer := PeerConfig{
2020-03-02 20:03:00 +01:00
Owner: owner,
Hostname: hostname,
Description: description,
PublicKey: publicKey,
PresharedKey: presharedKey,
// TODO Endpoint:
2020-03-02 20:26:08 +01:00
AllowedIPs: []JSONIPNet{
JSONIPNet{
2020-03-02 20:13:47 +01:00
IPNet: net.IPNet{
2020-03-02 20:26:08 +01:00
IP: IP,
2020-03-02 20:13:47 +01:00
Mask: conf.Network.IPNet.Mask,
},
},
},
}
conf.MustAddPeer(peer)
conf.MustSave()
2020-03-02 01:45:14 +01:00
}