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

feat(iroh-net): persist known peer info #1488

Merged
merged 30 commits into from
Sep 25, 2023

Conversation

divagant-martian
Copy link
Contributor

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

Description

Rough list of changes

  • add an option to the MagicEndpointBuilder to set the path in which peers are saved. This is used to read peers on start up and store them on an interval and on shutdown.
  • add KnownPeers to ease serializing and deserializing peer info
  • move the logic of add_known_addr to the PeerMap to facilitate instantiating from a known peer list
  • Add an IrohPath for the peers.
  • Add an option to the Nodes builder to set the path, passed down to the endpoint.
  • For serialization it makes sense to have an object modelling the peer addressing info. This is the AddrInfo, which now replaces the custom IrohInfo

Notes & open questions

Change checklist

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

@Frando Frando mentioned this pull request Sep 18, 2023
29 tasks
@divagant-martian divagant-martian changed the title refactor(iroh-net): persist known peer info feat(iroh-net): persist known peer info Sep 18, 2023
@divagant-martian divagant-martian marked this pull request as ready for review September 19, 2023 22:27
@divagant-martian divagant-martian linked an issue Sep 20, 2023 that may be closed by this pull request
@b5 b5 added this to the v0.6.0 milestone Sep 20, 2023
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.

Looks good!

iroh-gossip/src/net.rs Outdated Show resolved Hide resolved
iroh-net/src/magic_endpoint.rs Show resolved Hide resolved
iroh-net/src/magic_endpoint.rs Outdated Show resolved Hide resolved
iroh-net/src/magicsock.rs Show resolved Hide resolved
iroh/src/config.rs Outdated Show resolved Hide resolved
github-merge-queue bot pushed a commit that referenced this pull request 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 #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 #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

- [x] Self-review.
- [x] Documentation updates if relevant.
- [ ] Tests if relevant.
msock_sender: mpsc::Sender<ActorMessage>,
) -> anyhow::Result<Self> {
let mut me = PeerMap::default();
let contents = std::fs::read(path)?;
Copy link
Member

@Frando Frando Sep 25, 2023

Choose a reason for hiding this comment

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

We could read in chunks here. However the file would need to get really big for this to be an issue. A PeerAddr will take less than 100 bytes even with a few socket addresses. So if you store 10.000 peers that'd do a ~1MB allocation here. Could make it async then too. However as this is only run once when binding the socket it won't matter much in practice I'd guess.
I think it's fine to keep as-is now, and we could move to chunked reading easily in a follow-up.

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.

LGTM! Let's get this in 👍

We might want to add a full test with a "recovering" endpoint (shutdown, restart, reconnect) to test the save-on-shutdown and read-on-bin, but that can also be a followup I'd say.

@divagant-martian divagant-martian added this pull request to the merge queue Sep 25, 2023
Merged via the queue into n0-computer:main with commit 2e3516d Sep 25, 2023
@divagant-martian divagant-martian deleted the persist-peer-map branch September 25, 2023 17:33
github-merge-queue bot pushed a commit that referenced this pull request Sep 28, 2023
## Description

Adds an e2e test for #1488 

## Notes & open questions

na

## Change checklist

- [x] Self-review.
- [ ] Documentation updates if relevant.
- [x] Tests if relevant.
matheus23 pushed a commit that referenced this pull request Nov 14, 2024
## Description

Rough list of changes
- add an option to the `MagicEndpointBuilder` to set the path in which
peers are saved. This is used to read peers on start up and store them
on an interval and on shutdown.
- add `KnownPeers` to ease serializing and deserializing peer info
- move the logic of `add_known_addr` to the `PeerMap` to facilitate
instantiating from a known peer list
- Add an `IrohPath` for the peers.
- Add an option to the `Node`s builder to set the path, passed down to
the endpoint.
- For serialization it makes sense to have an object modelling the peer
addressing info. This is the `AddrInfo`, which now replaces the custom
`IrohInfo`

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [x] Self-review.
- [x] Documentation updates if relevant.
- [x] Tests if relevant.
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.

iroh-net: Persist peer information
4 participants