mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-06-27 21:09:28 +00:00
Cleanup
This commit is contained in:
parent
725633d587
commit
71a479a558
@ -1,7 +1,4 @@
|
||||
## NAT hole-punching scenario. See README.md.
|
||||
##
|
||||
## Success is asserted on node B's container log line (no REST surface for the
|
||||
## connection type); brittle if that message changes.
|
||||
|
||||
import std/[json, os, sequtils, strutils, times]
|
||||
import pkg/chronos
|
||||
@ -49,6 +46,8 @@ asyncchecksuite "NAT hole punching":
|
||||
info{"nat"}{"reachability"}.getStr == "NotReachable" and
|
||||
info.announcesCircuitAddr(),
|
||||
)
|
||||
|
||||
# C is Reachable
|
||||
check eventuallyInfo(clientC, info{"nat"}{"reachability"}.getStr == "Reachable")
|
||||
|
||||
# C dials B through the relay; a download is enough to open the connection
|
||||
|
||||
@ -69,16 +69,6 @@ proc delete(
|
||||
.} =
|
||||
return self.request(MethodDelete, url, headers = headers)
|
||||
|
||||
proc patch*(
|
||||
self: StorageClient,
|
||||
url: string,
|
||||
body: string = "",
|
||||
headers: seq[HttpHeaderTuple] = @[],
|
||||
): Future[HttpClientResponseRef] {.
|
||||
async: (raw: true, raises: [CancelledError, HttpError])
|
||||
.} =
|
||||
return self.request(MethodPatch, url, headers = headers, body = body)
|
||||
|
||||
proc body*(
|
||||
response: HttpClientResponseRef
|
||||
): Future[string] {.async: (raises: [CancelledError, HttpError]).} =
|
||||
@ -230,20 +220,6 @@ proc list*(
|
||||
|
||||
RestContentList.fromJson(await response.body)
|
||||
|
||||
proc space*(
|
||||
client: StorageClient
|
||||
): Future[?!RestRepoStore] {.async: (raises: [CancelledError, HttpError]).} =
|
||||
let url = client.baseurl & "/space"
|
||||
let response = await client.get(url)
|
||||
|
||||
if response.status != 200:
|
||||
return failure($response.status)
|
||||
|
||||
RestRepoStore.fromJson(await response.body)
|
||||
|
||||
proc buildUrl*(client: StorageClient, path: string): string =
|
||||
return client.baseurl & path
|
||||
|
||||
proc hasBlock*(
|
||||
client: StorageClient, cid: Cid
|
||||
): Future[?!bool] {.async: (raises: [CancelledError, HttpError]).} =
|
||||
@ -261,25 +237,3 @@ proc hasBlockRaw*(
|
||||
.} =
|
||||
let url = client.baseurl & "/data/" & cid & "/exists"
|
||||
return client.get(url)
|
||||
|
||||
proc natRelayRunning*(
|
||||
client: StorageClient
|
||||
): Future[?!bool] {.async: (raises: [CancelledError, HttpError]).} =
|
||||
let info = await client.info()
|
||||
if info.isErr:
|
||||
return failure "Failed to get node info"
|
||||
try:
|
||||
return info.get()["nat"]["relayRunning"].getBool().success
|
||||
except KeyError as e:
|
||||
return failure e.msg
|
||||
|
||||
proc natPortMapping*(
|
||||
client: StorageClient
|
||||
): Future[?!string] {.async: (raises: [CancelledError, HttpError]).} =
|
||||
let info = await client.info()
|
||||
if info.isErr:
|
||||
return failure "Failed to get node info"
|
||||
try:
|
||||
return info.get()["nat"]["portMapping"].getStr().success
|
||||
except KeyError as e:
|
||||
return failure e.msg
|
||||
|
||||
@ -5,9 +5,7 @@ import std/strutils
|
||||
import std/sugar
|
||||
import std/tables
|
||||
from pkg/chronicles import LogLevel
|
||||
import pkg/chronos
|
||||
import pkg/storage/conf
|
||||
import pkg/storage/units
|
||||
import pkg/confutils
|
||||
import pkg/confutils/defs
|
||||
import libp2p except setup
|
||||
@ -235,85 +233,6 @@ proc withBlockMaintenanceInterval*(
|
||||
config.addCliOption("--block-mi", $interval)
|
||||
return startConfig
|
||||
|
||||
proc logLevelWithTopics(
|
||||
config: StorageConfig, topics: varargs[string]
|
||||
): string {.raises: [StorageConfigError].} =
|
||||
convertError:
|
||||
var logLevel = LogLevel.INFO
|
||||
let built = config.buildConfig("Invalid storage config cli params")
|
||||
logLevel = parseEnum[LogLevel](built.logLevel.toUpperAscii)
|
||||
let level = $logLevel & ";TRACE: " & topics.join(",")
|
||||
return level
|
||||
|
||||
proc withLogTopics*(
|
||||
self: StorageConfigs, idx: int, topics: varargs[string]
|
||||
): StorageConfigs {.raises: [StorageConfigError].} =
|
||||
self.checkBounds idx
|
||||
|
||||
convertError:
|
||||
let config = self.configs[idx]
|
||||
let level = config.logLevelWithTopics(topics)
|
||||
var startConfig = self
|
||||
return startConfig.withLogLevel(idx, level)
|
||||
|
||||
proc withLogTopics*(
|
||||
self: StorageConfigs, topics: varargs[string]
|
||||
): StorageConfigs {.raises: [StorageConfigError].} =
|
||||
var startConfig = self
|
||||
for config in startConfig.configs.mitems:
|
||||
let level = config.logLevelWithTopics(topics)
|
||||
config = config.withLogLevel(level)
|
||||
return startConfig
|
||||
|
||||
proc withStorageQuota*(
|
||||
self: StorageConfigs, idx: int, quota: NBytes
|
||||
): StorageConfigs {.raises: [StorageConfigError].} =
|
||||
self.checkBounds idx
|
||||
|
||||
var startConfig = self
|
||||
startConfig.configs[idx].addCliOption("--storage-quota", $quota)
|
||||
return startConfig
|
||||
|
||||
proc withStorageQuota*(
|
||||
self: StorageConfigs, quota: NBytes
|
||||
): StorageConfigs {.raises: [StorageConfigError].} =
|
||||
var startConfig = self
|
||||
for config in startConfig.configs.mitems:
|
||||
config.addCliOption("--storage-quota", $quota)
|
||||
return startConfig
|
||||
|
||||
proc withNatNumPeersToAsk*(
|
||||
self: StorageConfigs, numPeersToAsk: int
|
||||
): StorageConfigs {.raises: [StorageConfigError].} =
|
||||
var startConfig = self
|
||||
for config in startConfig.configs.mitems:
|
||||
config.addCliOption("--nat-num-peers-to-ask", $numPeersToAsk)
|
||||
return startConfig
|
||||
|
||||
proc withNatMaxQueueSize*(
|
||||
self: StorageConfigs, maxQueueSize: int
|
||||
): StorageConfigs {.raises: [StorageConfigError].} =
|
||||
var startConfig = self
|
||||
for config in startConfig.configs.mitems:
|
||||
config.addCliOption("--nat-max-queue-size", $maxQueueSize)
|
||||
return startConfig
|
||||
|
||||
proc withNatMinConfidence*(
|
||||
self: StorageConfigs, minConfidence: float
|
||||
): StorageConfigs {.raises: [StorageConfigError].} =
|
||||
var startConfig = self
|
||||
for config in startConfig.configs.mitems:
|
||||
config.addCliOption("--nat-min-confidence", $minConfidence)
|
||||
return startConfig
|
||||
|
||||
proc withNatScheduleInterval*(
|
||||
self: StorageConfigs, scheduleInterval: Duration
|
||||
): StorageConfigs {.raises: [StorageConfigError].} =
|
||||
var startConfig = self
|
||||
for config in startConfig.configs.mitems:
|
||||
config.addCliOption("--nat-schedule-interval", $scheduleInterval)
|
||||
return startConfig
|
||||
|
||||
proc withExtIp*(
|
||||
self: StorageConfigs, idx: int, ip = "127.0.0.1"
|
||||
): StorageConfigs {.raises: [StorageConfigError].} =
|
||||
@ -323,15 +242,6 @@ proc withExtIp*(
|
||||
startConfig.configs[idx].addCliOption("--nat", "extip:" & ip)
|
||||
return startConfig
|
||||
|
||||
proc withRelay*(
|
||||
self: StorageConfigs, idx: int
|
||||
): StorageConfigs {.raises: [StorageConfigError].} =
|
||||
self.checkBounds idx
|
||||
|
||||
var startConfig = self
|
||||
startConfig.configs[idx].addCliOption("--relay-server")
|
||||
return startConfig
|
||||
|
||||
# For testing, a node with extip (not behind nat) with autonat server
|
||||
# enabled is a bootstrap node
|
||||
proc isBootstrapNode*(config: StorageConfig): bool {.raises: [].} =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user