dht: fix persisted permanent values never expiring

When values are exported and re-imported, permanent values retain their
time_point::max() expiration but lose their permanent flag. This caused
them to be stored as non-permanent with an effectively infinite
expiration, so they would never expire.

Cap the expiration of non-permanent values to created + type.expiration,
ensuring that imported permanent values get a finite expiration matching
their value type.
This commit is contained in:
Adrien Béraud committed 2026-05-09 00:39:49 -04:00
1 parent 3ff9338980
commit a363d573e3
1 file changed
+2
+2
View File
@@ -1432,6 +1432,8 @@ Dht::storageStore(const InfoHash& id,
created = std::min(created, now);
if (expiration == time_point::min())
expiration = permanent ? time_point::max() : created + getType(value->type).expiration;
else if (not permanent)
expiration = std::min(expiration, created + getType(value->type).expiration);
if (expiration < now)
return false;