Changeset c6fc8266 in trunk
- Timestamp:
- 2022-11-29T14:33:05Z (2 years ago)
- Branches:
- master
- Children:
- c4c9d138
- Parents:
- 537ab5c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/storage_client.py ¶
r537ab5c rc6fc8266 34 34 35 35 from six import ensure_text 36 from typing import Union 36 from typing import Union, Callable, Optional 37 37 import re, time, hashlib 38 38 from os import urandom … … 58 58 log_call, 59 59 ) 60 from foolscap.ipb import IRemoteReference 60 61 from foolscap.api import eventually, RemoteException 61 62 from foolscap.reconnector import ( … … 81 82 ReadVector, TestWriteVectors, WriteVector, TestVector, ClientException 82 83 ) 84 from .node import _Config 85 86 _log = Logger() 83 87 84 88 ANONYMOUS_STORAGE_NURLS = "anonymous-storage-NURLs" … … 733 737 734 738 739 def _make_storage_system( 740 node_config: _Config, 741 config: StorageClientConfig, 742 ann: dict, 743 server_id: bytes, 744 get_rref: Callable[[], Optional[IRemoteReference]], 745 ) -> IFoolscapStorageServer: 746 """ 747 Create an object for interacting with the storage server described by 748 the given announcement. 749 750 :param node_config: The node configuration to pass to any configured 751 storage plugins. 752 753 :param config: Configuration specifying desired storage client behavior. 754 755 :param ann: The storage announcement from the storage server we are meant 756 to communicate with. 757 758 :param server_id: The unique identifier for the server. 759 760 :param get_rref: A function which returns a remote reference to the 761 server-side object which implements this storage system, if one is 762 available (otherwise None). 763 764 :return: An object enabling communication via Foolscap with the server 765 which generated the announcement. 766 """ 767 # Try to match the announcement against a plugin. 768 try: 769 furl, storage_server = _storage_from_foolscap_plugin( 770 node_config, 771 config, 772 ann, 773 # Pass in an accessor for our _rref attribute. The value of 774 # the attribute may change over time as connections are lost 775 # and re-established. The _StorageServer should always be 776 # able to get the most up-to-date value. 777 get_rref, 778 ) 779 except AnnouncementNotMatched as e: 780 _log.error( 781 'No plugin for storage-server "{nickname}" from plugins: {plugins}', 782 nickname=ann.get("nickname", "<unknown>"), 783 plugins=e.args[0], 784 ) 785 except MissingPlugin as e: 786 _log.failure("Missing plugin") 787 ns = _NullStorage() 788 ns.longname = '<missing plugin "{}">'.format(e.args[0]) 789 return ns 790 else: 791 return _FoolscapStorage.from_announcement( 792 server_id, 793 furl, 794 ann, 795 storage_server, 796 ) 797 798 # Try to match the announcement against the anonymous access scheme. 799 try: 800 furl = ann[u"anonymous-storage-FURL"] 801 except KeyError: 802 # Nope 803 pass 804 else: 805 # See comment above for the _storage_from_foolscap_plugin case 806 # about passing in get_rref. 807 storage_server = _StorageServer(get_rref=get_rref) 808 return _FoolscapStorage.from_announcement( 809 server_id, 810 furl, 811 ann, 812 storage_server, 813 ) 814 815 # Nothing matched so we can't talk to this server. 816 return _null_storage 817 735 818 @implementer(IServer) 736 819 class NativeStorageServer(service.MultiService): … … 759 842 "application-version": "unknown: no get_version()", 760 843 }) 761 log = Logger()762 844 763 845 def __init__(self, server_id, ann, tub_maker, handler_overrides, node_config, config=StorageClientConfig()): … … 769 851 self._handler_overrides = handler_overrides 770 852 771 self._storage = self._make_storage_system(node_config, config, ann)853 self._storage = _make_storage_system(node_config, config, ann, self._server_id, self.get_rref) 772 854 773 855 self.last_connect_time = None … … 778 860 self._trigger_cb = None 779 861 self._on_status_changed = ObserverList() 780 781 def _make_storage_system(self, node_config, config, ann):782 """783 :param allmydata.node._Config node_config: The node configuration to pass784 to any configured storage plugins.785 786 :param StorageClientConfig config: Configuration specifying desired787 storage client behavior.788 789 :param dict ann: The storage announcement from the storage server we790 are meant to communicate with.791 792 :return IFoolscapStorageServer: An object enabling communication via793 Foolscap with the server which generated the announcement.794 """795 # Try to match the announcement against a plugin.796 try:797 furl, storage_server = _storage_from_foolscap_plugin(798 node_config,799 config,800 ann,801 # Pass in an accessor for our _rref attribute. The value of802 # the attribute may change over time as connections are lost803 # and re-established. The _StorageServer should always be804 # able to get the most up-to-date value.805 self.get_rref,806 )807 except AnnouncementNotMatched as e:808 self.log.error(809 'No plugin for storage-server "{nickname}" from plugins: {plugins}',810 nickname=ann.get("nickname", "<unknown>"),811 plugins=e.args[0],812 )813 except MissingPlugin as e:814 self.log.failure("Missing plugin")815 ns = _NullStorage()816 ns.longname = '<missing plugin "{}">'.format(e.args[0])817 return ns818 else:819 return _FoolscapStorage.from_announcement(820 self._server_id,821 furl,822 ann,823 storage_server,824 )825 826 # Try to match the announcement against the anonymous access scheme.827 try:828 furl = ann[u"anonymous-storage-FURL"]829 except KeyError:830 # Nope831 pass832 else:833 # See comment above for the _storage_from_foolscap_plugin case834 # about passing in get_rref.835 storage_server = _StorageServer(get_rref=self.get_rref)836 return _FoolscapStorage.from_announcement(837 self._server_id,838 furl,839 ann,840 storage_server,841 )842 843 # Nothing matched so we can't talk to this server.844 return _null_storage845 862 846 863 def get_permutation_seed(self):
Note: See TracChangeset
for help on using the changeset viewer.