Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using NIOTSEventLoopGroup on Apple Platforms #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/orlandos-nl/BSON.git",
"state" : {
"revision" : "98a2c90988895f1b985ed0066180995df995924c",
"version" : "7.0.28"
"revision" : "c29936981d39667429d4e0ec03aa8d6a722ea36a",
"version" : "7.0.31"
}
},
{
Expand All @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics",
"state" : {
"revision" : "919eb1d83e02121cdb434c7bfc1f0c66ef17febe",
"version" : "1.0.2"
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
"version" : "1.2.0"
}
},
{
Expand Down Expand Up @@ -104,8 +104,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "124119f0bb12384cef35aa041d7c3a686108722d",
"version" : "2.40.0"
"revision" : "54c85cb26308b89846d4671f23954dce088da2b0",
"version" : "2.60.0"
}
},
{
Expand All @@ -126,6 +126,15 @@
"version" : "2.17.2"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "ebf8b9c365a6ce043bf6e6326a04b15589bd285e",
"version" : "1.20.0"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
Expand Down
5 changes: 3 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ let package = Package(
// .package(name: "swift-nio-ssl", path: "/Users/joannisorlandos/git/joannis/swift-nio-ssl"),
// .package(name: "Dribble", path: "/Users/joannisorlandos/git/orlandos-nl/Dribble"),
.package(url: "https://github.com/apple/swift-distributed-actors.git", from: "1.0.0-beta.1.1"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.20.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.60.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.0.0"),
.package(url: "https://github.com/orlandos-nl/Dribble.git", from: "0.1.0"),
.package(url: "https://github.com/vapor/jwt-kit.git", from: "4.0.0"),
Expand Down Expand Up @@ -62,7 +63,7 @@ let package = Package(
.product(name: "NIO", package: "swift-nio"),
.product(name: "_NIOConcurrency", package: "swift-nio"),
.product(name: "NIOFoundationCompat", package: "swift-nio"),
// .product(name: "NIOTransportServices", package: "swift-nio-transport-services"),
.product(name: "NIOTransportServices", package: "swift-nio-transport-services"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "BSON", package: "BSON"),
]),
Expand Down
7 changes: 7 additions & 0 deletions Sources/CypherMessaging/Messenger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import Crypto
import TaskQueue
import NIO
import CypherProtocol
#if canImport(NIOTransportServices)
import NIOTransportServices
#endif

public enum DeviceRegisteryMode: Int, Codable, Sendable {
case masterDevice, childDevice, unregistered
Expand Down Expand Up @@ -257,7 +260,11 @@ public final class CypherMessenger: CypherTransportClientDelegate, P2PTransportC
p2pFactories: [P2PTransportClientFactory],
transport: CypherServerTransportClient
) async throws {
#if os(Linux) || os(Android) || os(Windows)
self.eventLoop = MultiThreadedEventLoopGroup(numberOfThreads: 1).next()
#else
self.eventLoop = NIOTSEventLoopGroup().next()
#endif
self.eventHandler = eventHandler
self.username = config.username
self.deviceId = config.deviceKeys.deviceId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Dribble
import NIO
//import NIOTransportServices
#if canImport(NIOTransportServices)
import NIOTransportServices
#endif

public enum IPv6TCPP2PError: Error {
case reconnectFailed, timeout, socketCreationFailed
Expand Down Expand Up @@ -102,10 +104,15 @@ public final class IPv6TCPP2PTransportClientFactory: P2PTransportClientFactory {
public let transportLayerIdentifier = "_ipv6-tcp"
public let isMeshEnabled = false
public weak var delegate: P2PTransportFactoryDelegate?

#if os(Linux) || os(Android) || os(Windows)
let eventLoop = MultiThreadedEventLoopGroup(numberOfThreads: 1).next()
#else
let eventLoop = NIOTSEventLoopGroup().next()
#endif
let stun: StunConfig?

public init(stun: StunConfig? = nil) {
public init(stun: StunConfig? = nil) async {
self.stun = stun
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/CypherMessaging/Primitives/Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Joannis Orlandos on 19/04/2021.
//

typealias CacheActor = MainActor
public typealias CacheActor = MainActor

public protocol CacheKey {
associatedtype Value
Expand Down
7 changes: 7 additions & 0 deletions Sources/CypherMessaging/TestSupport/SpoofTransport.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import CypherProtocol
import Foundation
import NIO
#if canImport(NIOTransportServices)
import NIOTransportServices
#endif

public enum SpoofTransportClientSettings {
public enum PacketType: Sendable {
Expand All @@ -25,7 +28,11 @@ public enum SpoofTransportClientSettings {
}

fileprivate final class SpoofServer {
#if os(Linux) || os(Android) || os(Windows)
fileprivate let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)
#else
fileprivate let elg = NIOTSEventLoopGroup()
#endif
fileprivate var onlineDevices = [SpoofTransportClient]()
private var backlog = [DeviceId: [CypherServerEvent]]()
private var userDevices = [Username: Set<DeviceId>]()
Expand Down
3 changes: 2 additions & 1 deletion Sources/MessagingHelpers/VaporTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import CypherProtocol
import CypherMessaging
import JWTKit
import WebSocketKit
import NIOTransportServices

// TODO: Secondary servers

Expand Down Expand Up @@ -209,7 +210,7 @@ public final class VaporTransport: CypherServerTransportClient {
self.host = host
self.username = username
self.deviceId = deviceId
self.eventLoop = MultiThreadedEventLoopGroup(numberOfThreads: 1).next()
self.eventLoop = NIOTSEventLoopGroup().next()
self.httpClient = httpClient
self.signer = signer
}
Expand Down