42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package shared
|
|
|
|
import "encoding/binary"
|
|
|
|
const PROTO_VERSION uint16 = 1
|
|
|
|
const (
|
|
_ uint16 = iota
|
|
// (client -> server) requests an IP
|
|
// [ pubkey - 1216 bytes ]
|
|
REQ_REGISTER
|
|
// (server -> client) returns the assigned IP and encapsulated multicast key
|
|
// [ ip - 16 bytes ] [ ciphertext - 1168 bytes ]
|
|
RESP_REGISTER
|
|
// (client -> server -> client2) relays an encrypted packet to a specified peer
|
|
// [ destIP - 16 bytes ] [ srcIP - 16 bytes ] [ encrypted pkt ]
|
|
ENC_PKT
|
|
// (client -> server -> *) broadcasts an encrypted packet
|
|
// [ encrypted pkt ]
|
|
BROADCAST_PKT
|
|
// (client -> server) requests peer's pubkey from the server for encapsulation
|
|
// [ ip - 16 bytes ]
|
|
REQ_GET_PUBKEY
|
|
// (server -> client) provides requested pubkey
|
|
// [ ip - 16 bytes ] [ pubkey - 1216 bytes ]
|
|
RESP_GET_PUBKEY
|
|
// (client -> server -> client2) establishes a session key with another peer
|
|
// [ destIP - 16 bytes ] [ srcIP - 16 bytes ] [ ciphertext - 1120 bytes ]
|
|
REQ_ESTABLISH
|
|
// (client2 -> server -> client) acknowledges the session key was established
|
|
// [ destIP - 16 bytes ] [ srcIP - 16 bytes ]
|
|
RESP_ESTABLISH
|
|
)
|
|
|
|
func BuildPkt(pktType uint16, data []byte) []byte {
|
|
out := make([]byte, 4+len(data))
|
|
binary.LittleEndian.PutUint16(out[0:], PROTO_VERSION)
|
|
binary.LittleEndian.PutUint16(out[2:], pktType)
|
|
copy(out[4:], data)
|
|
return out
|
|
}
|