-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0499c9a
commit 59688cf
Showing
14 changed files
with
301 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
core/src/main/java/com/github/shadowsocks/bg/V2ProxyInstance.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.github.shadowsocks.bg | ||
|
||
import com.github.shadowsocks.Core | ||
import com.github.shadowsocks.database.Profile | ||
import com.github.shadowsocks.net.HostsFile | ||
import kotlinx.coroutines.CoroutineScope | ||
import libv2ray.V2RayPoint | ||
import java.io.File | ||
|
||
class V2ProxyInstance(override val profile: Profile, private val route: String = profile.route) : ProxyInstance(profile,route) { | ||
private var v2rayPoint: V2RayPoint? =null | ||
constructor(v2Point: V2RayPoint,profile: Profile, route: String) : this(profile,route) { | ||
this.v2rayPoint=v2Point | ||
trafficMonitor = V2TrafficMonitor(File(Core.deviceStorage.noBackupFilesDir, "stat_main"),v2rayPoint!!) | ||
} | ||
|
||
override suspend fun init(service: BaseService.Interface, hosts: HostsFile) { | ||
} | ||
override fun start(service: BaseService.Interface, stat: File, configFile: File, extraFlag: String?) { | ||
} | ||
override fun scheduleUpdate() { | ||
} | ||
override fun shutdown(scope: CoroutineScope) { | ||
trafficMonitor?.apply { | ||
thread.shutdown(scope) | ||
persistStats(profile.id) // Make sure update total traffic when stopping the runner | ||
} | ||
trafficMonitor = null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
core/src/main/java/com/github/shadowsocks/bg/V2TrafficMonitor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.github.shadowsocks.bg | ||
|
||
import com.github.shadowsocks.aidl.TrafficStats | ||
import libv2ray.V2RayPoint | ||
import rx.Observable | ||
import java.io.File | ||
|
||
class V2TrafficMonitor(statFile: File): TrafficMonitor(statFile) { | ||
private var v2rayPoint: V2RayPoint? =null | ||
|
||
constructor(statFile: File,v2Point: V2RayPoint) : this(statFile) { | ||
this.v2rayPoint=v2Point | ||
} | ||
|
||
override fun requestUpdate(): Pair<TrafficStats, Boolean> { | ||
var updated = false | ||
if (v2rayPoint!!.isRunning ) { | ||
Observable.interval(3, java.util.concurrent.TimeUnit.SECONDS) | ||
.subscribe { | ||
val uplink = v2rayPoint!!.queryStats("socks", "uplink") | ||
val downlink = v2rayPoint!!.queryStats("socks", "downlink") | ||
val zero_speed = (uplink == 0L && downlink == 0L) | ||
if (!zero_speed ) { | ||
current.txTotal+=uplink | ||
current.txRate = uplink / 3 | ||
current.rxTotal+=downlink | ||
current.rxRate = downlink / 3 | ||
} | ||
} | ||
} | ||
if (current.txRate>0 || current.rxRate>0) updated = true | ||
return Pair(current, updated) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.