Skip to content

Commit 9fdfec8

Browse files
committed
chg: [correlation engine] add fct to search for ids in one depth correlation
1 parent 55f2040 commit 9fdfec8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

bin/lib/correlations_engine.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,25 @@ def delete_obj_correlations(obj_type, subtype, obj_id):
160160
subtype2, obj2_id = str_obj.split(':', 1)
161161
delete_obj_correlation(obj_type, subtype, obj_id, correl_type, subtype2, obj2_id)
162162

163+
def get_obj_one_depth_correlations(obj_type, subtype, obj_id, target_types, intermediate_types=set(), start=None, end=None):
164+
matches = set()
165+
src_obj_correlations = get_correlations(obj_type, subtype, obj_id, unpack=True)
166+
for c_type in src_obj_correlations:
167+
if not intermediate_types or c_type in intermediate_types:
168+
if src_obj_correlations[c_type]:
169+
for intermediate_obj_subtype, intermediate_obj_id in src_obj_correlations[c_type]:
170+
intermediate_obj_correlation = get_correlations(c_type, intermediate_obj_subtype, intermediate_obj_id, unpack=True)
171+
for t_type in intermediate_obj_correlation:
172+
if t_type in target_types:
173+
for t_obj_subtype, t_obj_id in intermediate_obj_correlation[t_type]:
174+
if start:
175+
if t_obj_id.startswith(start):
176+
matches.add(f'{t_type}:{t_obj_subtype}:{t_obj_id}')
177+
elif end:
178+
if t_obj_id.endswith(end):
179+
matches.add(f'{t_type}:{t_obj_subtype}:{t_obj_id}')
180+
return matches
181+
163182
# # bypass max result/objects ???
164183
# def get_correlation_depht(obj_type, subtype, obj_id, filter_types=[], level=1, nb_max=300):
165184
# objs = set()
@@ -234,3 +253,7 @@ def _get_correlations_graph_node(links, nodes, meta, obj_type, subtype, obj_id,
234253
next_level = level - 1
235254
_get_correlations_graph_node(links, nodes, meta, correl_type, subtype2, obj2_id, next_level, max_nodes, filter_types=filter_types, objs_hidden=objs_hidden, previous_str_obj=obj_str_id)
236255

256+
257+
if __name__ == '__main__':
258+
r = get_obj_one_depth_correlations('item', '', '', {'domain'}, intermediate_types=set(), end='.onion')
259+
print(r)

0 commit comments

Comments
 (0)