Skip to content

Commit

Permalink
Use Transmission instead of Transport
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr. Brandon Wiley committed Nov 2, 2021
1 parent 78fedcb commit ac289ec
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 277 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Package.resolved
.swiftpm
.DS_Store
/.build
Expand Down
97 changes: 0 additions & 97 deletions Package.resolved

This file was deleted.

13 changes: 4 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ let package = Package(
from: "1.0.3"),
.package(url: "https://github.com/OperatorFoundation/Datable.git",
from: "3.1.1"),
.package(url: "https://github.com/OperatorFoundation/Transmission.git", from: "0.4.1"),
.package(url: "https://github.com/OperatorFoundation/Transport.git",
from: "2.3.8"),
.package(url: "https://github.com/OperatorFoundation/Transmission.git", from: "0.6.0"),
.package(url: "https://github.com/OperatorFoundation/SwiftQueue.git",
from: "0.1.1")
],
Expand All @@ -34,7 +32,6 @@ let package = Package(
"Song",
"SwiftQueue",
"Transmission",
"Transport",
.product(name: "Logging", package: "swift-log"),
.product(name: "Keychain", package: "Keychain"),
]
Expand Down Expand Up @@ -62,11 +59,10 @@ let package = Package(
from: "1.0.2"),
.package(url: "https://github.com/OperatorFoundation/Datable.git",
from: "3.0.6"),
.package(url: "https://github.com/OperatorFoundation/TransmissionLinux.git", from: "0.3.4"),
.package(url: "https://github.com/OperatorFoundation/Transport.git",
from: "2.3.6"),
.package(url: "https://github.com/OperatorFoundation/Transmission.git", from: "0.6.0"),
.package(url: "https://github.com/OperatorFoundation/SwiftQueue.git",
from: "0.1.0")],
from: "0.1.0")
],
targets: [
.target(
name: "ReplicantSwift",
Expand All @@ -76,7 +72,6 @@ let package = Package(
"Song",
"SwiftQueue",
"TransmissionLinux",
"Transport",
.product(name: "Logging", package: "swift-log"),
.product(name: "KeychainLinux", package: "KeychainLinux"),
.product(name: "Crypto", package: "swift-crypto")
Expand Down
31 changes: 10 additions & 21 deletions Sources/ReplicantSwift/ToneBurst/Monotone/MonotoneClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@

import Foundation
import Datable
import Transport
#if os(Linux)
import NetworkLinux
#else
import Network
#endif
import Transmission
import Monolith

/// Injects byte sequences into a stream of bytes
Expand All @@ -22,7 +17,7 @@ public class MonotoneClient: Whalesong

extension MonotoneClient: ToneBurst
{
public func play(connection: Connection, completion: @escaping (Error?) -> Void)
public func play(connection: Transmission.Connection, completion: @escaping (Error?) -> Void)
{

let sendState = generate()
Expand All @@ -31,20 +26,14 @@ extension MonotoneClient: ToneBurst
{
case .generating(let nextTone):
print("\nGenerating tone bursts.\n")
connection.send(content: nextTone, contentContext: .defaultMessage, isComplete: false, completion: NWConnection.SendCompletion.contentProcessed(
{
(maybeToneSendError) in

guard maybeToneSendError == nil
else
{
print("Received error while sending tone burst: \(maybeToneSendError!)")
return
}

self.toneBurstReceive(connection: connection, finalToneSent: false, completion: completion)
}))

guard connection.write(data: nextTone) else
{
print("Received error while sending tone burst")
completion(MonotoneError.generateFailure)
return
}

self.toneBurstReceive(connection: connection, finalToneSent: false, completion: completion)
case .completion:
print("\nGenerated final toneburst\n")
toneBurstReceive(connection: connection, finalToneSent: true, completion: completion)
Expand Down
90 changes: 34 additions & 56 deletions Sources/ReplicantSwift/ToneBurst/Monotone/MonotoneConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
//

import Foundation
import Transport
#if os(Linux)
import NetworkLinux
#else
import Network
#endif
import Transmission

public class MonotoneConfig: Codable
{
Expand Down Expand Up @@ -146,28 +141,23 @@ public class MonotoneConfig: Codable
}
}

func toneBurstSend(connection: Connection, completion: @escaping (Error?) -> Void)
func toneBurstSend(connection: Transmission.Connection, completion: @escaping (Error?) -> Void)
{
let sendState = generate()

switch sendState
{
case .generating(let nextTone):
print("\nGenerating tone bursts.\n")
connection.send(content: nextTone, contentContext: .defaultMessage, isComplete: false, completion: NWConnection.SendCompletion.contentProcessed(
{
(maybeToneSendError) in

guard maybeToneSendError == nil
else
{
print("Received error while sending tone burst: \(maybeToneSendError!)")
return
}

self.toneBurstReceive(connection: connection, finalToneSent: false, completion: completion)
}))

guard connection.write(data: nextTone) else
{
print("Received error while sending tone burst")
completion(MonotoneError.removeFailure)
return
}

self.toneBurstReceive(connection: connection, finalToneSent: false, completion: completion)

case .completion:
print("\nGenerated final toneburst\n")
toneBurstReceive(connection: connection, finalToneSent: true, completion: completion)
Expand All @@ -186,46 +176,34 @@ public class MonotoneConfig: Codable
// Tone burst is finished
return
}

connection.receive(minimumIncompleteLength: Int(toneLength), maximumLength: Int(toneLength) , completion:
{
(maybeToneResponseData, maybeToneResponseContext, connectionComplete, maybeToneResponseError) in

guard maybeToneResponseError == nil
else
{
print("\nReceived an error in the server tone response: \(maybeToneResponseError!)\n")
return
}

guard let data = connection.read(size: Int(toneLength)) else
{
print("\nReceived an error in the server tone response\n")
completion(MonotoneError.removeFailure)
return
}

let receiveState = self.remove(newData: data)

guard let toneResponseData = maybeToneResponseData
else
switch receiveState
{
case .completion:
if finalToneSent
{
print("\nTone response was empty.\n")
return
completion(nil)
}

let receiveState = self.remove(newData: toneResponseData)

switch receiveState
else
{
case .completion:
if !finalToneSent
{
self.toneBurstSend(connection: connection, completion: completion)
}
else
{
completion(nil)
}

case .receiving:
self.toneBurstSend(connection: connection, completion: completion)

case .failure:
print("\nTone burst remove failure.\n")
completion(WhalesongError.removeFailure)
}
})

case .receiving:
self.toneBurstSend(connection: connection, completion: completion)

case .failure:
print("\nTone burst remove failure.\n")
completion(WhalesongError.removeFailure)
}
}
}
11 changes: 3 additions & 8 deletions Sources/ReplicantSwift/ToneBurst/Monotone/MonotoneServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,16 @@

import Foundation
import Datable
import Transport
#if os(Linux)
import NetworkLinux
#else
import Network
#endif
import Transmission

/// Injects byte sequences into a stream of bytes
public class MonotoneServer: Whalesong
public class MonotoneServer
{
}

extension MonotoneServer: ToneBurst
{
public func play(connection: Connection, completion: @escaping (Error?) -> Void)
public func play(connection: Transmission.Connection, completion: @escaping (Error?) -> Void)
{
self.toneBurstReceive(connection: connection, finalToneSent: false, completion: completion)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/ReplicantSwift/ToneBurst/ToneBurst.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import Foundation
import Datable
import Transport
import Transmission

/// Injects byte sequences into a stream of bytes
public protocol ToneBurst: Codable
{
mutating func play(connection: Connection, completion: @escaping (Error?) -> Void)
mutating func play(connection: Transmission.Connection, completion: @escaping (Error?) -> Void)
}
Loading

0 comments on commit ac289ec

Please sign in to comment.