WIP
This commit is contained in:
75
peer/init.go
75
peer/init.go
@@ -20,24 +20,26 @@ import (
|
||||
// LocalState is the persisted identity for this peer, written on first run and
|
||||
// loaded on every subsequent run.
|
||||
type LocalState struct {
|
||||
PrivKey wgtypes.Key
|
||||
SignKey [64]byte // nacl/sign Ed25519 private key
|
||||
VPNIP netip.Addr
|
||||
VPNNet netip.Prefix
|
||||
WGPort uint16
|
||||
IsRelay bool
|
||||
IsPublic bool
|
||||
PrivKey wgtypes.Key
|
||||
SignKey [64]byte // nacl/sign Ed25519 private key
|
||||
VPNIP netip.Addr
|
||||
VPNNet netip.Prefix
|
||||
WGPort uint16
|
||||
IsRelay bool
|
||||
IsPublic bool
|
||||
LocalDomain string
|
||||
}
|
||||
|
||||
// localStateJSON is the on-disk representation.
|
||||
type localStateJSON struct {
|
||||
PrivKey string `json:"priv_key"` // standard base64
|
||||
SignKey string `json:"sign_key"` // standard base64
|
||||
VPNIP netip.Addr `json:"vpn_ip"`
|
||||
VPNNet netip.Prefix `json:"vpn_net"`
|
||||
WGPort uint16 `json:"wg_port"`
|
||||
IsRelay bool `json:"is_relay"`
|
||||
IsPublic bool `json:"is_public"`
|
||||
PrivKey string `json:"priv_key"` // standard base64
|
||||
SignKey string `json:"sign_key"` // standard base64
|
||||
VPNIP netip.Addr `json:"vpn_ip"`
|
||||
VPNNet netip.Prefix `json:"vpn_net"`
|
||||
WGPort uint16 `json:"wg_port"`
|
||||
IsRelay bool `json:"is_relay"`
|
||||
IsPublic bool `json:"is_public"`
|
||||
LocalDomain string `json:"local_domain"`
|
||||
}
|
||||
|
||||
// LoadOrInit loads LocalState from path, or registers with the hub and creates
|
||||
@@ -117,13 +119,14 @@ func initFromHub(hubURL, apiKey string, privKey wgtypes.Key) (LocalState, error)
|
||||
}
|
||||
|
||||
return LocalState{
|
||||
PrivKey: privKey,
|
||||
SignKey: *signPrivKey,
|
||||
VPNIP: vpnIP,
|
||||
VPNNet: vpnNet,
|
||||
WGPort: wgPort,
|
||||
IsRelay: isRelay,
|
||||
IsPublic: isPublic,
|
||||
PrivKey: privKey,
|
||||
SignKey: *signPrivKey,
|
||||
VPNIP: vpnIP,
|
||||
VPNNet: vpnNet,
|
||||
WGPort: wgPort,
|
||||
IsRelay: isRelay,
|
||||
IsPublic: isPublic,
|
||||
LocalDomain: r.LocalDomain,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -150,25 +153,27 @@ func parseLocalState(data []byte) (LocalState, error) {
|
||||
var signKey [64]byte
|
||||
copy(signKey[:], signKeyBytes)
|
||||
return LocalState{
|
||||
PrivKey: key,
|
||||
SignKey: signKey,
|
||||
VPNIP: j.VPNIP,
|
||||
VPNNet: j.VPNNet,
|
||||
WGPort: j.WGPort,
|
||||
IsRelay: j.IsRelay,
|
||||
IsPublic: j.IsPublic,
|
||||
PrivKey: key,
|
||||
SignKey: signKey,
|
||||
VPNIP: j.VPNIP,
|
||||
VPNNet: j.VPNNet,
|
||||
WGPort: j.WGPort,
|
||||
IsRelay: j.IsRelay,
|
||||
IsPublic: j.IsPublic,
|
||||
LocalDomain: j.LocalDomain,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func saveLocalState(path string, s LocalState) error {
|
||||
j := localStateJSON{
|
||||
PrivKey: base64.StdEncoding.EncodeToString(s.PrivKey[:]),
|
||||
SignKey: base64.StdEncoding.EncodeToString(s.SignKey[:]),
|
||||
VPNIP: s.VPNIP,
|
||||
VPNNet: s.VPNNet,
|
||||
WGPort: s.WGPort,
|
||||
IsRelay: s.IsRelay,
|
||||
IsPublic: s.IsPublic,
|
||||
PrivKey: base64.StdEncoding.EncodeToString(s.PrivKey[:]),
|
||||
SignKey: base64.StdEncoding.EncodeToString(s.SignKey[:]),
|
||||
VPNIP: s.VPNIP,
|
||||
VPNNet: s.VPNNet,
|
||||
WGPort: s.WGPort,
|
||||
IsRelay: s.IsRelay,
|
||||
IsPublic: s.IsPublic,
|
||||
LocalDomain: s.LocalDomain,
|
||||
}
|
||||
data, err := json.MarshalIndent(j, "", " ")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user