Follow accept supports sending to onion and i2p handles

merge-requests/30/head
Bob Mottram 2022-03-12 10:41:36 +00:00
parent ca24fa3265
commit bf43d9cb34
4 changed files with 78 additions and 20 deletions

View File

@ -8423,6 +8423,10 @@ class PubServer(BaseHTTPRequestHandler):
signing_priv_key_pem = \
self.server.signing_priv_key_pem
manual_approve_follow_request_thread(curr_session,
self.server.session_onion,
self.server.session_i2p,
self.server.onion_domain,
self.server.i2p_domain,
base_dir, http_prefix,
follower_nickname,
domain, port,

View File

@ -1262,6 +1262,8 @@ if args.approve:
if '@' not in args.approve:
print('syntax: --approve nick@domain')
sys.exit()
session_onion = None
session_i2p = None
session = create_session(proxy_type)
send_threads = []
postLog = []
@ -1272,8 +1274,19 @@ if args.approve:
signing_priv_key_pem = None
if args.secure_mode:
signing_priv_key_pem = get_instance_actor_key(base_dir, domain)
manual_approve_follow_request(session, base_dir,
http_prefix,
onion_domain = get_config_param(base_dir, 'onionDomain')
if args.onionDomain:
onion_domain = args.onionDomain
if onion_domain:
session_onion = create_session('tor')
i2p_domain = get_config_param(base_dir, 'i2pDomain')
if args.i2pDomain:
i2p_domain = args.i2pDomain
if i2p_domain:
session_i2p = create_session('i2p')
manual_approve_follow_request(session, session_onion, session_i2p,
onion_domain, i2p_domain,
base_dir, http_prefix,
args.nickname, domain, port,
args.approve,
federation_list,

View File

@ -3926,7 +3926,8 @@ def _check_json_signature(base_dir: str, queue_json: {}) -> (bool, bool):
return has_json_signature, jwebsig_type
def _receive_follow_request(session, base_dir: str, http_prefix: str,
def _receive_follow_request(session, session_onion, session_i2p,
base_dir: str, http_prefix: str,
port: int, send_threads: [], post_log: [],
cached_webfingers: {}, person_cache: {},
message_json: {}, federation_list: [],
@ -4012,8 +4013,23 @@ def _receive_follow_request(session, base_dir: str, http_prefix: str,
approve_handle = nickname + '@' + domain_full
curr_session = session
curr_http_prefix = http_prefix
curr_domain = domain
curr_port = from_port
if onion_domain and domain_to_follow.endswith('.onion'):
curr_session = session_onion
curr_http_prefix = 'http'
curr_domain = onion_domain
curr_port = 80
elif i2p_domain and domain_to_follow.endswith('.i2p'):
curr_session = session_i2p
curr_http_prefix = 'http'
curr_domain = i2p_domain
curr_port = 80
# is the actor sending the request valid?
if not valid_sending_actor(session, base_dir,
if not valid_sending_actor(curr_session, base_dir,
nickname_to_follow, domain_to_follow,
person_cache, message_json,
signing_priv_key_pem, debug, unit_test):
@ -4050,9 +4066,11 @@ def _receive_follow_request(session, base_dir: str, http_prefix: str,
# Getting their public key has the same result
if debug:
print('Obtaining the following actor: ' + message_json['actor'])
if not get_person_pub_key(base_dir, session, message_json['actor'],
if not get_person_pub_key(base_dir, curr_session,
message_json['actor'],
person_cache, debug, project_version,
http_prefix, domain_to_follow, onion_domain,
curr_http_prefix,
domain_to_follow, onion_domain,
i2p_domain, signing_priv_key_pem):
if debug:
print('Unable to obtain following actor: ' +
@ -4088,9 +4106,10 @@ def _receive_follow_request(session, base_dir: str, http_prefix: str,
if debug:
print('Obtaining the following actor: ' +
message_json['actor'])
if not get_person_pub_key(base_dir, session, message_json['actor'],
if not get_person_pub_key(base_dir, curr_session,
message_json['actor'],
person_cache, debug, project_version,
http_prefix, domain_to_follow,
curr_http_prefix, domain_to_follow,
onion_domain, i2p_domain,
signing_priv_key_pem):
if debug:
@ -4134,9 +4153,9 @@ def _receive_follow_request(session, base_dir: str, http_prefix: str,
print('EX: unable to write ' + followers_filename)
print('Beginning follow accept')
return followed_account_accepts(session, base_dir, http_prefix,
return followed_account_accepts(curr_session, base_dir, curr_http_prefix,
nickname_to_follow, domain_to_follow, port,
nickname, domain, from_port,
nickname, curr_domain, curr_port,
message_json['actor'], federation_list,
message_json, send_threads, post_log,
cached_webfingers, person_cache,
@ -4504,7 +4523,7 @@ def run_inbox_queue(recent_posts_cache: {}, max_recent_posts: int,
if debug:
print('DEBUG: checking for follow requests')
if _receive_follow_request(curr_session,
if _receive_follow_request(curr_session, session_onion, session_i2p,
base_dir, http_prefix, port,
send_threads, post_log,
cached_webfingers,

View File

@ -120,8 +120,9 @@ def _approve_follower_handle(account_dir: str, approve_handle: str) -> None:
print('EX: unable to write ' + approved_filename)
def manual_approve_follow_request(session, base_dir: str,
http_prefix: str,
def manual_approve_follow_request(session, session_onion, session_i2p,
onion_domain: str, i2p_domain: str,
base_dir: str, http_prefix: str,
nickname: str, domain: str, port: int,
approve_handle: str,
federation_list: [],
@ -206,12 +207,31 @@ def manual_approve_follow_request(session, base_dir: str,
get_port_from_domain(approve_domain)
approve_domain = \
remove_domain_port(approve_domain)
curr_domain = domain
curr_port = port
curr_session = session
curr_http_prefix = http_prefix
if onion_domain and \
approve_domain.endswith('.onion'):
curr_domain = onion_domain
curr_port = 80
curr_session = session_onion
curr_http_prefix = 'http'
elif (i2p_domain and
approve_domain.endswith('.i2p')):
curr_domain = i2p_domain
curr_port = 80
curr_session = session_i2p
curr_http_prefix = 'http'
print('Manual follow accept: Sending Accept for ' +
handle + ' follow request from ' +
approve_nickname + '@' + approve_domain)
followed_account_accepts(session, base_dir,
http_prefix,
nickname, domain, port,
followed_account_accepts(curr_session, base_dir,
curr_http_prefix,
nickname,
curr_domain, curr_port,
approve_nickname,
approve_domain,
approve_port,
@ -281,8 +301,9 @@ def manual_approve_follow_request(session, base_dir: str,
approve_follows_filename + '.new')
def manual_approve_follow_request_thread(session, base_dir: str,
http_prefix: str,
def manual_approve_follow_request_thread(session, session_onion, session_i2p,
onion_domain: str, i2p_domain: str,
base_dir: str, http_prefix: str,
nickname: str, domain: str, port: int,
approve_handle: str,
federation_list: [],
@ -297,8 +318,9 @@ def manual_approve_follow_request_thread(session, base_dir: str,
"""
thr = \
thread_with_trace(target=manual_approve_follow_request,
args=(session, base_dir,
http_prefix,
args=(session, session_onion, session_i2p,
onion_domain, i2p_domain,
base_dir, http_prefix,
nickname, domain, port,
approve_handle,
federation_list,