create a StorageClientConfig object

Make it easier to pass more storage configuration down into StorageFarmBroker
and beyond
This commit is contained in:
Jean-Paul Calderone
2019-06-28 14:24:58 -04:00
parent 6e3cd2d91c
commit b5a2c70a4a
2 changed files with 29 additions and 5 deletions

View File

@ -536,8 +536,9 @@ def create_storage_farm_broker(config, default_connection_handlers, foolscap_con
:param list introducer_clients: IntroducerClient instances if :param list introducer_clients: IntroducerClient instances if
we're connecting to any we're connecting to any
""" """
ps = config.get_config("client", "peers.preferred", "").split(",") storage_client_config = storage_client.StorageClientConfig.from_node_config(
preferred_peers = tuple([p.strip() for p in ps if p != ""]) config,
)
def tub_creator(handler_overrides=None, **kwargs): def tub_creator(handler_overrides=None, **kwargs):
return node.create_tub( return node.create_tub(
@ -551,7 +552,7 @@ def create_storage_farm_broker(config, default_connection_handlers, foolscap_con
sb = storage_client.StorageFarmBroker( sb = storage_client.StorageFarmBroker(
permute_peers=True, permute_peers=True,
tub_maker=tub_creator, tub_maker=tub_creator,
preferred_peers=preferred_peers, storage_client_config=storage_client_config,
) )
for ic in introducer_clients: for ic in introducer_clients:
sb.use_introducer(ic) sb.use_introducer(ic)

View File

@ -69,7 +69,17 @@ from allmydata.util.hashutil import permute_server_hash
# look like? # look like?
# don't pass signatures: only pass validated blessed-objects # don't pass signatures: only pass validated blessed-objects
@attr.s
class StorageClientConfig(object):
preferred_peers = attr.ib(default=())
@classmethod
def from_node_config(cls, config):
ps = config.get_config("client", "peers.preferred", "").split(",")
preferred_peers = tuple([p.strip() for p in ps if p != ""])
return cls(
preferred_peers,
)
@implementer(IStorageBroker) @implementer(IStorageBroker)
class StorageFarmBroker(service.MultiService): class StorageFarmBroker(service.MultiService):
"""I live on the client, and know about storage servers. For each server """I live on the client, and know about storage servers. For each server
@ -78,12 +88,25 @@ class StorageFarmBroker(service.MultiService):
I'm also responsible for subscribing to the IntroducerClient to find out I'm also responsible for subscribing to the IntroducerClient to find out
about new servers as they are announced by the Introducer. about new servers as they are announced by the Introducer.
""" """
def __init__(self, permute_peers, tub_maker, preferred_peers=()):
@property
def preferred_peers(self):
return self.storage_client_config.preferred_peers
def __init__(
self,
permute_peers,
tub_maker,
storage_client_config=None,
):
service.MultiService.__init__(self) service.MultiService.__init__(self)
assert permute_peers # False not implemented yet assert permute_peers # False not implemented yet
self.permute_peers = permute_peers self.permute_peers = permute_peers
self._tub_maker = tub_maker self._tub_maker = tub_maker
self.preferred_peers = preferred_peers
if storage_client_config is None:
storage_client_config = StorageClientConfig()
self.storage_client_config = storage_client_config
# self.servers maps serverid -> IServer, and keeps track of all the # self.servers maps serverid -> IServer, and keeps track of all the
# storage servers that we've heard about. Each descriptor manages its # storage servers that we've heard about. Each descriptor manages its