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
9965a71c
Commit
9965a71c
authored
Mar 07, 2016
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine #594
parent
9e09e032
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
42 deletions
+38
-42
project/plugins.sbt
project/plugins.sbt
+1
-1
src/main/scala/com/github/shadowsocks/GuardedProcess.scala
src/main/scala/com/github/shadowsocks/GuardedProcess.scala
+28
-32
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
.../scala/com/github/shadowsocks/ShadowsocksNatService.scala
+5
-5
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
.../scala/com/github/shadowsocks/ShadowsocksVpnService.scala
+4
-4
No files found.
project/plugins.sbt
View file @
9965a71c
resolvers
+=
Resolver
.
url
(
"scalasbt releases"
,
new
URL
(
"http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-snapshots"
))(
Resolver
.
ivyStylePatterns
)
addSbtPlugin
(
"com.hanhuy.sbt"
%
"android-sdk-plugin"
%
"1.5.1
8
"
)
addSbtPlugin
(
"com.hanhuy.sbt"
%
"android-sdk-plugin"
%
"1.5.1
9
"
)
resolvers
+=
"Sonatype snapshots"
at
"https://oss.sonatype.org/content/repositories/snapshots/"
...
...
src/main/
jav
a/com/github/shadowsocks/GuardedProcess.scala
→
src/main/
scal
a/com/github/shadowsocks/GuardedProcess.scala
View file @
9965a71c
/*
* Shadowsocks - A shadowsocks client for Android
* Copyright (C) 201
5
<max.c.lv@gmail.com>
* Copyright (C) 201
6
<max.c.lv@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
...
...
@@ -48,53 +48,45 @@ import java.util.concurrent.atomic.AtomicReference
import
collection.JavaConversions._
object
GuardedProcess
{
private
val
TAG
:
String
=
classOf
[
GuardedProcess
].
getSimpleName
/**
* @author ayanamist@gmail.com
*/
class
GuardedProcess
(
cmd
:
Seq
[
String
],
onRestartCallback
:
Runnable
=
null
)
extends
Process
{
@throws
(
classOf
[
IOException
])
private
def
startProcess
(
cmd
:
Seq
[
String
])
:
Process
=
{
new
ProcessBuilder
(
cmd
).
redirectErrorStream
(
true
).
start
}
}
private
val
TAG
=
classOf
[
GuardedProcess
].
getSimpleName
class
GuardedProcess
extends
Process
{
private
var
guardThread
:
Thread
=
null
@volatile
private
var
isDestroyed
:
Boolean
=
false
@volatile
private
var
process
:
Process
=
null
@volatile
private
var
guardThread
:
Thread
=
null
@volatile
private
var
isDestroyed
:
Boolean
=
false
@volatile
private
var
process
:
Process
=
null
@throws
(
classOf
[
InterruptedException
])
@throws
(
classOf
[
IOException
])
def
this
(
cmd
:
Seq
[
String
],
onRestartCallback
:
Runnable
=
null
)
{
this
()
initThread
(
cmd
,
onRestartCallback
)
}
def
start
()
:
GuardedProcess
=
{
val
atomicIoException
=
new
AtomicReference
[
IOException
](
null
)
val
countDownLatch
=
new
CountDownLatch
(
1
)
def
initThread
(
cmd
:
Seq
[
String
],
onRestartCallback
:
Runnable
)
:
Unit
=
{
val
atomicIoException
:
AtomicReference
[
IOException
]
=
new
AtomicReference
[
IOException
](
null
)
val
countDownLatch
:
CountDownLatch
=
new
CountDownLatch
(
1
)
guardThread
=
new
Thread
(
new
Runnable
()
{
override
def
run
()
:
Unit
=
{
override
def
run
()
{
try
{
while
(!
isDestroyed
)
{
Log
.
i
(
GuardedProcess
.
TAG
,
"start process: "
+
cmd
)
val
startTime
:
Long
=
java
.
lang
.
System
.
currentTimeMillis
process
=
GuardedProcess
.
startProcess
(
cmd
)
Log
.
i
(
TAG
,
"start process: "
+
cmd
)
val
startTime
=
java
.
lang
.
System
.
currentTimeMillis
process
=
new
ProcessBuilder
(
cmd
).
redirectErrorStream
(
true
).
start
if
(
onRestartCallback
!=
null
&&
countDownLatch
.
getCount
<=
0
)
{
onRestartCallback
.
run
()
}
countDownLatch
.
countDown
()
process
.
waitFor
if
(
java
.
lang
.
System
.
currentTimeMillis
-
startTime
<
1000
)
{
Log
.
w
(
GuardedProcess
.
TAG
,
"process exit too fast, stop guard: "
+
cmd
)
Log
.
w
(
TAG
,
"process exit too fast, stop guard: "
+
cmd
)
return
}
}
}
catch
{
}
catch
{
case
ignored
:
InterruptedException
=>
Log
.
i
(
GuardedProcess
.
TAG
,
"thread interrupt, destroy process: "
+
cmd
)
Log
.
i
(
TAG
,
"thread interrupt, destroy process: "
+
cmd
)
process
.
destroy
()
case
e
:
IOException
=>
atomicIoException
.
compareAndSet
(
null
,
e
)
...
...
@@ -103,12 +95,16 @@ class GuardedProcess extends Process {
}
}
},
"GuardThread-"
+
cmd
)
guardThread
.
start
()
countDownLatch
.
await
()
val
ioException
:
IOException
=
atomicIoException
.
get
if
(
ioException
!=
null
)
{
throw
ioException
}
this
}
def
destroy
()
{
...
...
@@ -144,4 +140,4 @@ class GuardedProcess extends Process {
guardThread
.
join
()
0
}
}
\ No newline at end of file
}
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
View file @
9965a71c
...
...
@@ -196,7 +196,7 @@ class ShadowsocksNatService extends BaseService {
}
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
.
mkString
(
" "
))
sslocalProcess
=
new
GuardedProcess
(
cmd
)
sslocalProcess
=
new
GuardedProcess
(
cmd
)
.
start
()
}
def
startTunnel
()
{
...
...
@@ -222,7 +222,7 @@ class ShadowsocksNatService extends BaseService {
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
.
mkString
(
" "
))
sstunnelProcess
=
new
GuardedProcess
(
cmd
)
sstunnelProcess
=
new
GuardedProcess
(
cmd
)
.
start
()
}
else
{
val
conf
=
ConfigUtils
...
...
@@ -245,7 +245,7 @@ class ShadowsocksNatService extends BaseService {
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmdBuf
.
mkString
(
" "
))
sstunnelProcess
=
new
GuardedProcess
(
cmdBuf
)
sstunnelProcess
=
new
GuardedProcess
(
cmdBuf
)
.
start
()
}
}
...
...
@@ -268,7 +268,7 @@ class ShadowsocksNatService extends BaseService {
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
)
pdnsdProcess
=
new
GuardedProcess
(
cmd
.
split
(
" "
).
toSeq
)
pdnsdProcess
=
new
GuardedProcess
(
cmd
.
split
(
" "
).
toSeq
)
.
start
()
}
def
getVersionName
:
String
=
{
...
...
@@ -292,7 +292,7 @@ class ShadowsocksNatService extends BaseService {
})
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
)
redsocksProcess
=
new
GuardedProcess
(
cmd
.
split
(
" "
).
toSeq
)
redsocksProcess
=
new
GuardedProcess
(
cmd
.
split
(
" "
).
toSeq
)
.
start
()
}
/** Called when the activity is first created. */
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
View file @
9965a71c
...
...
@@ -296,7 +296,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
.
mkString
(
" "
))
sslocalProcess
=
new
GuardedProcess
(
cmd
)
sslocalProcess
=
new
GuardedProcess
(
cmd
)
.
start
()
}
def
startDnsTunnel
()
=
{
...
...
@@ -321,7 +321,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
.
mkString
(
" "
))
sstunnelProcess
=
new
GuardedProcess
(
cmd
)
sstunnelProcess
=
new
GuardedProcess
(
cmd
)
.
start
()
}
def
startDnsDaemon
()
{
...
...
@@ -344,7 +344,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
)
pdnsdProcess
=
new
GuardedProcess
(
cmd
.
split
(
" "
).
toSeq
)
pdnsdProcess
=
new
GuardedProcess
(
cmd
.
split
(
" "
).
toSeq
)
.
start
()
}
override
def
getContext
=
getBaseContext
...
...
@@ -438,7 +438,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
override
def
run
()
:
Unit
=
{
sendFd
(
fd
)
}
})
})
.
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