2020-07-08 12:28:41 +00:00
|
|
|
__filename__ = "socnet.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
2023-01-21 23:03:30 +00:00
|
|
|
__version__ = "1.4.0"
|
2020-07-08 12:28:41 +00:00
|
|
|
__maintainer__ = "Bob Mottram"
|
2021-09-10 16:14:50 +00:00
|
|
|
__email__ = "bob@libreserver.org"
|
2020-07-08 12:28:41 +00:00
|
|
|
__status__ = "Production"
|
2021-06-26 11:16:41 +00:00
|
|
|
__module_group__ = "Moderation"
|
2020-07-08 12:28:41 +00:00
|
|
|
|
2021-12-28 16:56:57 +00:00
|
|
|
from session import create_session
|
2021-12-29 21:55:09 +00:00
|
|
|
from webfinger import webfinger_handle
|
|
|
|
from posts import get_person_box
|
|
|
|
from posts import get_post_domains
|
2021-12-26 12:45:03 +00:00
|
|
|
from utils import get_full_domain
|
2020-07-08 12:28:41 +00:00
|
|
|
|
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def instances_graph(base_dir: str, handles: str,
|
|
|
|
proxy_type: str,
|
|
|
|
port: int, http_prefix: str,
|
|
|
|
debug: bool, project_version: str,
|
|
|
|
system_language: str, signing_priv_key_pem: str) -> str:
|
2020-07-08 12:28:41 +00:00
|
|
|
""" Returns a dot graph of federating instances
|
|
|
|
based upon a few sample handles.
|
|
|
|
The handles argument should contain a comma separated list
|
|
|
|
of handles on different instances
|
|
|
|
"""
|
2022-01-03 17:09:50 +00:00
|
|
|
dot_graph_str = 'digraph instances {\n'
|
2020-07-08 12:28:41 +00:00
|
|
|
if ',' not in handles:
|
2022-01-03 17:09:50 +00:00
|
|
|
return dot_graph_str + '}\n'
|
2021-12-28 16:56:57 +00:00
|
|
|
session = create_session(proxy_type)
|
2020-07-08 12:28:41 +00:00
|
|
|
if not session:
|
2022-01-03 17:09:50 +00:00
|
|
|
return dot_graph_str + '}\n'
|
2020-07-08 12:28:41 +00:00
|
|
|
|
2021-12-25 22:17:49 +00:00
|
|
|
person_cache = {}
|
2021-12-25 22:28:18 +00:00
|
|
|
cached_webfingers = {}
|
2020-07-08 12:28:41 +00:00
|
|
|
|
2022-01-03 17:09:50 +00:00
|
|
|
person_handles = handles.split(',')
|
|
|
|
for handle in person_handles:
|
2020-07-08 12:28:41 +00:00
|
|
|
handle = handle.strip()
|
|
|
|
if handle.startswith('@'):
|
|
|
|
handle = handle[1:]
|
|
|
|
if '@' not in handle:
|
|
|
|
continue
|
|
|
|
|
|
|
|
nickname = handle.split('@')[0]
|
|
|
|
domain = handle.split('@')[1]
|
|
|
|
|
2021-12-26 12:45:03 +00:00
|
|
|
domain_full = get_full_domain(domain, port)
|
2021-12-26 10:00:46 +00:00
|
|
|
handle = http_prefix + "://" + domain_full + "/@" + nickname
|
2022-01-02 14:51:02 +00:00
|
|
|
wf_request = \
|
2021-12-29 21:55:09 +00:00
|
|
|
webfinger_handle(session, handle, http_prefix,
|
|
|
|
cached_webfingers,
|
|
|
|
domain, project_version, debug, False,
|
|
|
|
signing_priv_key_pem)
|
2022-01-02 14:51:02 +00:00
|
|
|
if not wf_request:
|
2022-01-03 17:09:50 +00:00
|
|
|
return dot_graph_str + '}\n'
|
2022-01-02 14:51:02 +00:00
|
|
|
if not isinstance(wf_request, dict):
|
2020-07-08 12:28:41 +00:00
|
|
|
print('Webfinger for ' + handle + ' did not return a dict. ' +
|
2022-01-02 14:51:02 +00:00
|
|
|
str(wf_request))
|
2022-01-03 17:09:50 +00:00
|
|
|
return dot_graph_str + '}\n'
|
2020-07-08 12:28:41 +00:00
|
|
|
|
2022-01-03 17:09:50 +00:00
|
|
|
origin_domain = None
|
|
|
|
(person_url, _, _, _, _, _,
|
|
|
|
_, _) = get_person_box(signing_priv_key_pem,
|
|
|
|
origin_domain,
|
|
|
|
base_dir, session, wf_request,
|
|
|
|
person_cache,
|
|
|
|
project_version, http_prefix,
|
|
|
|
nickname, domain, 'outbox',
|
2023-10-25 19:55:40 +00:00
|
|
|
27261, system_language)
|
2022-01-03 17:09:50 +00:00
|
|
|
word_frequency = {}
|
|
|
|
post_domains = \
|
2022-05-31 17:13:28 +00:00
|
|
|
get_post_domains(session, person_url, 64, debug,
|
2021-12-29 21:55:09 +00:00
|
|
|
project_version, http_prefix, domain,
|
2022-01-03 17:09:50 +00:00
|
|
|
word_frequency, [], system_language,
|
2021-12-29 21:55:09 +00:00
|
|
|
signing_priv_key_pem)
|
2022-01-03 17:09:50 +00:00
|
|
|
post_domains.sort()
|
|
|
|
for fed_domain in post_domains:
|
|
|
|
dot_line_str = ' "' + domain + '" -> "' + fed_domain + '";\n'
|
|
|
|
if dot_line_str not in dot_graph_str:
|
|
|
|
dot_graph_str += dot_line_str
|
|
|
|
return dot_graph_str + '}\n'
|