mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 06:35:07 +03:00
fix address/prefix code, platform specific parts still need testing
This commit is contained in:
parent
330175889e
commit
e7fca66655
3 changed files with 7 additions and 6 deletions
|
@ -19,17 +19,18 @@ func (a *address) isValid() bool {
|
|||
return false
|
||||
}
|
||||
}
|
||||
return (*a)[len(address_prefix)-1]&0x80 == 0
|
||||
return true
|
||||
}
|
||||
|
||||
// isValid returns true if a prefix falls within the range usable by the network.
|
||||
func (s *subnet) isValid() bool {
|
||||
for idx := range address_prefix {
|
||||
l := len(address_prefix)
|
||||
for idx := range address_prefix[:l-1] {
|
||||
if (*s)[idx] != address_prefix[idx] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return (*s)[len(address_prefix)-1]&0x80 != 0
|
||||
return (*s)[l-1] == address_prefix[l-1]|0x01
|
||||
}
|
||||
|
||||
// address_addrForNodeID takes a *NodeID as an argument and returns an *address.
|
||||
|
@ -83,7 +84,7 @@ func address_subnetForNodeID(nid *NodeID) *subnet {
|
|||
addr := *address_addrForNodeID(nid)
|
||||
var snet subnet
|
||||
copy(snet[:], addr[:])
|
||||
snet[len(address_prefix)-1] |= 0x80
|
||||
snet[len(address_prefix)-1] |= 0x01
|
||||
return &snet
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue