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
66ceed86
Commit
66ceed86
authored
Aug 06, 2016
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restart kcptun when switching network
parent
a073f850
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
5 deletions
+37
-5
src/main/scala/com/github/shadowsocks/BaseService.scala
src/main/scala/com/github/shadowsocks/BaseService.scala
+24
-0
src/main/scala/com/github/shadowsocks/GuardedProcess.scala
src/main/scala/com/github/shadowsocks/GuardedProcess.scala
+13
-3
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
.../scala/com/github/shadowsocks/ShadowsocksNatService.scala
+0
-1
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
.../scala/com/github/shadowsocks/ShadowsocksVpnService.scala
+0
-1
No files found.
src/main/scala/com/github/shadowsocks/BaseService.scala
View file @
66ceed86
...
@@ -43,10 +43,12 @@ import java.util.{Timer, TimerTask}
...
@@ -43,10 +43,12 @@ import java.util.{Timer, TimerTask}
import
android.app.Service
import
android.app.Service
import
android.content.
{
BroadcastReceiver
,
Context
,
Intent
,
IntentFilter
}
import
android.content.
{
BroadcastReceiver
,
Context
,
Intent
,
IntentFilter
}
import
android.net.ConnectivityManager
import
android.os.
{
Handler
,
RemoteCallbackList
}
import
android.os.
{
Handler
,
RemoteCallbackList
}
import
android.text.TextUtils
import
android.text.TextUtils
import
android.util.Log
import
android.util.Log
import
android.widget.Toast
import
android.widget.Toast
import
com.github.kevinsawicki.http.HttpRequest
import
com.github.kevinsawicki.http.HttpRequest
import
com.github.shadowsocks.aidl.
{
IShadowsocksService
,
IShadowsocksServiceCallback
}
import
com.github.shadowsocks.aidl.
{
IShadowsocksService
,
IShadowsocksServiceCallback
}
import
com.github.shadowsocks.utils._
import
com.github.shadowsocks.utils._
...
@@ -71,6 +73,16 @@ trait BaseService extends Service {
...
@@ -71,6 +73,16 @@ trait BaseService extends Service {
}
}
var
closeReceiverRegistered
:
Boolean
=
_
var
closeReceiverRegistered
:
Boolean
=
_
var
kcptunProcess
:
GuardedProcess
=
_
private
val
networkReceiver
:
BroadcastReceiver
=
(
context
:
Context
,
intent
:
Intent
)
=>
{
val
cm
=
context
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
).
asInstanceOf
[
ConnectivityManager
]
val
activeNetwork
=
cm
.
getActiveNetworkInfo
()
val
isConnected
=
activeNetwork
!=
null
&&
activeNetwork
.
isConnected
()
if
(
isConnected
&&
profile
.
kcp
&&
kcptunProcess
!=
null
)
kcptunProcess
.
restart
()
}
var
networkReceiverRegistered
:
Boolean
=
_
val
binder
=
new
IShadowsocksService
.
Stub
{
val
binder
=
new
IShadowsocksService
.
Stub
{
override
def
getState
:
Int
=
{
override
def
getState
:
Int
=
{
state
state
...
@@ -162,6 +174,14 @@ trait BaseService extends Service {
...
@@ -162,6 +174,14 @@ trait BaseService extends Service {
closeReceiverRegistered
=
true
closeReceiverRegistered
=
true
}
}
if
(!
networkReceiverRegistered
)
{
// register network change receiver
val
filter
=
new
IntentFilter
()
filter
.
addAction
(
ConnectivityManager
.
CONNECTIVITY_ACTION
)
registerReceiver
(
networkReceiver
,
filter
)
networkReceiverRegistered
=
true
}
app
.
track
(
getClass
.
getSimpleName
,
"start"
)
app
.
track
(
getClass
.
getSimpleName
,
"start"
)
changeState
(
State
.
CONNECTING
)
changeState
(
State
.
CONNECTING
)
...
@@ -177,6 +197,10 @@ trait BaseService extends Service {
...
@@ -177,6 +197,10 @@ trait BaseService extends Service {
unregisterReceiver
(
closeReceiver
)
unregisterReceiver
(
closeReceiver
)
closeReceiverRegistered
=
false
closeReceiverRegistered
=
false
}
}
if
(
networkReceiverRegistered
)
{
unregisterReceiver
(
networkReceiver
)
networkReceiverRegistered
=
false
}
// Make sure update total traffic when stopping the runner
// Make sure update total traffic when stopping the runner
updateTrafficTotal
(
TrafficMonitor
.
txTotal
,
TrafficMonitor
.
rxTotal
)
updateTrafficTotal
(
TrafficMonitor
.
txTotal
,
TrafficMonitor
.
rxTotal
)
...
...
src/main/scala/com/github/shadowsocks/GuardedProcess.scala
View file @
66ceed86
...
@@ -56,6 +56,7 @@ class GuardedProcess(cmd: Seq[String]) extends Process {
...
@@ -56,6 +56,7 @@ class GuardedProcess(cmd: Seq[String]) extends Process {
@volatile
private
var
guardThread
:
Thread
=
_
@volatile
private
var
guardThread
:
Thread
=
_
@volatile
private
var
isDestroyed
:
Boolean
=
_
@volatile
private
var
isDestroyed
:
Boolean
=
_
@volatile
private
var
process
:
Process
=
_
@volatile
private
var
process
:
Process
=
_
@volatile
private
var
isRestart
=
false
def
start
(
onRestartCallback
:
()
=>
Unit
=
null
)
:
GuardedProcess
=
{
def
start
(
onRestartCallback
:
()
=>
Unit
=
null
)
:
GuardedProcess
=
{
val
semaphore
=
new
Semaphore
(
1
)
val
semaphore
=
new
Semaphore
(
1
)
...
@@ -76,11 +77,15 @@ class GuardedProcess(cmd: Seq[String]) extends Process {
...
@@ -76,11 +77,15 @@ class GuardedProcess(cmd: Seq[String]) extends Process {
semaphore
.
release
semaphore
.
release
process
.
waitFor
process
.
waitFor
if
(
isRestart
)
{
isRestart
=
false
}
else
{
if
(
currentTimeMillis
-
startTime
<
1000
)
{
if
(
currentTimeMillis
-
startTime
<
1000
)
{
Log
.
w
(
TAG
,
"process exit too fast, stop guard: "
+
cmd
)
Log
.
w
(
TAG
,
"process exit too fast, stop guard: "
+
cmd
)
isDestroyed
=
true
isDestroyed
=
true
}
}
}
}
}
}
catch
{
}
catch
{
case
ignored
:
InterruptedException
=>
case
ignored
:
InterruptedException
=>
Log
.
i
(
TAG
,
"thread interrupt, destroy process: "
+
cmd
)
Log
.
i
(
TAG
,
"thread interrupt, destroy process: "
+
cmd
)
...
@@ -108,6 +113,11 @@ class GuardedProcess(cmd: Seq[String]) extends Process {
...
@@ -108,6 +113,11 @@ class GuardedProcess(cmd: Seq[String]) extends Process {
}
}
}
}
def
restart
()
{
isRestart
=
true
process
.
destroy
()
}
def
exitValue
:
Int
=
throw
new
UnsupportedOperationException
def
exitValue
:
Int
=
throw
new
UnsupportedOperationException
def
getErrorStream
:
InputStream
=
throw
new
UnsupportedOperationException
def
getErrorStream
:
InputStream
=
throw
new
UnsupportedOperationException
def
getInputStream
:
InputStream
=
throw
new
UnsupportedOperationException
def
getInputStream
:
InputStream
=
throw
new
UnsupportedOperationException
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
View file @
66ceed86
...
@@ -65,7 +65,6 @@ class ShadowsocksNatService extends BaseService {
...
@@ -65,7 +65,6 @@ class ShadowsocksNatService extends BaseService {
private
var
notification
:
ShadowsocksNotification
=
_
private
var
notification
:
ShadowsocksNotification
=
_
val
myUid
=
android
.
os
.
Process
.
myUid
()
val
myUid
=
android
.
os
.
Process
.
myUid
()
var
kcptunProcess
:
Process
=
_
var
sslocalProcess
:
Process
=
_
var
sslocalProcess
:
Process
=
_
var
sstunnelProcess
:
Process
=
_
var
sstunnelProcess
:
Process
=
_
var
redsocksProcess
:
Process
=
_
var
redsocksProcess
:
Process
=
_
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
View file @
66ceed86
...
@@ -63,7 +63,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
...
@@ -63,7 +63,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
var
vpnThread
:
ShadowsocksVpnThread
=
_
var
vpnThread
:
ShadowsocksVpnThread
=
_
private
var
notification
:
ShadowsocksNotification
=
_
private
var
notification
:
ShadowsocksNotification
=
_
var
kcptunProcess
:
Process
=
_
var
sslocalProcess
:
Process
=
_
var
sslocalProcess
:
Process
=
_
var
sstunnelProcess
:
Process
=
_
var
sstunnelProcess
:
Process
=
_
var
pdnsdProcess
:
Process
=
_
var
pdnsdProcess
:
Process
=
_
...
...
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