27 lines
574 B
Go
27 lines
574 B
Go
package peer
|
|
|
|
import "unsafe"
|
|
|
|
func ParseNonceBytes(nb []byte, nonce *Nonce) {
|
|
nonce.Counter = *(*uint64)(unsafe.Pointer(&nb[0]))
|
|
nonce.SourceIP = nb[8]
|
|
nonce.ViaIP = nb[9]
|
|
nonce.DestIP = nb[10]
|
|
nonce.StreamID = nb[11]
|
|
nonce.PacketType = nb[12]
|
|
}
|
|
|
|
func MarshalNonce(nonce Nonce, buf []byte) {
|
|
*(*uint64)(unsafe.Pointer(&buf[0])) = nonce.Counter
|
|
buf[8] = nonce.SourceIP
|
|
buf[9] = nonce.ViaIP
|
|
buf[10] = nonce.DestIP
|
|
buf[11] = nonce.StreamID
|
|
buf[12] = nonce.PacketType
|
|
clear(buf[13:])
|
|
}
|
|
|
|
func CounterTimestamp(counter uint64) int64 {
|
|
return int64(counter >> 30)
|
|
}
|