Skip to content

Split into core + full libraries#48

Open
jagerman wants to merge 4 commits into
session-foundation:devfrom
jagerman:core-full-lib-split
Open

Split into core + full libraries#48
jagerman wants to merge 4 commits into
session-foundation:devfrom
jagerman:core-full-lib-split

Conversation

@jagerman

Copy link
Copy Markdown
Member

This PR restructures session-router so it builds as two layered libraries instead of one. The primary purpose is to solve a dependency ugliness:

  • -DSROUTER_FULL=OFF would build a library suitable for embedded usage, with some codepaths disabled at compilation time, and omitting various things like libunbound and liboxen-mq (which are only needed for full clients and relays).
  • -DSROUTER_FULL=ON (the default) would build a library that included everything, including libunbound-dev. While this library was perfectly usable for both embedded and full, it meant that you always had to bring along libunbound and liboxenmq (and transitives) as package dependencies, which is a little bit annoying if you only care about embedded mode.

Thus this PR splits the library into two, and removes all the compile-time differences in the build:

  • libsessionrouter-core contains all the core functionality common to embedded + full usage, but deliberately does not depend on code and external dependencies that are only needed in full client or relay mode, such as libunbound or oxen-mq.
  • libsessionrouter is the "everything" library - it links to libsessionrouter-core, plus includes the extras needed for a full client (including linking to unbound and oxen-mq). This includes things irrelevant to embedded usage such as oxend rpc, reachability testing, TUN endpoint, platform code.

This required some internal abstraction and mild reworking of the code to be able to cleanly sever the two components, but now builds and works successfully.

@jagerman
jagerman force-pushed the core-full-lib-split branch from 6570ed0 to 65a8517 Compare July 16, 2026 00:35
jagerman and others added 4 commits July 15, 2026 22:18
…ntry point

Move the service_manager global into the core library with a no-op default and
make it settable, so core can reference it unconditionally; the native
(systemd/win32) implementation installs itself. Introduce
srouter::full::initialize() -- the single entry point a full application calls
early in main() to install the full library's overrides (native service manager,
stricter config validators, ...) over the core defaults -- and drop the
SROUTER_EMBEDDED_ONLY guards around service_manager now that it is always present.

Validate the [oxend]:rpc config value through an optional hook installed by the
full library instead of constructing an oxenmq::address directly, so the core
config library no longer depends on oxenmq.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Router drives the oxend client and reachability tester through core-side
interfaces (rpc::IOxendClient, consensus::IReachability) and holds the oxenmq
instance and rpc server via forward-declared handles, all constructed by an
injected RpcBackendHooks seam that the full library installs in
srouter::full::initialize(). The concrete implementations (which need oxenmq)
live in the full library; Router still owns and drives them, but its construction
of them moves behind the hooks and it no longer names the concrete types.

With this the core library no longer references any oxenmq or rpc code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…BEDDED_ONLY

Give the TUN endpoint a core interface (handlers::ITunnel) and route the
net::Platform and vpn::Platform singletons through settable seams installed by the
full library. Relocate TUN/DNS construction into the full backend hooks so the
concrete platform/dns implementations -- and libunbound -- leave the core library,
and dispatch the remaining tun/oxend call sites in session and link_manager
through the interfaces.

With the last full-only references gone from core, delete SROUTER_EMBEDDED_ONLY
entirely. The core/full distinction is now purely whether the full backend is
installed at runtime, so the core translation units compile identically
regardless of SROUTER_FULL.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Build two aggregate libraries from the internal component libraries:
libsessionrouter-core (alias session-router::core, libsessionrouter-core.so) is
the embedded API plus the core components and has no oxenmq/libunbound dependency;
libsessionrouter (alias session-router::full, libsessionrouter.so) adds the
full-only components and links libsessionrouter-core. Embedded consumers build
with -DSROUTER_FULL=OFF and link the core library; the daemon links the full one.

To keep the core graph dependency-clean in a full build: split the dns library
into a core srv_data stub (session-router-dns-data) and the full parser
(session-router-dns); relocate the full-only concrete implementations out of the
core component libraries; cut the now-spurious core->full dependency edges; and
split session-router-base into base and base-full (oxenmq/unbound). The aggregate
shared libraries whole-archive their components (srouter_link_whole(), using
$<LINK_LIBRARY:WHOLE_ARCHIVE> on CMake >= 3.24 with a GNU --whole-archive
fallback) so each .so is self-complete.

Declare sessiondep::libzstd on session-router-utils (which contains util/zstd.cpp,
the only user of the zstd C API) rather than on session-router-addressing (which
uses no zstd symbols). The old placement relied on link ordering that happened to
work before the split; once the aggregate link line is reordered by the
whole-archive layering, the utils archive can precede libzstd on the link command
and the zstd.cpp references (ZSTD_createCCtx, ...) fail to resolve in static builds.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jagerman
jagerman force-pushed the core-full-lib-split branch from 65a8517 to 9a18f5e Compare July 16, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant