mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-08-26 19:37:39 +00:00
Add summary helpers to mobile wrapper
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package mobile
|
package mobile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/ed25519"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net"
|
"net"
|
||||||
@@ -273,3 +274,28 @@ func (m *Yggdrasil) GetMTU() int {
|
|||||||
func GetVersion() string {
|
func GetVersion() string {
|
||||||
return version.BuildVersion()
|
return version.BuildVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ConfigSummary struct {
|
||||||
|
PublicKey string
|
||||||
|
IPv6Address string
|
||||||
|
IPv6Subnet string
|
||||||
|
}
|
||||||
|
|
||||||
|
func SummaryForConfig(b []byte) *ConfigSummary {
|
||||||
|
cfg := config.GenerateConfig()
|
||||||
|
if err := cfg.UnmarshalHJSON(b); err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
pub := ed25519.PrivateKey(cfg.PrivateKey).Public().(ed25519.PublicKey)
|
||||||
|
hpub := hex.EncodeToString(pub)
|
||||||
|
addr := net.IP(address.AddrForKey(pub)[:])
|
||||||
|
snet := net.IPNet{
|
||||||
|
IP: append(address.SubnetForKey(pub)[:], 0, 0, 0, 0, 0, 0, 0, 0),
|
||||||
|
Mask: net.CIDRMask(64, 128),
|
||||||
|
}
|
||||||
|
return &ConfigSummary{
|
||||||
|
PublicKey: hpub,
|
||||||
|
IPv6Address: addr.String(),
|
||||||
|
IPv6Subnet: snet.String(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user