Consolidate DataPath with new flow
This commit is contained in:
parent
c01ac7e1e3
commit
c930cda065
|
@ -47,12 +47,11 @@
|
||||||
|
|
||||||
- (nonnull instancetype)initWithEncrypter:(nonnull id<DataPathEncrypter>)encrypter
|
- (nonnull instancetype)initWithEncrypter:(nonnull id<DataPathEncrypter>)encrypter
|
||||||
decrypter:(nonnull id<DataPathDecrypter>)decrypter
|
decrypter:(nonnull id<DataPathDecrypter>)decrypter
|
||||||
|
peerId:(uint32_t)peerId // 24-bit, discard most significant byte
|
||||||
|
compressionFraming:(CompressionFramingNative)compressionFraming
|
||||||
maxPackets:(NSInteger)maxPackets
|
maxPackets:(NSInteger)maxPackets
|
||||||
usesReplayProtection:(BOOL)usesReplayProtection;
|
usesReplayProtection:(BOOL)usesReplayProtection;
|
||||||
|
|
||||||
- (void)setPeerId:(uint32_t)peerId; // 24-bit, discard most significant byte
|
|
||||||
- (void)setCompressionFraming:(CompressionFramingNative)compressionFraming;
|
|
||||||
|
|
||||||
- (NSArray<NSData *> *)encryptPackets:(nonnull NSArray<NSData *> *)packets key:(uint8_t)key error:(NSError **)error;
|
- (NSArray<NSData *> *)encryptPackets:(nonnull NSArray<NSData *> *)packets key:(uint8_t)key error:(NSError **)error;
|
||||||
- (NSArray<NSData *> *)decryptPackets:(nonnull NSArray<NSData *> *)packets keepAlive:(nullable bool *)keepAlive error:(NSError **)error;
|
- (NSArray<NSData *> *)decryptPackets:(nonnull NSArray<NSData *> *)packets keepAlive:(nullable bool *)keepAlive error:(NSError **)error;
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
return (uint8_t *)addr;
|
return (uint8_t *)addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithEncrypter:(id<DataPathEncrypter>)encrypter decrypter:(id<DataPathDecrypter>)decrypter maxPackets:(NSInteger)maxPackets usesReplayProtection:(BOOL)usesReplayProtection
|
- (instancetype)initWithEncrypter:(id<DataPathEncrypter>)encrypter decrypter:(id<DataPathDecrypter>)decrypter peerId:(uint32_t)peerId compressionFraming:(CompressionFramingNative)compressionFraming maxPackets:(NSInteger)maxPackets usesReplayProtection:(BOOL)usesReplayProtection
|
||||||
{
|
{
|
||||||
NSParameterAssert(encrypter);
|
NSParameterAssert(encrypter);
|
||||||
NSParameterAssert(decrypter);
|
NSParameterAssert(decrypter);
|
||||||
|
@ -103,7 +103,9 @@
|
||||||
self.inReplay = [[ReplayProtector alloc] init];
|
self.inReplay = [[ReplayProtector alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
self.compressionFraming = CompressionFramingNativeDisabled;
|
[self.encrypter setPeerId:peerId];
|
||||||
|
[self.decrypter setPeerId:peerId];
|
||||||
|
[self setCompressionFraming:compressionFraming];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -150,15 +152,6 @@
|
||||||
return [[self class] alignedPointer:self.decBuffer];
|
return [[self class] alignedPointer:self.decBuffer];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setPeerId:(uint32_t)peerId
|
|
||||||
{
|
|
||||||
NSAssert(self.encrypter, @"Setting peer-id to nil encrypter");
|
|
||||||
NSAssert(self.decrypter, @"Setting peer-id to nil decrypter");
|
|
||||||
|
|
||||||
[self.encrypter setPeerId:peerId];
|
|
||||||
[self.decrypter setPeerId:peerId];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setCompressionFraming:(CompressionFramingNative)compressionFraming
|
- (void)setCompressionFraming:(CompressionFramingNative)compressionFraming
|
||||||
{
|
{
|
||||||
switch (compressionFraming) {
|
switch (compressionFraming) {
|
||||||
|
|
|
@ -74,8 +74,6 @@ extension SessionProxy {
|
||||||
|
|
||||||
private var isTLSConnected: Bool
|
private var isTLSConnected: Bool
|
||||||
|
|
||||||
private var canHandlePackets: Bool
|
|
||||||
|
|
||||||
init(id: UInt8) {
|
init(id: UInt8) {
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
|
@ -83,7 +81,6 @@ extension SessionProxy {
|
||||||
state = .invalid
|
state = .invalid
|
||||||
softReset = false
|
softReset = false
|
||||||
isTLSConnected = false
|
isTLSConnected = false
|
||||||
canHandlePackets = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ruby: Key.hard_reset_timeout
|
// Ruby: Key.hard_reset_timeout
|
||||||
|
@ -109,21 +106,11 @@ extension SessionProxy {
|
||||||
return isTLSConnected
|
return isTLSConnected
|
||||||
}
|
}
|
||||||
|
|
||||||
func startHandlingPackets(withPeerId peerId: UInt32? = nil, compressionFraming: CompressionFraming = .disabled) {
|
|
||||||
dataPath?.setPeerId(peerId ?? PacketPeerIdDisabled)
|
|
||||||
dataPath?.setCompressionFraming(compressionFraming.native)
|
|
||||||
canHandlePackets = true
|
|
||||||
}
|
|
||||||
|
|
||||||
func encrypt(packets: [Data]) throws -> [Data]? {
|
func encrypt(packets: [Data]) throws -> [Data]? {
|
||||||
guard let dataPath = dataPath else {
|
guard let dataPath = dataPath else {
|
||||||
log.warning("Data: Set dataPath first")
|
log.warning("Data: Set dataPath first")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
guard canHandlePackets else {
|
|
||||||
log.warning("Data: Invoke startHandlingPackets() before encrypting")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return try dataPath.encryptPackets(packets, key: id)
|
return try dataPath.encryptPackets(packets, key: id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,10 +119,6 @@ extension SessionProxy {
|
||||||
log.warning("Data: Set dataPath first")
|
log.warning("Data: Set dataPath first")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
guard canHandlePackets else {
|
|
||||||
log.warning("Data: Invoke startHandlingPackets() before decrypting")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
var keepAlive = false
|
var keepAlive = false
|
||||||
let decrypted = try dataPath.decryptPackets(packets, keepAlive: &keepAlive)
|
let decrypted = try dataPath.decryptPackets(packets, keepAlive: &keepAlive)
|
||||||
if keepAlive {
|
if keepAlive {
|
||||||
|
|
|
@ -702,7 +702,6 @@ public class SessionProxy {
|
||||||
|
|
||||||
if negotiationKey.softReset {
|
if negotiationKey.softReset {
|
||||||
authenticator = nil
|
authenticator = nil
|
||||||
negotiationKey.startHandlingPackets(withPeerId: peerId)
|
|
||||||
negotiationKey.controlState = .connected
|
negotiationKey.controlState = .connected
|
||||||
connectedDate = Date()
|
connectedDate = Date()
|
||||||
transitionKeys()
|
transitionKeys()
|
||||||
|
@ -890,12 +889,7 @@ public class SessionProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
setupEncryption()
|
setupEncryption()
|
||||||
|
|
||||||
authenticator = nil
|
authenticator = nil
|
||||||
negotiationKey.startHandlingPackets(
|
|
||||||
withPeerId: peerId,
|
|
||||||
compressionFraming: configuration.compressionFraming
|
|
||||||
)
|
|
||||||
negotiationKey.controlState = .connected
|
negotiationKey.controlState = .connected
|
||||||
connectedDate = Date()
|
connectedDate = Date()
|
||||||
transitionKeys()
|
transitionKeys()
|
||||||
|
@ -1051,6 +1045,8 @@ public class SessionProxy {
|
||||||
negotiationKey.dataPath = DataPath(
|
negotiationKey.dataPath = DataPath(
|
||||||
encrypter: bridge.encrypter(),
|
encrypter: bridge.encrypter(),
|
||||||
decrypter: bridge.decrypter(),
|
decrypter: bridge.decrypter(),
|
||||||
|
peerId: peerId ?? PacketPeerIdDisabled,
|
||||||
|
compressionFraming: configuration.compressionFraming.native,
|
||||||
maxPackets: link?.packetBufferSize ?? 200,
|
maxPackets: link?.packetBufferSize ?? 200,
|
||||||
usesReplayProtection: CoreConfiguration.usesReplayProtection
|
usesReplayProtection: CoreConfiguration.usesReplayProtection
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue