mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 06:35:07 +03:00
Try to convert TUN/TAP to use new yggdrasil.Conn, search masks are still broken
This commit is contained in:
parent
319366513c
commit
d01662c1fb
14 changed files with 502 additions and 366 deletions
|
@ -37,10 +37,37 @@ func (n *NodeID) String() string {
|
|||
return hex.EncodeToString(n[:])
|
||||
}
|
||||
|
||||
// Network returns "nodeid" nearly always right now.
|
||||
func (n *NodeID) Network() string {
|
||||
return "nodeid"
|
||||
}
|
||||
|
||||
// PrefixLength returns the number of bits set in a masked NodeID.
|
||||
func (n *NodeID) PrefixLength() int {
|
||||
var len int
|
||||
for i, v := range *n {
|
||||
_, _ = i, v
|
||||
if v == 0xff {
|
||||
len += 8
|
||||
continue
|
||||
}
|
||||
for v&0x80 != 0 {
|
||||
len++
|
||||
v <<= 1
|
||||
}
|
||||
if v != 0 {
|
||||
return -1
|
||||
}
|
||||
for i++; i < NodeIDLen; i++ {
|
||||
if n[i] != 0 {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
return len
|
||||
}
|
||||
|
||||
func GetNodeID(pub *BoxPubKey) *NodeID {
|
||||
h := sha512.Sum512(pub[:])
|
||||
return (*NodeID)(&h)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue