Skip to content

Commit

Permalink
updated toneburst
Browse files Browse the repository at this point in the history
  • Loading branch information
bragelbytes committed Mar 29, 2024
1 parent 91752b7 commit 8645bd0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 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

let package = Package(
name: "Omni",
platforms: [
.macOS(.v13),
.iOS(.v15),
.macOS(.v14),
.iOS(.v17),
],
products: [
.library(
Expand Down
5 changes: 2 additions & 3 deletions Sources/Omni/Omni.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ 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)
}

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)
}

}
4 changes: 2 additions & 2 deletions Sources/Omni/OmniConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 7 additions & 19 deletions Sources/Omni/Omnitone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public struct OmnitoneInstance
{
case .POP3Client:
try await handlePOP3Client()

case .POP3Server:
try await handlePOP3Server()

}
}

Expand Down Expand Up @@ -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)))
}

Expand Down

0 comments on commit 8645bd0

Please sign in to comment.