Merge branch 'master' into fix/runner-image-tag

This commit is contained in:
Giuliano Mega 2026-06-19 15:14:33 -03:00 committed by GitHub
commit ec4e1f754e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 23 additions and 14 deletions

View File

@ -24,5 +24,6 @@ proc process*(
defer:
destroyShared(self)
let previous = storage[].node.togglePrivateQueries(self.privateQueries)
let previous = storage[].node.togglePrivateQueries(self.privateQueries).valueOr:
return err(error.msg)
return ok($previous)

View File

@ -262,10 +262,12 @@ proc close*(d: Discovery) {.async: (raises: []).} =
else:
trace "Discovery store closed"
proc togglePrivateQueries*(d: Discovery, enabled: bool): bool =
proc togglePrivateQueries*(d: Discovery, enabled: bool): ?!bool =
if enabled and (d.mixProto.isNil or d.dhtMixProxies.len == 0):
return failure("Cannot enable private queries: Mix is not configured")
let old = d.privateQueries
d.privateQueries = enabled
return old
success(old)
proc new*(
T: type Discovery,

View File

@ -450,8 +450,8 @@ proc iterateManifests*(self: StorageNodeRef, onManifest: OnManifest) {.async.} =
onManifest(cid, manifest)
proc togglePrivateQueries*(self: StorageNodeRef, enable: bool): bool =
return self.discovery.togglePrivateQueries(enable)
proc togglePrivateQueries*(self: StorageNodeRef, enable: bool): ?!bool =
self.discovery.togglePrivateQueries(enable)
proc onExpiryUpdate(
self: StorageNodeRef, rootCid: Cid, expiry: SecondsSince1970

View File

@ -120,6 +120,9 @@ proc start*(s: StorageServer) {.async.} =
s.storageNode.discovery.mixProto = mixProto
discard s.storageNode.discovery.togglePrivateQueries(s.config.mixEnabled).valueOr:
raise newException(StorageError, "Failed to enable private queries: " & error.msg)
s.storageNode.engine.network.excludeRelays(relayPool.keys.toSeq)
let (announceAddrs, discoveryAddrs) = nattedAddress(
@ -373,11 +376,6 @@ proc new*(
switch.mount(network)
switch.mount(manifestProto)
# Enables private queries by default when mix is enabled.
if config.mixEnabled:
info "Enabling private queries over DHT by default", enabled = config.mixEnabled
discard discovery.togglePrivateQueries(true)
StorageServer(
config: config,
storageNode: storageNode,

View File

@ -869,9 +869,9 @@ int check_toggle_private_queries(void *storage_ctx)
}
int ret = is_resp_ok(r, &res);
if (res == NULL || strcmp(res, "false") != 0)
if (ret == RET_OK)
{
fprintf(stderr, "toggle private queries content mismatch, res:%s\n", res ? res : "(null)");
fprintf(stderr, "expected toggle(true) to fail when mix is not configured, got ok\n");
free(res);
return RET_ERR;
}
@ -886,7 +886,7 @@ int check_toggle_private_queries(void *storage_ctx)
}
ret = is_resp_ok(r, &res);
if (res == NULL || strcmp(res, "true") != 0)
if (res == NULL || strcmp(res, "false") != 0)
{
fprintf(stderr, "toggle private queries content mismatch, res:%s\n", res ? res : "(null)");
free(res);

View File

@ -151,5 +151,13 @@ asyncchecksuite "Block Advertising and Discovery":
discovery.refCid = refCid
check (await discovery.find(refCid)) == @[directSpr]
check discovery.togglePrivateQueries(true) == false
let toggleRes = discovery.togglePrivateQueries(true)
check toggleRes.isOk
check toggleRes.get == false
check (await discovery.find(refCid)) == @[privateSpr]
test "should fail to enable private queries when MixProtocol is nil":
let discovery = MixMockDiscovery.new()
discovery.dhtMixProxies = @[SignedPeerRecord.example]
let res = discovery.togglePrivateQueries(true)
check res.isErr