From 8645bd0479e3c5fb76f3d39d4cb276c349689cde Mon Sep 17 00:00:00 2001 From: bragelbytes Date: Fri, 29 Mar 2024 16:38:30 -0700 Subject: [PATCH] updated toneburst --- Package.swift | 6 +++--- Sources/Omni/Omni.swift | 5 ++--- Sources/Omni/OmniConfig.swift | 4 ++-- Sources/Omni/Omnitone.swift | 26 +++++++------------------- 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/Package.swift b/Package.swift index a9a255e..eb1ea3a 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.8 +// swift-tools-version: 5.9 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -6,8 +6,8 @@ import PackageDescription let package = Package( name: "Omni", platforms: [ - .macOS(.v13), - .iOS(.v15), + .macOS(.v14), + .iOS(.v17), ], products: [ .library( diff --git a/Sources/Omni/Omni.swift b/Sources/Omni/Omni.swift index 9d17454..71df52b 100644 --- a/Sources/Omni/Omni.swift +++ b/Sources/Omni/Omni.swift @@ -21,7 +21,7 @@ public class Omni public func listen(config: OmniServerConfig) throws -> AsyncListener { - let serverToneburst = Omnitone(.POP3Server) + let serverToneburst = Omnitone(.POP3Client) let polishConfig = PolishServerConfig(serverAddress: config.serverAddress, serverPrivateKey: config.serverPrivateKey) let replicant = Replicant(logger: self.logger, polish: polishConfig, toneburst: serverToneburst) return try ReplicantListener(replicant: replicant, serverIP: config.serverIP, serverPort: Int(config.serverPort), logger: self.logger) @@ -29,12 +29,11 @@ public class Omni public func connect(config: OmniClientConfig) async throws -> AsyncConnection { - let clientToneburst = Omnitone(.POP3Client) + let clientToneburst = Omnitone(.POP3Server) let polishConfig = PolishClientConfig(serverAddress: config.serverAddress, serverPublicKey: config.serverPublicKey) let replicant = Replicant(logger: self.logger, polish: polishConfig, toneburst: clientToneburst) let network = try await AsyncTcpSocketConnection(config.serverIP, Int(config.serverPort), logger) return try await replicant.replicantClientTransformation(connection: network) } - } diff --git a/Sources/Omni/OmniConfig.swift b/Sources/Omni/OmniConfig.swift index 0404577..94392ea 100644 --- a/Sources/Omni/OmniConfig.swift +++ b/Sources/Omni/OmniConfig.swift @@ -102,7 +102,7 @@ public class OmniConfig: Codable public class OmniServerConfig: OmniConfig, Equatable { - public static func == (lhs: OmniServerConfig, rhs: OmniServerConfig) -> Bool + public static func == (lhs: OmniServerConfig, rhs: OmniServerConfig) -> Bool { return lhs.serverPrivateKey == rhs.serverPrivateKey && lhs.serverAddress == rhs.serverAddress } @@ -145,7 +145,7 @@ public class OmniServerConfig: OmniConfig, Equatable try self.init(from: data) } - public override func encode(to encoder: any Encoder) throws + public override func encode(to encoder: any Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(serverPrivateKey, forKey: .serverPrivateKey) diff --git a/Sources/Omni/Omnitone.swift b/Sources/Omni/Omnitone.swift index 190ad22..3a6fdca 100644 --- a/Sources/Omni/Omnitone.swift +++ b/Sources/Omni/Omnitone.swift @@ -74,9 +74,9 @@ public struct OmnitoneInstance { case .POP3Client: try await handlePOP3Client() - case .POP3Server: try await handlePOP3Server() + } } @@ -125,31 +125,19 @@ public struct OmnitoneInstance throw OmnitoneError.writeFailed } } + - private func handlePOP3Server() async throws + private func handlePOP3Client() async throws { - try await Timeout(Duration.seconds(5)).wait - { - let _ = try await self.listen(structuredText: StructuredText(TypedText.text("+OK POP3 server ready."), TypedText.newline(Newline.crlf))) - } - + let _ = try await self.listen(structuredText: StructuredText(TypedText.text("+OK POP3 server ready."), TypedText.newline(Newline.crlf))) try await self.speak(structuredText: StructuredText(TypedText.text("STLS"), TypedText.newline(Newline.crlf))) - try await Timeout(Duration.seconds(5)).wait - { - let _ = try await self.listen(structuredText: StructuredText(TypedText.text("+OK Begin TLS Negotiation"), TypedText.newline(Newline.crlf))) - } - - return + let _ = try await self.listen(structuredText: StructuredText(TypedText.text("+OK Begin TLS Negotiation"), TypedText.newline(Newline.crlf))) } - private func handlePOP3Client() async throws + private func handlePOP3Server() async throws { try await self.speak(structuredText: StructuredText(TypedText.text("+OK POP3 server ready."), TypedText.newline(Newline.crlf))) - try await Timeout(Duration.seconds(5)).wait - { - let _ = try await self.listen(structuredText: StructuredText(TypedText.text("STLS"), TypedText.newline(Newline.crlf))) - } - + let _ = try await self.listen(structuredText: StructuredText(TypedText.text("STLS"), TypedText.newline(Newline.crlf))) try await self.speak(structuredText: StructuredText(TypedText.text("+OK Begin TLS Negotiation"), TypedText.newline(Newline.crlf))) }