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
e5cd145b
Commit
e5cd145b
authored
Dec 16, 2017
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unnecessary bypassHostnames in Acl
Fix #1505
parent
f89088ef
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
50 deletions
+46
-50
mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt
mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt
+27
-31
mobile/src/main/java/com/github/shadowsocks/acl/CustomRulesFragment.kt
...in/java/com/github/shadowsocks/acl/CustomRulesFragment.kt
+19
-19
No files found.
mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt
View file @
e5cd145b
...
@@ -52,9 +52,12 @@ class Acl {
...
@@ -52,9 +52,12 @@ class Acl {
val
acl
=
Acl
()
val
acl
=
Acl
()
try
{
try
{
acl
.
fromId
(
CUSTOM_RULES
)
acl
.
fromId
(
CUSTOM_RULES
)
if
(!
acl
.
bypass
)
{
acl
.
subnets
.
clear
()
acl
.
hostnames
.
clear
()
}
}
catch
(
_
:
FileNotFoundException
)
{
}
}
catch
(
_
:
FileNotFoundException
)
{
}
acl
.
bypass
=
true
acl
.
bypass
=
true
acl
.
bypassHostnames
.
clear
()
// everything is bypassed
return
acl
return
acl
}
}
fun
save
(
id
:
String
,
acl
:
Acl
)
=
getFile
(
id
).
writeText
(
acl
.
toString
())
fun
save
(
id
:
String
,
acl
:
Acl
)
=
getFile
(
id
).
writeText
(
acl
.
toString
())
...
@@ -83,32 +86,33 @@ class Acl {
...
@@ -83,32 +86,33 @@ class Acl {
@DatabaseField
(
generatedId
=
true
)
@DatabaseField
(
generatedId
=
true
)
var
id
=
0
var
id
=
0
val
bypassHostnames
=
SortedList
(
String
::
class
.
java
,
StringSorter
)
val
hostnames
=
SortedList
(
String
::
class
.
java
,
StringSorter
)
val
proxyHostnames
=
SortedList
(
String
::
class
.
java
,
StringSorter
)
val
subnets
=
SortedList
(
Subnet
::
class
.
java
,
SubnetSorter
)
val
subnets
=
SortedList
(
Subnet
::
class
.
java
,
SubnetSorter
)
val
urls
=
SortedList
(
URL
::
class
.
java
,
URLSorter
)
val
urls
=
SortedList
(
URL
::
class
.
java
,
URLSorter
)
@DatabaseField
@DatabaseField
var
bypass
=
false
var
bypass
=
false
fun
fromAcl
(
other
:
Acl
):
Acl
{
fun
clear
():
Acl
{
bypassHostnames
.
clear
()
hostnames
.
clear
()
for
(
item
in
other
.
bypassHostnames
.
asIterable
())
bypassHostnames
.
add
(
item
)
proxyHostnames
.
clear
()
for
(
item
in
other
.
proxyHostnames
.
asIterable
())
proxyHostnames
.
add
(
item
)
subnets
.
clear
()
subnets
.
clear
()
for
(
item
in
other
.
subnets
.
asIterable
())
subnets
.
add
(
item
)
urls
.
clear
()
urls
.
clear
()
return
this
}
fun
fromAcl
(
other
:
Acl
):
Acl
{
clear
()
for
(
item
in
other
.
hostnames
.
asIterable
())
hostnames
.
add
(
item
)
for
(
item
in
other
.
subnets
.
asIterable
())
subnets
.
add
(
item
)
for
(
item
in
other
.
urls
.
asIterable
())
urls
.
add
(
item
)
for
(
item
in
other
.
urls
.
asIterable
())
urls
.
add
(
item
)
bypass
=
other
.
bypass
bypass
=
other
.
bypass
return
this
return
this
}
}
fun
fromReader
(
reader
:
Reader
,
defaultBypass
:
Boolean
=
false
):
Acl
{
fun
fromReader
(
reader
:
Reader
,
defaultBypass
:
Boolean
=
false
):
Acl
{
bypassHostnames
.
clear
()
clear
()
proxyHostnames
.
clear
()
subnets
.
clear
()
urls
.
clear
()
bypass
=
defaultBypass
bypass
=
defaultBypass
val
proxyHostnames
by
lazy
{
SortedList
(
String
::
class
.
java
,
StringSorter
)
}
val
bypassHostnames
by
lazy
{
SortedList
(
String
::
class
.
java
,
StringSorter
)
}
val
bypassSubnets
by
lazy
{
SortedList
(
Subnet
::
class
.
java
,
SubnetSorter
)
}
val
bypassSubnets
by
lazy
{
SortedList
(
Subnet
::
class
.
java
,
SubnetSorter
)
}
val
proxySubnets
by
lazy
{
SortedList
(
Subnet
::
class
.
java
,
SubnetSorter
)
}
val
proxySubnets
by
lazy
{
SortedList
(
Subnet
::
class
.
java
,
SubnetSorter
)
}
var
hostnames
:
SortedList
<
String
>?
=
if
(
defaultBypass
)
proxyHostnames
else
bypassHostnames
var
hostnames
:
SortedList
<
String
>?
=
if
(
defaultBypass
)
proxyHostnames
else
bypassHostnames
...
@@ -142,6 +146,7 @@ class Acl {
...
@@ -142,6 +146,7 @@ class Acl {
}
}
}
}
}
}
for
(
item
in
(
if
(
bypass
)
proxyHostnames
else
bypassHostnames
).
asIterable
())
this
.
hostnames
.
add
(
item
)
for
(
item
in
(
if
(
bypass
)
proxySubnets
else
bypassSubnets
).
asIterable
())
this
.
subnets
.
add
(
item
)
for
(
item
in
(
if
(
bypass
)
proxySubnets
else
bypassSubnets
).
asIterable
())
this
.
subnets
.
add
(
item
)
return
this
return
this
}
}
...
@@ -154,11 +159,12 @@ class Acl {
...
@@ -154,11 +159,12 @@ class Acl {
if
(
bypass
!=
child
.
bypass
)
{
if
(
bypass
!=
child
.
bypass
)
{
Log
.
w
(
TAG
,
"Imported network ACL has a conflicting mode set. "
+
Log
.
w
(
TAG
,
"Imported network ACL has a conflicting mode set. "
+
"This will probably not work as intended. URL: $url"
)
"This will probably not work as intended. URL: $url"
)
child
.
subnets
.
clear
()
// subnets for the different mode are discarded
// rules for the different mode are discarded
child
.
hostnames
.
clear
()
child
.
subnets
.
clear
()
child
.
bypass
=
bypass
child
.
bypass
=
bypass
}
}
for
(
item
in
child
.
bypassHostnames
.
asIterable
())
bypassHostnames
.
add
(
item
)
for
(
item
in
child
.
hostnames
.
asIterable
())
hostnames
.
add
(
item
)
for
(
item
in
child
.
proxyHostnames
.
asIterable
())
proxyHostnames
.
add
(
item
)
for
(
item
in
child
.
subnets
.
asIterable
())
subnets
.
add
(
item
)
for
(
item
in
child
.
subnets
.
asIterable
())
subnets
.
add
(
item
)
}
}
urls
.
clear
()
urls
.
clear
()
...
@@ -167,21 +173,11 @@ class Acl {
...
@@ -167,21 +173,11 @@ class Acl {
override
fun
toString
():
String
{
override
fun
toString
():
String
{
val
result
=
StringBuilder
()
val
result
=
StringBuilder
()
result
.
append
(
if
(
bypass
)
"[bypass_all]\n"
else
"[proxy_all]\n"
)
result
.
append
(
if
(
bypass
)
"[bypass_all]\n[proxy_list]\n"
else
"[proxy_all]\n[bypass_list]\n"
)
val
bypassList
=
(
if
(
bypass
)
bypassHostnames
.
asIterable
().
asSequence
()
else
result
.
append
(
subnets
.
asIterable
().
joinToString
(
"\n"
))
subnets
.
asIterable
().
asSequence
().
map
(
Subnet
::
toString
)
+
proxyHostnames
.
asIterable
().
asSequence
()).
toList
()
val
proxyList
=
(
if
(
bypass
)
subnets
.
asIterable
().
asSequence
().
map
(
Subnet
::
toString
)
+
proxyHostnames
.
asIterable
().
asSequence
()
else
bypassHostnames
.
asIterable
().
asSequence
()).
toList
()
if
(
bypassList
.
isNotEmpty
())
{
result
.
append
(
"[bypass_list]\n"
)
result
.
append
(
bypassList
.
joinToString
(
"\n"
))
result
.
append
(
'\n'
)
result
.
append
(
'\n'
)
}
result
.
append
(
hostnames
.
asIterable
().
joinToString
(
"\n"
))
if
(
proxyList
.
isNotEmpty
())
{
result
.
append
(
"[proxy_list]\n"
)
result
.
append
(
proxyList
.
joinToString
(
"\n"
))
result
.
append
(
'\n'
)
result
.
append
(
'\n'
)
}
result
.
append
(
urls
.
asIterable
().
joinToString
(
""
)
{
"#IMPORT_URL <$it>\n"
})
result
.
append
(
urls
.
asIterable
().
joinToString
(
""
)
{
"#IMPORT_URL <$it>\n"
})
return
result
.
toString
()
return
result
.
toString
()
}
}
...
...
mobile/src/main/java/com/github/shadowsocks/acl/CustomRulesFragment.kt
View file @
e5cd145b
...
@@ -132,20 +132,20 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
...
@@ -132,20 +132,20 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
override
fun
onBindViewHolder
(
holder
:
AclRuleViewHolder
,
i
:
Int
)
{
override
fun
onBindViewHolder
(
holder
:
AclRuleViewHolder
,
i
:
Int
)
{
val
j
=
i
-
acl
.
subnets
.
size
()
val
j
=
i
-
acl
.
subnets
.
size
()
if
(
j
<
0
)
holder
.
bind
(
acl
.
subnets
[
i
])
else
{
if
(
j
<
0
)
holder
.
bind
(
acl
.
subnets
[
i
])
else
{
val
k
=
j
-
acl
.
proxyH
ostnames
.
size
()
val
k
=
j
-
acl
.
h
ostnames
.
size
()
if
(
k
<
0
)
holder
.
bind
(
acl
.
proxyH
ostnames
[
j
])
else
holder
.
bind
(
acl
.
urls
[
k
])
if
(
k
<
0
)
holder
.
bind
(
acl
.
h
ostnames
[
j
])
else
holder
.
bind
(
acl
.
urls
[
k
])
}
}
}
}
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
)
=
AclRuleViewHolder
(
LayoutInflater
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
)
=
AclRuleViewHolder
(
LayoutInflater
.
from
(
parent
.
context
).
inflate
(
android
.
R
.
layout
.
simple_list_item_1
,
parent
,
false
))
.
from
(
parent
.
context
).
inflate
(
android
.
R
.
layout
.
simple_list_item_1
,
parent
,
false
))
override
fun
getItemCount
():
Int
=
acl
.
subnets
.
size
()
+
acl
.
proxyH
ostnames
.
size
()
+
acl
.
urls
.
size
()
override
fun
getItemCount
():
Int
=
acl
.
subnets
.
size
()
+
acl
.
h
ostnames
.
size
()
+
acl
.
urls
.
size
()
override
fun
getSectionTitle
(
i
:
Int
):
String
{
override
fun
getSectionTitle
(
i
:
Int
):
String
{
val
j
=
i
-
acl
.
subnets
.
size
()
val
j
=
i
-
acl
.
subnets
.
size
()
return
try
{
return
try
{
(
if
(
j
<
0
)
acl
.
subnets
[
i
].
address
.
hostAddress
.
substring
(
0
,
1
)
else
{
(
if
(
j
<
0
)
acl
.
subnets
[
i
].
address
.
hostAddress
.
substring
(
0
,
1
)
else
{
val
k
=
j
-
acl
.
proxyH
ostnames
.
size
()
val
k
=
j
-
acl
.
h
ostnames
.
size
()
if
(
k
<
0
)
{
if
(
k
<
0
)
{
val
hostname
=
acl
.
proxyH
ostnames
[
j
]
val
hostname
=
acl
.
h
ostnames
[
j
]
// don't convert IDN yet
// don't convert IDN yet
PATTERN_DOMAIN
.
find
(
hostname
)
?.
value
?.
replace
(
"\\."
,
"."
)
?:
hostname
PATTERN_DOMAIN
.
find
(
hostname
)
?.
value
?.
replace
(
"\\."
,
"."
)
?:
hostname
}
else
acl
.
urls
[
k
].
host
}
else
acl
.
urls
[
k
].
host
...
@@ -179,9 +179,9 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
...
@@ -179,9 +179,9 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
return
index
return
index
}
}
fun
addHostname
(
hostname
:
String
):
Int
{
fun
addHostname
(
hostname
:
String
):
Int
{
val
old
=
acl
.
proxyH
ostnames
.
size
()
val
old
=
acl
.
h
ostnames
.
size
()
val
index
=
acl
.
subnets
.
size
()
+
acl
.
proxyH
ostnames
.
add
(
hostname
)
val
index
=
acl
.
subnets
.
size
()
+
acl
.
h
ostnames
.
add
(
hostname
)
if
(
old
!=
acl
.
proxyH
ostnames
.
size
())
{
if
(
old
!=
acl
.
h
ostnames
.
size
())
{
notifyItemInserted
(
index
)
notifyItemInserted
(
index
)
apply
()
apply
()
}
}
...
@@ -189,7 +189,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
...
@@ -189,7 +189,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
}
}
fun
addURL
(
url
:
URL
):
Int
{
fun
addURL
(
url
:
URL
):
Int
{
val
old
=
acl
.
urls
.
size
()
val
old
=
acl
.
urls
.
size
()
val
index
=
acl
.
subnets
.
size
()
+
acl
.
proxyH
ostnames
.
size
()
+
acl
.
urls
.
add
(
url
)
val
index
=
acl
.
subnets
.
size
()
+
acl
.
h
ostnames
.
size
()
+
acl
.
urls
.
add
(
url
)
if
(
old
!=
acl
.
urls
.
size
())
{
if
(
old
!=
acl
.
urls
.
size
())
{
notifyItemInserted
(
index
)
notifyItemInserted
(
index
)
apply
()
apply
()
...
@@ -201,7 +201,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
...
@@ -201,7 +201,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
var
result
:
Int
?
=
null
var
result
:
Int
?
=
null
if
(
acl
.
bypass
)
acl
.
subnets
.
asIterable
().
asSequence
().
map
{
addSubnet
(
it
)
}
if
(
acl
.
bypass
)
acl
.
subnets
.
asIterable
().
asSequence
().
map
{
addSubnet
(
it
)
}
.
forEach
{
if
(
result
==
null
)
result
=
it
}
.
forEach
{
if
(
result
==
null
)
result
=
it
}
(
acl
.
proxyH
ostnames
.
asIterable
().
asSequence
().
map
{
addHostname
(
it
)
}
+
(
acl
.
h
ostnames
.
asIterable
().
asSequence
().
map
{
addHostname
(
it
)
}
+
acl
.
urls
.
asIterable
().
asSequence
().
map
{
addURL
(
it
)
})
acl
.
urls
.
asIterable
().
asSequence
().
map
{
addURL
(
it
)
})
.
forEach
{
if
(
result
==
null
)
result
=
it
}
.
forEach
{
if
(
result
==
null
)
result
=
it
}
return
result
return
result
...
@@ -227,10 +227,10 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
...
@@ -227,10 +227,10 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
undoManager
.
remove
(
Pair
(
i
,
acl
.
subnets
[
i
]))
undoManager
.
remove
(
Pair
(
i
,
acl
.
subnets
[
i
]))
acl
.
subnets
.
removeItemAt
(
i
)
acl
.
subnets
.
removeItemAt
(
i
)
}
else
{
}
else
{
val
k
=
j
-
acl
.
proxyH
ostnames
.
size
()
val
k
=
j
-
acl
.
h
ostnames
.
size
()
if
(
k
<
0
)
{
if
(
k
<
0
)
{
undoManager
.
remove
(
Pair
(
j
,
acl
.
proxyH
ostnames
[
j
]))
undoManager
.
remove
(
Pair
(
j
,
acl
.
h
ostnames
[
j
]))
acl
.
proxyH
ostnames
.
removeItemAt
(
j
)
acl
.
h
ostnames
.
removeItemAt
(
j
)
}
else
{
}
else
{
undoManager
.
remove
(
Pair
(
k
,
acl
.
urls
[
k
]))
undoManager
.
remove
(
Pair
(
k
,
acl
.
urls
[
k
]))
acl
.
urls
.
removeItemAt
(
k
)
acl
.
urls
.
removeItemAt
(
k
)
...
@@ -247,12 +247,12 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
...
@@ -247,12 +247,12 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
apply
()
apply
()
}
}
is
String
->
{
is
String
->
{
notifyItemRemoved
(
acl
.
subnets
.
size
()
+
acl
.
proxyH
ostnames
.
indexOf
(
item
))
notifyItemRemoved
(
acl
.
subnets
.
size
()
+
acl
.
h
ostnames
.
indexOf
(
item
))
acl
.
proxyH
ostnames
.
remove
(
item
)
acl
.
h
ostnames
.
remove
(
item
)
apply
()
apply
()
}
}
is
URL
->
{
is
URL
->
{
notifyItemRemoved
(
acl
.
subnets
.
size
()
+
acl
.
proxyH
ostnames
.
size
()
+
acl
.
urls
.
indexOf
(
item
))
notifyItemRemoved
(
acl
.
subnets
.
size
()
+
acl
.
h
ostnames
.
size
()
+
acl
.
urls
.
indexOf
(
item
))
acl
.
urls
.
remove
(
item
)
acl
.
urls
.
remove
(
item
)
apply
()
apply
()
}
}
...
@@ -271,7 +271,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
...
@@ -271,7 +271,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
fun
selectAll
()
{
fun
selectAll
()
{
selectedItems
.
clear
()
selectedItems
.
clear
()
selectedItems
.
addAll
(
acl
.
subnets
.
asIterable
())
selectedItems
.
addAll
(
acl
.
subnets
.
asIterable
())
selectedItems
.
addAll
(
acl
.
proxyH
ostnames
.
asIterable
())
selectedItems
.
addAll
(
acl
.
h
ostnames
.
asIterable
())
selectedItems
.
addAll
(
acl
.
urls
.
asIterable
())
selectedItems
.
addAll
(
acl
.
urls
.
asIterable
())
onSelectedItemsUpdated
()
onSelectedItemsUpdated
()
notifyDataSetChanged
()
notifyDataSetChanged
()
...
@@ -386,7 +386,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
...
@@ -386,7 +386,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
selectedItems
.
forEach
{
selectedItems
.
forEach
{
when
(
it
)
{
when
(
it
)
{
is
Subnet
->
acl
.
subnets
.
add
(
it
)
is
Subnet
->
acl
.
subnets
.
add
(
it
)
is
String
->
acl
.
proxyH
ostnames
.
add
(
it
)
is
String
->
acl
.
h
ostnames
.
add
(
it
)
is
URL
->
acl
.
urls
.
add
(
it
)
is
URL
->
acl
.
urls
.
add
(
it
)
}
}
}
}
...
@@ -432,7 +432,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
...
@@ -432,7 +432,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
R
.
id
.
action_import_gfwlist
->
{
R
.
id
.
action_import_gfwlist
->
{
val
acl
=
Acl
().
fromId
(
Acl
.
GFWLIST
)
val
acl
=
Acl
().
fromId
(
Acl
.
GFWLIST
)
if
(!
acl
.
bypass
)
acl
.
subnets
.
asIterable
().
forEach
{
adapter
.
addSubnet
(
it
)
}
if
(!
acl
.
bypass
)
acl
.
subnets
.
asIterable
().
forEach
{
adapter
.
addSubnet
(
it
)
}
acl
.
proxyH
ostnames
.
asIterable
().
forEach
{
adapter
.
addHostname
(
it
)
}
acl
.
h
ostnames
.
asIterable
().
forEach
{
adapter
.
addHostname
(
it
)
}
acl
.
urls
.
asIterable
().
forEach
{
adapter
.
addURL
(
it
)
}
acl
.
urls
.
asIterable
().
forEach
{
adapter
.
addURL
(
it
)
}
true
true
}
}
...
...
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