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) {
|
2020-03-02 04:08:28 +01:00
|
|
|
conf := MustLoadDsnetConfig()
|
|
|
|
|
|
|
|
privateKey := GenerateJSONPrivateKey()
|
|
|
|
presharedKey := GenerateJSONKey()
|
|
|
|
publicKey := privateKey.PublicKey()
|
|
|
|
|
2020-03-02 20:29:08 +01:00
|
|
|
IP := conf.MustChooseIP()
|
2020-03-02 19:44:19 +01:00
|
|
|
|
2020-03-02 04:08:28 +01:00
|
|
|
peer := PeerConfig{
|
2020-03-02 20:03:00 +01:00
|
|
|
Owner: owner,
|
|
|
|
Hostname: hostname,
|
|
|
|
Description: description,
|
|
|
|
PublicKey: publicKey,
|
2020-03-02 04:08:28 +01:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-03-02 04:08:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
conf.MustAddPeer(peer)
|
|
|
|
conf.MustSave()
|
2020-03-02 01:45:14 +01:00
|
|
|
}
|