Rename packet header to opcode (first byte)

This commit is contained in:
Davide De Rosa 2018-09-18 19:12:47 +02:00
parent fe92fcd91c
commit aa39414a77
3 changed files with 7 additions and 7 deletions

View File

@ -50,15 +50,15 @@ extension ControlChannel {
var offset = start
let end = end ?? packet.count
guard end >= offset + PacketHeaderLength else {
throw ControlChannelError("Missing header")
guard end >= offset + PacketOpcodeLength else {
throw ControlChannelError("Missing opcode")
}
let codeValue = packet[offset] >> 3
guard let code = PacketCode(rawValue: codeValue) else {
throw ControlChannelError("Unknown code: \(codeValue))")
}
let key = packet[offset] & 0b111
offset += PacketHeaderLength
offset += PacketOpcodeLength
log.debug("Control: Try read packet with code \(code) and key \(key)")

View File

@ -80,7 +80,7 @@
const BOOL isAck = self.isAck;
const NSUInteger ackLength = self.ackIds.count;
NSCAssert(!isAck || ackLength > 0, @"Ack packet must provide positive ackLength");
NSInteger n = PacketHeaderLength + PacketSessionIdLength;
NSInteger n = PacketOpcodeLength + PacketSessionIdLength;
n += PacketAckLengthLength;
if (ackLength > 0) {
n += ackLength * PacketIdLength + PacketSessionIdLength;

View File

@ -39,7 +39,7 @@
NS_ASSUME_NONNULL_BEGIN
#define PacketHeaderLength ((NSInteger)1)
#define PacketOpcodeLength ((NSInteger)1)
#define PacketIdLength ((NSInteger)4)
#define PacketSessionIdLength ((NSInteger)8)
#define PacketAckLengthLength ((NSInteger)1)
@ -66,7 +66,7 @@ extern const uint8_t DataPacketPingData[16];
static inline int PacketHeaderSet(uint8_t *to, PacketCode code, uint8_t key, const uint8_t *_Nullable sessionId)
{
*(uint8_t *)to = (code << 3) | (key & 0b111);
int offset = PacketHeaderLength;
int offset = PacketOpcodeLength;
if (sessionId) {
memcpy(to + offset, sessionId, PacketSessionIdLength);
offset += PacketSessionIdLength;
@ -77,7 +77,7 @@ static inline int PacketHeaderSet(uint8_t *to, PacketCode code, uint8_t key, con
static inline int PacketHeaderSetDataV2(uint8_t *to, uint8_t key, uint32_t peerId)
{
*(uint32_t *)to = ((PacketCodeDataV2 << 3) | (key & 0b111)) | htonl(peerId & 0xffffff);
return PacketHeaderLength + PacketPeerIdLength;
return PacketOpcodeLength + PacketPeerIdLength;
}
static inline int PacketHeaderGetDataV2PeerId(const uint8_t *from)