source: launchers/macosx/I2PLauncher/routermgmt/RouterServices/HttpTunnelService.swift @ 7cb0c9b

Last change on this file since 7cb0c9b was 7cb0c9b, checked in by meeh <meeh@…>, 14 months ago

Mac OSX Launcher: Router management/healthcheck code updates.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1//
2//  HttpTunnelService.swift
3//  I2PLauncher
4//
5//  Created by Mikal Villa on 03/04/2019.
6//  Copyright © 2019 The I2P Project. All rights reserved.
7//
8
9import Foundation
10import Kanna
11
12class HttpTunnelService : Service {
13 
14  let dataURL: URL = URL(string: "http://127.0.0.1:7657/i2ptunnel/")!
15 
16  override func updateStatus(callback: @escaping (BaseService) -> Void) {
17    URLSession.shared.dataTask(with: dataURL) { [weak self] data, _, error in
18      guard let strongSelf = self else { return }
19      defer { callback(strongSelf) }
20     
21      guard let doc = try? HTML(html: data!, encoding: .utf8) else { return /*strongSelf._fail("Couldn't parse response")*/ }
22     
23      _ = doc.css("table#clientTunnels > tr.tunnelProperties > td.tunnelStatus").first
24      let maxStatus: ServiceStatus = .started
25      strongSelf.status = maxStatus
26     
27      switch maxStatus {
28      case .waiting:
29        strongSelf.message = "Waiting on router"
30      case .started:
31        strongSelf.message = "Started"
32      case .stopped:
33        strongSelf.message = "Stopped"
34      case .undetermined:
35        strongSelf.message = "Undetermined"
36      default:
37        strongSelf.message = "Undetermined" /*downComponents.map { $0["name"] as? String }.compactMap { $0 }.joined(separator: ", ")*/
38      }
39    }.resume()
40  }
41 
42}
Note: See TracBrowser for help on using the repository browser.