mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-23 18:15:24 +00:00
Use crypto.GetNodeID instead of sha512 directly
This commit is contained in:
parent
e3a5e4f3b7
commit
e310a25e59
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha512"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
@ -194,20 +193,29 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Have we been asked for the node address yet? If so, print it and then stop.
|
// Have we been asked for the node address yet? If so, print it and then stop.
|
||||||
|
getNodeID := func() *crypto.NodeID {
|
||||||
|
if pubkey, err := hex.DecodeString(cfg.EncryptionPublicKey); err == nil {
|
||||||
|
var box crypto.BoxPubKey
|
||||||
|
copy(box[:], pubkey[:])
|
||||||
|
return crypto.GetNodeID(&box)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
switch {
|
switch {
|
||||||
case *getaddr:
|
case *getaddr:
|
||||||
if pubkey, err := hex.DecodeString(cfg.EncryptionPublicKey); err == nil {
|
if nodeid := getNodeID(); nodeid != nil {
|
||||||
nodeid := sha512.Sum512(pubkey)
|
addr := *address.AddrForNodeID(nodeid)
|
||||||
fromnodeid := address.AddrForNodeID((*crypto.NodeID)(&nodeid))
|
ip := net.IP(addr[:])
|
||||||
fmt.Println(net.IP(fromnodeid[:]).String())
|
fmt.Println(ip.String())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
case *getsnet:
|
case *getsnet:
|
||||||
if pubkey, err := hex.DecodeString(cfg.EncryptionPublicKey); err == nil {
|
if nodeid := getNodeID(); nodeid != nil {
|
||||||
nodeid := sha512.Sum512(pubkey)
|
snet := *address.SubnetForNodeID(nodeid)
|
||||||
fromnodeid := address.SubnetForNodeID((*crypto.NodeID)(&nodeid))
|
ipnet := net.IPNet{
|
||||||
subnet := append(fromnodeid[:], 0, 0, 0, 0, 0, 0, 0, 0)
|
IP: append(snet[:], 0, 0, 0, 0, 0, 0, 0, 0),
|
||||||
ipnet := net.IPNet{IP: subnet, Mask: net.CIDRMask(64, 128)}
|
Mask: net.CIDRMask(len(snet)*8, 128),
|
||||||
|
}
|
||||||
fmt.Println(ipnet.String())
|
fmt.Println(ipnet.String())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user