Improve handling of yggdrasil addresses

main
bashrc 2026-08-28 16:47:29 +01:00
parent 11b4184f00
commit 54a7d1d36a
12 changed files with 70 additions and 26 deletions

View File

@ -468,7 +468,7 @@ def _accept_follow(base_dir: str, message_json: {},
followed_actor)
return
# convert from onion/i2p to clearnet accepted domain
# convert from onion/i2p/yggdrasil to clearnet accepted domain
if onion_domain:
if accepted_domain.endswith('.onion') and \
not curr_domain.endswith('.onion'):

View File

@ -2405,19 +2405,26 @@ def daemon_http_get(self) -> None:
self.server.debug)
if self.path.endswith('/about'):
if calling_domain.endswith('.onion'):
if calling_domain.endswith('.onion') and self.server.onion_domain:
msg = \
html_about(self.server.base_dir, 'http',
self.server.onion_domain,
None, self.server.translate,
self.server.system_language)
elif calling_domain.endswith('.i2p'):
elif calling_domain.endswith('.i2p') and self.server.i2p_domain:
msg = \
html_about(self.server.base_dir, 'http',
self.server.i2p_domain,
self.server.yggdrasil_domain,
self.server.translate,
self.server.system_language)
elif (is_yggdrasil_address(calling_domain) and
self.server.yggdrasil_domain):
msg = \
html_about(self.server.base_dir, 'http',
self.server.yggdrasil_domain,
None, self.server.translate,
self.server.system_language)
else:
msg = \
html_about(self.server.base_dir,
@ -6683,7 +6690,8 @@ def _get_ontology(self, calling_domain: str,
ontology_file.replace('static.datafoodconsortium.org',
calling_domain)
if not calling_domain.endswith('.i2p') and \
not calling_domain.endswith('.onion'):
not calling_domain.endswith('.onion') and \
not is_yggdrasil_address(calling_domain):
ontology_file = \
ontology_file.replace('http://' +
calling_domain,

View File

@ -275,15 +275,17 @@ def _person_options_view(self, options_confirm_params: str,
# establish the session
curr_proxy_type = proxy_type
if '.onion/' in profile_handle or \
profile_handle.endswith('.onion'):
if (('.onion/' in profile_handle or
profile_handle.endswith('.onion')) and self.server.session_onion):
curr_proxy_type = 'tor'
curr_session = self.server.session_onion
elif ('.i2p/' in profile_handle or
profile_handle.endswith('.i2p')):
elif (('.i2p/' in profile_handle or
profile_handle.endswith('.i2p')) and
self.server.session_i2p):
curr_proxy_type = 'i2p'
curr_session = self.server.session_i2p
elif is_yggdrasil_url(profile_handle):
elif (is_yggdrasil_url(profile_handle) and
self.server.session_yggdrasil):
curr_proxy_type = 'yggdrasil'
curr_session = self.server.session_yggdrasil

View File

@ -584,15 +584,17 @@ def _receive_search_handle(self, search_str: str,
# establish the session
curr_proxy_type = proxy_type
if '.onion/' in profile_handle or \
profile_handle.endswith('.onion'):
if (('.onion/' in profile_handle or
profile_handle.endswith('.onion')) and self.server.session_onion):
curr_proxy_type = 'tor'
curr_session = self.server.session_onion
elif ('.i2p/' in profile_handle or
profile_handle.endswith('.i2p')):
elif (('.i2p/' in profile_handle or
profile_handle.endswith('.i2p')) and
self.server.session_i2p):
curr_proxy_type = 'i2p'
curr_session = self.server.session_i2p
elif is_yggdrasil_url(profile_handle):
elif (is_yggdrasil_url(profile_handle) and
self.server.session_yggdrasil):
curr_proxy_type = 'yggdrasil'
curr_session = self.server.session_yggdrasil

View File

@ -22,6 +22,7 @@ from src.categories import set_hashtag_category
from src.flags import is_suspended
from src.flags import is_local_network_address
from src.flags import is_public_post
from src.utils import local_network_host
from src.utils import is_yggdrasil_address
from src.utils import data_dir
from src.utils import string_contains
@ -159,7 +160,10 @@ def get_newswire_favicon_url(url: str) -> str:
if '://' not in url:
return '/newswire_favicon.ico'
if url.startswith('http://'):
if not (url.endswith('.onion') or url.endswith('.i2p')):
if not (url.endswith('.onion') or
url.endswith('.i2p') or
is_yggdrasil_address(url) or
local_network_host(url)):
return '/newswire_favicon.ico'
domain: str = url.split('://')[1]
if '/' not in domain:

View File

@ -15,6 +15,8 @@ from src.utils import resembles_url
from src.utils import get_nickname_from_actor
from src.utils import get_domain_from_actor
from src.utils import get_full_domain
from src.utils import is_yggdrasil_address
from src.utils import local_network_host
pixelfed_fieldnames = ('pixelfed', 'fotos', 'photos')
@ -62,7 +64,9 @@ def get_pixelfed(actor_json: {}) -> str:
continue
http_prefix = 'https://'
if domain.endswith('.onion') or \
domain.endswith('.i2p'):
domain.endswith('.i2p') or \
is_yggdrasil_address(domain) or \
local_network_host(domain):
http_prefix = 'http://'
pixelfed_text = \
http_prefix + \

View File

@ -45,6 +45,7 @@ from src.timeFunctions import date_utcnow
from src.timeFunctions import date_from_string_format
from src.timeFunctions import date_epoch
from src.timeFunctions import valid_post_date
from src.utils import local_network_host
from src.utils import resembles_domain
from src.utils import string_starts_with
from src.utils import is_yggdrasil_address
@ -3542,7 +3543,10 @@ def send_signed_json(post_json_object: {}, session, base_dir: str,
return 8
with_digest = True
if to_domain.endswith('.onion') or to_domain.endswith('.i2p'):
if to_domain.endswith('.onion') or \
to_domain.endswith('.i2p') or \
is_yggdrasil_address(to_domain) or \
local_network_host(to_domain):
http_prefix = 'http'
if to_nickname == 'inbox':
@ -3698,7 +3702,8 @@ def send_signed_json(post_json_object: {}, session, base_dir: str,
domain + ' ' + curr_domain)
if domain != curr_domain:
if not curr_domain.endswith('.onion') and \
not curr_domain.endswith('.i2p'):
not curr_domain.endswith('.i2p') and \
not is_yggdrasil_address(curr_domain):
if debug:
print('send_signed_json ' +
'changing post content sender domain from ' +

View File

@ -14,6 +14,7 @@ from socket import error as SocketError
from http.client import HTTPConnection
from src.flags import is_image_file
from src.flags import url_permitted
from src.utils import local_network_host
from src.utils import get_port_from_domain
from src.utils import remove_domain_port
from src.utils import text_in_file
@ -520,7 +521,10 @@ def verify_html(session, url: str, debug: bool,
domain + '/users/' + nickname
]
for actor in actor_links:
if domain.endswith('.onion') or domain.endswith('.i2p'):
if domain.endswith('.onion') or \
domain.endswith('.i2p') or \
is_yggdrasil_address(domain) or \
local_network_host(domain):
actor = 'http://' + actor
else:
actor = http_prefix + '://' + actor

View File

@ -12,6 +12,7 @@ import http.client
import ssl
import socket
from urllib.parse import urlparse
from src.utils import local_network_host
from src.utils import data_dir
from src.utils import string_starts_with
from src.utils import is_yggdrasil_address
@ -113,7 +114,8 @@ def site_is_active(url: str, timeout: int,
return False
if '.onion/' in url or '.i2p/' in url or \
url.endswith('.onion') or \
url.endswith('.i2p'):
url.endswith('.i2p') or \
local_network_host(url):
# skip this check for onion and i2p
return True
if 'http://' in url:

View File

@ -583,9 +583,10 @@ def decoded_host(host: str) -> str:
if ':' not in host:
# eg. mydomain:8000
if not local_network_host(host):
if not host.endswith('.onion'):
if not host.endswith('.i2p'):
return idna.decode(host)
if not host.endswith('.onion') and \
not host.endswith('.i2p') and \
not is_yggdrasil_address(host):
return idna.decode(host)
return host
@ -3059,7 +3060,9 @@ def get_alt_path(actor: str, domain_full: str, calling_domain: str) -> str:
post_actor: str = actor
if calling_domain not in actor and domain_full in actor:
if calling_domain.endswith('.onion') or \
calling_domain.endswith('.i2p'):
calling_domain.endswith('.i2p') or \
is_yggdrasil_address(calling_domain) or \
local_network_host(calling_domain):
post_actor = \
'http://' + calling_domain + actor.split(domain_full)[1]
print('Changed POST domain from ' + actor + ' to ' + post_actor)

View File

@ -10,6 +10,8 @@ __module_group__ = "Timeline"
from src.utils import data_dir
from src.utils import string_ends_with
from src.utils import valid_url_prefix
from src.utils import is_yggdrasil_address
from src.utils import local_network_host
from src.data import load_string
from src.data import is_a_file
@ -263,7 +265,10 @@ def _add_embedded_video_from_sites(content: str,
site = site.replace('http://', '')
elif site.startswith('https://'):
site = site.replace('https://', '')
if site.endswith('.onion') or site.endswith('.i2p'):
if site.endswith('.onion') or \
site.endswith('.i2p') or \
is_yggdrasil_address(site) or \
local_network_host(site):
site_str = 'http://' + site
else:
site_str = 'https://' + site
@ -329,7 +334,10 @@ def _add_embedded_video_from_sites(content: str,
site = site.replace('http://', '')
elif site.startswith('https://'):
site = site.replace('https://', '')
if site.endswith('.onion') or site.endswith('.i2p'):
if site.endswith('.onion') or \
site.endswith('.i2p') or \
is_yggdrasil_address(site) or \
local_network_host(site):
site_str = 'http://' + site
else:
site_str = 'https://' + site

View File

@ -15,6 +15,7 @@ from src.session import get_json_valid
from src.flags import is_float
from src.flags import is_moderator
from src.formats import media_file_mime_type
from src.utils import is_yggdrasil_address
from src.utils import get_preferred_username
from src.utils import replace_embedded_map_with_link
from src.utils import chatbot_nicknames
@ -2521,6 +2522,7 @@ def html_known_epicyon_instances(base_dir: str, http_prefix: str,
http_prefix = 'https'
if instance.endswith('.onion') or \
instance.endswith('.i2p') or \
is_yggdrasil_address(instance) or \
local_network_host(instance):
http_prefix = 'http'
instances_text += \