getting there...
This commit is contained in:
parent
5e35346f17
commit
2eef9d22e6
11 changed files with 278 additions and 45 deletions
|
@ -15,10 +15,22 @@ package zerotier
|
|||
|
||||
import (
|
||||
"encoding/base32"
|
||||
"net"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var base32StdLowerCase = base32.NewEncoding("abcdefghijklmnopqrstuvwxyz234567")
|
||||
|
||||
// TimeMs returns the time in milliseconds since epoch.
|
||||
func TimeMs() int64 { return int64(time.Now().UnixNano()) / int64(1000000) }
|
||||
|
||||
// ipNetToKey creates a key that can be used in a map[] from a net.IPNet
|
||||
func ipNetToKey(ipn *net.IPNet) (k [3]uint64) {
|
||||
if len(ipn.IP) > 0 {
|
||||
copy(((*[16]byte)(unsafe.Pointer(&k[0])))[:], ipn.IP)
|
||||
}
|
||||
ones, bits := ipn.Mask.Size()
|
||||
k[2] = (uint64(ones) << 32) | uint64(bits)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue