# named-data/psync architecture

> Architecture diagram of the GitHub repository named-data/psync, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/named-data/psync
- Repository: https://github.com/named-data/psync

## Overview

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`](https://github.com/named-data/psync/tree/master/tests) (Test suite), [`PSync/detail/iblt.hpp`](https://github.com/named-data/psync/blob/master/PSync/detail/iblt.hpp) (IBLT), [`PSync/consumer.hpp`](https://github.com/named-data/psync/blob/master/PSync/consumer.hpp) (Consumer), [`PSync/partial-producer.hpp`](https://github.com/named-data/psync/blob/master/PSync/partial-producer.hpp) (Partial producer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public_api["Public API"]
  node_common["Common<br/>shared defs<br/>[common.hpp]"]
  node_consumer["Consumer<br/>sync client<br/>[consumer.hpp]"]
  node_producer_base["Producer base<br/>sync core<br/>[producer-base.hpp]"]
  node_partial_producer["Partial producer<br/>partial sync"]
  node_full_producer["Full producer<br/>full sync<br/>[full-producer.hpp]"]
  node_segment_publisher["Segment publisher<br/>NDN publish"]
end

subgraph group_internal_algo["Internal Algo"]
  node_bloom_filter["Bloom filter<br/>probabilistic set<br/>[bloom-filter.hpp]"]
  node_iblt["IBLT<br/>reconciliation table<br/>[iblt.hpp]"]
  node_state["State<br/>[state.hpp]"]
  node_util["Util<br/>helpers<br/>[util.hpp]"]
  node_access_specifiers["Access specifiers<br/>internal shim"]
end

subgraph group_integration["Integration"]
  node_consumer_example["Consumer app<br/>example app<br/>[consumer.cpp]"]
  node_producer_example["Producer app<br/>example app<br/>[producer.cpp]"]
  node_full_sync_example["Full sync demo<br/>example app<br/>[full-sync.cpp]"]
  node_test_suite["Test suite<br/>validation"]
  node_build_packaging["Build & package<br/>build system"]
end

node_consumer -->|"summarizes"| node_bloom_filter
node_consumer -->|"interacts"| node_producer_base
node_producer_base -->|"tracks"| node_state
node_partial_producer -->|"extends"| node_producer_base
node_full_producer -->|"extends"| node_producer_base
node_partial_producer -->|"diffs with"| node_iblt
node_full_producer -->|"diffs with"| node_iblt
node_bloom_filter -->|"pairs with"| node_iblt
node_state -->|"uses"| node_util
node_iblt -->|"uses"| node_util
node_bloom_filter -->|"uses"| node_util
node_segment_publisher -->|"uses"| node_util
node_consumer_example -->|"demonstrates"| node_consumer
node_producer_example -->|"demonstrates"| node_partial_producer
node_full_sync_example -->|"demonstrates"| node_full_producer
node_test_suite -->|"covers"| node_bloom_filter
node_test_suite -->|"covers"| node_iblt
node_test_suite -->|"covers"| node_state
node_test_suite -->|"covers"| node_consumer
node_test_suite -->|"covers"| node_partial_producer
node_test_suite -->|"covers"| node_full_producer
node_test_suite -->|"covers"| node_segment_publisher
node_build_packaging -->|"runs"| node_test_suite
node_build_packaging -->|"builds"| node_consumer_example

click node_common "https://github.com/named-data/psync/blob/master/PSync/common.hpp"
click node_consumer "https://github.com/named-data/psync/blob/master/PSync/consumer.hpp"
click node_producer_base "https://github.com/named-data/psync/blob/master/PSync/producer-base.hpp"
click node_partial_producer "https://github.com/named-data/psync/blob/master/PSync/partial-producer.hpp"
click node_full_producer "https://github.com/named-data/psync/blob/master/PSync/full-producer.hpp"
click node_segment_publisher "https://github.com/named-data/psync/blob/master/PSync/segment-publisher.hpp"
click node_bloom_filter "https://github.com/named-data/psync/blob/master/PSync/detail/bloom-filter.hpp"
click node_iblt "https://github.com/named-data/psync/blob/master/PSync/detail/iblt.hpp"
click node_state "https://github.com/named-data/psync/blob/master/PSync/detail/state.hpp"
click node_util "https://github.com/named-data/psync/blob/master/PSync/detail/util.hpp"
click node_access_specifiers "https://github.com/named-data/psync/blob/master/PSync/detail/access-specifiers.hpp"
click node_consumer_example "https://github.com/named-data/psync/blob/master/examples/consumer.cpp"
click node_producer_example "https://github.com/named-data/psync/blob/master/examples/producer.cpp"
click node_full_sync_example "https://github.com/named-data/psync/blob/master/examples/full-sync.cpp"
click node_test_suite "https://github.com/named-data/psync/tree/master/tests"
click node_build_packaging "https://github.com/named-data/psync/tree/master/wscript"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_common,node_consumer,node_producer_base,node_partial_producer,node_full_producer,node_segment_publisher toneBlue
class node_bloom_filter,node_iblt,node_state,node_util,node_access_specifiers toneAmber
class node_consumer_example,node_producer_example,node_full_sync_example,node_test_suite,node_build_packaging toneMint
```

