|
|
@ -88,7 +88,8 @@ class DomainTreeNode(): |
|
|
|
|
|
|
|
class IpTreeNode(): |
|
|
|
def __init__(self) -> None: |
|
|
|
self.children: typing.List[typing.Optional[IpTreeNode]] = [None, None] |
|
|
|
self.zero: typing.Optional[IpTreeNode] = None |
|
|
|
self.one: typing.Optional[IpTreeNode] = None |
|
|
|
self.match = Match() |
|
|
|
|
|
|
|
|
|
|
@ -131,7 +132,7 @@ class Profiler(): |
|
|
|
|
|
|
|
|
|
|
|
class Database(Profiler): |
|
|
|
VERSION = 10 |
|
|
|
VERSION = 11 |
|
|
|
PATH = "blocking.p" |
|
|
|
|
|
|
|
def initialize(self) -> None: |
|
|
@ -258,7 +259,7 @@ class Database(Profiler): |
|
|
|
callback(_par, _dic, arg) |
|
|
|
|
|
|
|
# 0 |
|
|
|
dic = _dic.children[0] |
|
|
|
dic = _dic.zero |
|
|
|
if dic: |
|
|
|
addr0 = _par.value & (0xFFFFFFFF ^ (1 << (32-_par.prefixlen))) |
|
|
|
assert addr0 == _par.value |
|
|
@ -269,7 +270,7 @@ class Database(Profiler): |
|
|
|
_par=Ip4Path(addr0, _par.prefixlen+1) |
|
|
|
) |
|
|
|
# 1 |
|
|
|
dic = _dic.children[1] |
|
|
|
dic = _dic.one |
|
|
|
if dic: |
|
|
|
addr1 = _par.value | (1 << (32-_par.prefixlen)) |
|
|
|
yield from self.exec_each_ip4( |
|
|
@ -351,7 +352,7 @@ class Database(Profiler): |
|
|
|
self.enter_step('get_ip4_yield') |
|
|
|
yield Ip4Path(ip4.value, 32-i) |
|
|
|
self.enter_step('get_ip4_brws') |
|
|
|
next_dic = dic.children[part] |
|
|
|
next_dic = dic.one if part else dic.zero |
|
|
|
if next_dic is None: |
|
|
|
return |
|
|
|
dic = next_dic |
|
|
@ -432,10 +433,13 @@ class Database(Profiler): |
|
|
|
if dic.match.active(): |
|
|
|
# Refuse to add ip4* whose network is already matching |
|
|
|
return |
|
|
|
next_dic = dic.children[part] |
|
|
|
next_dic = dic.one if part else dic.zero |
|
|
|
if next_dic is None: |
|
|
|
next_dic = IpTreeNode() |
|
|
|
dic.children[part] = next_dic |
|
|
|
if part: |
|
|
|
dic.one = next_dic |
|
|
|
else: |
|
|
|
dic.zero = next_dic |
|
|
|
dic = next_dic |
|
|
|
dic.match.set( |
|
|
|
updated, |
|
|
|