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
df1e40d6
Commit
df1e40d6
authored
Feb 02, 2017
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine Subnet
parent
ee08f026
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
25 deletions
+20
-25
mobile/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
.../scala/com/github/shadowsocks/ShadowsocksVpnService.scala
+4
-9
mobile/src/main/scala/com/github/shadowsocks/acl/Subnet.scala
...le/src/main/scala/com/github/shadowsocks/acl/Subnet.scala
+7
-16
mobile/src/main/scala/com/github/shadowsocks/utils/Utils.scala
...e/src/main/scala/com/github/shadowsocks/utils/Utils.scala
+9
-0
No files found.
mobile/src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
View file @
df1e40d6
...
@@ -23,14 +23,13 @@ package com.github.shadowsocks
...
@@ -23,14 +23,13 @@ package com.github.shadowsocks
import
java.io.File
import
java.io.File
import
java.util.Locale
import
java.util.Locale
import
android.annotation.SuppressLint
import
android.content._
import
android.content._
import
android.content.pm.PackageManager.NameNotFoundException
import
android.content.pm.PackageManager.NameNotFoundException
import
android.net.VpnService
import
android.net.VpnService
import
android.os._
import
android.os._
import
android.util.Log
import
android.util.Log
import
com.github.shadowsocks.ShadowsocksApplication.app
import
com.github.shadowsocks.ShadowsocksApplication.app
import
com.github.shadowsocks.acl.
{
Acl
,
AclSyncJob
}
import
com.github.shadowsocks.acl.
{
Acl
,
AclSyncJob
,
Subnet
}
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.utils._
import
com.github.shadowsocks.utils._
...
@@ -212,7 +211,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
...
@@ -212,7 +211,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
pdnsdProcess
=
new
GuardedProcess
(
cmd
:
_
*
).
start
()
pdnsdProcess
=
new
GuardedProcess
(
cmd
:
_
*
).
start
()
}
}
@SuppressLint
(
Array
(
"NewApi"
))
def
startVpn
()
:
Int
=
{
def
startVpn
()
:
Int
=
{
val
builder
=
new
Builder
()
val
builder
=
new
Builder
()
...
@@ -249,15 +247,12 @@ class ShadowsocksVpnService extends VpnService with BaseService {
...
@@ -249,15 +247,12 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if
(
profile
.
route
==
Acl
.
ALL
||
profile
.
route
==
Acl
.
BYPASS_CHN
)
{
if
(
profile
.
route
==
Acl
.
ALL
||
profile
.
route
==
Acl
.
BYPASS_CHN
)
{
builder
.
addRoute
(
"0.0.0.0"
,
0
)
builder
.
addRoute
(
"0.0.0.0"
,
0
)
}
else
{
}
else
{
val
privateList
=
getResources
.
getStringArray
(
R
.
array
.
bypass_private_route
)
getResources
.
getStringArray
(
R
.
array
.
bypass_private_route
).
foreach
(
cidr
=>
{
privateList
.
foreach
(
cidr
=>
{
val
subnet
=
Subnet
.
fromString
(
cidr
)
val
addr
=
cidr
.
split
(
'/'
)
builder
.
addRoute
(
subnet
.
address
.
getHostAddress
,
subnet
.
prefixSize
)
builder
.
addRoute
(
addr
(
0
),
addr
(
1
).
toInt
)
})
})
}
}
builder
.
addRoute
(
"8.8.0.0"
,
16
)
conn
=
builder
.
establish
()
conn
=
builder
.
establish
()
if
(
conn
==
null
)
throw
new
NullConnectionException
if
(
conn
==
null
)
throw
new
NullConnectionException
...
...
mobile/src/main/scala/com/github/shadowsocks/acl/Subnet.scala
View file @
df1e40d6
package
com.github.shadowsocks.acl
package
com.github.shadowsocks.acl
import
java.net.
{
Inet4Address
,
Inet6Address
,
InetAddress
}
import
java.net.
InetAddress
import
com.github.shadowsocks.utils.Utils
import
com.github.shadowsocks.utils.Utils
...
@@ -9,16 +9,11 @@ import com.github.shadowsocks.utils.Utils
...
@@ -9,16 +9,11 @@ import com.github.shadowsocks.utils.Utils
*/
*/
@throws
[
IllegalArgumentException
]
@throws
[
IllegalArgumentException
]
class
Subnet
(
val
address
:
InetAddress
,
val
prefixSize
:
Int
)
extends
Comparable
[
Subnet
]
{
class
Subnet
(
val
address
:
InetAddress
,
val
prefixSize
:
Int
)
extends
Comparable
[
Subnet
]
{
if
(
prefixSize
<
0
)
throw
new
IllegalArgumentException
private
def
addressLength
=
address
.
getAddress
.
length
<<
3
address
match
{
if
(
prefixSize
<
0
||
prefixSize
>
addressLength
)
throw
new
IllegalArgumentException
case
_:
Inet4Address
=>
if
(
prefixSize
>
32
)
throw
new
IllegalArgumentException
case
_:
Inet6Address
=>
if
(
prefixSize
>
128
)
throw
new
IllegalArgumentException
}
override
def
toString
:
String
=
if
(
address
match
{
override
def
toString
:
String
=
case
_:
Inet4Address
=>
prefixSize
==
32
if
(
prefixSize
==
addressLength
)
address
.
getHostAddress
else
address
.
getHostAddress
+
'/'
+
prefixSize
case
_:
Inet6Address
=>
prefixSize
==
128
})
address
.
getHostAddress
else
address
.
getHostAddress
+
'/'
+
prefixSize
override
def
compareTo
(
that
:
Subnet
)
:
Int
=
{
override
def
compareTo
(
that
:
Subnet
)
:
Int
=
{
val
addrThis
=
address
.
getAddress
val
addrThis
=
address
.
getAddress
...
@@ -37,13 +32,9 @@ object Subnet {
...
@@ -37,13 +32,9 @@ object Subnet {
@throws
[
IllegalArgumentException
]
@throws
[
IllegalArgumentException
]
def
fromString
(
value
:
String
)
:
Subnet
=
{
def
fromString
(
value
:
String
)
:
Subnet
=
{
val
parts
=
value
.
split
(
"/"
)
val
parts
=
value
.
split
(
"/"
)
if
(!
Utils
.
isNumeric
(
parts
(
0
)))
throw
new
IllegalArgumentException
()
val
addr
=
Utils
.
parseNumericAddress
(
parts
(
0
))
val
addr
=
InetAddress
.
getByName
(
parts
(
0
))
parts
.
length
match
{
parts
.
length
match
{
case
1
=>
new
Subnet
(
addr
,
addr
match
{
case
1
=>
new
Subnet
(
addr
,
addr
.
getAddress
.
length
<<
3
)
case
_:
Inet4Address
=>
32
case
_:
Inet6Address
=>
128
})
case
2
=>
new
Subnet
(
addr
,
parts
(
1
).
toInt
)
case
2
=>
new
Subnet
(
addr
,
parts
(
1
).
toInt
)
case
_
=>
throw
new
IllegalArgumentException
()
case
_
=>
throw
new
IllegalArgumentException
()
}
}
...
...
mobile/src/main/scala/com/github/shadowsocks/utils/Utils.scala
View file @
df1e40d6
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
package
com.github.shadowsocks.utils
package
com.github.shadowsocks.utils
import
java.lang.reflect.InvocationTargetException
import
java.net._
import
java.net._
import
java.security.MessageDigest
import
java.security.MessageDigest
...
@@ -108,7 +109,15 @@ object Utils {
...
@@ -108,7 +109,15 @@ object Utils {
.
orElse
(
resolve
(
host
))
.
orElse
(
resolve
(
host
))
private
lazy
val
isNumericMethod
=
classOf
[
InetAddress
].
getMethod
(
"isNumeric"
,
classOf
[
String
])
private
lazy
val
isNumericMethod
=
classOf
[
InetAddress
].
getMethod
(
"isNumeric"
,
classOf
[
String
])
private
lazy
val
parseNumericAddressMethod
=
classOf
[
InetAddress
].
getMethod
(
"parseNumericAddress"
,
classOf
[
String
])
def
isNumeric
(
address
:
String
)
:
Boolean
=
isNumericMethod
.
invoke
(
null
,
address
).
asInstanceOf
[
Boolean
]
def
isNumeric
(
address
:
String
)
:
Boolean
=
isNumericMethod
.
invoke
(
null
,
address
).
asInstanceOf
[
Boolean
]
def
parseNumericAddress
(
address
:
String
)
:
InetAddress
=
try
parseNumericAddressMethod
.
invoke
(
null
,
address
).
asInstanceOf
[
InetAddress
]
catch
{
case
exc
:
InvocationTargetException
=>
throw
exc
.
getCause
match
{
case
null
=>
exc
case
cause
=>
cause
}
}
/**
/**
* If there exists a valid IPv6 interface
* 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