How named-data/psync works
1. What this repo is
PSync is a C++17 library for Named Data Networking (NDN) that implements the PSync protocol. Its architectural center is set reconciliation: nodes exchange compact summaries of name state instead of raw lists, then compute differences efficiently.
2. Top-level layering
The code is split into a public API layer under PSync/ and an internal algorithm layer under PSync/detail/. The public layer exposes sync roles and transport-facing helpers; the detail layer holds the compact data structures and state-diff logic that make the protocol work.
3. Core public roles
The main user-facing components are consumer, producer-base, partial-producer, full-producer, and segment-publisher. These define the main runtime roles in the system: a consumer that tracks subscriptions, two producer variants for partial/full synchronization, and a helper for publishing larger content in NDN segments.
4. Partial synchronization path
In partial sync, the consumer side is represented by PSync::Consumer, which uses a Bloom filter to summarize its subscription list. PSync::PartialProducer represents the producer side for this mode, maintaining its own state and using compact set-reconciliation machinery to determine which subscribed names need to be announced.
5. Full synchronization path
PSync::FullProducer supports a mode where a node’s full state is synchronized rather than only a partial subscription set. This is the other major runtime path in the library, built on the same reconciliation primitives but with a different scope of state.
6. Synchronization state and algorithms
The detail/iblt.* and detail/bloom-filter.* files implement the core probabilistic data structures: IBLT/IBF for efficiently diffing two states, and Bloom filters for compact subscription membership tests. detail/state.* models the producer state that gets summarized and exchanged.
7. Transport and publication boundary
The library depends on ndn-cxx and operates in the NDN packet model rather than a traditional request/response web stack. segment-publisher.* is the bridge for publishing content that needs segmentation, keeping the synchronization logic separate from the mechanics of serving segmented NDN Data packets.
8. Shared utilities and API surface
common.hpp and detail/util.* provide shared definitions and helper functions used across the public classes and the internal algorithm code. This helps keep the higher-level sync classes thin and lets the reconciliation logic remain centralized.
9. Examples as integration entrypoints
The examples/ directory shows the intended application shapes: a consumer app, a producer app, and a full-sync demo. These examples are useful for understanding how the library is composed into an NDN application, but they are not separate services.
10. Tests and quality gates
The tests/ tree contains unit tests for the Bloom filter, IBLT, state handling, producer variants, consumer behavior, and segment publishing. This indicates that the architecture is heavily validated at the algorithm and role-integration level, not just via end-to-end demos.
11. Build and packaging
The project is built with waf, with optional test builds, docs generation, and release packaging. There is also a PSync.pc.in pkg-config template, which shows the library is meant to be consumed as a reusable native dependency rather than only as an application.
12. External dependencies that matter architecturally
The key external runtime dependency is ndn-cxx, which supplies NDN naming, Interests, Data, and faces. The sync protocol’s architecture is therefore defined by NDN transport semantics and by compact probabilistic set-reconciliation structures, not by a conventional server/database stack.
Main entry points: tests Test suite · iblt.hpp IBLT · consumer.hpp Consumer · partial-producer.hpp Partial producer
Components 16
Public API
User-facing sync roles and publication helpers.
- Common · Public shared declarations and constants used across the library.
PSync/common.hpp - Consumer · Tracks subscriptions and participates in partial synchronization.
PSync/consumer.hpp - Producer base · Common producer logic shared by partial and full producer variants.
PSync/producer-base.hpp - Partial producer · Producer role for partial synchronization over a subset of names.
PSync/partial-producer.hpp - Full producer · Producer role that synchronizes the full state of a node.
PSync/full-producer.hpp - Segment publisher · Publishes larger content as segmented NDN Data packets.
PSync/segment-publisher.hpp
Internal Algo
Compact reconciliation data structures and shared state logic.
- Bloom filter · Compact membership summary used by the consumer side.
PSync/detail/bloom-filter.hpp - IBLT · Invertible Bloom lookup table used to compute state differences.
PSync/detail/iblt.hpp - State · Models the name-state held and reconciled by producers.
PSync/detail/state.hpp - Util · Shared internal helpers used by the sync and reconciliation code.
PSync/detail/util.hpp - Access specifiers · Private visibility helper used to control internal API exposure.
PSync/detail/access-specifiers.hpp
Integration
Examples, tests, and packaging/build entrypoints.
- Consumer app · Example application showing consumer-side integration.
examples/consumer.cpp - Producer app · Example application showing producer-side integration.
examples/producer.cpp - Full sync demo · Example application demonstrating full synchronization.
examples/full-sync.cpp - Test suite · Unit and integration tests covering algorithms, roles, and publication behavior.
tests - Build & package · Waf-based build, packaging, docs, and CI/release support.
wscript
Connections 24
- Consumer → Bloom filter: summarizes · Consumer uses a Bloom filter to compact its subscription set.
- Consumer → Producer base: interacts · Consumer participates in the shared sync protocol implemented by the producer base.
- Producer base → State: tracks · Base producer logic operates on reconciled name state.
- Partial producer → Producer base: extends · Partial producer specializes the common producer behavior.
- Full producer → Producer base: extends · Full producer specializes the common producer behavior.
- Partial producer → IBLT: diffs with · Partial sync uses reconciliation tables to compute set differences.
- Full producer → IBLT: diffs with · Full sync also relies on reconciliation tables for state exchange.
- Bloom filter → IBLT: pairs with · Compact summary structures work together in the reconciliation flow.
- State → Util: uses · State logic depends on shared internal helpers.
- IBLT → Util: uses · IBLT implementation depends on shared internal helpers.
- Bloom filter → Util: uses · Bloom filter implementation depends on shared internal helpers.
- Segment publisher → Util: uses · Segment publishing relies on shared helper functions.
- Consumer app → Consumer: demonstrates · Example shows how to embed the consumer role.
- Producer app → Partial producer: demonstrates · Example shows the producer-side partial sync path.
- Full sync demo → Full producer: demonstrates · Example shows the full synchronization path.
- Test suite → Bloom filter: covers · Tests validate Bloom filter behavior.
- Test suite → IBLT: covers · Tests validate IBLT behavior.
- Test suite → State: covers · Tests validate state handling.
- Test suite → Consumer: covers · Tests validate consumer behavior.
- Test suite → Partial producer: covers · Tests validate partial producer behavior.
- Test suite → Full producer: covers · Tests validate full producer behavior.
- Test suite → Segment publisher: covers · Tests validate segmented publication behavior.
- Build & package → Test suite: runs · Build system supports test execution and validation workflows.
- Build & package → Consumer app: builds · Build system compiles example applications.