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

target a subset of pool relays for subscriptions and report on which relays have events #168

Closed
DanConwayDev opened this issue Sep 14, 2023 · 6 comments · Fixed by #176, #178 or #273
Closed
Labels
enhancement New feature or request
Milestone

Comments

@DanConwayDev
Copy link
Contributor

Describe the enhancement

  1. target subscriptions to a subset of relays in a pool
  2. record which relays returned events and provide method to query this

Use case

  1. Use of the orthodox / gossip model
  2. Increase privacy by reducing the queries sent to each relay
  3. Refining relays being sent queries based on likelihood they will have a given message

Additional context
I'm very much interested in your thoughts on this generally and how you would approach it. I'm also happy to contribute towards a PR.

@DanConwayDev DanConwayDev added the enhancement New feature or request label Sep 14, 2023
@yukibtc
Copy link
Member

yukibtc commented Sep 15, 2023

Hi, currently it's possible to subscribe only to specific relays:

let relay = client.relay("wss://relay.example.com").await?;
relay.subscribe(filters, wait).await?; // This use the default internal ID (the pool use a different internal ID)
// OR
relay.subscribe_with_internal_id(InternalSubscriptionId::Custom("my_custom_id".to_string()), filters, wait).await?;

But yes, I can try to add a method to do this automatically, specifying a list of relays.


record which relays returned events and provide method to query this

Regarding this, I suppose that it's needed a DB. I tried to implement it times ago but it's difficult to generalize it. I'm thinking a way to implement again a DB to store all the received events and allow the user to query from it without messing up the code. Probably using nostrdb.
Anyway, it's currently possible to know what relay sent an event by listening for notifications (but you have to record the events by yourself for now):

client
    .handle_notifications(|notification| async {
        if let RelayPoolNotification::Message(url, message) = notification {
            // handle message
        }
        Ok(false) // Set to true to exit from the loop
})
.await?;

@DanConwayDev
Copy link
Contributor Author

But yes, I can try to add a method to do this automatically, specifying a list of relays.

Thanks! That sounds ideal.

I suppose that it's needed a DB.

Perhaps my use of the word query is misleading. I can see a need for a full event cache stored in a database but this requirement is way more simplistic. What about adding a events_on_relays: Arc<Mutex<Vec<(& EventId, Vec<&Url>)>>>, property to RelayPoolTask, coupled with a recently_seen_on_relays(&EventId) -> Vec<Url>?

@yukibtc
Copy link
Member

yukibtc commented Sep 18, 2023

Ah, yeah, I already store in RAM the seen event ids in the RelayPoolTask (Arc<Mutex<VecDeque<EventId>>>). I can try to upgrade that field and store also urls.
To avoid to increase too much the RAM storing also the relays URLs for every ID, probably it's better to add something like RelayId that will be a unique (incremental) usize for every relay.
The RelayId can be used then to get the relay URL.

What do you think?

@DanConwayDev
Copy link
Contributor Author

Yes that sounds good, or potentially for cleaner lifetime management use a reference to a Url.

This was linked to pull requests Oct 12, 2023
@yukibtc yukibtc added this to the Release v0.25 milestone Oct 12, 2023
@yukibtc yukibtc modified the milestones: Release v0.25, Release v0.26 Nov 1, 2023
@yukibtc yukibtc reopened this Nov 13, 2023
@yukibtc yukibtc modified the milestones: Release v0.26, Release v0.27 Dec 13, 2023
@yukibtc yukibtc modified the milestones: Release v0.27, Release v0.28 Jan 17, 2024
@yukibtc
Copy link
Member

yukibtc commented Feb 1, 2024

Hey, it's not possible to send, get or request events (or messages) to/from specific relays.

Get events from specific relays:

client.get_events_from(["wss://relay1.com", "wss://other.relay"], ...).await?;

Send event to specific relays:

client.send_event_to(["wss://relay1.com", "wss://other.relay"], ...).await?;

To know where an event was seen:

let database = client.database();
let urls = database.event_seen_on_relays(event_id).await?;

@yukibtc
Copy link
Member

yukibtc commented Feb 1, 2024

The database.event_seen_on_relays method is already available in v0.27. The other changes are available in master branch and will be included in v0.28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants