diff --git a/src/_zkapauthorizer/config.py b/src/_zkapauthorizer/config.py index 064ff52220e67080b6d3dd587b0fd94190b5ae09..b30b43fbf7e3b49091ba8bc8fd4175000ee755fa 100644 --- a/src/_zkapauthorizer/config.py +++ b/src/_zkapauthorizer/config.py @@ -82,6 +82,40 @@ def lease_maintenance_from_tahoe_config(node_config): ) +def get_configured_lease_duration(node_config): + """ + Return the minimum amount of time for which a newly granted lease will + ensure data is stored. + + The actual lease duration is hard-coded in Tahoe-LAFS in many places. + However, we have local configuration that tells us when to renew a lease. + Since lease renewal discards any remaining time on a current lease and + puts a new lease period in its place, starting from the time of the + operation, the amount of time we effectively get from a lease is based on + Tahoe-LAFS' hard-coded lease duration and our own lease renewal + configuration. + + Since this function only promises to return the *minimum* time a client + can expect a lease to last, we respond with a lease time shortened by our + configuration. + + An excellent goal to pursue in the future would be to change the lease + renewal behavior in Tahoe-LAFS so that we can control the length of leases + and/or add to an existing lease instead of replacing it. The former + option would let us really configure lease durations. The latter would + let us stop worrying so much about what is lost by renewing a lease before + the last second of its validity period. + + :return int: The minimum number of seconds for which a newly acquired + lease will be valid. + """ + # See lots of places in Tahoe-LAFS, eg src/allmydata/storage/server.py + upper_bound = 31 * 24 * 60 * 60 + lease_maint_config = lease_maintenance_from_tahoe_config(node_config) + min_time_remaining = lease_maint_config.min_lease_remaining.total_seconds() + return int(upper_bound - min_time_remaining) + + def _read_duration(cfg, option, default): """ Read an integer number of seconds from the ZKAPAuthorizer section of a diff --git a/src/_zkapauthorizer/resource.py b/src/_zkapauthorizer/resource.py index 7b81c26579e36108a2a369271841a6f355f528b2..4f955e2c46304260d40be28a091ced5e43223511 100644 --- a/src/_zkapauthorizer/resource.py +++ b/src/_zkapauthorizer/resource.py @@ -33,12 +33,12 @@ from zope.interface import Attribute from . import __version__ as _zkapauthorizer_version from ._base64 import urlsafe_b64decode +from .config import get_configured_lease_duration from .controller import PaymentController, get_redeemer from .pricecalculator import PriceCalculator from .private import create_private_tree from .storage_common import ( get_configured_allowed_public_keys, - get_configured_lease_duration, get_configured_pass_value, get_configured_shares_needed, get_configured_shares_total, diff --git a/src/_zkapauthorizer/storage_common.py b/src/_zkapauthorizer/storage_common.py index 908a6ec755e6499b77ac28a4fbaeb15d1d04d5d8..9ecefe6e5e9c514c1c863fec093c449aa1cab4b8 100644 --- a/src/_zkapauthorizer/storage_common.py +++ b/src/_zkapauthorizer/storage_common.py @@ -121,17 +121,6 @@ def get_configured_pass_value(node_config): ) -def get_configured_lease_duration(node_config): - """ - Just kidding. Lease duration is hard-coded. - - :return int: The number of seconds after which a newly acquired lease will - be valid. - """ - # See lots of places in Tahoe-LAFS, eg src/allmydata/storage/server.py - return 31 * 24 * 60 * 60 - - def get_configured_allowed_public_keys(node_config): """ Read the set of allowed issuer public keys from the given configuration. diff --git a/src/_zkapauthorizer/tests/test_client_resource.py b/src/_zkapauthorizer/tests/test_client_resource.py index 954ad66d0dcf99d73bff11e75d443b2d1345dfad..490665f4e0b2cf12830e117eb6ef207888d737e0 100644 --- a/src/_zkapauthorizer/tests/test_client_resource.py +++ b/src/_zkapauthorizer/tests/test_client_resource.py @@ -73,6 +73,7 @@ from twisted.web.resource import IResource, getChildForRequest from .. import __version__ as zkapauthorizer_version from .._base64 import urlsafe_b64decode +from ..config import get_configured_lease_duration from ..configutil import config_string_from_sections from ..model import ( DoubleSpend, @@ -88,7 +89,6 @@ from ..pricecalculator import PriceCalculator from ..resource import NUM_TOKENS, from_configuration, get_token_count from ..storage_common import ( get_configured_allowed_public_keys, - get_configured_lease_duration, get_configured_pass_value, required_passes, )