dsnet/add.go

36 lines
648 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:29:08 +01:00
IP := conf.MustChooseIP()
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
}