Skip to content

Conversation

jsparber
Copy link
Collaborator

@jsparber jsparber commented Aug 9, 2025

This is ready for a review, but it breaks the tests ( forgot to change them to reflect api changes)

jsparber added 10 commits August 9, 2025 11:49
This is the first step of removing the unnecessary complex abstraction
over p2panda. In the next commit the `Network` struct is renamed to
`NodeInner`.
We don't need an abstraction over `p2panda::Network` and over the next
commits logic from `Node` will be moved to `NodeInner`, therefore
`Network` isn't a good name for the struct.
This still seams like a hack, but at least it avoids a race-condition.
This adds an abstraction over the SqliteStore from p2panda. The main
purpose is to guarantee sequential writes which SqliteStore doesn't.
Eventually we could also cache inside this struct the latest operation
for each subscribed document, so that we don't need to read it from
sqlite on every new operation.
In a future commit the `Subscription` struct is returned when a user
subscribes to a document. At that point all interactions, after
subscribing to a document, have to go through this struct so that we can
guarantee that the user actually has subscribed to the document.
Tracking the online status via gossip system events isn't correct since
we may only see a small subset of peers we are talking to directly.
The author tracking is added back in a future commit.

See: #70
We want users only to interact with a document once they have subscribed
to it e.g. we need to prevent users from sending operations before they
subscribed. By only using the `Subscription` struct to handle interaction with
the document we can guarantee this programmatically. The current methods
on `Node` to interact with a document will be removed in a future
commit.
We can use the default MainContext for service startup since, no
MainLoop is running.
There is no reason to block internally.
@jsparber jsparber force-pushed the jsparber/refactor_node branch from db8ea7e to 25ceb62 Compare August 22, 2025 15:34
This allows to use a main context different then the global one.
This is needed for running tests, since tests share the same process and
hence the same global main context. We want to run one `GLib::MainLoop`
per test.
This also fixes a panic that was introduced when removing the wrong
author online state tracker. The tracker kept the runtime alive and
therefore the tests didn't panic on the drop of the tokio runtime in an
async context.
The old api will be dropped in the next commit.
We need to make sure that all task run to completion before
unsubscribing, since they may end up in a undefined state. We already
stop spawning tasks when not subscribed to the document.
We can unsubscribe from all documents for the user, when they call
shutdown.
This also ensure all spawned tasks are run to completion when
shutting down a service.
@jsparber jsparber force-pushed the jsparber/refactor_node branch from 25ceb62 to c34c6ff Compare August 22, 2025 17:49
Getting the id for a new document requires async. Having block_on() code
in reflection-doc is bad and doesn't work well with tests.
The `Document` object can't hold a strong reference to `Service` since
the document list contains a strong reference to `Document`.
We have now the `Subscription` struct that can be used to send
operations and interact with the subscribed document.
Having the entire method code inside a `tokio::spawn()` is quite
ugly and makes it harder to read. Therefore move as much code as
possible to `NodeInner`.
This implements a custom mechanism to track whether authors are online.
Each author sends a `Hello` message when they join a document, all other
authors respond with a `Ping` message. Before a author leaves a document
they send a `Bye` message. Authors also send a `Ping` message every 30
seconds to signal that they are still online, since it may be possible
that an author is unable to send a `Bye` message. If no `Ping` is
received in 60 seconds then it's assumed the author went offline.

Closes: #70
Before the `NodeInner` creation was split between `Node::run()` and
`NodeInner::new()` it makes more sense to do it all in one place.
@jsparber jsparber force-pushed the jsparber/refactor_node branch from c34c6ff to 805e0f9 Compare August 22, 2025 18:21
@jsparber jsparber marked this pull request as ready for review August 22, 2025 18:22
@jsparber
Copy link
Collaborator Author

Closes #115

@jsparber jsparber merged commit 1b03c10 into main Aug 22, 2025
3 checks passed
@jsparber jsparber mentioned this pull request Aug 22, 2025
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