Skip to content

Commit

Permalink
Merge branch 'master_private'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
kqueue2020 committed Feb 16, 2018
2 parents b199f3c + cc14cf5 commit 38d7d61
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 165 deletions.
2 changes: 1 addition & 1 deletion Kwazii/RequestsVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import XRuler
import XProxy
final class RequestsVC: RequestsBasic {
@IBOutlet weak var detail:NSView!
let report:SFVPNStatistics = SFVPNStatistics.shared

var refreshTime = DispatchSource.makeTimerSource(flags: DispatchSource.TimerFlags(rawValue: 0), queue: DispatchQueue.main)
func startProxy(){
SKit.startGCDProxy(port: 10081, dispatchQueue: DispatchQueue.init(label: "Kwazii.dispatch"), socketQueue: DispatchQueue.init(label: "Kwazii.dispatch.socket"))
Expand Down
2 changes: 1 addition & 1 deletion PacketTunnel/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//

import NetworkExtension
import SwiftyJSON

import SFSocket
import AxLogger
import Crashlytics
Expand Down
8 changes: 6 additions & 2 deletions Surf-Mac/AdvancedWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ class AdvancedWindowController: NSWindowController {
}else {
ProxyGroupSettings.share.saveiCloudSync(false)
}

try! ProxyGroupSettings.share.save()
do {
try ProxyGroupSettings.share.save()
}catch let e {
alertMesage(e.localizedDescription)
}

window?.performClose(nil)
}

Expand Down
67 changes: 27 additions & 40 deletions Surf-Mac/StatusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import Cocoa
import SFSocket
import XRuler
import NetworkExtension
import SwiftyJSON

class StatusView: NSView {
var report:SFVPNStatistics = SFVPNStatistics.shared

var reportTimer:Timer?
@IBOutlet weak var iconView: NSImageView!
@IBOutlet weak var upView: NSTextField!
Expand Down Expand Up @@ -53,24 +53,24 @@ class StatusView: NSView {
let now = getInterfaceTraffic()
if now.TunSent != 0 && now.TunReceived != 0 {
//report.lastTraffice.tx = now.TunSent -

if now.TunSent > report.totalTraffice.tx {
report.lastTraffice.tx = now.TunSent - report.totalTraffice.tx
report.lastTraffice.rx = now.TunReceived - report.totalTraffice.rx
report.updateMax()
}
report.totalTraffice.tx = now.TunSent
report.totalTraffice.rx = now.TunReceived
let t = report.lastTraffice
upTrafficeView.stringValue = self.toString(x: t.tx,label: "",speed: true)
downTrafficView.stringValue = self.toString(x: t.rx,label: "",speed: true)
//FIXME:
// if now.TunSent > report.totalTraffice.tx {
// report.lastTraffice.tx = now.TunSent - report.totalTraffice.tx
//
// report.lastTraffice.rx = now.TunReceived - report.totalTraffice.rx
// report.updateMax()
// }
//
//
//
// report.totalTraffice.tx = now.TunSent
// report.totalTraffice.rx = now.TunReceived
//
// let t = report.lastTraffice
//
//
// upTrafficeView.stringValue = self.toString(x: t.tx,label: "",speed: true)
// downTrafficView.stringValue = self.toString(x: t.rx,label: "",speed: true)
}else {
upTrafficeView.stringValue = "0 B/s"
downTrafficView.stringValue = "0 B/s"
Expand Down Expand Up @@ -129,36 +129,23 @@ class StatusView: NSView {

}
func processData(data:Data) {

//results.removeAll()
//print("111")
//let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
let obj = try! JSON.init(data: data)
if obj.error == nil {

//alertMessageAction("message dont init",complete: nil)
report.map(j: obj)




do {
let report:SFStatistics = try JSONDecoder().decode(SFStatistics.self, from: data)
//bug here
if let m = SFVPNManager.shared.manager, m.connection.status == .connected{
//chartsView.updateFlow(report.netflow)
//chartsView.isHidden = false
if let last = report.netflow.totalFlows.last {
if let last = report.netflow.total.last {
upTrafficeView.stringValue = self.toString(x: last.tx,label: "",speed: true)
downTrafficView.stringValue = self.toString(x: last.rx,label: "",speed: true)
}

}else {

}
//print(report.netflow.currentFlows)



}catch let e {
print(e.localizedDescription)
}



}
}
74 changes: 29 additions & 45 deletions Surf-Today/RequestsWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Cocoa
import SwiftyJSON

import NetworkExtension
import SFSocket
import XProxy
Expand Down Expand Up @@ -61,58 +61,42 @@ class RequestsWindowController: NSWindowController,NSTableViewDelegate,NSTableVi
let oldresults = results
results.removeAll()

let obj = try! JSON.init(data: data)
if obj.error == nil {
let helper = try! JSONDecoder().decode(ConnectionHelper.self, from: data)

for item in helper.data {

let count = obj["count"]

if count.intValue != 0 {

let result = obj["data"]
if result.type == .array {
for item in result {

let json = item.1
let r = SFRequestInfo.init(rID: 0)
r.map(json)
let rr = oldresults.filter({ info -> Bool in
if info.reqID == r.reqID && info.subID == r.subID {
return true
}
return false
})

if rr.isEmpty {
results.append(r)
r.speedtraffice = r.traffice
}else {
let old = rr.first!
if r.traffice.rx > old.traffice.rx {
//sub id reset
r.speedtraffice.rx = r.traffice.rx - old.traffice.rx
}

if r.traffice.tx > old.traffice.tx{
//?
r.speedtraffice.tx = r.traffice.tx - old.traffice.tx
}


results.append(r)
}

}
let rr = oldresults.filter({ info -> Bool in
if info.reqID == item.reqID && info.subID == item.subID {
return true
}
if results.count > 0 {
results.sort(by: { $0.reqID < $1.reqID })

return false
})

if rr.isEmpty {
results.append(item)
item.speedtraffice = item.traffice
}else {
let old = rr.first!
if item.traffice.rx > old.traffice.rx {
//sub id reset
item.speedtraffice.rx = item.traffice.rx - old.traffice.rx
}

if item.traffice.tx > old.traffice.tx{
//?
item.speedtraffice.tx = item.traffice.tx - old.traffice.tx
}


results.append(item)
}


}

if results.count > 0 {
results.sort(by: { $0.reqID < $1.reqID })

}
tableView.reloadData()

}
Expand Down
2 changes: 1 addition & 1 deletion Surf/AnalyzeTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit
import NetworkExtension
import SwiftyJSON

import SFSocket
import CoreTelephony
import Fabric
Expand Down
2 changes: 1 addition & 1 deletion Surf/RecentReqViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit
import NetworkExtension
import SwiftyJSON

import SFSocket
import XRuler
import Xcon
Expand Down
2 changes: 1 addition & 1 deletion Surf/RequestDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import UIKit
import SwiftyJSON

import SFSocket
import XRuler
import Xcon
Expand Down
2 changes: 1 addition & 1 deletion Surf/RuleResultsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit
import NetworkExtension
import SwiftyJSON

import SFSocket
class RuleResultsViewController: SFTableViewController {

Expand Down
48 changes: 29 additions & 19 deletions Surf/SFCountry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import SwiftyJSON

import MMDB
import AxLogger
class CData {
Expand All @@ -19,32 +19,42 @@ class CData {
}
}

//"code": "AD",
//"emoji": "🇦🇩",
//"unicode": "U+1F1E6 U+1F1E9",
//"name": "Andorra",
//"title": "flag for Andorra"

struct CountryCode:Codable {
var code:String = ""
var emoji:String = ""
var unicode:String = ""
var name:String = ""
var title:String = ""
}
struct CountryCodeList:Codable {
var list:[CountryCode] = []
}
class Country {
var db:MMDB?
//var data:JSON?
var list:[String:CData] = [:]
var list:[String:CountryCode] = [:]
static let setting:Country = {
let c = Country()
if let path = Bundle.main.path(forResource:"data.json", ofType: nil) {
let d = try! Data.init(contentsOf: URL.init(fileURLWithPath: path))
let data = try! JSON(data: d)
if data.error == nil {
for (k,v) in data {
let code = v["code"].stringValue
let e = v["emoji"].stringValue
let x = CData.init(c: code, e: e)
c.list[code] = x
//print("\(code),\(e)")
do {
let d = try Data.init(contentsOf: URL.init(fileURLWithPath: path))
let list = try JSONDecoder().decode(CountryCodeList.self, from: d)
for i in list.list {

c.list[i.code] = i

}
}else {
//fatalError()
if let error = data.error {
print("\(error)")
}

}catch let e {
print(e)
}



}else {
fatalError()
Expand Down
Loading

0 comments on commit 38d7d61

Please sign in to comment.