mirror of https://gitlab.com/bashrc2/epicyon
				
				
				
			Cache for follower synchronization results
							parent
							
								
									f1ab81b853
								
							
						
					
					
						commit
						f0de2cda22
					
				
							
								
								
									
										28
									
								
								daemon.py
								
								
								
								
							
							
						
						
									
										28
									
								
								daemon.py
								
								
								
								
							|  | @ -120,6 +120,7 @@ from inbox import save_post_to_inbox_queue | ||||||
| from inbox import populate_replies | from inbox import populate_replies | ||||||
| from inbox import receive_edit_to_post | from inbox import receive_edit_to_post | ||||||
| from follow import get_followers_sync_json | from follow import get_followers_sync_json | ||||||
|  | from follow import get_followers_sync_hash | ||||||
| from follow import follower_approval_active | from follow import follower_approval_active | ||||||
| from follow import is_following_actor | from follow import is_following_actor | ||||||
| from follow import get_following_feed | from follow import get_following_feed | ||||||
|  | @ -16917,12 +16918,24 @@ class PubServer(BaseHTTPRequestHandler): | ||||||
|             # check authorized fetch |             # check authorized fetch | ||||||
|             if self._secure_mode(curr_session, proxy_type): |             if self._secure_mode(curr_session, proxy_type): | ||||||
|                 nickname = get_nickname_from_actor(self.path) |                 nickname = get_nickname_from_actor(self.path) | ||||||
|                 sync_json = \ |                 foll_sync_key = nickname + ':' + calling_domain | ||||||
|                     get_followers_sync_json(self.server.base_dir, |                 sync_dict = self.server.followers_sync_cache | ||||||
|                                             nickname, self.server.domain, |                 if sync_dict.get(foll_sync_key): | ||||||
|                                             self.server.http_prefix, |                     sync_hash = sync_dict[foll_sync_key]['hash'] | ||||||
|                                             self.server.domain_full, |                     sync_json = sync_dict[foll_sync_key]['response'] | ||||||
|                                             calling_domain) |                 else: | ||||||
|  |                     sync_json = \ | ||||||
|  |                         get_followers_sync_json(self.server.base_dir, | ||||||
|  |                                                 nickname, self.server.domain, | ||||||
|  |                                                 self.server.http_prefix, | ||||||
|  |                                                 self.server.domain_full, | ||||||
|  |                                                 calling_domain) | ||||||
|  |                     sync_hash = get_followers_sync_hash(sync_json) | ||||||
|  |                     if sync_hash: | ||||||
|  |                         self.server.followers_sync_cache[foll_sync_key] = { | ||||||
|  |                             "hash": sync_hash, | ||||||
|  |                             "response": sync_json | ||||||
|  |                         } | ||||||
|                 msg_str = json.dumps(sync_json, ensure_ascii=False) |                 msg_str = json.dumps(sync_json, ensure_ascii=False) | ||||||
|                 msg_str = self._convert_domains(calling_domain, referer_domain, |                 msg_str = self._convert_domains(calling_domain, referer_domain, | ||||||
|                                                 msg_str) |                                                 msg_str) | ||||||
|  | @ -23382,6 +23395,9 @@ def run_daemon(max_hashtags: int, | ||||||
|     # lock for followers synchronization |     # lock for followers synchronization | ||||||
|     httpd.followers_synchronization = False |     httpd.followers_synchronization = False | ||||||
| 
 | 
 | ||||||
|  |     # cache containing followers synchronization hashes and json | ||||||
|  |     httpd.followers_sync_cache = {} | ||||||
|  | 
 | ||||||
|     # permitted sites from which the buy button may be displayed |     # permitted sites from which the buy button may be displayed | ||||||
|     httpd.buy_sites = load_buy_sites(base_dir) |     httpd.buy_sites = load_buy_sites(base_dir) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										20
									
								
								follow.py
								
								
								
								
							
							
						
						
									
										20
									
								
								follow.py
								
								
								
								
							|  | @ -9,6 +9,7 @@ __module_group__ = "ActivityPub" | ||||||
| 
 | 
 | ||||||
| from pprint import pprint | from pprint import pprint | ||||||
| import os | import os | ||||||
|  | from hashlib import sha256 | ||||||
| from utils import get_user_paths | from utils import get_user_paths | ||||||
| from utils import acct_handle_dir | from utils import acct_handle_dir | ||||||
| from utils import has_object_string_object | from utils import has_object_string_object | ||||||
|  | @ -1401,6 +1402,7 @@ def _get_followers_for_domain(base_dir: str, | ||||||
|                     break |                     break | ||||||
|         elif '://' + search_domain in line_str: |         elif '://' + search_domain in line_str: | ||||||
|             result.append(line_str) |             result.append(line_str) | ||||||
|  |     result.sort() | ||||||
|     return result |     return result | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -1426,6 +1428,24 @@ def get_followers_sync_json(base_dir: str, | ||||||
|     return sync_json |     return sync_json | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | def get_followers_sync_hash(sync_json: {}) -> str: | ||||||
|  |     """Returns a hash used within the Collection-Synchronization http header | ||||||
|  |     See https://github.com/mastodon/mastodon/pull/14510 | ||||||
|  |     """ | ||||||
|  |     if not sync_json: | ||||||
|  |         return None | ||||||
|  |     sync_hash = None | ||||||
|  |     for actor in sync_json['orderedItems']: | ||||||
|  |         actor_hash = sha256(actor.encode('utf-8')) | ||||||
|  |         if sync_hash: | ||||||
|  |             sync_hash = sync_hash ^ actor_hash | ||||||
|  |         else: | ||||||
|  |             sync_hash = actor_hash | ||||||
|  |     if sync_hash: | ||||||
|  |         sync_hash = sync_hash.hexdigest() | ||||||
|  |     return sync_hash | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def get_followers_of_actor(base_dir: str, actor: str, debug: bool) -> {}: | def get_followers_of_actor(base_dir: str, actor: str, debug: bool) -> {}: | ||||||
|     """In a shared inbox if we receive a post we know who it's from |     """In a shared inbox if we receive a post we know who it's from | ||||||
|     and if it's addressed to followers then we need to get a list of those. |     and if it's addressed to followers then we need to get a list of those. | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue