Fix Swiftlints
This commit is contained in:
parent
669eed0dac
commit
286ecfa590
2 changed files with 15 additions and 15 deletions
|
|
@ -7,10 +7,10 @@ enum BurrowError: Error {
|
||||||
case resultIsNone
|
case resultIsNone
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol Request: Codable where T: Codable{
|
protocol Request: Codable where CommandT: Codable {
|
||||||
associatedtype T
|
associatedtype CommandT
|
||||||
var id: UInt { get set }
|
var id: UInt { get set }
|
||||||
var command: T { get set }
|
var command: CommandT { get set }
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BurrowSingleCommand: Request {
|
struct BurrowSingleCommand: Request {
|
||||||
|
|
@ -18,27 +18,30 @@ struct BurrowSingleCommand: Request {
|
||||||
var command: String
|
var command: String
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BurrowRequest<T>: Request where T: Codable{
|
struct BurrowRequest<T>: Request where T: Codable {
|
||||||
var id: UInt
|
var id: UInt
|
||||||
var command: T
|
var command: T
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BurrowStartRequest: Codable {
|
struct BurrowStartRequest: Codable {
|
||||||
struct TunOptions: Codable{
|
struct TunOptions: Codable {
|
||||||
let name: String?
|
let name: String?
|
||||||
let no_pi: Bool
|
let no_pi: Bool
|
||||||
let tun_excl: Bool
|
let tun_excl: Bool
|
||||||
let tun_retrieve: Bool
|
let tun_retrieve: Bool
|
||||||
let address: String?
|
let address: String?
|
||||||
}
|
}
|
||||||
struct StartOptions: Codable{
|
struct StartOptions: Codable {
|
||||||
let tun: TunOptions
|
let tun: TunOptions
|
||||||
}
|
}
|
||||||
let Start: StartOptions
|
let Start: StartOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func start_req_fd(id: UInt) -> BurrowRequest<BurrowStartRequest> {
|
func start_req_fd(id: UInt) -> BurrowRequest<BurrowStartRequest> {
|
||||||
return BurrowRequest(id: id, command: BurrowStartRequest(Start: BurrowStartRequest.StartOptions(tun: BurrowStartRequest.TunOptions(name: nil, no_pi: false, tun_excl: false, tun_retrieve: true, address: nil))))
|
let command = BurrowStartRequest(Start: BurrowStartRequest.StartOptions(
|
||||||
|
tun: BurrowStartRequest.TunOptions(name: nil, no_pi: false, tun_excl: false, tun_retrieve: true, address: nil)
|
||||||
|
))
|
||||||
|
return BurrowRequest(id: id, command: command)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Response<T>: Decodable where T: Decodable {
|
struct Response<T>: Decodable where T: Decodable {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
let logger = Logger(subsystem: "com.hackclub.burrow", category: "frontend")
|
let logger = Logger(subsystem: "com.hackclub.burrow", category: "frontend")
|
||||||
var client: BurrowIpc?
|
var client: BurrowIpc?
|
||||||
var osInitialized = false
|
var osInitialized = false
|
||||||
override func startTunnel(options: [String : NSObject]? = nil) async throws {
|
override func startTunnel(options: [String: NSObject]? = nil) async throws {
|
||||||
logger.log("Starting tunnel")
|
logger.log("Starting tunnel")
|
||||||
if !osInitialized {
|
if !osInitialized {
|
||||||
libburrow.initialize_oslog()
|
libburrow.initialize_oslog()
|
||||||
|
|
@ -34,13 +34,13 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
|
|
||||||
// let tunFd = self.packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int;
|
// let tunFd = self.packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int;
|
||||||
// self.logger.info("Found File Descriptor: \(tunFd)")
|
// self.logger.info("Found File Descriptor: \(tunFd)")
|
||||||
let start_command = start_req_fd(id: 1)
|
let startCommand = start_req_fd(id: 1)
|
||||||
guard let data = try await client?.request(start_command, type: Response<BurrowResult<String>>.self)
|
guard let data = try await client?.request(startCommand, type: Response<BurrowResult<String>>.self)
|
||||||
else {
|
else {
|
||||||
throw BurrowError.cantParseResult
|
throw BurrowError.cantParseResult
|
||||||
}
|
}
|
||||||
let encoded_startres = try JSONEncoder().encode(data.result)
|
let encodedStartRes = try JSONEncoder().encode(data.result)
|
||||||
self.logger.log("Received start server response: \(String(decoding: encoded_startres, as: UTF8.self))")
|
self.logger.log("Received start server response: \(String(decoding: encodedStartRes, as: UTF8.self))")
|
||||||
} catch {
|
} catch {
|
||||||
self.logger.error("An error occurred: \(error)")
|
self.logger.error("An error occurred: \(error)")
|
||||||
throw error
|
throw error
|
||||||
|
|
@ -58,15 +58,12 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
return nst
|
return nst
|
||||||
}
|
}
|
||||||
override func stopTunnel(with reason: NEProviderStopReason) async {
|
override func stopTunnel(with reason: NEProviderStopReason) async {
|
||||||
|
|
||||||
}
|
}
|
||||||
override func handleAppMessage(_ messageData: Data) async -> Data? {
|
override func handleAppMessage(_ messageData: Data) async -> Data? {
|
||||||
messageData
|
messageData
|
||||||
}
|
}
|
||||||
override func sleep() async {
|
override func sleep() async {
|
||||||
|
|
||||||
}
|
}
|
||||||
override func wake() {
|
override func wake() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue