Skip to content
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

Nostr Client #2

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open

Conversation

buttercat1791
Copy link
Collaborator

This PR adds a nostr namespace to the project that defines a Nostr client, built using WebSocket++ and nlohmann/json.

Notes for Reviewer

  • I am trying to write this code in such a way that we can take parts of it and produce a Nostr dev kit library to help other C++ devs who want to use the Nostr protocol. Any feedback on how to better move towards that goal is welcome.

@buttercat1791 buttercat1791 added the in-progress The issue is in progress label Jan 28, 2024
Copy link

@SilberWitch SilberWitch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First feedback.

src/nostr/nostr.hpp Outdated Show resolved Hide resolved
src/nostr/nostr_utils.cpp Outdated Show resolved Hide resolved
src/nostr/nostr.hpp Outdated Show resolved Hide resolved
src/nostr/nostr_utils.cpp Outdated Show resolved Hide resolved
src/nostr/nostr_utils.cpp Outdated Show resolved Hide resolved
src/nostr/nostr_utils.cpp Outdated Show resolved Hide resolved
src/nostr/nostr.hpp Outdated Show resolved Hide resolved
src/nostr/nostr_utils.cpp Outdated Show resolved Hide resolved
src/nostr/nostr.hpp Outdated Show resolved Hide resolved
- Rename NostrUtils -> NostrService
- Define interface IWebSocketClient
- NostrService only interacts with WebSocket protocol via the IWebSocketClient interface
- NostrService accepts a client instance in its constructor
- Create an IWebSocketClient implementation based on WebSocket++
- Create a mock implementation of IWebSocket client to use in unit tests for the NostrService class.
- Fetch and build Google Test via CMake to ensure it uses the same compiler settings and targets as the project it is testing.
// Configure the connection here via the connection pointer.
connection->set_fail_handler([this, uri](auto handle) {
// PLOG_ERROR << "Error connecting to relay " << relay << ": Handshake failed.";
lock_guard<mutex> lock(this->_propertyMutex);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isConnected also locks the mutex - I assume it works, but the lock_guard could be placed inside the if

for (string relay : unconnectedRelays)
{
thread connectionThread([this, relay]() {
this->connect(relay);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this fails? Not sure if that's possible or already covered in the function itself.


void Event::deserialize(string jsonString)
{
nlohmann::json j = nlohmann::json::parse(jsonString);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think .at() would be more safe than the index (even if it is very controlled here). Maybe you could also check out serialization https://github.com/nlohmann/json?tab=readme-ov-file#serialization--deserialization

- Add unit tests for some of the methods of `NostrService`.
- Explicitly declare specific usings rather than entire namespaces (e.g., don't to `using namespace std;`).
- Add some additional logging with Plog.
buttercat1791 added a commit to ShadowySupercode/aedile-ndk that referenced this pull request Mar 3, 2024
- Port existing work over from ShadowySupercode/gitrepublic-core#2
- Adjust project layout and configure CMake scripts accordingly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in-progress The issue is in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants