mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-06-26 12:29:30 +00:00
Merge branch 'master' into fix/runner-image-tag
This commit is contained in:
commit
ec4e1f754e
@ -24,5 +24,6 @@ proc process*(
|
|||||||
defer:
|
defer:
|
||||||
destroyShared(self)
|
destroyShared(self)
|
||||||
|
|
||||||
let previous = storage[].node.togglePrivateQueries(self.privateQueries)
|
let previous = storage[].node.togglePrivateQueries(self.privateQueries).valueOr:
|
||||||
|
return err(error.msg)
|
||||||
return ok($previous)
|
return ok($previous)
|
||||||
|
|||||||
@ -262,10 +262,12 @@ proc close*(d: Discovery) {.async: (raises: []).} =
|
|||||||
else:
|
else:
|
||||||
trace "Discovery store closed"
|
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
|
let old = d.privateQueries
|
||||||
d.privateQueries = enabled
|
d.privateQueries = enabled
|
||||||
return old
|
success(old)
|
||||||
|
|
||||||
proc new*(
|
proc new*(
|
||||||
T: type Discovery,
|
T: type Discovery,
|
||||||
|
|||||||
@ -450,8 +450,8 @@ proc iterateManifests*(self: StorageNodeRef, onManifest: OnManifest) {.async.} =
|
|||||||
|
|
||||||
onManifest(cid, manifest)
|
onManifest(cid, manifest)
|
||||||
|
|
||||||
proc togglePrivateQueries*(self: StorageNodeRef, enable: bool): bool =
|
proc togglePrivateQueries*(self: StorageNodeRef, enable: bool): ?!bool =
|
||||||
return self.discovery.togglePrivateQueries(enable)
|
self.discovery.togglePrivateQueries(enable)
|
||||||
|
|
||||||
proc onExpiryUpdate(
|
proc onExpiryUpdate(
|
||||||
self: StorageNodeRef, rootCid: Cid, expiry: SecondsSince1970
|
self: StorageNodeRef, rootCid: Cid, expiry: SecondsSince1970
|
||||||
|
|||||||
@ -120,6 +120,9 @@ proc start*(s: StorageServer) {.async.} =
|
|||||||
|
|
||||||
s.storageNode.discovery.mixProto = mixProto
|
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)
|
s.storageNode.engine.network.excludeRelays(relayPool.keys.toSeq)
|
||||||
|
|
||||||
let (announceAddrs, discoveryAddrs) = nattedAddress(
|
let (announceAddrs, discoveryAddrs) = nattedAddress(
|
||||||
@ -373,11 +376,6 @@ proc new*(
|
|||||||
switch.mount(network)
|
switch.mount(network)
|
||||||
switch.mount(manifestProto)
|
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(
|
StorageServer(
|
||||||
config: config,
|
config: config,
|
||||||
storageNode: storageNode,
|
storageNode: storageNode,
|
||||||
|
|||||||
@ -869,9 +869,9 @@ int check_toggle_private_queries(void *storage_ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ret = is_resp_ok(r, &res);
|
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);
|
free(res);
|
||||||
return RET_ERR;
|
return RET_ERR;
|
||||||
}
|
}
|
||||||
@ -886,7 +886,7 @@ int check_toggle_private_queries(void *storage_ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = is_resp_ok(r, &res);
|
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)");
|
fprintf(stderr, "toggle private queries content mismatch, res:%s\n", res ? res : "(null)");
|
||||||
free(res);
|
free(res);
|
||||||
|
|||||||
@ -151,5 +151,13 @@ asyncchecksuite "Block Advertising and Discovery":
|
|||||||
discovery.refCid = refCid
|
discovery.refCid = refCid
|
||||||
|
|
||||||
check (await discovery.find(refCid)) == @[directSpr]
|
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]
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user