2020-07-08 12:28:41 +00:00
|
|
|
__filename__ = "socnet.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
2021-01-26 10:07:42 +00:00
|
|
|
__version__ = "1.2.0"
|
2020-07-08 12:28:41 +00:00
|
|
|
__maintainer__ = "Bob Mottram"
|
|
|
|
__email__ = "bob@freedombone.net"
|
|
|
|
__status__ = "Production"
|
2021-06-26 11:16:41 +00:00
|
|
|
__module_group__ = "Moderation"
|
2020-07-08 12:28:41 +00:00
|
|
|
|
|
|
|
from session import createSession
|
|
|
|
from webfinger import webfingerHandle
|
|
|
|
from posts import getPersonBox
|
|
|
|
from posts import getPostDomains
|
2020-12-16 11:38:40 +00:00
|
|
|
from utils import getFullDomain
|
2020-07-08 12:28:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
def instancesGraph(baseDir: str, handles: str,
|
|
|
|
proxyType: str,
|
|
|
|
port: int, httpPrefix: str,
|
2021-07-18 14:15:16 +00:00
|
|
|
debug: bool, projectVersion: str,
|
2021-08-31 14:17:11 +00:00
|
|
|
systemLanguage: str, signingPrivateKeyPem: 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
|
|
|
|
"""
|
|
|
|
dotGraphStr = 'digraph instances {\n'
|
|
|
|
if ',' not in handles:
|
|
|
|
return dotGraphStr + '}\n'
|
|
|
|
session = createSession(proxyType)
|
|
|
|
if not session:
|
|
|
|
return dotGraphStr + '}\n'
|
|
|
|
|
|
|
|
personCache = {}
|
|
|
|
cachedWebfingers = {}
|
|
|
|
federationList = []
|
|
|
|
maxMentions = 99
|
|
|
|
maxEmoji = 99
|
|
|
|
maxAttachments = 5
|
|
|
|
|
|
|
|
personHandles = handles.split(',')
|
|
|
|
for handle in personHandles:
|
|
|
|
handle = handle.strip()
|
|
|
|
if handle.startswith('@'):
|
|
|
|
handle = handle[1:]
|
|
|
|
if '@' not in handle:
|
|
|
|
continue
|
|
|
|
|
|
|
|
nickname = handle.split('@')[0]
|
|
|
|
domain = handle.split('@')[1]
|
|
|
|
|
2020-12-16 11:38:40 +00:00
|
|
|
domainFull = getFullDomain(domain, port)
|
2020-07-08 12:28:41 +00:00
|
|
|
handle = httpPrefix + "://" + domainFull + "/@" + nickname
|
|
|
|
wfRequest = \
|
|
|
|
webfingerHandle(session, handle, httpPrefix,
|
|
|
|
cachedWebfingers,
|
2021-08-31 14:17:11 +00:00
|
|
|
domain, projectVersion, debug, False,
|
|
|
|
signingPrivateKeyPem)
|
2020-07-08 12:28:41 +00:00
|
|
|
if not wfRequest:
|
|
|
|
return dotGraphStr + '}\n'
|
|
|
|
if not isinstance(wfRequest, dict):
|
|
|
|
print('Webfinger for ' + handle + ' did not return a dict. ' +
|
|
|
|
str(wfRequest))
|
|
|
|
return dotGraphStr + '}\n'
|
|
|
|
|
|
|
|
(personUrl, pubKeyId, pubKey,
|
|
|
|
personId, shaedInbox,
|
2021-08-31 14:17:11 +00:00
|
|
|
avatarUrl, displayName) = getPersonBox(signingPrivateKeyPem,
|
|
|
|
baseDir, session, wfRequest,
|
2020-07-08 12:28:41 +00:00
|
|
|
personCache,
|
|
|
|
projectVersion, httpPrefix,
|
2020-12-18 17:49:17 +00:00
|
|
|
nickname, domain, 'outbox',
|
|
|
|
27261)
|
2021-01-11 13:14:22 +00:00
|
|
|
wordFrequency = {}
|
2020-07-08 12:28:41 +00:00
|
|
|
postDomains = \
|
|
|
|
getPostDomains(session, personUrl, 64, maxMentions, maxEmoji,
|
|
|
|
maxAttachments, federationList,
|
|
|
|
personCache, debug,
|
2021-01-11 13:14:22 +00:00
|
|
|
projectVersion, httpPrefix, domain,
|
2021-08-31 14:17:11 +00:00
|
|
|
wordFrequency, [], systemLanguage,
|
|
|
|
signingPrivateKeyPem)
|
2020-07-08 12:28:41 +00:00
|
|
|
postDomains.sort()
|
|
|
|
for fedDomain in postDomains:
|
|
|
|
dotLineStr = ' "' + domain + '" -> "' + fedDomain + '";\n'
|
|
|
|
if dotLineStr not in dotGraphStr:
|
|
|
|
dotGraphStr += dotLineStr
|
|
|
|
return dotGraphStr + '}\n'
|