mirror of
https://github.com/logos-storage/nim-libplum.git
synced 2026-06-07 09:40:01 +00:00
1.4 KiB
1.4 KiB
nim-libplum
Nim binding for libplum (PCP / NAT-PMP / UPnP-IGD port mapping), with a chronos-based async wrapper.
Commands
git submodule update --init # vendor/libplum is required for everything
nimble test # builds vendor/libplum.a via cmake, then runs unit tests
nimble testIntegration # miniupnpd integration tests in Docker/Podman (NET_ADMIN)
nimble format # nph on libplum/ and tests/
Debug env vars: LIBPLUM_VERBOSE=1, TEST_VERBOSE=1, MINIUPNPD_VERBOSE=1.
Architecture
libplum/libplum.nim— raw C bindings (importc), no logiclibplum/plum.nim— public API: bridges libplum's C callback thread to chronostests/test_plum.nim— unit suite + integration suites gated by-d:miniupnp_protocolapi.md— user-facing API doc, keep in sync with plum.nimvendor/libplum— git submodule, built statically by nimble tasks
Threading invariants (critical)
mappingCallbackruns on libplum's internal C thread, wrapped inforeignThreadGc; it must stayraises: []and only touch thread-safe state- Never call
ThreadSignalPtr.close()from the C thread: close() unregisters the fd from the calling thread's dispatcher; only the chronos loop thread may close a signal MappingHandleis pinned withGC_refwhile libplum holdsuser_ptr; unpinned only in the DESTROYED callbackactiveMappingsis guarded byactiveMappingsLock(withSafeLock)