mirror of https://gitlab.com/bashrc2/epicyon
Create sessions for sending posts if needed
parent
e8de643760
commit
f9812ce1ed
|
|
@ -668,6 +668,7 @@ def post_message_to_outbox(session, translate: {},
|
||||||
version,
|
version,
|
||||||
shared_items_federated_domains,
|
shared_items_federated_domains,
|
||||||
shared_item_federation_tokens,
|
shared_item_federation_tokens,
|
||||||
signing_priv_key_pem)
|
signing_priv_key_pem,
|
||||||
|
proxy_type)
|
||||||
followers_threads.append(named_addresses_thread)
|
followers_threads.append(named_addresses_thread)
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
33
posts.py
33
posts.py
|
|
@ -3002,7 +3002,8 @@ def _send_to_named_addresses(session, session_onion, session_i2p,
|
||||||
project_version: str,
|
project_version: str,
|
||||||
shared_items_federated_domains: [],
|
shared_items_federated_domains: [],
|
||||||
shared_item_federation_tokens: {},
|
shared_item_federation_tokens: {},
|
||||||
signing_priv_key_pem: str) -> None:
|
signing_priv_key_pem: str,
|
||||||
|
proxy_type: str) -> None:
|
||||||
"""sends a post to the specific named addresses in to/cc
|
"""sends a post to the specific named addresses in to/cc
|
||||||
"""
|
"""
|
||||||
if not session:
|
if not session:
|
||||||
|
|
@ -3114,6 +3115,7 @@ def _send_to_named_addresses(session, session_onion, session_i2p,
|
||||||
from_domain_full = get_full_domain(domain, port)
|
from_domain_full = get_full_domain(domain, port)
|
||||||
from_http_prefix = http_prefix
|
from_http_prefix = http_prefix
|
||||||
curr_session = session
|
curr_session = session
|
||||||
|
curr_proxy_type = proxy_type
|
||||||
if onion_domain:
|
if onion_domain:
|
||||||
if not from_domain.endswith('.onion') and \
|
if not from_domain.endswith('.onion') and \
|
||||||
to_domain.endswith('.onion'):
|
to_domain.endswith('.onion'):
|
||||||
|
|
@ -3123,6 +3125,7 @@ def _send_to_named_addresses(session, session_onion, session_i2p,
|
||||||
curr_session = session_onion
|
curr_session = session_onion
|
||||||
port = 80
|
port = 80
|
||||||
to_port = 80
|
to_port = 80
|
||||||
|
curr_proxy_type = 'tor'
|
||||||
if i2p_domain:
|
if i2p_domain:
|
||||||
if not from_domain.endswith('.i2p') and \
|
if not from_domain.endswith('.i2p') and \
|
||||||
to_domain.endswith('.i2p'):
|
to_domain.endswith('.i2p'):
|
||||||
|
|
@ -3132,6 +3135,7 @@ def _send_to_named_addresses(session, session_onion, session_i2p,
|
||||||
curr_session = session_i2p
|
curr_session = session_i2p
|
||||||
port = 80
|
port = 80
|
||||||
to_port = 80
|
to_port = 80
|
||||||
|
curr_proxy_type = 'i2p'
|
||||||
cc_list = []
|
cc_list = []
|
||||||
|
|
||||||
# if the "to" domain is within the shared items
|
# if the "to" domain is within the shared items
|
||||||
|
|
@ -3145,6 +3149,10 @@ def _send_to_named_addresses(session, session_onion, session_i2p,
|
||||||
|
|
||||||
group_account = has_group_type(base_dir, address, person_cache)
|
group_account = has_group_type(base_dir, address, person_cache)
|
||||||
|
|
||||||
|
if not curr_session:
|
||||||
|
# TODO add this to the server object
|
||||||
|
curr_session = create_session(curr_proxy_type)
|
||||||
|
|
||||||
send_signed_json(post_json_object, curr_session, base_dir,
|
send_signed_json(post_json_object, curr_session, base_dir,
|
||||||
nickname, from_domain, port,
|
nickname, from_domain, port,
|
||||||
to_nickname, to_domain, to_port,
|
to_nickname, to_domain, to_port,
|
||||||
|
|
@ -3168,7 +3176,8 @@ def send_to_named_addresses_thread(session, session_onion, session_i2p,
|
||||||
project_version: str,
|
project_version: str,
|
||||||
shared_items_federated_domains: [],
|
shared_items_federated_domains: [],
|
||||||
shared_item_federation_tokens: {},
|
shared_item_federation_tokens: {},
|
||||||
signing_priv_key_pem: str):
|
signing_priv_key_pem: str,
|
||||||
|
proxy_type: str):
|
||||||
"""Returns a thread used to send a post to named addresses
|
"""Returns a thread used to send a post to named addresses
|
||||||
"""
|
"""
|
||||||
print('THREAD: _send_to_named_addresses')
|
print('THREAD: _send_to_named_addresses')
|
||||||
|
|
@ -3184,7 +3193,8 @@ def send_to_named_addresses_thread(session, session_onion, session_i2p,
|
||||||
project_version,
|
project_version,
|
||||||
shared_items_federated_domains,
|
shared_items_federated_domains,
|
||||||
shared_item_federation_tokens,
|
shared_item_federation_tokens,
|
||||||
signing_priv_key_pem), daemon=True)
|
signing_priv_key_pem,
|
||||||
|
proxy_type), daemon=True)
|
||||||
try:
|
try:
|
||||||
send_thread.start()
|
send_thread.start()
|
||||||
except SocketError as ex:
|
except SocketError as ex:
|
||||||
|
|
@ -3264,6 +3274,12 @@ def send_to_followers(session, session_onion, session_i2p,
|
||||||
# this is after the message has arrived at the server
|
# this is after the message has arrived at the server
|
||||||
client_to_server = False
|
client_to_server = False
|
||||||
|
|
||||||
|
curr_proxy_type = None
|
||||||
|
if domain.endswith('.onion'):
|
||||||
|
curr_proxy_type = 'tor'
|
||||||
|
elif domain.endswith('.i2p'):
|
||||||
|
curr_proxy_type = 'i2p'
|
||||||
|
|
||||||
# for each instance
|
# for each instance
|
||||||
sending_start_time = datetime.datetime.utcnow()
|
sending_start_time = datetime.datetime.utcnow()
|
||||||
print('Sending post to followers begins ' +
|
print('Sending post to followers begins ' +
|
||||||
|
|
@ -3307,10 +3323,6 @@ def send_to_followers(session, session_onion, session_i2p,
|
||||||
if follower_domain.endswith('.i2p'):
|
if follower_domain.endswith('.i2p'):
|
||||||
curr_session = session_i2p
|
curr_session = session_i2p
|
||||||
curr_http_prefix = 'http'
|
curr_http_prefix = 'http'
|
||||||
if not curr_session:
|
|
||||||
print('WARN: session not found when sending to follower ' +
|
|
||||||
follower_domain_url)
|
|
||||||
continue
|
|
||||||
|
|
||||||
with_shared_inbox = \
|
with_shared_inbox = \
|
||||||
_has_shared_inbox(curr_session, curr_http_prefix, follower_domain,
|
_has_shared_inbox(curr_session, curr_http_prefix, follower_domain,
|
||||||
|
|
@ -3335,18 +3347,25 @@ def send_to_followers(session, session_onion, session_i2p,
|
||||||
# have an alt onion domain then use the alt
|
# have an alt onion domain then use the alt
|
||||||
from_domain = domain
|
from_domain = domain
|
||||||
from_http_prefix = http_prefix
|
from_http_prefix = http_prefix
|
||||||
|
|
||||||
if onion_domain:
|
if onion_domain:
|
||||||
if to_domain.endswith('.onion'):
|
if to_domain.endswith('.onion'):
|
||||||
from_domain = onion_domain
|
from_domain = onion_domain
|
||||||
from_http_prefix = 'http'
|
from_http_prefix = 'http'
|
||||||
port = 80
|
port = 80
|
||||||
to_port = 80
|
to_port = 80
|
||||||
|
curr_proxy_type = 'tor'
|
||||||
if i2p_domain:
|
if i2p_domain:
|
||||||
if to_domain.endswith('.i2p'):
|
if to_domain.endswith('.i2p'):
|
||||||
from_domain = i2p_domain
|
from_domain = i2p_domain
|
||||||
from_http_prefix = 'http'
|
from_http_prefix = 'http'
|
||||||
port = 80
|
port = 80
|
||||||
to_port = 80
|
to_port = 80
|
||||||
|
curr_proxy_type = 'i2p'
|
||||||
|
|
||||||
|
if not curr_session:
|
||||||
|
# TODO add this to the server object
|
||||||
|
curr_session = create_session(curr_proxy_type)
|
||||||
|
|
||||||
if with_shared_inbox:
|
if with_shared_inbox:
|
||||||
to_nickname = follower_handles[index].split('@')[0]
|
to_nickname = follower_handles[index].split('@')[0]
|
||||||
|
|
|
||||||
2
tests.py
2
tests.py
|
|
@ -1457,7 +1457,7 @@ def test_post_message_between_servers(base_dir: str) -> None:
|
||||||
bob_domain, None, None)
|
bob_domain, None, None)
|
||||||
announce_message_arrived = False
|
announce_message_arrived = False
|
||||||
outbox_message_arrived = False
|
outbox_message_arrived = False
|
||||||
for i in range(10):
|
for i in range(20):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
if not os.path.isdir(inbox_path):
|
if not os.path.isdir(inbox_path):
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue