working incomplete adding of peers. Now sleep.
This commit is contained in:
parent
c419dfed48
commit
1bd215600c
20
add.go
20
add.go
@ -1,4 +1,22 @@
|
||||
package dsnet
|
||||
|
||||
func Add(hostname string, owner string, description string, publicKey string) {
|
||||
func Add(hostname string, owner string, description string) {//, publicKey string) {
|
||||
conf := MustLoadDsnetConfig()
|
||||
|
||||
privateKey := GenerateJSONPrivateKey()
|
||||
presharedKey := GenerateJSONKey()
|
||||
publicKey := privateKey.PublicKey()
|
||||
|
||||
peer := PeerConfig{
|
||||
Owner: owner,
|
||||
Hostname: hostname,
|
||||
Description: description,
|
||||
PublicKey: publicKey,
|
||||
PresharedKey: presharedKey,
|
||||
// TODO Endpoint:
|
||||
// TODO pick an available IP AllowedIPs
|
||||
}
|
||||
|
||||
conf.MustAddPeer(peer)
|
||||
conf.MustSave()
|
||||
}
|
||||
|
@ -24,11 +24,11 @@ func main() {
|
||||
hostname := dsnet.MustPromptString("Hostname (unique)", true)
|
||||
owner := dsnet.MustPromptString("owner", true)
|
||||
description := dsnet.MustPromptString("Description", true)
|
||||
publicKey := dsnet.MustPromptString("PublicKey (optional)", false)
|
||||
//publicKey := dsnet.MustPromptString("PublicKey (optional)", false)
|
||||
|
||||
dsnet.ConfirmOrAbort("\nDo you want to add the above configuration?")
|
||||
|
||||
dsnet.Add(hostname, owner, description, publicKey)
|
||||
dsnet.Add(hostname, owner, description)//, publicKey)
|
||||
|
||||
case "up":
|
||||
|
||||
|
11
types.go
11
types.go
@ -76,6 +76,11 @@ func (conf *DsnetConfig) MustSave() {
|
||||
check(err)
|
||||
}
|
||||
|
||||
func (conf *DsnetConfig) MustAddPeer(peer PeerConfig) {
|
||||
// TODO validate PeerConfig!!!
|
||||
conf.Peers = append(conf.Peers, peer)
|
||||
}
|
||||
|
||||
type Dsnet struct {
|
||||
Name string
|
||||
PrivateKey wgtypes.Key
|
||||
@ -111,6 +116,12 @@ func (k JSONKey) MarshalJSON() ([]byte, error) {
|
||||
return []byte("\"" + k.Key.String() + "\""), nil
|
||||
}
|
||||
|
||||
func (k JSONKey) PublicKey() JSONKey {
|
||||
return JSONKey{
|
||||
Key: k.Key.PublicKey(),
|
||||
}
|
||||
}
|
||||
|
||||
func (k *JSONKey) UnmarshalJSON(b []byte) error {
|
||||
b64Key := strings.Trim(string(b), "\"")
|
||||
key, err := wgtypes.ParseKey(b64Key)
|
||||
|
Loading…
Reference in New Issue
Block a user