getting there...

This commit is contained in:
Adam Ierymenko 2019-09-21 18:22:25 -07:00
parent 5e35346f17
commit 2eef9d22e6
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
11 changed files with 278 additions and 45 deletions

View file

@ -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
}