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

Cademlia and p2p peer pool (please dont merge) #253

Closed
wants to merge 24 commits into from

Conversation

zelig
Copy link
Contributor

@zelig zelig commented Jan 9, 2015

initial untested commit for review @fjl
further architecture design coming in a comment

- SuggestPeer lookup convenience method from backend to server
- now takes (host, pubkey) arguments
- earlier suggest peer -> AddPeer which now calls the peer selector
- delete peer_util (save, restore functionality belongs to peer selector)
- peerRecord implements peerInfo (a record entry object for peer info)
- introduce lastActive timestamping via the protocol pingpong loop
- instead of connect channel, peer simply takes 2 functions (addPeer, getPeers) this is inline with blockPool etc
- protocol.PeerList now many phases (server gives active peers including own address, selector proximity peers, and protocol filters for recipient peer and does encoding)
- fix and simplify peer_selector
Conflicts:
	p2p/protocol.go
	p2p/protocol_test.go
…te file - maybe should be in a different package...
- peerInfo interface has Disconnect(Reason) func only
- peerSelector.AddPeer returns boolean only (for acceptance); all connection is managed by the server
- peerSelector.GetPeers returns peer objects

remove cademlia implementation into a different file
- get rid of dialLoop entirely
- get rid of peerConnect channel in favour of simple function call
- server handles the peerSelector hook for prospective outbound peers
- no need for NoDial anymore really
- changed how peer is initialised
- changed peer initialisation (now peer can be just a record)
- peer.Addr (always listening address)
- peer.Hash() memoized hash of the address (pubkey from dialaddr or listenaddr)
- LastActive updates with channel
- ActiveAddresses convenience filter method returns addresses of all connected peers
- connectFunc on server, by default it calles srv.connect(peer, conn)
- srv.connect(peer, conn) is the init code from peer
- this still provides a nice hook for testing
- adapt server and peer tests
…on peer

- keep missing, mismatch and invalid pubkey errors to errPubkeyInvalid -> DiscInvalidIdentity
- introduce errBlacklistedPeer, errSelfConnection, errConnectedPeer, errRejectedPeer -> DiscUselessPeer
- peer.pubkeyHook -> peer.verifyPeerHook
- peer.verifyPeerHook called on peer by protocol after handshake info set
- peer.Pubkey looks into identity.Pubkey  too (redundant though)
- after handshake when nodeID is known
- part of verifyPeerHook
- peerSelector.AddPeer now returns error
- parameter are Cademlia public fields
- compulsory Hash, verifiable HashBits, Hash, RowLength, adjustable MaxAge, PurgeInterval, ProxSize
- they default to package level constants and vars
- row initialisation
- adjustProx, updateProx to 'update depth'
- proper global locking thanks to Prox
- map from entries to peerInfo for GetPeers
- call disconnect on the worst peer expunged when inserting
- locking for purge
- extract self.Distance <- self.DistanceTo (made public method)
- call disconnect when purging
- distance -> proximity
- proximity bin properly implemented
- fix update and adjust prox functions
- rename fields and methods
- comments
@fjl
Copy link
Contributor

fjl commented Jan 9, 2015

We had a long conversation and arrived at this. This is probably not going to be implemented, let's remember it for the future.

The idea is that we maintain a protocol-specific rating of peers in peer pools. We already
have the whisper.Whisper and eth.Blockpool objects which can serve as peer pools
(they know which peers have been good in the past). Swarm/TCP requires kademlia peers
for lookups and would also implement a pool. Peer pools would need to take care of
persistence internally, package p2p could provide common helpers for them.

The p2p.Server needs to find good
peers to connect to and can ask the protocol specific pools for good peers.
When new inbound peers connect or peer suggestions are received, package p2p would try
to add them to all pools. If none of them wants to keep the peer, it would be discarded.

What needs to be solved (which is also a general open question in the ethereum project) is
how to combine the requirements of all protocols to arrive at a good overall peer set.
A stupid initial implementation could just divide the available number of peer connections
into N sections (where N is the number of available pools) and fill each section from its
respective pool.

type Peer interface {
    Addr() net.Addr
    Pubkey() []byte
    LastActive() time.Time
}

type PeerPool interface {
    // AddPeer adds knowledge about a peer to the pool.
    // The pool should check whether this peer is
    // good and return an error if it considers
    // the peer unsuitable.
    AddPeer(Peer) error

    // GoodPeers fills the peers slice with suggestions
    // of peers that should be connected to, in order
    // of their goodness.
    // It returns the number of peers written.
    GoodPeers(peers []Peer) (n int)
}

type Protocol struct {
    Name string
    // ...and the other fields

    // PeerPool is the peer selection algorithm for
    // the protocol. It may be nil if the protocol
    // does not prefer a particular algorithm.
    PeerPool
}

@obscuren obscuren added the review label Jan 9, 2015
@zelig
Copy link
Contributor Author

zelig commented Jan 10, 2015

Cademlia on wiki https://github.com/ethereum/wiki/wiki/Cademlia-Peer-Selection
For completeness sake, see what C++ guys have to say about this: https://github.com/ethereum/cpp-ethereum/wiki/RLPx-changes

@gbalint gbalint deleted the kademlia branch May 25, 2018 14:45
ngtuna pushed a commit to ngtuna/tomochain that referenced this pull request Nov 10, 2018
…dation

tiny fix M2 duplicate sign a block
Zergity pushed a commit to Zergity/go-ethereum that referenced this pull request Apr 28, 2020
* add web3 extension for dccs

* Update internal/web3ext/web3ext.go

* Update internal/web3ext/web3ext.go
maoueh pushed a commit to streamingfast/go-ethereum that referenced this pull request Aug 13, 2021
sduchesneau pushed a commit to streamingfast/go-ethereum that referenced this pull request Jan 4, 2024
fix hex-based inputs in TestUnMarshalHexOrDecimal64
atenjin pushed a commit to alt-research/go-ethereum that referenced this pull request Apr 4, 2024
…otone-update-mar-14

Update Ecotone mainnet activation to Mar 14 00:00:01 UTC
luanxu-mxc pushed a commit to MXCzkEVM/mxc-geth that referenced this pull request Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants