mirror of https://github.com/CIRCL/lookyloo
fix: Properly handle unlimited requests in body hash lookup
parent
c8606ff167
commit
7b142277ed
|
@ -196,11 +196,14 @@ class Indexing():
|
||||||
|
|
||||||
:param filter_url: URL of the hash we're searching for
|
:param filter_url: URL of the hash we're searching for
|
||||||
:param filter_capture_uuid: UUID of the capture the hash was found in
|
:param filter_capture_uuid: UUID of the capture the hash was found in
|
||||||
:param limit: Max matching captures to return
|
:param limit: Max matching captures to return, -1 means unlimited.
|
||||||
:param prefered_uuids: UUID cached right now, so we don't rebuild trees.
|
:param prefered_uuids: UUID cached right now, so we don't rebuild trees.
|
||||||
'''
|
'''
|
||||||
to_return: List[Tuple[str, str, str, bool]] = []
|
to_return: List[Tuple[str, str, str, bool]] = []
|
||||||
len_captures = self.redis.scard(f'bh|{body_hash}|captures')
|
len_captures = self.redis.scard(f'bh|{body_hash}|captures')
|
||||||
|
unlimited = False
|
||||||
|
if limit == -1:
|
||||||
|
unlimited = True
|
||||||
for capture_uuid in self.redis.sscan_iter(f'bh|{body_hash}|captures'):
|
for capture_uuid in self.redis.sscan_iter(f'bh|{body_hash}|captures'):
|
||||||
if capture_uuid == filter_capture_uuid:
|
if capture_uuid == filter_capture_uuid:
|
||||||
# Used to skip hits in current capture
|
# Used to skip hits in current capture
|
||||||
|
@ -208,6 +211,7 @@ class Indexing():
|
||||||
continue
|
continue
|
||||||
if prefered_uuids and capture_uuid not in prefered_uuids:
|
if prefered_uuids and capture_uuid not in prefered_uuids:
|
||||||
continue
|
continue
|
||||||
|
if not unlimited:
|
||||||
limit -= 1
|
limit -= 1
|
||||||
for entry in self.redis.zrevrange(f'bh|{body_hash}|captures|{capture_uuid}', 0, -1):
|
for entry in self.redis.zrevrange(f'bh|{body_hash}|captures|{capture_uuid}', 0, -1):
|
||||||
url_uuid, hostnode_uuid, url = entry.split('|', 2)
|
url_uuid, hostnode_uuid, url = entry.split('|', 2)
|
||||||
|
@ -216,7 +220,7 @@ class Indexing():
|
||||||
to_return.append((capture_uuid, hostnode_uuid, hostname, url == filter_url))
|
to_return.append((capture_uuid, hostnode_uuid, hostname, url == filter_url))
|
||||||
else:
|
else:
|
||||||
to_return.append((capture_uuid, hostnode_uuid, hostname, False))
|
to_return.append((capture_uuid, hostnode_uuid, hostname, False))
|
||||||
if limit <= 0:
|
if not unlimited and limit <= 0:
|
||||||
break
|
break
|
||||||
return len_captures, to_return
|
return len_captures, to_return
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue