Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
656bb28a
Commit
656bb28a
authored
Nov 21, 2015
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop the timer when all callbacks removed
parent
6e974da8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
52 deletions
+52
-52
src/main/jni/shadowsocks-libev
src/main/jni/shadowsocks-libev
+1
-1
src/main/scala/com/github/shadowsocks/BaseService.scala
src/main/scala/com/github/shadowsocks/BaseService.scala
+20
-17
src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala
...in/scala/com/github/shadowsocks/ServiceBoundContext.scala
+7
-0
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
.../scala/com/github/shadowsocks/ShadowsocksNatService.scala
+0
-11
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
.../scala/com/github/shadowsocks/ShadowsocksVpnService.scala
+0
-11
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
...n/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
+23
-8
src/main/scala/com/github/shadowsocks/utils/TrafficMonitorThread.scala
...a/com/github/shadowsocks/utils/TrafficMonitorThread.scala
+1
-4
No files found.
shadowsocks-libev
@
d462e4cd
Subproject commit
f226d47ea43fe4705e80d2b922f5ecdaf9d8cc24
Subproject commit
d462e4cd8d44d7275957afab9255b98e54bb2630
src/main/scala/com/github/shadowsocks/BaseService.scala
View file @
656bb28a
...
@@ -73,6 +73,10 @@ trait BaseService {
...
@@ -73,6 +73,10 @@ trait BaseService {
callbacks
.
unregister
(
cb
)
callbacks
.
unregister
(
cb
)
callbackCount
-=
1
callbackCount
-=
1
}
}
if
(
callbackCount
==
0
&&
timer
!=
null
)
{
timer
.
cancel
()
timer
=
null
}
if
(
callbackCount
==
0
&&
state
!=
State
.
CONNECTING
&&
state
!=
State
.
CONNECTED
)
{
if
(
callbackCount
==
0
&&
state
!=
State
.
CONNECTING
&&
state
!=
State
.
CONNECTED
)
{
stopBackgroundService
()
stopBackgroundService
()
}
}
...
@@ -80,6 +84,18 @@ trait BaseService {
...
@@ -80,6 +84,18 @@ trait BaseService {
override
def
registerCallback
(
cb
:
IShadowsocksServiceCallback
)
{
override
def
registerCallback
(
cb
:
IShadowsocksServiceCallback
)
{
if
(
cb
!=
null
)
{
if
(
cb
!=
null
)
{
if
(
callbackCount
==
0
&&
timer
==
null
)
{
val
task
=
new
TimerTask
{
def
run
{
TrafficMonitor
.
updateRate
()
updateTrafficTotal
(
TrafficMonitor
.
getDeltaTx
,
TrafficMonitor
.
getDeltaRx
)
updateTrafficRate
(
TrafficMonitor
.
getTxRate
,
TrafficMonitor
.
getRxRate
,
TrafficMonitor
.
getTxTotal
,
TrafficMonitor
.
getRxTotal
)
}
}
timer
=
new
Timer
(
true
)
timer
.
schedule
(
task
,
1000
,
1000
)
}
callbacks
.
register
(
cb
)
callbacks
.
register
(
cb
)
callbackCount
+=
1
callbackCount
+=
1
}
}
...
@@ -102,30 +118,19 @@ trait BaseService {
...
@@ -102,30 +118,19 @@ trait BaseService {
this
.
config
=
config
this
.
config
=
config
TrafficMonitor
.
reset
()
TrafficMonitor
.
reset
()
trafficMonitorThread
=
new
TrafficMonitorThread
(
this
)
trafficMonitorThread
=
new
TrafficMonitorThread
()
trafficMonitorThread
.
start
()
trafficMonitorThread
.
start
()
val
task
=
new
TimerTask
{
def
run
{
clearChildProcessStream
()
}
}
timer
=
new
Timer
(
true
)
timer
.
schedule
(
task
,
60
*
1000
,
60
*
1000
)
}
}
def
stopRunner
()
{
def
stopRunner
()
{
// Make sure update total traffic when stopping the runner
updateTrafficTotal
(
TrafficMonitor
.
getDeltaTx
,
TrafficMonitor
.
getDeltaRx
)
TrafficMonitor
.
reset
()
TrafficMonitor
.
reset
()
if
(
trafficMonitorThread
!=
null
)
{
if
(
trafficMonitorThread
!=
null
)
{
trafficMonitorThread
.
stopThread
()
trafficMonitorThread
.
stopThread
()
trafficMonitorThread
=
null
trafficMonitorThread
=
null
}
}
if
(
timer
!=
null
)
{
timer
.
cancel
()
timer
=
null
}
}
}
def
updateTrafficTotal
(
tx
:
Long
,
rx
:
Long
)
{
def
updateTrafficTotal
(
tx
:
Long
,
rx
:
Long
)
{
...
@@ -136,7 +141,6 @@ trait BaseService {
...
@@ -136,7 +141,6 @@ trait BaseService {
case
Some
(
profile
)
=>
case
Some
(
profile
)
=>
profile
.
tx
+=
tx
profile
.
tx
+=
tx
profile
.
rx
+=
rx
profile
.
rx
+=
rx
Log
.
d
(
"test"
,
profile
.
tx
+
" "
+
profile
.
rx
)
ShadowsocksApplication
.
profileManager
.
updateProfile
(
profile
)
ShadowsocksApplication
.
profileManager
.
updateProfile
(
profile
)
case
None
=>
// Ignore
case
None
=>
// Ignore
}
}
...
@@ -144,7 +148,6 @@ trait BaseService {
...
@@ -144,7 +148,6 @@ trait BaseService {
})
})
}
}
def
clearChildProcessStream
()
def
stopBackgroundService
()
def
stopBackgroundService
()
def
getServiceMode
:
Int
def
getServiceMode
:
Int
def
getTag
:
String
def
getTag
:
String
...
...
src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala
View file @
656bb28a
...
@@ -55,6 +55,13 @@ trait ServiceBoundContext extends Context {
...
@@ -55,6 +55,13 @@ trait ServiceBoundContext extends Context {
def
deattachService
()
{
def
deattachService
()
{
if
(
bgService
!=
null
)
{
if
(
bgService
!=
null
)
{
if
(
callback
!=
null
)
{
try
{
bgService
.
unregisterCallback
(
callback
)
}
catch
{
case
ignored
:
RemoteException
=>
// Nothing
}
}
unbindService
(
connection
)
unbindService
(
connection
)
bgService
=
null
bgService
=
null
}
}
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
View file @
656bb28a
...
@@ -429,17 +429,6 @@ class ShadowsocksNatService extends Service with BaseService {
...
@@ -429,17 +429,6 @@ class ShadowsocksNatService extends Service with BaseService {
Console
.
runRootCommand
(
http_sb
.
toArray
)
Console
.
runRootCommand
(
http_sb
.
toArray
)
}
}
override
def
clearChildProcessStream
()
{
try
{
sslocalProcess
.
getInputStream
.
skip
(
65535
)
sstunnelProcess
.
getInputStream
.
skip
(
65535
)
pdnsdProcess
.
getInputStream
.
skip
(
65535
)
redsocksProcess
.
getInputStream
.
skip
(
65535
)
}
catch
{
case
ex
:
Exception
=>
// Ignore
}
}
override
def
startRunner
(
config
:
Config
)
{
override
def
startRunner
(
config
:
Config
)
{
super
.
startRunner
(
config
)
super
.
startRunner
(
config
)
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
View file @
656bb28a
...
@@ -214,17 +214,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
...
@@ -214,17 +214,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
}
}
}
}
override
def
clearChildProcessStream
()
{
try
{
sslocalProcess
.
getInputStream
.
skip
(
65535
)
sstunnelProcess
.
getInputStream
.
skip
(
65535
)
pdnsdProcess
.
getInputStream
.
skip
(
65535
)
tun2socksProcess
.
getInputStream
.
skip
(
65535
)
}
catch
{
case
ex
:
Exception
=>
// Ignore
}
}
override
def
startRunner
(
config
:
Config
)
{
override
def
startRunner
(
config
:
Config
)
{
super
.
startRunner
(
config
)
super
.
startRunner
(
config
)
...
...
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
View file @
656bb28a
...
@@ -39,20 +39,23 @@ object TrafficMonitor {
...
@@ -39,20 +39,23 @@ object TrafficMonitor {
else
numberFormat
.
format
(
n
)
+
' '
+
units
(
i
)
else
numberFormat
.
format
(
n
)
+
' '
+
units
(
i
)
}
}
def
update
(
tx
:
Long
,
rx
:
Long
)
{
def
update
Rate
(
)
{
val
now
=
getTraffic
(
tx
,
rx
)
val
now
=
getTraffic
(
tx
Total
,
rxTotal
)
val
delta
=
now
.
timestamp
-
last
.
timestamp
val
delta
=
now
.
timestamp
-
last
.
timestamp
txLast
=
now
.
tx
-
last
.
tx
val
deltaTx
=
now
.
tx
-
last
.
tx
rxLast
=
now
.
rx
-
last
.
rx
val
deltaRx
=
now
.
rx
-
last
.
rx
if
(
delta
!=
0
)
{
if
(
delta
!=
0
)
{
txRate
=
txLast
*
1000
/
delta
txRate
=
deltaTx
*
1000
/
delta
rxRate
=
rxLast
*
1000
/
delta
rxRate
=
deltaRx
*
1000
/
delta
}
}
txTotal
+=
txLast
rxTotal
+=
rxLast
last
=
now
last
=
now
}
}
def
update
(
tx
:
Long
,
rx
:
Long
)
{
txTotal
=
tx
;
rxTotal
=
rx
;
}
def
reset
()
{
def
reset
()
{
txRate
=
0
txRate
=
0
rxRate
=
0
rxRate
=
0
...
@@ -84,5 +87,17 @@ object TrafficMonitor {
...
@@ -84,5 +87,17 @@ object TrafficMonitor {
def
getRate
()
:
String
=
{
def
getRate
()
:
String
=
{
formatTraffic
(
txRate
+
rxRate
)
formatTraffic
(
txRate
+
rxRate
)
}
}
def
getDeltaTx
()
:
Long
=
{
val
last
=
txLast
txLast
=
txTotal
txTotal
-
last
}
def
getDeltaRx
()
:
Long
=
{
val
last
=
rxLast
rxLast
=
rxTotal
rxTotal
-
last
}
}
}
src/main/scala/com/github/shadowsocks/utils/TrafficMonitorThread.scala
View file @
656bb28a
...
@@ -46,7 +46,7 @@ import android.net.{LocalServerSocket, LocalSocket, LocalSocketAddress}
...
@@ -46,7 +46,7 @@ import android.net.{LocalServerSocket, LocalSocket, LocalSocketAddress}
import
android.util.Log
import
android.util.Log
import
com.github.shadowsocks.BaseService
import
com.github.shadowsocks.BaseService
class
TrafficMonitorThread
(
service
:
BaseService
)
extends
Thread
{
class
TrafficMonitorThread
()
extends
Thread
{
val
TAG
=
"TrafficMonitorThread"
val
TAG
=
"TrafficMonitorThread"
val
PATH
=
"/data/data/com.github.shadowsocks/stat_path"
val
PATH
=
"/data/data/com.github.shadowsocks/stat_path"
...
@@ -108,9 +108,6 @@ class TrafficMonitorThread(service: BaseService) extends Thread {
...
@@ -108,9 +108,6 @@ class TrafficMonitorThread(service: BaseService) extends Thread {
val
stat
=
new
String
(
array
,
"UTF-8"
).
split
(
"\\|"
)
val
stat
=
new
String
(
array
,
"UTF-8"
).
split
(
"\\|"
)
if
(
stat
.
length
==
2
)
{
if
(
stat
.
length
==
2
)
{
TrafficMonitor
.
update
(
stat
(
0
).
toLong
,
stat
(
1
).
toLong
)
TrafficMonitor
.
update
(
stat
(
0
).
toLong
,
stat
(
1
).
toLong
)
service
.
updateTrafficTotal
(
TrafficMonitor
.
txLast
,
TrafficMonitor
.
rxLast
)
service
.
updateTrafficRate
(
TrafficMonitor
.
getTxRate
,
TrafficMonitor
.
getRxRate
,
TrafficMonitor
.
getTxTotal
,
TrafficMonitor
.
getRxTotal
)
}
}
output
.
write
(
0
)
output
.
write
(
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment