mirror of
https://github.com/logos-storage/nim-libplum.git
synced 2026-06-07 17:49:25 +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
|
TCP = PLUM_IP_PROTOCOL_TCP.int
|
||||||
UDP = PLUM_IP_PROTOCOL_UDP.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
|
PlumState* = enum
|
||||||
Destroyed = PLUM_STATE_DESTROYED.int
|
Destroyed = PLUM_STATE_DESTROYED.int
|
||||||
Pending = PLUM_STATE_PENDING.int
|
Pending = PLUM_STATE_PENDING.int
|
||||||
@ -158,15 +167,15 @@ proc mappingCallback(
|
|||||||
handle.onStateChange(plumState, mapping)
|
handle.onStateChange(plumState, mapping)
|
||||||
|
|
||||||
proc init*(
|
proc init*(
|
||||||
logLevel: plum_log_level_t = PLUM_LOG_LEVEL_NONE,
|
logLevel: PlumLogLevel = PlumLogLevel.None,
|
||||||
discoverTimeout: int = 0,
|
discoverTimeout: int32 = 0,
|
||||||
mappingTimeout: int = 0,
|
mappingTimeout: int32 = 0,
|
||||||
recheckPeriod: int = 0,
|
recheckPeriod: int32 = 0,
|
||||||
): Result[void, string] =
|
): Result[void, string] =
|
||||||
## init MUST be called to setup internal plum thread (plum_init).
|
## init MUST be called to setup internal plum thread (plum_init).
|
||||||
|
|
||||||
var config = plum_config_t(
|
var config = plum_config_t(
|
||||||
log_level: logLevel,
|
log_level: plum_log_level_t(logLevel.int),
|
||||||
log_callback: nil,
|
log_callback: nil,
|
||||||
dummytls_domain: nil,
|
dummytls_domain: nil,
|
||||||
discover_timeout: discoverTimeout.cint,
|
discover_timeout: discoverTimeout.cint,
|
||||||
|
|||||||
@ -73,7 +73,7 @@ when miniupnp_protocol != "":
|
|||||||
let mappingTimeout = seconds(40)
|
let mappingTimeout = seconds(40)
|
||||||
|
|
||||||
let logLevel =
|
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]
|
var gRenewed: Atomic[bool]
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ when miniupnp_protocol != "":
|
|||||||
|
|
||||||
suite "plum - " & miniupnp_protocol & " using miniupnp":
|
suite "plum - " & miniupnp_protocol & " using miniupnp":
|
||||||
test "createMapping TCP and destroyMapping":
|
test "createMapping TCP and destroyMapping":
|
||||||
require init(discoverTimeout = discoverMs, logLevel = logLevel).isOk()
|
require init(discoverTimeout = discoverMs.int32, logLevel = logLevel).isOk()
|
||||||
defer:
|
defer:
|
||||||
discard cleanup()
|
discard cleanup()
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ when miniupnp_protocol != "":
|
|||||||
destroyMapping(res.id)
|
destroyMapping(res.id)
|
||||||
|
|
||||||
test "createMapping UDP and destroying":
|
test "createMapping UDP and destroying":
|
||||||
require init(discoverTimeout = discoverMs, logLevel = logLevel).isOk()
|
require init(discoverTimeout = discoverMs.int32, logLevel = logLevel).isOk()
|
||||||
defer:
|
defer:
|
||||||
discard cleanup()
|
discard cleanup()
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ when miniupnp_protocol != "":
|
|||||||
|
|
||||||
test "mapping is renewed after miniupnpd restart":
|
test "mapping is renewed after miniupnpd restart":
|
||||||
require init(
|
require init(
|
||||||
discoverTimeout = discoverMs, logLevel = logLevel, recheckPeriod = recheckMs
|
discoverTimeout = discoverMs.int32, logLevel = logLevel, recheckPeriod = recheckMs.int32
|
||||||
)
|
)
|
||||||
.isOk()
|
.isOk()
|
||||||
defer:
|
defer:
|
||||||
@ -189,7 +189,7 @@ when miniupnp_protocol != "":
|
|||||||
check waitRenewal()
|
check waitRenewal()
|
||||||
|
|
||||||
test "cleanup releases active mappings":
|
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)
|
let r = waitFor createMapping(TCP, 8401, timeout = mappingTimeout)
|
||||||
require r.isOk()
|
require r.isOk()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user