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
f2292fb8
Commit
f2292fb8
authored
Nov 20, 2015
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use ProcessBuilder instead of fork/exec
parent
fe81182d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
52 deletions
+77
-52
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
.../scala/com/github/shadowsocks/ShadowsocksNatService.scala
+39
-27
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
.../scala/com/github/shadowsocks/ShadowsocksVpnService.scala
+38
-25
No files found.
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
View file @
f2292fb8
...
...
@@ -42,6 +42,7 @@ package com.github.shadowsocks
import
java.io.File
import
java.net.
{
Inet6Address
,
InetAddress
}
import
java.util.Locale
import
java.lang.
{
Process
,
ProcessBuilder
}
import
android.app._
import
android.content._
...
...
@@ -56,6 +57,7 @@ import com.github.shadowsocks.aidl.Config
import
com.github.shadowsocks.utils._
import
scala.collection._
import
scala.collection.JavaConversions._
import
scala.collection.mutable.ArrayBuffer
import
scala.concurrent.ExecutionContext.Implicits.global
import
scala.concurrent.Future
...
...
@@ -72,12 +74,12 @@ class ShadowsocksNatService extends Service with BaseService {
var
closeReceiver
:
BroadcastReceiver
=
null
var
connReceiver
:
BroadcastReceiver
=
null
var
apps
:
Array
[
ProxiedApp
]
=
null
val
myUid
=
Process
.
myUid
()
val
myUid
=
android
.
os
.
Process
.
myUid
()
var
sslocalP
id
:
Int
=
0
var
sstunnelP
id
:
Int
=
0
var
redsocksP
id
:
Int
=
0
var
pdnsdP
id
:
Int
=
0
var
sslocalP
rocess
:
Process
=
null
var
sstunnelP
rocess
:
Process
=
null
var
redsocksP
rocess
:
Process
=
null
var
pdnsdP
rocess
:
Process
=
null
private
val
dnsAddressCache
=
new
SparseArray
[
String
]
...
...
@@ -198,7 +200,10 @@ class ShadowsocksNatService extends Service with BaseService {
}
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
.
mkString
(
" "
))
sslocalPid
=
System
.
exec
(
cmd
.
mkString
(
" "
))
sslocalProcess
=
new
ProcessBuilder
()
.
command
(
cmd
)
.
redirectErrorStream
(
false
)
.
start
()
}
def
startTunnel
()
{
...
...
@@ -223,7 +228,10 @@ class ShadowsocksNatService extends Service with BaseService {
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
.
mkString
(
" "
))
sstunnelPid
=
System
.
exec
(
cmd
.
mkString
(
" "
))
sstunnelProcess
=
new
ProcessBuilder
()
.
command
(
cmd
)
.
redirectErrorStream
(
false
)
.
start
()
}
else
{
val
conf
=
ConfigUtils
...
...
@@ -245,7 +253,10 @@ class ShadowsocksNatService extends Service with BaseService {
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmdBuf
.
mkString
(
" "
))
sstunnelPid
=
System
.
exec
(
cmdBuf
.
mkString
(
" "
))
sstunnelProcess
=
new
ProcessBuilder
()
.
command
(
cmdBuf
)
.
redirectErrorStream
(
false
)
.
start
()
}
}
...
...
@@ -268,8 +279,10 @@ class ShadowsocksNatService extends Service with BaseService {
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
)
pdnsdPid
=
System
.
exec
(
cmd
)
pdnsdProcess
=
new
ProcessBuilder
()
.
command
(
cmd
.
split
(
" "
).
toSeq
)
.
redirectErrorStream
(
false
)
.
start
()
}
def
getVersionName
:
String
=
{
...
...
@@ -293,7 +306,10 @@ class ShadowsocksNatService extends Service with BaseService {
})
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
)
redsocksPid
=
System
.
exec
(
cmd
)
redsocksProcess
=
new
ProcessBuilder
()
.
command
(
cmd
.
split
(
" "
).
toSeq
)
.
redirectErrorStream
(
false
)
.
start
()
}
/** Called when the activity is first created. */
...
...
@@ -350,25 +366,21 @@ class ShadowsocksNatService extends Service with BaseService {
}
def
killProcesses
()
{
try
{
Process
.
killProcess
(
sslocalPid
)
}
catch
{
case
e
:
Throwable
=>
Log
.
e
(
TAG
,
"unable to kill ss-local"
)
if
(
sslocalProcess
!=
null
)
{
sslocalProcess
.
destroy
()
sslocalProcess
=
null
}
try
{
Process
.
killProcess
(
sstunnelPid
)
}
catch
{
case
e
:
Throwable
=>
Log
.
e
(
TAG
,
"unable to kill ss-tunnel"
)
if
(
sstunnelProcess
!=
null
)
{
sstunnelProcess
.
destroy
()
sstunnelProcess
=
null
}
try
{
Process
.
killProcess
(
redsocksPid
)
}
catch
{
case
e
:
Throwable
=>
Log
.
e
(
TAG
,
"unable to kill redsocks"
)
if
(
redsocksProcess
!=
null
)
{
redsocksProcess
.
destroy
()
redsocksProcess
=
null
}
try
{
Process
.
killProcess
(
pdnsdPid
)
}
catch
{
case
e
:
Throwable
=>
Log
.
e
(
TAG
,
"unable to kill pdnsd"
)
if
(
pdnsdProcess
!=
null
)
{
pdnsdProcess
.
destroy
()
pdnsdProcess
=
null
}
Console
.
runRootCommand
(
Utils
.
getIptables
+
" -t nat -F OUTPUT"
)
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
View file @
f2292fb8
...
...
@@ -41,6 +41,7 @@ package com.github.shadowsocks
import
java.io.File
import
java.util.Locale
import
java.lang.
{
Process
,
ProcessBuilder
}
import
android.app._
import
android.content._
...
...
@@ -55,6 +56,7 @@ import com.github.shadowsocks.aidl.Config
import
com.github.shadowsocks.utils._
import
org.apache.commons.net.util.SubnetUtils
import
scala.collection.JavaConversions._
import
scala.collection.mutable
import
scala.collection.mutable.ArrayBuffer
import
scala.concurrent.ExecutionContext.Implicits.global
...
...
@@ -70,10 +72,10 @@ class ShadowsocksVpnService extends VpnService with BaseService {
var
vpnThread
:
ShadowsocksVpnThread
=
null
var
closeReceiver
:
BroadcastReceiver
=
null
var
sslocalP
id
:
Int
=
0
var
sstunnelP
id
:
Int
=
0
var
tun2socksPid
:
Int
=
0
var
pdnsdPid
:
Int
=
0
var
sslocalP
rocess
:
Process
=
null
var
sstunnelP
rocess
:
Process
=
null
var
pdnsdProcess
:
Process
=
null
var
tun2socksProcess
:
Process
=
null
def
isByass
(
net
:
SubnetUtils
)
:
Boolean
=
{
val
info
=
net
.
getInfo
...
...
@@ -194,25 +196,21 @@ class ShadowsocksVpnService extends VpnService with BaseService {
}
def
killProcesses
()
{
try
{
Process
.
killProcess
(
sslocalPid
)
}
catch
{
case
e
:
Throwable
=>
Log
.
e
(
TAG
,
"unable to kill ss-local"
)
if
(
sslocalProcess
!=
null
)
{
sslocalProcess
.
destroy
()
sslocalProcess
=
null
}
try
{
Process
.
killProcess
(
sstunnelPid
)
}
catch
{
case
e
:
Throwable
=>
Log
.
e
(
TAG
,
"unable to kill ss-tunnel"
)
if
(
sstunnelProcess
!=
null
)
{
sstunnelProcess
.
destroy
()
sstunnelProcess
=
null
}
try
{
Process
.
killProcess
(
tun2socksPid
)
}
catch
{
case
e
:
Throwable
=>
Log
.
e
(
TAG
,
"unable to kill tun2socks"
)
if
(
tun2socksProcess
!=
null
)
{
tun2socksProcess
.
destroy
()
tun2socksProcess
=
null
}
try
{
Process
.
killProcess
(
pdnsdPid
)
}
catch
{
case
e
:
Throwable
=>
Log
.
e
(
TAG
,
"unable to kill pdnsd"
)
if
(
pdnsdProcess
!=
null
)
{
pdnsdProcess
.
destroy
()
pdnsdProcess
=
null
}
}
...
...
@@ -344,7 +342,11 @@ class ShadowsocksVpnService extends VpnService with BaseService {
}
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
.
mkString
(
" "
))
sslocalPid
=
System
.
exec
(
cmd
.
mkString
(
" "
))
sslocalProcess
=
new
ProcessBuilder
()
.
command
(
cmd
)
.
redirectErrorStream
(
false
)
.
start
()
}
def
startDnsTunnel
()
=
{
...
...
@@ -367,7 +369,11 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if
(
config
.
isAuth
)
cmd
+=
"-A"
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
.
mkString
(
" "
))
sstunnelPid
=
System
.
exec
(
cmd
.
mkString
(
" "
))
sstunnelProcess
=
new
ProcessBuilder
()
.
command
(
cmd
)
.
redirectErrorStream
(
false
)
.
start
()
}
def
startDnsDaemon
()
{
...
...
@@ -389,7 +395,11 @@ class ShadowsocksVpnService extends VpnService with BaseService {
val
cmd
=
Path
.
BASE
+
"pdnsd -c "
+
Path
.
BASE
+
"pdnsd-vpn.conf"
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
)
pdnsdPid
=
System
.
exec
(
cmd
)
pdnsdProcess
=
new
ProcessBuilder
()
.
command
(
cmd
.
split
(
" "
).
toSeq
)
.
redirectErrorStream
(
false
)
.
start
()
}
override
def
getContext
=
getBaseContext
...
...
@@ -465,7 +475,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
+
"--socks-server-addr 127.0.0.1:%d "
+
"--tunfd %d "
+
"--tunmtu %d "
+
"--loglevel 3
"
)
+
"--loglevel 3"
)
.
formatLocal
(
Locale
.
ENGLISH
,
PRIVATE_VLAN
.
formatLocal
(
Locale
.
ENGLISH
,
"2"
),
config
.
localPort
,
fd
,
VPN_MTU
,
Path
.
BASE
)
...
...
@@ -480,7 +490,10 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
)
tun2socksPid
=
System
.
exec
(
cmd
)
tun2socksProcess
=
new
ProcessBuilder
()
.
command
(
cmd
.
split
(
" "
).
toSeq
)
.
redirectErrorStream
(
false
)
.
start
()
fd
}
...
...
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