mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-03-26 22:23:11 +00:00
formatting
# Conflicts: # storage/rest/api.nim # storage/storage.nim
This commit is contained in:
parent
9c0fd2f0c3
commit
2795732e44
@ -52,14 +52,15 @@ proc getDebug(
|
||||
let node = storage[].node
|
||||
let table = RestRoutingTable.init(node.discovery.protocol.routingTable)
|
||||
|
||||
let json = %*{
|
||||
"id": $node.switch.peerInfo.peerId,
|
||||
"addrs": node.switch.peerInfo.addrs.mapIt($it),
|
||||
"spr":
|
||||
if node.discovery.dhtRecord.isSome: node.discovery.dhtRecord.get.toURI else: "",
|
||||
"announceAddresses": node.discovery.announceAddrs,
|
||||
"table": table,
|
||||
}
|
||||
let json =
|
||||
%*{
|
||||
"id": $node.switch.peerInfo.peerId,
|
||||
"addrs": node.switch.peerInfo.addrs.mapIt($it),
|
||||
"spr":
|
||||
if node.discovery.dhtRecord.isSome: node.discovery.dhtRecord.get.toURI else: "",
|
||||
"announceAddresses": node.discovery.announceAddrs,
|
||||
"table": table,
|
||||
}
|
||||
|
||||
return ok($json)
|
||||
|
||||
|
||||
@ -375,12 +375,13 @@ proc initDataApi(node: StorageNodeRef, repoStore: RepoStore, router: var RestRou
|
||||
return RestApiResponse.response($json, contentType = "application/json")
|
||||
|
||||
router.api(MethodGet, "/api/storage/v1/space") do() -> RestApiResponse:
|
||||
let json = %RestRepoStore(
|
||||
totalBlocks: repoStore.totalBlocks,
|
||||
quotaMaxBytes: repoStore.quotaMaxBytes,
|
||||
quotaUsedBytes: repoStore.quotaUsedBytes,
|
||||
quotaReservedBytes: repoStore.quotaReservedBytes,
|
||||
)
|
||||
let json =
|
||||
%RestRepoStore(
|
||||
totalBlocks: repoStore.totalBlocks,
|
||||
quotaMaxBytes: repoStore.quotaMaxBytes,
|
||||
quotaUsedBytes: repoStore.quotaUsedBytes,
|
||||
quotaReservedBytes: repoStore.quotaReservedBytes,
|
||||
)
|
||||
return RestApiResponse.response($json, contentType = "application/json")
|
||||
|
||||
proc initNodeApi(node: StorageNodeRef, conf: StorageConf, router: var RestRouter) =
|
||||
@ -477,17 +478,20 @@ proc initDebugApi(node: StorageNodeRef, conf: StorageConf, router: var RestRoute
|
||||
|
||||
try:
|
||||
let table = RestRoutingTable.init(node.discovery.protocol.routingTable)
|
||||
|
||||
let json = %*{
|
||||
"id": $node.switch.peerInfo.peerId,
|
||||
"addrs": node.switch.peerInfo.addrs.mapIt($it),
|
||||
"repo": $conf.dataDir,
|
||||
"spr":
|
||||
if node.discovery.dhtRecord.isSome: node.discovery.dhtRecord.get.toURI else: "",
|
||||
"announceAddresses": node.discovery.announceAddrs,
|
||||
"table": table,
|
||||
"storage": {"version": $storageVersion, "revision": $storageRevision},
|
||||
}
|
||||
let json =
|
||||
%*{
|
||||
"id": $node.switch.peerInfo.peerId,
|
||||
"addrs": node.switch.peerInfo.addrs.mapIt($it),
|
||||
"repo": $conf.dataDir,
|
||||
"spr":
|
||||
if node.discovery.dhtRecord.isSome:
|
||||
node.discovery.dhtRecord.get.toURI
|
||||
else:
|
||||
"",
|
||||
"announceAddresses": node.discovery.announceAddrs,
|
||||
"table": table,
|
||||
"storage": {"version": $codexVersion, "revision": $codexRevision},
|
||||
}
|
||||
|
||||
# return pretty json for human readability
|
||||
return RestApiResponse.response(
|
||||
|
||||
@ -96,12 +96,13 @@ proc stop*(s: StorageServer) {.async.} =
|
||||
|
||||
notice "Stopping Storage node"
|
||||
|
||||
var futures = @[
|
||||
s.storageNode.switch.stop(),
|
||||
s.storageNode.stop(),
|
||||
s.repoStore.stop(),
|
||||
s.maintenance.stop(),
|
||||
]
|
||||
var futures =
|
||||
@[
|
||||
s.storageNode.switch.stop(),
|
||||
s.storageNode.stop(),
|
||||
s.repoStore.stop(),
|
||||
s.maintenance.stop(),
|
||||
]
|
||||
|
||||
if s.restServer != nil:
|
||||
futures.add(s.restServer.stop())
|
||||
|
||||
@ -58,10 +58,11 @@ twonodessuite "REST API":
|
||||
check (await response.body) != ""
|
||||
|
||||
test "node retrieve the metadata", twoNodesConfig:
|
||||
let headers = @[
|
||||
("Content-Type", "text/plain"),
|
||||
("Content-Disposition", "attachment; filename=\"example.txt\""),
|
||||
]
|
||||
let headers =
|
||||
@[
|
||||
("Content-Type", "text/plain"),
|
||||
("Content-Disposition", "attachment; filename=\"example.txt\""),
|
||||
]
|
||||
let uploadResponse = await client1.uploadRaw("some file contents", headers)
|
||||
let cid = await uploadResponse.body
|
||||
let listResponse = await client1.listRaw()
|
||||
@ -82,10 +83,11 @@ twonodessuite "REST API":
|
||||
check manifest["mimetype"].getStr() == "text/plain"
|
||||
|
||||
test "node set the headers when for download", twoNodesConfig:
|
||||
let headers = @[
|
||||
("Content-Disposition", "attachment; filename=\"example.txt\""),
|
||||
("Content-Type", "text/plain"),
|
||||
]
|
||||
let headers =
|
||||
@[
|
||||
("Content-Disposition", "attachment; filename=\"example.txt\""),
|
||||
("Content-Type", "text/plain"),
|
||||
]
|
||||
|
||||
let uploadResponse = await client1.uploadRaw("some file contents", headers)
|
||||
let cid = await uploadResponse.body
|
||||
|
||||
@ -33,17 +33,17 @@ proc request(
|
||||
async: (raw: true, raises: [CancelledError, HttpError])
|
||||
.} =
|
||||
HttpClientRequestRef
|
||||
.new(
|
||||
self.session,
|
||||
url,
|
||||
httpMethod,
|
||||
version = HttpVersion11,
|
||||
flags = {},
|
||||
maxResponseHeadersSize = HttpMaxHeadersSize,
|
||||
headers = headers,
|
||||
body = body.toOpenArrayByte(0, len(body) - 1),
|
||||
).get
|
||||
.send()
|
||||
.new(
|
||||
self.session,
|
||||
url,
|
||||
httpMethod,
|
||||
version = HttpVersion11,
|
||||
flags = {},
|
||||
maxResponseHeadersSize = HttpMaxHeadersSize,
|
||||
headers = headers,
|
||||
body = body.toOpenArrayByte(0, len(body) - 1),
|
||||
).get
|
||||
.send()
|
||||
|
||||
proc post*(
|
||||
self: StorageClient,
|
||||
|
||||
@ -57,14 +57,14 @@ asyncchecksuite "NetworkStore engine - 2 nodes":
|
||||
|
||||
check:
|
||||
(await allFinished(blocks1[0 .. 3].mapIt(nodeCmps2.localStore.getBlock(it.cid))))
|
||||
.filterIt(it.completed and it.read.isOk)
|
||||
.mapIt($it.read.get.cid)
|
||||
.sorted(cmp[string]) == blocks1[0 .. 3].mapIt($it.cid).sorted(cmp[string])
|
||||
.filterIt(it.completed and it.read.isOk)
|
||||
.mapIt($it.read.get.cid)
|
||||
.sorted(cmp[string]) == blocks1[0 .. 3].mapIt($it.cid).sorted(cmp[string])
|
||||
|
||||
(await allFinished(blocks2[0 .. 3].mapIt(nodeCmps1.localStore.getBlock(it.cid))))
|
||||
.filterIt(it.completed and it.read.isOk)
|
||||
.mapIt($it.read.get.cid)
|
||||
.sorted(cmp[string]) == blocks2[0 .. 3].mapIt($it.cid).sorted(cmp[string])
|
||||
.filterIt(it.completed and it.read.isOk)
|
||||
.mapIt($it.read.get.cid)
|
||||
.sorted(cmp[string]) == blocks2[0 .. 3].mapIt($it.cid).sorted(cmp[string])
|
||||
|
||||
test "Should send want-have for block":
|
||||
let blk = bt.Block.new("Block 1".toBytes).tryGet()
|
||||
@ -138,9 +138,9 @@ asyncchecksuite "NetworkStore - multiple nodes":
|
||||
|
||||
check:
|
||||
(await allFinished(downloadCids.mapIt(downloader.localStore.getBlock(it))))
|
||||
.filterIt(it.completed and it.read.isOk)
|
||||
.mapIt($it.read.get.cid)
|
||||
.sorted(cmp[string]) == downloadCids.mapIt($it).sorted(cmp[string])
|
||||
.filterIt(it.completed and it.read.isOk)
|
||||
.mapIt($it.read.get.cid)
|
||||
.sorted(cmp[string]) == downloadCids.mapIt($it).sorted(cmp[string])
|
||||
|
||||
test "Should exchange blocks with multiple nodes":
|
||||
let
|
||||
|
||||
@ -97,9 +97,10 @@ template setupAndTearDown*() {.dirty.} =
|
||||
|
||||
blockDiscovery = Discovery.new(
|
||||
switch.peerInfo.privateKey,
|
||||
announceAddrs = @[
|
||||
MultiAddress.init("/ip4/127.0.0.1/tcp/0").expect("Should return multiaddress")
|
||||
],
|
||||
announceAddrs =
|
||||
@[
|
||||
MultiAddress.init("/ip4/127.0.0.1/tcp/0").expect("Should return multiaddress")
|
||||
],
|
||||
)
|
||||
peerStore = PeerCtxStore.new()
|
||||
pendingBlocks = PendingBlocksManager.new()
|
||||
|
||||
@ -205,10 +205,11 @@ checksuite "Test logging output":
|
||||
check loggedJson("ma", "\"/ip4/127.0.0.1/tcp/0\"")
|
||||
|
||||
test "logs seq[MultiAddress] correctly":
|
||||
let ma = @[
|
||||
MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet,
|
||||
MultiAddress.init("/ip4/127.0.0.2/tcp/1").tryGet,
|
||||
]
|
||||
let ma =
|
||||
@[
|
||||
MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet,
|
||||
MultiAddress.init("/ip4/127.0.0.2/tcp/1").tryGet,
|
||||
]
|
||||
log ma
|
||||
check logged("ma", "\"@[/ip4/127.0.0.1/tcp/0, /ip4/127.0.0.2/tcp/1]\"")
|
||||
check loggedJson("ma", "[\"/ip4/127.0.0.1/tcp/0\",\"/ip4/127.0.0.2/tcp/1\"]")
|
||||
|
||||
@ -22,16 +22,18 @@ suite "NAT Address Tests":
|
||||
|
||||
# Expected results
|
||||
let
|
||||
expectedDiscoveryAddrs = @[
|
||||
MultiAddress.init("/ip4/8.8.8.8/udp/1234").expect("valid multiaddr"),
|
||||
MultiAddress.init("/ip4/8.8.8.8/udp/1234").expect("valid multiaddr"),
|
||||
MultiAddress.init("/ip4/8.8.8.8/udp/1234").expect("valid multiaddr"),
|
||||
]
|
||||
expectedlibp2pAddrs = @[
|
||||
MultiAddress.init("/ip4/8.8.8.8/tcp/5000").expect("valid multiaddr"),
|
||||
MultiAddress.init("/ip4/8.8.8.8/tcp/5000").expect("valid multiaddr"),
|
||||
MultiAddress.init("/ip4/8.8.8.8/tcp/5000").expect("valid multiaddr"),
|
||||
]
|
||||
expectedDiscoveryAddrs =
|
||||
@[
|
||||
MultiAddress.init("/ip4/8.8.8.8/udp/1234").expect("valid multiaddr"),
|
||||
MultiAddress.init("/ip4/8.8.8.8/udp/1234").expect("valid multiaddr"),
|
||||
MultiAddress.init("/ip4/8.8.8.8/udp/1234").expect("valid multiaddr"),
|
||||
]
|
||||
expectedlibp2pAddrs =
|
||||
@[
|
||||
MultiAddress.init("/ip4/8.8.8.8/tcp/5000").expect("valid multiaddr"),
|
||||
MultiAddress.init("/ip4/8.8.8.8/tcp/5000").expect("valid multiaddr"),
|
||||
MultiAddress.init("/ip4/8.8.8.8/tcp/5000").expect("valid multiaddr"),
|
||||
]
|
||||
|
||||
#ipv6Addr = MultiAddress.init("/ip6/::1/tcp/5000").expect("valid multiaddr")
|
||||
addrs = @[localAddr, anyAddr, publicAddr]
|
||||
|
||||
@ -7,12 +7,13 @@ suite "findIt":
|
||||
type AnObject = object
|
||||
attribute1*: int
|
||||
|
||||
var objList = @[
|
||||
AnObject(attribute1: 1),
|
||||
AnObject(attribute1: 3),
|
||||
AnObject(attribute1: 5),
|
||||
AnObject(attribute1: 3),
|
||||
]
|
||||
var objList =
|
||||
@[
|
||||
AnObject(attribute1: 1),
|
||||
AnObject(attribute1: 3),
|
||||
AnObject(attribute1: 5),
|
||||
AnObject(attribute1: 3),
|
||||
]
|
||||
|
||||
test "should retur index of first object matching predicate":
|
||||
assert objList.findIt(it.attribute1 == 3) == 1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user