35 lines
753 B
Go
35 lines
753 B
Go
package peer
|
|
|
|
import "unsafe"
|
|
|
|
type Nonce struct {
|
|
Counter uint64
|
|
SourceIP byte
|
|
ViaIP byte
|
|
DestIP byte
|
|
StreamID byte // The stream, see STREAM_* constants
|
|
PacketType byte // The packet type. See PACKET_* constants.
|
|
}
|
|
|
|
func (nonce *Nonce) Parse(nb []byte) {
|
|
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 (nonce Nonce) Marshal(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
|
|
}
|
|
|
|
func CounterTimestamp(counter uint64) int64 {
|
|
return int64(counter >> 30)
|
|
}
|