## Components

### Public API

User-facing sync roles and publication helpers.

- [Common](https://github.com/named-data/psync/blob/master/PSync/common.hpp): shared defs · Public shared declarations and constants used across the library. · `PSync/common.hpp`
- [Consumer](https://github.com/named-data/psync/blob/master/PSync/consumer.hpp): sync client · Tracks subscriptions and participates in partial synchronization. · `PSync/consumer.hpp`
- [Producer base](https://github.com/named-data/psync/blob/master/PSync/producer-base.hpp): sync core · Common producer logic shared by partial and full producer variants. · `PSync/producer-base.hpp`
- [Partial producer](https://github.com/named-data/psync/blob/master/PSync/partial-producer.hpp): partial sync · Producer role for partial synchronization over a subset of names. · `PSync/partial-producer.hpp`
- [Full producer](https://github.com/named-data/psync/blob/master/PSync/full-producer.hpp): full sync · Producer role that synchronizes the full state of a node. · `PSync/full-producer.hpp`
- [Segment publisher](https://github.com/named-data/psync/blob/master/PSync/segment-publisher.hpp): NDN publish · Publishes larger content as segmented NDN Data packets. · `PSync/segment-publisher.hpp`

### Internal Algo

Compact reconciliation data structures and shared state logic.

- [Bloom filter](https://github.com/named-data/psync/blob/master/PSync/detail/bloom-filter.hpp): probabilistic set · Compact membership summary used by the consumer side. · `PSync/detail/bloom-filter.hpp`
- [IBLT](https://github.com/named-data/psync/blob/master/PSync/detail/iblt.hpp): reconciliation table · Invertible Bloom lookup table used to compute state differences. · `PSync/detail/iblt.hpp`
- [State](https://github.com/named-data/psync/blob/master/PSync/detail/state.hpp): producer state · Models the name-state held and reconciled by producers. · `PSync/detail/state.hpp`
- [Util](https://github.com/named-data/psync/blob/master/PSync/detail/util.hpp): helpers · Shared internal helpers used by the sync and reconciliation code. · `PSync/detail/util.hpp`
- [Access specifiers](https://github.com/named-data/psync/blob/master/PSync/detail/access-specifiers.hpp): internal shim · Private visibility helper used to control internal API exposure. · `PSync/detail/access-specifiers.hpp`

### Integration

Examples, tests, and packaging/build entrypoints.

- [Consumer app](https://github.com/named-data/psync/blob/master/examples/consumer.cpp): example app · Example application showing consumer-side integration. · `examples/consumer.cpp`
- [Producer app](https://github.com/named-data/psync/blob/master/examples/producer.cpp): example app · Example application showing producer-side integration. · `examples/producer.cpp`
- [Full sync demo](https://github.com/named-data/psync/blob/master/examples/full-sync.cpp): example app · Example application demonstrating full synchronization. · `examples/full-sync.cpp`
- [Test suite](https://github.com/named-data/psync/tree/master/tests): validation · Unit and integration tests covering algorithms, roles, and publication behavior. · `tests`
- [Build & package](https://github.com/named-data/psync/tree/master/wscript): build system · Waf-based build, packaging, docs, and CI/release support. · `wscript`

## Connections

- 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.
