mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-03-09 13:53:08 +00:00
formatting
# Conflicts: # storage/rest/api.nim # storage/storage.nim
This commit is contained in:
parent
8502b64763
commit
2be296ed58
@ -52,15 +52,14 @@ 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,13 +375,12 @@ 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) =
|
||||
|
||||
@ -58,11 +58,10 @@ 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()
|
||||
@ -83,11 +82,10 @@ 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,10 +97,9 @@ 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,11 +205,10 @@ 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,18 +22,16 @@ 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,13 +7,12 @@ 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