Mostly fixes error handling, but there are a few functional changes:
* ReadMessageContent() returns an error upon SetReadDeadline() failures.
* hostv2 SendMessage() returns an error upon write failures.
This is a move-only refactor, intended to bubble the Host interface
(which is the main p2p interface) to the top. It also has the effect of
reducing name stutter (host.Host → p2p.Host).
This is mainly for hostv2 libp2p support.
addPeer will add new peer into the peerstore.
NewHost function add Identity support for libp2p after generating
keypair. The PeerID is generated from the public key, will be used to
find the right PeerInfo for libp2p communication.
Signed-off-by: Leo Chen <leo@harmony.one>
In p2p library, I added a channel notification mechansim when it failed
to send messages after retries. The failed p2p.Peer will be notified to
caller via the channel. Then the leader knows which peer is offline and
adds to an offline list.
Before another consensus is started, the ledaer will check the offline
list and remove the node from the validator list. Leader will have to
broadcast the Pong message to all validators to sync the public key
list.
Signed-off-by: Leo Chen <leo@harmony.one>
In general, protocol designs should not assume the underlying layer to
provide reliable transmission of a message or guaranteed receipt of
confirmation. Application level protocols that wish to guarantee
delivery should implement its own acknowledgement mechanism.
Note that our consensus (modeled after PBFT) does not require such
positive acknowledgements of each message sent.
If one peer is bogged down, it hinders the entire progress of the
consensus. Consensus should be allowed to proceed even with a few
outliers still lagging behind, if enough quorum has received the message
and sent replies back.