Comments (8)
@Vurich @rphmeier could you provide some feedback on the interface of the Peer Store as defined in https://github.com/paritytech/libp2p-rs/blob/fh-add-peer/libp2p-peerstore/src/peerstore.rs
The implementation (memory_peerstore.rs
) is sort of retarded, and probably not even correct, I just put stuff in to satisfy the tests and make sure that the implementation "feels" alright.
from rust-libp2p.
I feel like you should have a get(&self) -> &Peer
and get_mut(&mut self) -> &mut Peer
(or if you need more complex logic you can use some PeerMut
gatekeeper type). I don't like the duplication of get_*
since they all do the getting logic, so it wastes cycles and keystrokes if you want to edit multiple things at once.
from rust-libp2p.
clear_addrs
should return Vec<Multiaddr>
.
Isn't PeerId
a really light type? seems weird to return the Vec<&PeerId>
when getting known peers. In general, what about returning/accepting iterators instead of Vec
for arguments? I guess it doesn't play as well with the Box<PeerStore>
situation.
from rust-libp2p.
Ideally we would prevent any use of unavoidable allocations in a library. My recommendation is an associated type that implements Iterator<Item = Multiaddr>
and defaults to Vec
.
from rust-libp2p.
One question I have myself is if PeerId
and PeerInfo
should somehow actually be the same type, but then I'm not sure how you'd efficiently do lookups, right now there's HashMap<PeerId, PeerInfo>
.
But PeerId
is really just a multihash, and PeerInfo
is responsible for a few things, most importantly managing Multiaddr
s. The set of Multiaddr
needs to be mutated either implictly or explicitly. The Go implementation mutates implicitly, when adding or removing a Multiaddr
it goes through and removes ones with expired TTLs. I'd probably be in favor of an implicit thing as well, when you call get only returning ones with non-expired TTLs and when calling add/set you actually remove the expired ones to "clean up".
Ideally I would've wanted Multiaddr
to be a HashSet
, not a Vec
, because that's what it is. But it might even be a HashMap<Multiaddr,TTL>
, the problem right now is that Multiaddr
doesn't implement Hash
.
seems weird to return the Vec<&PeerId> when getting known peers.
Yeah, i actually forgot this in there. My idea was to return an iterator, but the problem is that the set of Peers can be modified after getting it, so the lifetime of the iterator isn't long enough, though I think there's a way around this. This particular case was a hack to get around it :P
so it wastes cycles and keystrokes if you want to edit multiple things at once
You would never edit a PeerId
at all, you'd edit it's associated PeerInfo
, and then really only through the Peerstore
, this is exactly why I feel the two structures need to be more strongly linked, i'm just not exactly sure how.
My recommendation is an associated type that implements
Iterator<Item = Multiaddr>
and defaults toVec
.
I'm not sure that Iterator
would be enough. PeerInfo
needs to own the datastructure completely because it actually needs to do some stuff like deduplicating it (or updating the TTL) if another Multiaddr
is added, and remove stuff if the TTL expires.
from rust-libp2p.
So hopefully Multiaddr
will implement Hash
soon enough. There are a bunch of problems I have with that API and internal representation but I guess it's good enough for now. If the PeerId
is immutable and the PeerInfo
is mutable then can we just expose something similar to the entry API and keep them seperate?
from rust-libp2p.
#38 is an initial implementation, but chances are that it will require some modifications in the future.
from rust-libp2p.
Closing this in favor of more specific issues needed for potential modifications in the future.
from rust-libp2p.
Related Issues (20)
- Using VecDeque for pending events in various protocols causes task to not wake when a new event is added HOT 11
- Second node not building. Error: InvalidMultiaddr HOT 7
- Relay : 'Hop' spec supports zero limit, but the impl does not HOT 3
- Confusing PING tutorial HOT 4
- Opening a stream with MultiAddr as well as PeerId HOT 2
- Refactor file-sharing example to use tokio instead of async-std
- `Gossipsub`'s substreams keep all connections alive after `idle_connection_timeout`
- mergify continously approving approved pull requests HOT 6
- WebRTC connection doesn't close after timeout HOT 2
- Promote common dependencies to workspace level
- file-sharing works only on local interface HOT 1
- kad: FIND_NODE not conform to specs HOT 9
- Improve request/response documentation HOT 4
- Compilation on docs.rs is failing
- mdns tokio timer panics HOT 2
- Signature verification fails on handshake if 1024 bit RSA key is used HOT 2
- relay: panics due to unimplemented time in wasm HOT 2
- kad: consume `FromSwarm::NewExternalAddrOfPeer` HOT 14
- Reduce `NewExternalAddrCandidate` reports from `identify`
- kad: make `automatic_bootstrap_interval` publicly configurable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-libp2p.