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
fa240eae
Commit
fa240eae
authored
Jul 31, 2018
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Remove unnecessary bypassHostnames in Acl" and fix inconsistencies of ACL file handling
This reverts commit
e5cd145b
. Fixes #1895.
parent
7d21fb78
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
52 deletions
+56
-52
core/src/main/jni/shadowsocks-libev
core/src/main/jni/shadowsocks-libev
+1
-1
mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt
mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt
+38
-34
mobile/src/main/java/com/github/shadowsocks/acl/CustomRulesFragment.kt
...in/java/com/github/shadowsocks/acl/CustomRulesFragment.kt
+17
-17
No files found.
shadowsocks-libev
@
d107f9ec
Subproject commit
a9d56518bb3e0662e76f60e0ce087a35d6af8323
Subproject commit
d107f9ecdb76d6503bba1288ea2bc16052b62f16
mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt
View file @
fa240eae
...
...
@@ -52,19 +52,16 @@ class Acl {
get
()
{
val
acl
=
Acl
()
val
str
=
DataStore
.
publicStore
.
getString
(
CUSTOM_RULES
)
if
(
str
!=
null
)
{
acl
.
fromReader
(
str
.
reader
())
if
(
str
!=
null
)
acl
.
fromReader
(
str
.
reader
(),
true
)
if
(!
acl
.
bypass
)
{
acl
.
subnets
.
clear
()
acl
.
hostnames
.
clear
()
acl
.
bypass
=
true
acl
.
subnets
.
clear
()
}
}
else
acl
.
bypass
=
true
return
acl
}
set
(
value
)
=
DataStore
.
publicStore
.
putString
(
CUSTOM_RULES
,
if
((!
value
.
bypass
||
value
.
subnets
.
size
()
==
0
&&
value
.
hostnames
.
size
()
==
0
)
&&
value
.
urls
.
size
()
==
0
)
null
else
value
.
toString
())
set
(
value
)
=
DataStore
.
publicStore
.
putString
(
CUSTOM_RULES
,
if
((!
value
.
bypass
||
value
.
subnets
.
size
()
==
0
)
&&
value
.
bypassHostnames
.
size
()
==
0
&&
value
.
proxyHostnames
.
size
()
==
0
&&
value
.
urls
.
size
()
==
0
)
null
else
value
.
toString
())
fun
save
(
id
:
String
,
acl
:
Acl
)
=
getFile
(
id
).
writeText
(
acl
.
toString
())
}
...
...
@@ -89,31 +86,30 @@ class Acl {
override
fun
compareNonNull
(
o1
:
URL
,
o2
:
URL
):
Int
=
ordering
.
compare
(
o1
,
o2
)
}
val
hostnames
=
SortedList
(
String
::
class
.
java
,
StringSorter
)
val
bypassHostnames
=
SortedList
(
String
::
class
.
java
,
StringSorter
)
val
proxyHostnames
=
SortedList
(
String
::
class
.
java
,
StringSorter
)
val
subnets
=
SortedList
(
Subnet
::
class
.
java
,
SubnetSorter
)
val
urls
=
SortedList
(
URL
::
class
.
java
,
URLSorter
)
var
bypass
=
false
fun
clear
():
Acl
{
hostnames
.
clear
()
subnets
.
clear
()
urls
.
clear
()
return
this
}
fun
fromAcl
(
other
:
Acl
):
Acl
{
clear
()
for
(
item
in
other
.
hostnames
.
asIterable
())
hostnames
.
add
(
item
)
bypassHostnames
.
clear
()
for
(
item
in
other
.
bypassHostnames
.
asIterable
())
bypassHostnames
.
add
(
item
)
proxyHostnames
.
clear
()
for
(
item
in
other
.
proxyHostnames
.
asIterable
())
proxyHostnames
.
add
(
item
)
subnets
.
clear
()
for
(
item
in
other
.
subnets
.
asIterable
())
subnets
.
add
(
item
)
urls
.
clear
()
for
(
item
in
other
.
urls
.
asIterable
())
urls
.
add
(
item
)
bypass
=
other
.
bypass
return
this
}
fun
fromReader
(
reader
:
Reader
,
defaultBypass
:
Boolean
=
false
):
Acl
{
clear
()
bypassHostnames
.
clear
()
proxyHostnames
.
clear
()
subnets
.
clear
()
urls
.
clear
()
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
proxySubnets
by
lazy
{
SortedList
(
Subnet
::
class
.
java
,
SubnetSorter
)
}
var
hostnames
:
SortedList
<
String
>?
=
if
(
defaultBypass
)
proxyHostnames
else
bypassHostnames
...
...
@@ -147,7 +143,6 @@ 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
)
return
this
}
...
...
@@ -167,12 +162,11 @@ class Acl {
if
(
bypass
!=
child
.
bypass
)
{
Crashlytics
.
log
(
Log
.
WARN
,
TAG
,
"Imported network ACL has a conflicting mode set. "
+
"This will probably not work as intended. URL: $url"
)
// rules for the different mode are discarded
child
.
hostnames
.
clear
()
child
.
subnets
.
clear
()
child
.
subnets
.
clear
()
// subnets for the different mode are discarded
child
.
bypass
=
bypass
}
for
(
item
in
child
.
hostnames
.
asIterable
())
hostnames
.
add
(
item
)
for
(
item
in
child
.
bypassHostnames
.
asIterable
())
bypassHostnames
.
add
(
item
)
for
(
item
in
child
.
proxyHostnames
.
asIterable
())
proxyHostnames
.
add
(
item
)
for
(
item
in
child
.
subnets
.
asIterable
())
subnets
.
add
(
item
)
}
urls
.
clear
()
...
...
@@ -181,11 +175,21 @@ class Acl {
override
fun
toString
():
String
{
val
result
=
StringBuilder
()
result
.
append
(
if
(
bypass
)
"[bypass_all]\n[proxy_list]\n"
else
"[proxy_all]\n[bypass_list]\n"
)
result
.
append
(
subnets
.
asIterable
().
joinToString
(
"\n"
))
result
.
append
(
if
(
bypass
)
"[bypass_all]\n"
else
"[proxy_all]\n"
)
val
bypassList
=
(
if
(
bypass
)
bypassHostnames
.
asIterable
().
asSequence
()
else
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
(
hostnames
.
asIterable
().
joinToString
(
"\n"
))
}
if
(
proxyList
.
isNotEmpty
())
{
result
.
append
(
"[proxy_list]\n"
)
result
.
append
(
proxyList
.
joinToString
(
"\n"
))
result
.
append
(
'\n'
)
}
result
.
append
(
urls
.
asIterable
().
joinToString
(
""
)
{
"#IMPORT_URL <$it>\n"
})
return
result
.
toString
()
}
...
...
mobile/src/main/java/com/github/shadowsocks/acl/CustomRulesFragment.kt
View file @
fa240eae
...
...
@@ -215,13 +215,13 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
override
fun
onBindViewHolder
(
holder
:
AclRuleViewHolder
,
i
:
Int
)
{
val
j
=
i
-
acl
.
subnets
.
size
()
if
(
j
<
0
)
holder
.
bind
(
acl
.
subnets
[
i
])
else
{
val
k
=
j
-
acl
.
h
ostnames
.
size
()
if
(
k
<
0
)
holder
.
bind
(
acl
.
h
ostnames
[
j
])
else
holder
.
bind
(
acl
.
urls
[
k
])
val
k
=
j
-
acl
.
proxyH
ostnames
.
size
()
if
(
k
<
0
)
holder
.
bind
(
acl
.
proxyH
ostnames
[
j
])
else
holder
.
bind
(
acl
.
urls
[
k
])
}
}
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
)
=
AclRuleViewHolder
(
LayoutInflater
.
from
(
parent
.
context
).
inflate
(
android
.
R
.
layout
.
simple_list_item_1
,
parent
,
false
))
override
fun
getItemCount
():
Int
=
acl
.
subnets
.
size
()
+
acl
.
h
ostnames
.
size
()
+
acl
.
urls
.
size
()
override
fun
getItemCount
():
Int
=
acl
.
subnets
.
size
()
+
acl
.
proxyH
ostnames
.
size
()
+
acl
.
urls
.
size
()
private
fun
apply
()
{
if
(!
savePending
)
{
...
...
@@ -249,9 +249,9 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
return
index
}
fun
addHostname
(
hostname
:
String
):
Int
{
val
old
=
acl
.
h
ostnames
.
size
()
val
index
=
acl
.
subnets
.
size
()
+
acl
.
h
ostnames
.
add
(
hostname
)
if
(
old
!=
acl
.
h
ostnames
.
size
())
{
val
old
=
acl
.
proxyH
ostnames
.
size
()
val
index
=
acl
.
subnets
.
size
()
+
acl
.
proxyH
ostnames
.
add
(
hostname
)
if
(
old
!=
acl
.
proxyH
ostnames
.
size
())
{
notifyItemInserted
(
index
)
apply
()
}
...
...
@@ -259,7 +259,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
}
fun
addURL
(
url
:
URL
):
Int
{
val
old
=
acl
.
urls
.
size
()
val
index
=
acl
.
subnets
.
size
()
+
acl
.
h
ostnames
.
size
()
+
acl
.
urls
.
add
(
url
)
val
index
=
acl
.
subnets
.
size
()
+
acl
.
proxyH
ostnames
.
size
()
+
acl
.
urls
.
add
(
url
)
if
(
old
!=
acl
.
urls
.
size
())
{
notifyItemInserted
(
index
)
apply
()
...
...
@@ -271,7 +271,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
var
result
:
Int
?
=
null
if
(
acl
.
bypass
)
acl
.
subnets
.
asIterable
().
asSequence
().
map
{
addSubnet
(
it
)
}
.
forEach
{
if
(
result
==
null
)
result
=
it
}
(
acl
.
h
ostnames
.
asIterable
().
asSequence
().
map
{
addHostname
(
it
)
}
+
(
acl
.
proxyH
ostnames
.
asIterable
().
asSequence
().
map
{
addHostname
(
it
)
}
+
acl
.
urls
.
asIterable
().
asSequence
().
map
{
addURL
(
it
)
})
.
forEach
{
if
(
result
==
null
)
result
=
it
}
return
result
...
...
@@ -283,10 +283,10 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
undoManager
.
remove
(
Pair
(
i
,
acl
.
subnets
[
i
]))
acl
.
subnets
.
removeItemAt
(
i
)
}
else
{
val
k
=
j
-
acl
.
h
ostnames
.
size
()
val
k
=
j
-
acl
.
proxyH
ostnames
.
size
()
if
(
k
<
0
)
{
undoManager
.
remove
(
Pair
(
j
,
acl
.
h
ostnames
[
j
]))
acl
.
h
ostnames
.
removeItemAt
(
j
)
undoManager
.
remove
(
Pair
(
j
,
acl
.
proxyH
ostnames
[
j
]))
acl
.
proxyH
ostnames
.
removeItemAt
(
j
)
}
else
{
undoManager
.
remove
(
Pair
(
k
,
acl
.
urls
[
k
]))
acl
.
urls
.
removeItemAt
(
k
)
...
...
@@ -303,12 +303,12 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
apply
()
}
is
String
->
{
notifyItemRemoved
(
acl
.
subnets
.
size
()
+
acl
.
h
ostnames
.
indexOf
(
item
))
acl
.
h
ostnames
.
remove
(
item
)
notifyItemRemoved
(
acl
.
subnets
.
size
()
+
acl
.
proxyH
ostnames
.
indexOf
(
item
))
acl
.
proxyH
ostnames
.
remove
(
item
)
apply
()
}
is
URL
->
{
notifyItemRemoved
(
acl
.
subnets
.
size
()
+
acl
.
h
ostnames
.
size
()
+
acl
.
urls
.
indexOf
(
item
))
notifyItemRemoved
(
acl
.
subnets
.
size
()
+
acl
.
proxyH
ostnames
.
size
()
+
acl
.
urls
.
indexOf
(
item
))
acl
.
urls
.
remove
(
item
)
apply
()
}
...
...
@@ -327,7 +327,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
fun
selectAll
()
{
selectedItems
.
clear
()
selectedItems
.
addAll
(
acl
.
subnets
.
asIterable
())
selectedItems
.
addAll
(
acl
.
h
ostnames
.
asIterable
())
selectedItems
.
addAll
(
acl
.
proxyH
ostnames
.
asIterable
())
selectedItems
.
addAll
(
acl
.
urls
.
asIterable
())
onSelectedItemsUpdated
()
notifyDataSetChanged
()
...
...
@@ -406,7 +406,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
selectedItems
.
forEach
{
when
(
it
)
{
is
Subnet
->
acl
.
subnets
.
add
(
it
)
is
String
->
acl
.
h
ostnames
.
add
(
it
)
is
String
->
acl
.
proxyH
ostnames
.
add
(
it
)
is
URL
->
acl
.
urls
.
add
(
it
)
}
}
...
...
@@ -432,7 +432,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
R
.
id
.
action_import_gfwlist
->
{
val
acl
=
Acl
().
fromId
(
Acl
.
GFWLIST
)
if
(!
acl
.
bypass
)
acl
.
subnets
.
asIterable
().
forEach
{
adapter
.
addSubnet
(
it
)
}
acl
.
h
ostnames
.
asIterable
().
forEach
{
adapter
.
addHostname
(
it
)
}
acl
.
proxyH
ostnames
.
asIterable
().
forEach
{
adapter
.
addHostname
(
it
)
}
acl
.
urls
.
asIterable
().
forEach
{
adapter
.
addURL
(
it
)
}
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