From 92dbb576665dbf481e5402abc860009134586087 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 8 Sep 2018 13:13:14 +0200 Subject: [PATCH] Revert CommonPacket name to ControlPacket --- TunnelKit/Sources/Core/Packet.swift | 5 +++-- TunnelKit/Sources/Core/SessionProxy.swift | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/TunnelKit/Sources/Core/Packet.swift b/TunnelKit/Sources/Core/Packet.swift index a585e1c..1116a2f 100644 --- a/TunnelKit/Sources/Core/Packet.swift +++ b/TunnelKit/Sources/Core/Packet.swift @@ -98,7 +98,7 @@ public class PacketStream { } } -class CommonPacket { +class ControlPacket { let packetId: UInt32 let code: PacketCode @@ -123,7 +123,8 @@ class CommonPacket { // Ruby: send_ctrl func toBuffer() -> Data { var raw = PacketWithHeader(code, key, sessionId) - raw.append(UInt8(0)) + // TODO: put HMAC here when tls-auth + raw.append(UInt8(0)) // ackSize raw.append(UInt32(packetId).bigEndian) if let payload = payload { raw.append(payload) diff --git a/TunnelKit/Sources/Core/SessionProxy.swift b/TunnelKit/Sources/Core/SessionProxy.swift index dfc1309..74c4375 100644 --- a/TunnelKit/Sources/Core/SessionProxy.swift +++ b/TunnelKit/Sources/Core/SessionProxy.swift @@ -159,9 +159,9 @@ public class SessionProxy { private let controlPlainBuffer: ZeroingData - private var controlQueueOut: [CommonPacket] + private var controlQueueOut: [ControlPacket] - private var controlQueueIn: [CommonPacket] + private var controlQueueIn: [ControlPacket] private var controlPendingAcks: Set @@ -544,7 +544,7 @@ public class SessionProxy { } } - let controlPacket = CommonPacket(packetId, code, key, sessionId, payload) + let controlPacket = ControlPacket(packetId, code, key, sessionId, payload) controlQueueIn.append(controlPacket) controlQueueIn.sort { $0.packetId < $1.packetId } @@ -750,7 +750,7 @@ public class SessionProxy { // MARK: Control // Ruby: handle_ctrl_pkt - private func handleControlPacket(_ packet: CommonPacket) { + private func handleControlPacket(_ packet: ControlPacket) { guard (packet.key == negotiationKey.id) else { log.error("Bad key in control packet (\(packet.key) != \(negotiationKey.id))") // deferStop(.shutdown, SessionError.badKey) @@ -955,7 +955,7 @@ public class SessionProxy { repeat { let subPayloadLength = min(maxCount, payload.count - offset) let subPayloadData = payload.subdata(offset: offset, count: subPayloadLength) - let packet = CommonPacket(controlPacketIdOut, code, key, sessionId, subPayloadData) + let packet = ControlPacket(controlPacketIdOut, code, key, sessionId, subPayloadData) controlQueueOut.append(packet) controlPacketIdOut += 1