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
a3acfbeb
Commit
a3acfbeb
authored
May 06, 2013
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolve the IP using dnsjava
parent
7c4a6c40
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
26 deletions
+38
-26
build.sbt
build.sbt
+2
-1
src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
+36
-25
No files found.
build.sbt
View file @
a3acfbeb
...
...
@@ -11,6 +11,7 @@ libraryDependencies ++= Seq(
"com.actionbarsherlock"
%
"actionbarsherlock"
%
"4.2.0"
artifacts
(
Artifact
(
"actionbarsherlock"
,
"apklib"
,
"apklib"
)),
"net.saik0.android.unifiedpreference"
%
"unifiedpreference"
%
"0.0.2"
artifacts
(
Artifact
(
"unifiedpreference"
,
"apklib"
,
"apklib"
)),
"org.jraf"
%
"android-switch-backport"
%
"1.0"
artifacts
(
Artifact
(
"android-switch-backport"
,
"apklib"
,
"apklib"
)),
"de.keyboardsurfer.android.widget"
%
"crouton"
%
"1.7"
"de.keyboardsurfer.android.widget"
%
"crouton"
%
"1.7"
,
"dnsjava"
%
"dnsjava"
%
"2.1.1"
)
src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
View file @
a3acfbeb
...
...
@@ -52,11 +52,11 @@ import android.util.Log
import
com.google.analytics.tracking.android.EasyTracker
import
java.io._
import
java.lang.ref.WeakReference
import
java.net.Inet6Address
import
java.net.InetAddress
import
java.net.UnknownHostException
import
android.net.VpnService
import
org.apache.http.conn.util.InetAddressUtils
import
org.xbill.DNS._
import
android.os.Message
import
scala.Some
object
ShadowVpnService
{
def
isServiceStarted
:
Boolean
=
{
...
...
@@ -118,6 +118,23 @@ class ShadowVpnService extends VpnService {
}.
start
()
}
def
resolve
(
host
:
String
,
addrType
:
Int
)
:
Option
[
String
]
=
{
val
lookup
=
new
Lookup
(
host
,
addrType
)
val
resolver
=
new
SimpleResolver
(
"8.8.8.8"
)
resolver
.
setTimeout
(
5
)
lookup
.
setResolver
(
resolver
)
val
records
=
lookup
.
run
()
for
(
r
<-
records
)
{
addrType
match
{
case
org
.
xbill
.
DNS
.
Type
.
A
=>
return
Some
(
r
.
asInstanceOf
[
ARecord
].
getAddress
.
getHostAddress
)
case
org
.
xbill
.
DNS
.
Type
.
AAAA
=>
return
Some
(
r
.
asInstanceOf
[
AAAARecord
].
getAddress
.
getHostAddress
)
}
}
None
}
def
getVersionName
:
String
=
{
var
version
:
String
=
null
try
{
...
...
@@ -168,35 +185,30 @@ class ShadowVpnService extends VpnService {
def
run
()
{
handler
.
sendEmptyMessage
(
MSG_CONNECT_START
)
var
resolved
:
Boolean
=
false
if
(
appHost
!=
null
)
{
var
addr
:
InetAddress
=
null
val
isIPv6Support
:
Boolean
=
Utils
.
isIPv6Support
try
{
val
addrs
=
InetAddress
.
getAllByName
(
appHost
)
for
(
a
<-
addrs
)
{
if
(
isIPv6Support
&&
addr
==
null
&&
a
.
isInstanceOf
[
Inet6Address
])
{
addr
=
a
if
(!
InetAddressUtils
.
isIPv4Address
(
appHost
)
&&
!
InetAddressUtils
.
isIPv6Address
(
appHost
))
{
if
(
Utils
.
isIPv6Support
)
{
resolve
(
appHost
,
Type
.
AAAA
)
match
{
case
Some
(
host
)
=>
{
appHost
=
host
resolved
=
true
}
}
if
(
addr
==
null
)
addr
=
addrs
(
0
)
}
catch
{
case
ignored
:
UnknownHostException
=>
{
addr
=
null
}
}
if
(
addr
!=
null
)
{
appHost
=
addr
.
getHostAddress
resolved
=
true
if
(!
resolved
)
{
resolve
(
appHost
,
Type
.
A
)
match
{
case
Some
(
host
)
=>
{
appHost
=
host
resolved
=
true
}
}
}
}
else
{
resolved
=
true
}
Log
.
d
(
TAG
,
"IPTABLES: "
+
Utils
.
getIptables
)
hasRedirectSupport
=
Utils
.
getHasRedirectSupport
if
(
resolved
&&
handleConnection
)
{
notifyAlert
(
getString
(
R
.
string
.
forward_success
),
getString
(
R
.
string
.
service_running
))
handler
.
sendEmptyMessageDelayed
(
MSG_CONNECT_SUCCESS
,
500
)
}
else
{
}
else
{
notifyAlert
(
getString
(
R
.
string
.
forward_fail
),
getString
(
R
.
string
.
service_failed
))
stopSelf
()
handler
.
sendEmptyMessageDelayed
(
MSG_CONNECT_FAIL
,
500
)
...
...
@@ -391,7 +403,6 @@ class ShadowVpnService extends VpnService {
var
localPort
:
Int
=
0
var
sitekey
:
String
=
null
var
settings
:
SharedPreferences
=
null
var
hasRedirectSupport
:
Boolean
=
true
var
isGlobalProxy
:
Boolean
=
false
var
isGFWList
:
Boolean
=
false
var
isBypassApps
:
Boolean
=
false
...
...
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