-
Notifications
You must be signed in to change notification settings - Fork 2
Refactor Node and abstraction over p2panda #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
db8ea7e
to
25ceb62
Compare
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.
25ceb62
to
c34c6ff
Compare
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.
c34c6ff
to
805e0f9
Compare
Closes #115 |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is ready for a review, but it breaks the tests ( forgot to change them to reflect api changes)