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
fb519799
Commit
fb519799
authored
Dec 14, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle subnets with duplications
parent
476a6257
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
4 deletions
+14
-4
core/src/main/java/com/github/shadowsocks/acl/AclMatcher.kt
core/src/main/java/com/github/shadowsocks/acl/AclMatcher.kt
+12
-4
core/src/main/java/com/github/shadowsocks/net/Subnet.kt
core/src/main/java/com/github/shadowsocks/net/Subnet.kt
+2
-0
No files found.
core/src/main/java/com/github/shadowsocks/acl/AclMatcher.kt
View file @
fb519799
...
@@ -34,16 +34,24 @@ class AclMatcher {
...
@@ -34,16 +34,24 @@ class AclMatcher {
private
var
bypass
=
false
private
var
bypass
=
false
suspend
fun
init
(
id
:
String
)
{
suspend
fun
init
(
id
:
String
)
{
fun
Sequence
<
Subnet
>.
dedup
()
=
sequence
{
val
iterator
=
map
{
it
.
toImmutable
()
}.
sortedWith
(
Subnet
.
Immutable
).
iterator
()
var
current
:
Subnet
.
Immutable
?
=
null
while
(
iterator
.
hasNext
())
{
val
next
=
iterator
.
next
()
if
(
current
?.
matches
(
next
)
==
true
)
continue
yield
(
next
)
current
=
next
}
}.
toList
()
val
time
=
measureNanoTime
{
val
time
=
measureNanoTime
{
val
(
bypass
,
subnets
)
=
Acl
.
parse
(
Acl
.
getFile
(
id
).
bufferedReader
(),
{
val
(
bypass
,
subnets
)
=
Acl
.
parse
(
Acl
.
getFile
(
id
).
bufferedReader
(),
{
// bypassDomains.add(it.toRegex())
// bypassDomains.add(it.toRegex())
},
{
},
{
if
(
it
.
startsWith
(
"(?:^|\\.)googleapis"
))
proxyDomains
.
add
(
it
.
toRegex
())
if
(
it
.
startsWith
(
"(?:^|\\.)googleapis"
))
proxyDomains
.
add
(
it
.
toRegex
())
})
})
subnetsIpv4
=
subnets
.
asSequence
().
filter
{
it
.
address
is
Inet4Address
}.
map
{
it
.
toImmutable
()
}
subnetsIpv4
=
subnets
.
asSequence
().
filter
{
it
.
address
is
Inet4Address
}.
dedup
()
.
sortedWith
(
Subnet
.
Immutable
).
toList
()
subnetsIpv6
=
subnets
.
asSequence
().
filter
{
it
.
address
is
Inet6Address
}.
dedup
()
subnetsIpv6
=
subnets
.
asSequence
().
filter
{
it
.
address
is
Inet6Address
}.
map
{
it
.
toImmutable
()
}
.
sortedWith
(
Subnet
.
Immutable
).
toList
()
this
.
bypass
=
bypass
this
.
bypass
=
bypass
}
}
Log
.
d
(
"AclMatcher"
,
"ACL initialized in $time ns"
)
Log
.
d
(
"AclMatcher"
,
"ACL initialized in $time ns"
)
...
...
core/src/main/java/com/github/shadowsocks/net/Subnet.kt
View file @
fb519799
...
@@ -56,6 +56,8 @@ class Subnet(val address: InetAddress, val prefixSize: Int) : Comparable<Subnet>
...
@@ -56,6 +56,8 @@ class Subnet(val address: InetAddress, val prefixSize: Int) : Comparable<Subnet>
return
0
return
0
}
}
}
}
fun
matches
(
b
:
Immutable
)
=
matches
(
b
.
a
)
fun
matches
(
b
:
ByteArray
):
Boolean
{
fun
matches
(
b
:
ByteArray
):
Boolean
{
if
(
a
.
size
!=
b
.
size
)
return
false
if
(
a
.
size
!=
b
.
size
)
return
false
var
i
=
0
var
i
=
0
...
...
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