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
abf050a4
Commit
abf050a4
authored
Jan 26, 2014
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refine the service shutdown
parent
b4937785
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
33 deletions
+23
-33
src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
+10
-20
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+1
-1
src/main/scala/com/github/shadowsocks/ShadowsocksService.scala
...ain/scala/com/github/shadowsocks/ShadowsocksService.scala
+8
-12
src/main/scala/com/github/shadowsocks/utils/Constants.scala
src/main/scala/com/github/shadowsocks/utils/Constants.scala
+4
-0
No files found.
src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
View file @
abf050a4
...
...
@@ -51,13 +51,11 @@ import java.io._
import
android.net.VpnService
import
org.apache.http.conn.util.InetAddressUtils
import
android.os.Message
import
scala.Some
import
scala.concurrent.ops._
import
org.apache.commons.net.util.SubnetUtils
import
java.net.InetAddress
import
com.github.shadowsocks.utils._
import
scala.Some
import
com.github.shadowsocks.ProxiedApp
object
ShadowVpnService
{
def
isServiceStarted
(
context
:
Context
)
:
Boolean
=
{
...
...
@@ -68,7 +66,6 @@ object ShadowVpnService {
class
ShadowVpnService
extends
VpnService
{
val
TAG
=
"ShadowVpnService"
val
BASE
=
"/data/data/com.github.shadowsocks/"
val
MSG_CONNECT_FINISH
=
1
val
MSG_CONNECT_SUCCESS
=
2
...
...
@@ -114,7 +111,6 @@ class ShadowVpnService extends VpnService {
case
MSG_VPN_ERROR
=>
if
(
msg
.
obj
!=
null
)
changeState
(
State
.
STOPPED
,
msg
.
obj
.
asInstanceOf
[
String
])
case
MSG_STOP_SELF
=>
destroy
()
stopSelf
()
case
_
=>
}
...
...
@@ -124,7 +120,7 @@ class ShadowVpnService extends VpnService {
def
getPid
(
name
:
String
)
:
Int
=
{
try
{
val
reader
:
BufferedReader
=
new
BufferedReader
(
new
FileReader
(
BASE
+
name
+
".pid"
))
val
reader
:
BufferedReader
=
new
BufferedReader
(
new
FileReader
(
Path
.
BASE
+
name
+
".pid"
))
val
line
=
reader
.
readLine
return
Integer
.
valueOf
(
line
)
}
catch
{
...
...
@@ -142,18 +138,18 @@ class ShadowVpnService extends VpnService {
}
def
startShadowsocksDaemon
()
{
val
cmd
:
String
=
(
BASE
+
val
cmd
:
String
=
(
Path
.
BASE
+
"shadowsocks -b 127.0.0.1 -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\" -f "
+
BASE
+
"shadowsocks.pid"
)
Path
.
BASE
+
"shadowsocks.pid"
)
.
format
(
config
.
proxy
,
config
.
remotePort
,
config
.
localPort
,
config
.
sitekey
,
config
.
encMethod
)
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
)
System
.
exec
(
cmd
)
}
def
startDnsDaemon
()
{
val
cmd
:
String
=
BASE
+
"pdnsd -c "
+
BASE
+
"pdnsd.conf"
val
cmd
:
String
=
Path
.
BASE
+
"pdnsd -c "
+
Path
.
BASE
+
"pdnsd.conf"
val
conf
:
String
=
Config
.
PDNSD
.
format
(
"0.0.0.0"
)
Config
.
printToFile
(
new
File
(
BASE
+
"pdnsd.conf"
))(
p
=>
{
Config
.
printToFile
(
new
File
(
Path
.
BASE
+
"pdnsd.conf"
))(
p
=>
{
p
.
println
(
conf
)
})
Utils
.
runCommand
(
cmd
)
...
...
@@ -329,7 +325,7 @@ class ShadowVpnService extends VpnService {
val
fd
=
conn
.
getFd
val
cmd
=
(
BASE
+
val
cmd
=
(
Path
.
BASE
+
"tun2socks --netif-ipaddr %s "
+
"--dnsgw %s:8153 "
+
"--netif-netmask 255.255.255.0 "
...
...
@@ -339,7 +335,7 @@ class ShadowVpnService extends VpnService {
+
"--loglevel 3 "
+
"--pid %stun2socks.pid"
)
.
format
(
PRIVATE_VLAN
.
format
(
"2"
),
PRIVATE_VLAN
.
format
(
"1"
),
config
.
localPort
,
fd
,
VPN_MTU
,
BASE
)
Path
.
BASE
)
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
)
System
.
exec
(
cmd
)
}
...
...
@@ -402,14 +398,13 @@ class ShadowVpnService extends VpnService {
filter
.
addAction
(
Action
.
CLOSE
)
receiver
=
new
BroadcastReceiver
{
def
onReceive
(
p1
:
Context
,
p2
:
Intent
)
{
destroy
()
stopSelf
()
}
}
registerReceiver
(
receiver
,
filter
)
}
def
d
estroy
()
{
override
def
onD
estroy
()
{
killProcesses
()
changeState
(
State
.
STOPPED
)
...
...
@@ -425,16 +420,14 @@ class ShadowVpnService extends VpnService {
unregisterReceiver
(
receiver
)
receiver
=
null
}
if
(
conn
!=
null
)
{
conn
.
close
()
conn
=
null
}
notificationManager
.
cancel
(
1
)
}
/** Called when the activity is closed. */
override
def
onDestroy
()
{
destroy
()
super
.
onDestroy
()
}
...
...
@@ -464,7 +457,4 @@ class ShadowVpnService extends VpnService {
Service
.
START_STICKY
}
override
def
onRevoke
()
{
stopSelf
()
}
}
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
abf050a4
...
...
@@ -355,7 +355,7 @@ class Shadowsocks
}
else
{
in
=
assetManager
.
open
(
file
)
}
out
=
new
FileOutputStream
(
"/data/data/com.github.shadowsocks/"
+
file
)
out
=
new
FileOutputStream
(
Path
.
BASE
+
file
)
copyFile
(
in
,
out
)
in
.
close
()
in
=
null
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksService.scala
View file @
abf050a4
...
...
@@ -57,13 +57,10 @@ import org.apache.http.conn.util.InetAddressUtils
import
scala.collection._
import
java.util.
{
TimerTask
,
Timer
}
import
android.net.TrafficStats
import
android.graphics._
import
scala.concurrent.ops._
import
scala.Some
import
com.github.shadowsocks.utils._
import
scala.Some
import
com.github.shadowsocks.ProxiedApp
import
com.github.shadowsocks.TrafficStat
import
android.graphics.Color
case
class
TrafficStat
(
tx
:
Long
,
rx
:
Long
,
timestamp
:
Long
)
...
...
@@ -76,7 +73,6 @@ object ShadowsocksService {
class
ShadowsocksService
extends
Service
{
val
TAG
=
"ShadowsocksService"
val
BASE
=
"/data/data/com.github.shadowsocks/"
val
CMD_IPTABLES_RETURN
=
" -t nat -A OUTPUT -p tcp -d 0.0.0.0 -j RETURN\n"
val
CMD_IPTABLES_REDIRECT_ADD_SOCKS
=
" -t nat -A OUTPUT -p tcp "
+
"-j REDIRECT --to 8123\n"
...
...
@@ -141,7 +137,7 @@ class ShadowsocksService extends Service {
def
getPid
(
name
:
String
)
:
Int
=
{
try
{
val
reader
:
BufferedReader
=
new
BufferedReader
(
new
FileReader
(
BASE
+
name
+
".pid"
))
val
reader
:
BufferedReader
=
new
BufferedReader
(
new
FileReader
(
Path
.
BASE
+
name
+
".pid"
))
val
line
=
reader
.
readLine
return
Integer
.
valueOf
(
line
)
}
catch
{
...
...
@@ -159,18 +155,18 @@ class ShadowsocksService extends Service {
}
def
startShadowsocksDaemon
()
{
val
cmd
:
String
=
(
BASE
+
val
cmd
:
String
=
(
Path
.
BASE
+
"shadowsocks -b 127.0.0.1 -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\" -f "
+
BASE
+
"shadowsocks.pid"
)
Path
.
BASE
+
"shadowsocks.pid"
)
.
format
(
config
.
proxy
,
config
.
remotePort
,
config
.
localPort
,
config
.
sitekey
,
config
.
encMethod
)
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
)
Utils
.
runCommand
(
cmd
)
}
def
startDnsDaemon
()
{
val
cmd
:
String
=
BASE
+
"pdnsd -c "
+
BASE
+
"pdnsd.conf"
val
cmd
:
String
=
Path
.
BASE
+
"pdnsd -c "
+
Path
.
BASE
+
"pdnsd.conf"
val
conf
:
String
=
Config
.
PDNSD
.
format
(
"127.0.0.1"
)
Config
.
printToFile
(
new
File
(
BASE
+
"pdnsd.conf"
))(
p
=>
{
Config
.
printToFile
(
new
File
(
Path
.
BASE
+
"pdnsd.conf"
))(
p
=>
{
p
.
println
(
conf
)
})
Utils
.
runCommand
(
cmd
)
...
...
@@ -275,8 +271,8 @@ class ShadowsocksService extends Service {
def
startRedsocksDaemon
()
{
val
conf
=
Config
.
REDSOCKS
.
format
(
config
.
localPort
)
val
cmd
=
"%sredsocks -p %sredsocks.pid -c %sredsocks.conf"
.
format
(
BASE
,
BASE
,
BASE
)
Config
.
printToFile
(
new
File
(
BASE
+
"redsocks.conf"
))(
p
=>
{
val
cmd
=
"%sredsocks -p %sredsocks.pid -c %sredsocks.conf"
.
format
(
Path
.
BASE
,
Path
.
BASE
,
Path
.
BASE
)
Config
.
printToFile
(
new
File
(
Path
.
BASE
+
"redsocks.conf"
))(
p
=>
{
p
.
println
(
conf
)
})
Utils
.
runRootCommand
(
cmd
)
...
...
src/main/scala/com/github/shadowsocks/utils/Constants.scala
View file @
abf050a4
...
...
@@ -2,6 +2,10 @@ package com.github.shadowsocks.utils
import
android.content.
{
Intent
,
SharedPreferences
}
object
Path
{
val
BASE
=
"/data/data/com.github.shadowsocks/"
}
object
Key
{
val
profileId
=
"profileId"
val
profileName
=
"profileName"
...
...
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