mirror of
https://github.com/logos-storage/nim-libplum.git
synced 2026-06-07 09:40:01 +00:00
Use Nim types in init signature
This commit is contained in:
parent
f3d74da7bc
commit
e50f341ad8
@ -35,6 +35,15 @@ type
|
||||
TCP = PLUM_IP_PROTOCOL_TCP.int
|
||||
UDP = PLUM_IP_PROTOCOL_UDP.int
|
||||
|
||||
PlumLogLevel* {.pure.} = enum
|
||||
Verbose = PLUM_LOG_LEVEL_VERBOSE.int
|
||||
Debug = PLUM_LOG_LEVEL_DEBUG.int
|
||||
Info = PLUM_LOG_LEVEL_INFO.int
|
||||
Warn = PLUM_LOG_LEVEL_WARN.int
|
||||
Error = PLUM_LOG_LEVEL_ERROR.int
|
||||
Fatal = PLUM_LOG_LEVEL_FATAL.int
|
||||
None = PLUM_LOG_LEVEL_NONE.int
|
||||
|
||||
PlumState* = enum
|
||||
Destroyed = PLUM_STATE_DESTROYED.int
|
||||
Pending = PLUM_STATE_PENDING.int
|
||||
@ -158,15 +167,15 @@ proc mappingCallback(
|
||||
handle.onStateChange(plumState, mapping)
|
||||
|
||||
proc init*(
|
||||
logLevel: plum_log_level_t = PLUM_LOG_LEVEL_NONE,
|
||||
discoverTimeout: int = 0,
|
||||
mappingTimeout: int = 0,
|
||||
recheckPeriod: int = 0,
|
||||
logLevel: PlumLogLevel = PlumLogLevel.None,
|
||||
discoverTimeout: int32 = 0,
|
||||
mappingTimeout: int32 = 0,
|
||||
recheckPeriod: int32 = 0,
|
||||
): Result[void, string] =
|
||||
## init MUST be called to setup internal plum thread (plum_init).
|
||||
|
||||
var config = plum_config_t(
|
||||
log_level: logLevel,
|
||||
log_level: plum_log_level_t(logLevel.int),
|
||||
log_callback: nil,
|
||||
dummytls_domain: nil,
|
||||
discover_timeout: discoverTimeout.cint,
|
||||
|
||||
@ -73,7 +73,7 @@ when miniupnp_protocol != "":
|
||||
let mappingTimeout = seconds(40)
|
||||
|
||||
let logLevel =
|
||||
if getEnv("LIBPLUM_VERBOSE") == "1": PLUM_LOG_LEVEL_VERBOSE else: PLUM_LOG_LEVEL_NONE
|
||||
if getEnv("LIBPLUM_VERBOSE") == "1": PlumLogLevel.Verbose else: PlumLogLevel.None
|
||||
|
||||
var gRenewed: Atomic[bool]
|
||||
|
||||
@ -108,7 +108,7 @@ when miniupnp_protocol != "":
|
||||
|
||||
suite "plum - " & miniupnp_protocol & " using miniupnp":
|
||||
test "createMapping TCP and destroyMapping":
|
||||
require init(discoverTimeout = discoverMs, logLevel = logLevel).isOk()
|
||||
require init(discoverTimeout = discoverMs.int32, logLevel = logLevel).isOk()
|
||||
defer:
|
||||
discard cleanup()
|
||||
|
||||
@ -135,7 +135,7 @@ when miniupnp_protocol != "":
|
||||
destroyMapping(res.id)
|
||||
|
||||
test "createMapping UDP and destroying":
|
||||
require init(discoverTimeout = discoverMs, logLevel = logLevel).isOk()
|
||||
require init(discoverTimeout = discoverMs.int32, logLevel = logLevel).isOk()
|
||||
defer:
|
||||
discard cleanup()
|
||||
|
||||
@ -159,7 +159,7 @@ when miniupnp_protocol != "":
|
||||
|
||||
test "mapping is renewed after miniupnpd restart":
|
||||
require init(
|
||||
discoverTimeout = discoverMs, logLevel = logLevel, recheckPeriod = recheckMs
|
||||
discoverTimeout = discoverMs.int32, logLevel = logLevel, recheckPeriod = recheckMs.int32
|
||||
)
|
||||
.isOk()
|
||||
defer:
|
||||
@ -189,7 +189,7 @@ when miniupnp_protocol != "":
|
||||
check waitRenewal()
|
||||
|
||||
test "cleanup releases active mappings":
|
||||
require init(discoverTimeout = discoverMs, logLevel = logLevel).isOk()
|
||||
require init(discoverTimeout = discoverMs.int32, logLevel = logLevel).isOk()
|
||||
|
||||
let r = waitFor createMapping(TCP, 8401, timeout = mappingTimeout)
|
||||
require r.isOk()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user