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

refactor(*): rework NodeAddr #1506

Merged
merged 6 commits into from
Sep 21, 2023

Conversation

divagant-martian
Copy link
Contributor

@divagant-martian divagant-martian commented Sep 21, 2023

Description

  • Adds a AddrInfo that contains the addressing information of peers. This is necessary as it's own type since it's serialized both in gossip and in feat(iroh-net): persist known peer info #1488
  • Renames NodeAddr to PeerData (better name suggestions are well received) this helps consolidate the "peer" terminology already present throughout gossip, sync, downloader, and many other places
  • Use this type in different parts of the code. Some other types that can be replaced by this are left to refactor: Use iroh_net::PeerAddr more #1493

Notes & open questions

This applies the suggestion of doing connect using the full type. It's debatable if this is better than connect(PublicKey, AddrInfo) but both are imo an improvement over the current way since the idea if "what does iroh need to connect to a peer" is now fully described in a type

Change checklist

  • Self-review.
  • Documentation updates if relevant.
  • Tests if relevant.

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct NodeAddr {
pub struct PeerData {
Copy link
Member

@Frando Frando Sep 21, 2023

Choose a reason for hiding this comment

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

About the name - What about PeerAddr? To me having addr in there suggests "this is what you need to connect", which is what it is. So if we decided for Peer, not Node, then I'd say let's do PeerAddr.
And then maybe have info: AddrInfo, without the addr_ prefix.

) -> Result<quinn::Connection> {
self.add_known_addrs(node_id, derp_region, known_addrs)
.await?;
pub async fn connect(&self, peer_data: PeerData, alpn: &[u8]) -> Result<quinn::Connection> {
Copy link
Member

Choose a reason for hiding this comment

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

I think here peer_addr: PeerAddr reads much nicer than PeerData

@Frando
Copy link
Member

Frando commented Sep 21, 2023

LGTM! Would change the naming of the combined type to include Addr.
Otherwise this does everything that #1493 did, right? Only difference I've seen is that #1493 also replaced the PeerSource type in iroh/sync_engine/live.rs.

Copy link
Member

@Frando Frando left a comment

Choose a reason for hiding this comment

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

Approving, with the suggestion to change the naming to PeerAddr or similar.
Finer details or further can be done in followups but let's get the actual change in to have a combined type we use in the interface 👍

endpoints: endpoints.to_vec(),
};
self.msock.add_known_addr(addr).await?;
pub async fn add_peer_data(&self, peer_data: PeerData) -> Result<()> {
Copy link
Member

Choose a reason for hiding this comment

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

This could be add_peer_addr with the other suggested rename, which sounds fine to me too.

@divagant-martian divagant-martian added this to the v0.6.0 milestone Sep 21, 2023
@divagant-martian divagant-martian added this pull request to the merge queue Sep 21, 2023
Merged via the queue into n0-computer:main with commit f16e439 Sep 21, 2023
15 checks passed
@divagant-martian divagant-martian deleted the rework-node-addr branch September 21, 2023 16:12
divagant-martian pushed a commit that referenced this pull request Sep 22, 2023
…able tests (#1512)

fix(gossip): properly encode peer data.** #1506 introduced a bug:
github-merge-queue bot pushed a commit that referenced this pull request Sep 22, 2023
…able tests (#1513)

## Description

* **fix(gossip): properly encode peer data.** #1506 introduced a bug:
The `PeerData` was encoded from the `PeerAddr` (including the peer id)
but decoded to `AddrInfo` (without the peer id). So it failed, and
dialing peers failed. It only did not matter much because most tests use
tickets separately, so do not rely on the `PeerData` gossip.
* **feat: expose neighbor events** through document subscriptions. for
now used to write better and less flakey tests. also useful for stats
like usecases, and potentially others.
* **tests: improve sync tests** and make `sync_full_basic` not flakey
anymore (hopefully). the main change is that for some events, we don't
care about the exact order in tests anymore, because the exact order is
too unpredictable timing-wise for things that happen concurrently.
instead they are matched in chunks.

## Change checklist

- [x] Self-review.
- [x] Documentation updates if relevant.
- [x] Tests if relevant.

Replaces #1512
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants