Hosted onseed.hyper.mediavia theHypermedia Protocol

Where the “haves” are computed

There are two levels.

1. Build the local “what I have” store

File:

backend/hmnet/syncing/discovery.go

In:

DiscoverObjectWithProgress(...)

The code builds one local RBSR store:

store := newAuthorizedStore()
err := s.db.WithSave(ctx, func(conn *sqlite.Conn) error {
    return loadRBSRStore(conn, dkeys, store)
})
store.Seal()

The DB-heavy part is:

loadRBSRStore(...)

which calls:

collectBlobs(...)
fillTables(...)

and then inserts CIDs into the in-memory RBSR store.

2. Filter haves per peer based on private-doc authorization

File:

backend/hmnet/syncing/syncing.go

In:

syncWithPeer(...)

Each peer gets authorization-specific filtering:

authorizedSpaces, err := s.index.GetAuthorizedSpacesForPeer(ctx, pid, requestedIRIs)
filteredStore := store.WithFilter(authorizedSpaces)

Then:

syncResources(..., filteredStore, ...)

Inside syncResources, haves/wants are computed by RBSR:

msg, err = ne.ReconcileWithIDs(msg, &haves, &wants)

Actual haves append is in:

backend/hmnet/syncing/rbsr/rbsr.go
*haveIDs = append(*haveIDs, have)

Why private docs make grouping harder

Before private docs, all peers could see the same local store:

same haves for everyone

After private docs, each peer may be authorized for different private spaces:

peer A can see public + private space X
peer B can see public only
peer C can see public + private space Y

So the daemon cannot blindly reuse the exact same “haves” list for every peer.

That is why the code has:

store.WithFilter(authorizedSpaces)

But there is still optimization room

Even with private docs, we can group peers by authorization set.

Example:

peer A authorized spaces: [space1, space2]
peer B authorized spaces: [space1, space2]
peer C authorized spaces: []
peer D authorized spaces: []

Then A and B can share one filtered store/session, and C and D can share another.

Potential optimization:

build base store once
compute authorizedSpaces per peer
group peers by authorizedSpaces key
create filteredStore once per group
reuse within group

Also, public-only peers probably all share the same filtered store.

Recap

The haves are computed in syncing.go via RBSR reconciliation, using a store built in discovery.go.

  • DB-heavy store build: discovery.goloadRBSRStore.

  • Per-peer private filtering: syncing.gostore.WithFilter(authorizedSpaces).

  • Actual haves append: rbsr.goReconcileWithIDs.

  • Private docs make global grouping harder, but grouping by identical authorization sets is still possible.

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime