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
062f4970
Commit
062f4970
authored
May 08, 2013
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update udpgw
parent
f38981e5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
2 deletions
+44
-2
src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
+15
-2
src/main/scala/com/github/shadowsocks/Utils.scala
src/main/scala/com/github/shadowsocks/Utils.scala
+29
-0
No files found.
src/main/scala/com/github/shadowsocks/ShadowVpnService.scala
View file @
062f4970
...
...
@@ -86,7 +86,9 @@ class ShadowVpnService extends VpnService {
val
MSG_HOST_CHANGE
:
Int
=
4
val
MSG_STOP_SELF
:
Int
=
5
val
VPN_MTU
=
1500
var
conn
:
ParcelFileDescriptor
=
null
var
udpgw
:
String
=
null
def
getPid
(
name
:
String
)
:
Int
=
{
try
{
...
...
@@ -184,6 +186,8 @@ class ShadowVpnService extends VpnService {
new
Thread
(
new
Runnable
{
def
run
()
{
handler
.
sendEmptyMessage
(
MSG_CONNECT_START
)
// Resolve server address
var
resolved
:
Boolean
=
false
if
(!
InetAddressUtils
.
isIPv4Address
(
appHost
)
&&
!
InetAddressUtils
.
isIPv6Address
(
appHost
))
{
if
(
Utils
.
isIPv6Support
)
{
...
...
@@ -207,6 +211,15 @@ class ShadowVpnService extends VpnService {
}
else
{
resolved
=
true
}
// Resolve UDP gateway
if
(
resolved
)
{
resolve
(
"u.maxcdn.info"
,
Type
.
A
)
match
{
case
Some
(
host
)
=>
udpgw
=
host
case
None
=>
resolved
=
false
}
}
if
(
resolved
&&
handleConnection
)
{
notifyAlert
(
getString
(
R
.
string
.
forward_success
),
getString
(
R
.
string
.
service_running
))
handler
.
sendEmptyMessageDelayed
(
MSG_CONNECT_SUCCESS
,
500
)
...
...
@@ -294,9 +307,9 @@ class ShadowVpnService extends VpnService {
val
fd
=
conn
.
getFd
val
cmd
=
(
BASE
+
"tun2socks --netif-ipaddr 172.16.0.2 --udpgw-remote-server-addr
158.255.208.201
:7300 "
+
val
cmd
=
(
BASE
+
"tun2socks --netif-ipaddr 172.16.0.2 --udpgw-remote-server-addr
%s
:7300 "
+
"--netif-netmask 255.255.255.0 --socks-server-addr 127.0.0.1:%d --tunfd %d --tunmtu %d --pid "
+
BASE
+
"tun2socks.pid"
)
.
format
(
localPort
,
fd
,
VPN_MTU
)
.
format
(
udpgw
,
localPort
,
fd
,
VPN_MTU
)
Log
.
d
(
TAG
,
cmd
)
System
.
exec
(
cmd
)
...
...
src/main/scala/com/github/shadowsocks/Utils.scala
View file @
062f4970
...
...
@@ -49,6 +49,35 @@ import org.apache.http.conn.util.InetAddressUtils
import
scala.collection.mutable.ArrayBuffer
object
Utils
{
/**
* Get local IPv4 address
*/
def
getIPv4Address
:
Option
[
String
]
=
{
try
{
val
interfaces
=
NetworkInterface
.
getNetworkInterfaces
while
(
interfaces
.
hasMoreElements
)
{
val
intf
=
interfaces
.
nextElement
()
val
addrs
=
intf
.
getInetAddresses
while
(
addrs
.
hasMoreElements
)
{
val
addr
=
addrs
.
nextElement
()
if
(!
addr
.
isLoopbackAddress
&&
!
addr
.
isLinkLocalAddress
)
{
val
sAddr
=
addr
.
getHostAddress
.
toUpperCase
if
(
InetAddressUtils
.
isIPv4Address
(
sAddr
))
{
return
Some
(
sAddr
)
}
}
}
}
}
catch
{
case
ex
:
Exception
=>
{
Log
.
e
(
TAG
,
"Failed to get interfaces' addresses."
,
ex
)
}
}
None
}
/**
* If there exists a valid IPv6 interface
*/
...
...
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