Builds RPC infrastructure to handle RPC responses

This commit is contained in:
Age Manning
2019-03-19 12:47:36 +11:00
parent 31333e8f8e
commit 2657dc1465
5 changed files with 42 additions and 14 deletions

View File

@@ -46,7 +46,9 @@ impl<TSubstream: AsyncRead + AsyncWrite> NetworkBehaviourEventProcess<RPCMessage
RPCMessage::PeerDialed(peer_id) => {
self.events.push(BehaviourEvent::PeerDialed(peer_id))
}
RPCMessage::RPC(rpc_event) => self.events.push(BehaviourEvent::RPC(rpc_event)),
RPCMessage::RPC(peer_id, rpc_event) => {
self.events.push(BehaviourEvent::RPC(peer_id, rpc_event))
}
}
}
}
@@ -87,7 +89,7 @@ impl<TSubstream: AsyncRead + AsyncWrite> Behaviour<TSubstream> {
/// The types of events than can be obtained from polling the behaviour.
pub enum BehaviourEvent {
RPC(RPCEvent),
RPC(PeerId, RPCEvent),
PeerDialed(PeerId),
// TODO: This is a stub at the moment
Message(String),

View File

@@ -76,7 +76,7 @@ where
fn inject_node_event(
&mut self,
_source: PeerId,
source: PeerId,
event: <Self::ProtocolsHandler as ProtocolsHandler>::OutEvent,
) {
// ignore successful send events
@@ -88,7 +88,7 @@ where
// send the event to the user
self.events
.push(NetworkBehaviourAction::GenerateEvent(RPCMessage::RPC(
event,
source, event,
)));
}
@@ -110,7 +110,7 @@ where
/// Messages sent to the user from the RPC protocol.
pub enum RPCMessage {
RPC(RPCEvent),
RPC(PeerId, RPCEvent),
PeerDialed(PeerId),
}

View File

@@ -105,8 +105,8 @@ impl Stream for Service {
debug!(self.log, "Message received: {}", m);
return Ok(Async::Ready(Some(Libp2pEvent::Message(m))));
}
Ok(Async::Ready(Some(BehaviourEvent::RPC(event)))) => {
return Ok(Async::Ready(Some(Libp2pEvent::RPC(event))));
Ok(Async::Ready(Some(BehaviourEvent::RPC(peer_id, event)))) => {
return Ok(Async::Ready(Some(Libp2pEvent::RPC(peer_id, event))));
}
Ok(Async::Ready(Some(BehaviourEvent::PeerDialed(peer_id)))) => {
return Ok(Async::Ready(Some(Libp2pEvent::PeerDialed(peer_id))));
@@ -158,7 +158,7 @@ fn build_transport(
/// Events that can be obtained from polling the Libp2p Service.
pub enum Libp2pEvent {
// We have received an RPC event on the swarm
RPC(RPCEvent),
RPC(PeerId, RPCEvent),
PeerDialed(PeerId),
Message(String),
}