refactor(gossipsub): revise symbol naming to follow conventions (#3303)

Changes regarding the  #2217
This commit is contained in:
StemCll
2023-01-27 05:44:04 +01:00
committed by GitHub
parent e2b3c1190a
commit ab59af4d46
18 changed files with 639 additions and 633 deletions

View File

@ -18,9 +18,9 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
use crate::error::{GossipsubHandlerError, ValidationError};
use crate::error::{HandlerError, ValidationError};
use crate::protocol::{GossipsubCodec, ProtocolConfig};
use crate::types::{GossipsubRpc, PeerKind, RawGossipsubMessage};
use crate::types::{PeerKind, RawMessage, Rpc};
use asynchronous_codec::Framed;
use futures::prelude::*;
use futures::StreamExt;
@ -53,10 +53,10 @@ pub enum HandlerEvent {
/// any) that were received.
Message {
/// The GossipsubRPC message excluding any invalid messages.
rpc: GossipsubRpc,
rpc: Rpc,
/// Any invalid messages that were received in the RPC, along with the associated
/// validation error.
invalid_messages: Vec<(RawGossipsubMessage, ValidationError)>,
invalid_messages: Vec<(RawMessage, ValidationError)>,
},
/// An inbound or outbound substream has been established with the peer and this informs over
/// which protocol. This message only occurs once per connection.
@ -65,7 +65,7 @@ pub enum HandlerEvent {
/// A message sent from the behaviour to the handler.
#[derive(Debug)]
pub enum GossipsubHandlerIn {
pub enum HandlerIn {
/// A gossipsub message to send.
Message(crate::rpc_proto::Rpc),
/// The peer has joined the mesh.
@ -82,7 +82,7 @@ pub enum GossipsubHandlerIn {
const MAX_SUBSTREAM_CREATION: usize = 5;
/// Protocol Handler that manages a single long-lived substream with a peer.
pub struct GossipsubHandler {
pub struct Handler {
/// Upgrade configuration for the gossipsub protocol.
listen_protocol: SubstreamProtocol<ProtocolConfig, ()>,
@ -124,7 +124,7 @@ pub struct GossipsubHandler {
idle_timeout: Duration,
/// Collection of errors from attempting an upgrade.
upgrade_errors: VecDeque<ConnectionHandlerUpgrErr<GossipsubHandlerError>>,
upgrade_errors: VecDeque<ConnectionHandlerUpgrErr<HandlerError>>,
/// Flag determining whether to maintain the connection to the peer.
keep_alive: KeepAlive,
@ -161,10 +161,10 @@ enum OutboundSubstreamState {
Poisoned,
}
impl GossipsubHandler {
/// Builds a new [`GossipsubHandler`].
impl Handler {
/// Builds a new [`Handler`].
pub fn new(protocol_config: ProtocolConfig, idle_timeout: Duration) -> Self {
GossipsubHandler {
Handler {
listen_protocol: SubstreamProtocol::new(protocol_config, ()),
inbound_substream: None,
outbound_substream: None,
@ -245,10 +245,10 @@ impl GossipsubHandler {
}
}
impl ConnectionHandler for GossipsubHandler {
type InEvent = GossipsubHandlerIn;
impl ConnectionHandler for Handler {
type InEvent = HandlerIn;
type OutEvent = HandlerEvent;
type Error = GossipsubHandlerError;
type Error = HandlerError;
type InboundOpenInfo = ();
type InboundProtocol = ProtocolConfig;
type OutboundOpenInfo = crate::rpc_proto::Rpc;
@ -258,17 +258,17 @@ impl ConnectionHandler for GossipsubHandler {
self.listen_protocol.clone()
}
fn on_behaviour_event(&mut self, message: GossipsubHandlerIn) {
fn on_behaviour_event(&mut self, message: HandlerIn) {
if !self.protocol_unsupported {
match message {
GossipsubHandlerIn::Message(m) => self.send_queue.push(m),
HandlerIn::Message(m) => self.send_queue.push(m),
// If we have joined the mesh, keep the connection alive.
GossipsubHandlerIn::JoinedMesh => {
HandlerIn::JoinedMesh => {
self.in_mesh = true;
self.keep_alive = KeepAlive::Yes;
}
// If we have left the mesh, start the idle timer.
GossipsubHandlerIn::LeftMesh => {
HandlerIn::LeftMesh => {
self.in_mesh = false;
self.keep_alive = KeepAlive::Until(Instant::now() + self.idle_timeout);
}
@ -296,7 +296,7 @@ impl ConnectionHandler for GossipsubHandler {
let reported_error = match error {
// Timeout errors get mapped to NegotiationTimeout and we close the connection.
ConnectionHandlerUpgrErr::Timeout | ConnectionHandlerUpgrErr::Timer => {
Some(GossipsubHandlerError::NegotiationTimeout)
Some(HandlerError::NegotiationTimeout)
}
// There was an error post negotiation, close the connection.
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)) => Some(e),
@ -319,7 +319,7 @@ impl ConnectionHandler for GossipsubHandler {
}
}
NegotiationError::ProtocolError(e) => {
Some(GossipsubHandlerError::NegotiationProtocolError(e))
Some(HandlerError::NegotiationProtocolError(e))
}
}
}
@ -343,7 +343,7 @@ impl ConnectionHandler for GossipsubHandler {
if self.inbound_substreams_created > MAX_SUBSTREAM_CREATION {
// Too many inbound substreams have been created, end the connection.
return Poll::Ready(ConnectionHandlerEvent::Close(
GossipsubHandlerError::MaxInboundSubstreams,
HandlerError::MaxInboundSubstreams,
));
}
@ -354,7 +354,7 @@ impl ConnectionHandler for GossipsubHandler {
{
if self.outbound_substreams_created >= MAX_SUBSTREAM_CREATION {
return Poll::Ready(ConnectionHandlerEvent::Close(
GossipsubHandlerError::MaxOutboundSubstreams,
HandlerError::MaxOutboundSubstreams,
));
}
let message = self.send_queue.remove(0);
@ -384,7 +384,7 @@ impl ConnectionHandler for GossipsubHandler {
}
Poll::Ready(Some(Err(error))) => {
match error {
GossipsubHandlerError::MaxTransmissionSize => {
HandlerError::MaxTransmissionSize => {
warn!("Message exceeded the maximum transmission size");
self.inbound_substream =
Some(InboundSubstreamState::WaitingInput(substream));
@ -471,7 +471,7 @@ impl ConnectionHandler for GossipsubHandler {
self.outbound_substream =
Some(OutboundSubstreamState::PendingFlush(substream))
}
Err(GossipsubHandlerError::MaxTransmissionSize) => {
Err(HandlerError::MaxTransmissionSize) => {
error!("Message exceeded the maximum transmission size and was not sent.");
self.outbound_substream =
Some(OutboundSubstreamState::WaitingOutput(substream));