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
b682cb3a
Commit
b682cb3a
authored
Feb 25, 2022
by
chenhuaqing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed restart
parent
0b81449f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
62 deletions
+76
-62
core/src/main/java/com/github/shadowsocks/bg/GuardedProcessPool.kt
...main/java/com/github/shadowsocks/bg/GuardedProcessPool.kt
+20
-10
core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
.../src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
+55
-51
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
+1
-1
No files found.
core/src/main/java/com/github/shadowsocks/bg/GuardedProcessPool.kt
View file @
b682cb3a
...
@@ -39,18 +39,23 @@ import kotlin.concurrent.thread
...
@@ -39,18 +39,23 @@ import kotlin.concurrent.thread
class
GuardedProcessPool
(
private
val
onFatal
:
suspend
(
IOException
)
->
Unit
)
:
CoroutineScope
{
class
GuardedProcessPool
(
private
val
onFatal
:
suspend
(
IOException
)
->
Unit
)
:
CoroutineScope
{
companion
object
{
companion
object
{
private
val
pid
by
lazy
{
private
val
pid
by
lazy
{
Class
.
forName
(
"java.lang.ProcessManager\$ProcessImpl"
).
getDeclaredField
(
"pid"
).
apply
{
isAccessible
=
true
}
Class
.
forName
(
"java.lang.ProcessManager\$ProcessImpl"
).
getDeclaredField
(
"pid"
)
.
apply
{
isAccessible
=
true
}
}
}
}
}
private
inner
class
Guard
(
private
val
cmd
:
List
<
String
>)
{
private
inner
class
Guard
(
private
val
cmd
Supplier
:
suspend
()
->
List
<
String
>)
{
private
lateinit
var
process
:
Process
private
lateinit
var
process
:
Process
private
lateinit
var
cmd
:
List
<
String
>
private
fun
streamLogger
(
input
:
InputStream
,
logger
:
(
String
)
->
Unit
)
=
try
{
private
fun
streamLogger
(
input
:
InputStream
,
logger
:
(
String
)
->
Unit
)
=
try
{
input
.
bufferedReader
().
forEachLine
(
logger
)
input
.
bufferedReader
().
forEachLine
(
logger
)
}
catch
(
_
:
IOException
)
{
}
// ignore
}
catch
(
_
:
IOException
)
{
}
// ignore
fun
start
()
{
suspend
fun
start
()
{
cmd
=
cmdSupplier
.
invoke
()
Timber
.
i
(
"start process: ${Commandline.toString(cmd)}"
)
process
=
ProcessBuilder
(
cmd
).
directory
(
Core
.
deviceStorage
.
noBackupFilesDir
).
start
()
process
=
ProcessBuilder
(
cmd
).
directory
(
Core
.
deviceStorage
.
noBackupFilesDir
).
start
()
}
}
...
@@ -74,7 +79,8 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C
...
@@ -74,7 +79,8 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C
when
{
when
{
exitCode
==
OsConstants
.
ECONNREFUSED
->
throw
IOException
(
"connection refused by server"
)
exitCode
==
OsConstants
.
ECONNREFUSED
->
throw
IOException
(
"connection refused by server"
)
SystemClock
.
elapsedRealtime
()
-
startTime
<
1000
->
throw
IOException
(
SystemClock
.
elapsedRealtime
()
-
startTime
<
1000
->
throw
IOException
(
"$cmdName exits too fast (exit code: $exitCode)"
)
"$cmdName exits too fast (exit code: $exitCode)"
)
exitCode
==
128
+
OsConstants
.
SIGKILL
->
Timber
.
w
(
"$cmdName was killed"
)
exitCode
==
128
+
OsConstants
.
SIGKILL
->
Timber
.
w
(
"$cmdName was killed"
)
else
->
Timber
.
w
(
IOException
(
"$cmdName unexpectedly exits with code $exitCode"
))
else
->
Timber
.
w
(
IOException
(
"$cmdName unexpectedly exits with code $exitCode"
))
}
}
...
@@ -112,11 +118,15 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C
...
@@ -112,11 +118,15 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C
override
val
coroutineContext
=
Dispatchers
.
Main
.
immediate
+
Job
()
override
val
coroutineContext
=
Dispatchers
.
Main
.
immediate
+
Job
()
@MainThread
@MainThread
fun
start
(
cmd
:
List
<
String
>,
onRestartCallback
:
(
suspend
()
->
Unit
)?
=
null
)
{
fun
start
(
Timber
.
i
(
"start process: ${Commandline.toString(cmd)}"
)
cmdSupplier
:
suspend
()
->
List
<
String
>,
Guard
(
cmd
).
apply
{
onRestartCallback
:
(
suspend
()
->
Unit
)?
=
null
)
{
Guard
(
cmdSupplier
).
apply
{
launch
{
start
()
// if start fails, IOException will be thrown directly
start
()
// if start fails, IOException will be thrown directly
launch
{
looper
(
onRestartCallback
)
}
looper
(
onRestartCallback
)
}
}
}
}
}
...
...
core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
View file @
b682cb3a
...
@@ -59,10 +59,11 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
...
@@ -59,10 +59,11 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
* Sensitive shadowsocks configuration file requires extra protection. It may be stored in encrypted storage or
* Sensitive shadowsocks configuration file requires extra protection. It may be stored in encrypted storage or
* device storage, depending on which is currently available.
* device storage, depending on which is currently available.
*/
*/
fun
start
(
service
:
BaseService
.
Interface
,
stat
:
File
,
configFile
:
File
,
mode
:
String
,
dnsRelay
:
Boolean
=
true
)
{
suspend
fun
start
(
service
:
BaseService
.
Interface
,
stat
:
File
,
configFile
:
File
,
mode
:
String
,
dnsRelay
:
Boolean
=
true
)
{
// setup traffic monitor path
// setup traffic monitor path
trafficMonitor
=
TrafficMonitor
(
stat
)
trafficMonitor
=
TrafficMonitor
(
stat
)
val
cmdSupplier
:
suspend
()
->
List
<
String
>
=
{
AuthManager
.
initAuthProfile
(
profile
)
// init JSON config
// init JSON config
this
.
configFile
=
configFile
this
.
configFile
=
configFile
val
config
=
profile
.
toJson
()
val
config
=
profile
.
toJson
()
...
@@ -116,6 +117,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
...
@@ -116,6 +117,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
if
(
route
!=
Acl
.
ALL
)
{
if
(
route
!=
Acl
.
ALL
)
{
cmd
+=
"--acl"
cmd
+=
"--acl"
cmd
+=
Acl
.
getFile
(
route
).
absolutePath
cmd
+=
Acl
.
getFile
(
route
).
absolutePath
Timber
.
d
(
"start vpn service with acl ${Acl.getFile(route).readText()}"
)
}
}
if
(
BuildConfig
.
DEBUG
)
{
if
(
BuildConfig
.
DEBUG
)
{
...
@@ -124,8 +126,10 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
...
@@ -124,8 +126,10 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
cmd
+=
"-v"
cmd
+=
"-v"
cmd
+=
"-v"
cmd
+=
"-v"
}
}
cmd
}
service
.
data
.
processes
!!
.
start
(
cmd
)
service
.
data
.
processes
!!
.
start
(
cmd
Supplier
)
}
}
fun
scheduleUpdate
()
{
fun
scheduleUpdate
()
{
...
...
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
View file @
b682cb3a
...
@@ -224,7 +224,7 @@ class VpnService : BaseVpnService(), BaseService.Interface {
...
@@ -224,7 +224,7 @@ class VpnService : BaseVpnService(), BaseService.Interface {
cmd
+=
PRIVATE_VLAN6_ROUTER
cmd
+=
PRIVATE_VLAN6_ROUTER
}
}
cmd
+=
"--enable-udprelay"
cmd
+=
"--enable-udprelay"
data
.
processes
!!
.
start
(
cmd
,
onRestartCallback
=
{
data
.
processes
!!
.
start
(
cmd
Supplier
=
{
cmd
}
,
onRestartCallback
=
{
try
{
try
{
sendFd
(
conn
.
fileDescriptor
)
sendFd
(
conn
.
fileDescriptor
)
}
catch
(
e
:
ErrnoException
)
{
}
catch
(
e
:
ErrnoException
)
{
...
...
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