Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Rename on_demand to light_dispatch and various minor changes (#3315)
Browse files Browse the repository at this point in the history
* Rename on_demand to light_server

* Small docs improvement

* Rename on_block_announce to update_best_number

* More minor documentation

* Light server -> light dispatch

* is_light_rq_response -> is_light_response
  • Loading branch information
tomaka authored and gavofyork committed Aug 7, 2019
1 parent e560b2a commit 25f68b3
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 178 deletions.
2 changes: 1 addition & 1 deletion core/network/src/on_demand_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! On-demand requests service.
use crate::protocol::on_demand::RequestData;
use crate::protocol::light_dispatch::RequestData;
use std::sync::Arc;
use futures::{prelude::*, sync::mpsc, sync::oneshot};
use futures03::compat::{Compat01As03, Future01CompatExt as _};
Expand Down
42 changes: 21 additions & 21 deletions core/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use message::{BlockAttributes, Direction, FromBlock, Message, RequestId};
use message::generic::{Message as GenericMessage, ConsensusMessage};
use event::Event;
use consensus_gossip::{ConsensusGossip, MessageRecipient as GossipMessageRecipient};
use on_demand::{OnDemandCore, OnDemandNetwork, RequestData};
use light_dispatch::{LightDispatch, LightDispatchNetwork, RequestData};
use specialization::NetworkSpecialization;
use sync::{ChainSync, SyncState};
use crate::service::{TransactionPool, ExHashT};
Expand All @@ -53,7 +53,7 @@ mod util;
pub mod consensus_gossip;
pub mod message;
pub mod event;
pub mod on_demand;
pub mod light_dispatch;
pub mod specialization;
pub mod sync;

Expand Down Expand Up @@ -96,8 +96,8 @@ pub struct Protocol<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> {
/// Interval at which we call `propagate_extrinsics`.
propagate_timeout: Box<dyn Stream<Item = (), Error = ()> + Send>,
config: ProtocolConfig,
/// Handler for on-demand requests.
on_demand_core: OnDemandCore<B>,
/// Handler for light client requests.
light_dispatch: LightDispatch<B>,
genesis_hash: B::Hash,
sync: ChainSync<B>,
specialization: S,
Expand Down Expand Up @@ -149,12 +149,12 @@ pub struct PeerInfo<B: BlockT> {
pub best_number: <B::Header as HeaderT>::Number,
}

struct OnDemandIn<'a, B: BlockT> {
struct LightDispatchIn<'a, B: BlockT> {
behaviour: &'a mut CustomProto<B, Substream<StreamMuxerBox>>,
peerset: peerset::PeersetHandle,
}

impl<'a, B: BlockT> OnDemandNetwork<B> for OnDemandIn<'a, B> {
impl<'a, B: BlockT> LightDispatchNetwork<B> for LightDispatchIn<'a, B> {
fn report_peer(&mut self, who: &PeerId, reputation: i32) {
self.peerset.report_peer(who.clone(), reputation)
}
Expand Down Expand Up @@ -373,7 +373,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
peers: HashMap::new(),
chain,
},
on_demand_core: OnDemandCore::new(checker),
light_dispatch: LightDispatch::new(checker),
genesis_hash: info.chain.genesis_hash,
sync,
specialization: specialization,
Expand Down Expand Up @@ -445,15 +445,15 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
/// Starts a new data demand request.
///
/// The parameter contains a `Sender` where the result, once received, must be sent.
pub(crate) fn add_on_demand_request(&mut self, rq: RequestData<B>) {
self.on_demand_core.add_request(OnDemandIn {
pub(crate) fn add_light_client_request(&mut self, rq: RequestData<B>) {
self.light_dispatch.add_request(LightDispatchIn {
behaviour: &mut self.behaviour,
peerset: self.peerset_handle.clone(),
}, rq);
}

fn is_on_demand_response(&self, who: &PeerId, response_id: message::RequestId) -> bool {
self.on_demand_core.is_on_demand_response(&who, response_id)
fn is_light_response(&self, who: &PeerId, response_id: message::RequestId) -> bool {
self.light_dispatch.is_light_response(&who, response_id)
}

fn handle_response(
Expand Down Expand Up @@ -506,7 +506,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
GenericMessage::BlockRequest(r) => self.on_block_request(who, r),
GenericMessage::BlockResponse(r) => {
// Note, this is safe because only `ordinary bodies` and `remote bodies` are received in this matter.
if self.is_on_demand_response(&who, r.id) {
if self.is_light_response(&who, r.id) {
self.on_remote_body_response(who, r);
} else {
if let Some(request) = self.handle_response(who.clone(), &r) {
Expand Down Expand Up @@ -629,7 +629,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
}
self.sync.peer_disconnected(peer.clone());
self.specialization.on_disconnect(&mut context, peer.clone());
self.on_demand_core.on_disconnect(OnDemandIn {
self.light_dispatch.on_disconnect(LightDispatchIn {
behaviour: &mut self.behaviour,
peerset: self.peerset_handle.clone(),
}, peer);
Expand Down Expand Up @@ -793,7 +793,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
&mut ProtocolContext::new(&mut self.context_data, &mut self.behaviour, &self.peerset_handle)
);
self.maintain_peers();
self.on_demand_core.maintain_peers(OnDemandIn {
self.light_dispatch.maintain_peers(LightDispatchIn {
behaviour: &mut self.behaviour,
peerset: self.peerset_handle.clone(),
});
Expand Down Expand Up @@ -914,7 +914,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
};

let info = self.context_data.peers.get(&who).expect("We just inserted above; QED").info.clone();
self.on_demand_core.on_connect(OnDemandIn {
self.light_dispatch.on_connect(LightDispatchIn {
behaviour: &mut self.behaviour,
peerset: self.peerset_handle.clone(),
}, who.clone(), status.roles, status.best_number);
Expand Down Expand Up @@ -1053,7 +1053,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
peer.known_blocks.insert(hash.clone());
}
}
self.on_demand_core.on_block_announce(OnDemandIn {
self.light_dispatch.update_best_number(LightDispatchIn {
behaviour: &mut self.behaviour,
peerset: self.peerset_handle.clone(),
}, who.clone(), *header.number());
Expand Down Expand Up @@ -1253,7 +1253,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
response: message::RemoteCallResponse
) {
trace!(target: "sync", "Remote call response {} from {}", response.id, who);
self.on_demand_core.on_remote_call_response(OnDemandIn {
self.light_dispatch.on_remote_call_response(LightDispatchIn {
behaviour: &mut self.behaviour,
peerset: self.peerset_handle.clone(),
}, who, response);
Expand Down Expand Up @@ -1294,7 +1294,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
response: message::RemoteReadResponse
) {
trace!(target: "sync", "Remote read response {} from {}", response.id, who);
self.on_demand_core.on_remote_read_response(OnDemandIn {
self.light_dispatch.on_remote_read_response(LightDispatchIn {
behaviour: &mut self.behaviour,
peerset: self.peerset_handle.clone(),
}, who, response);
Expand Down Expand Up @@ -1335,7 +1335,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
response: message::RemoteHeaderResponse<B::Header>,
) {
trace!(target: "sync", "Remote header proof response {} from {}", response.id, who);
self.on_demand_core.on_remote_header_response(OnDemandIn {
self.light_dispatch.on_remote_header_response(LightDispatchIn {
behaviour: &mut self.behaviour,
peerset: self.peerset_handle.clone(),
}, who, response);
Expand Down Expand Up @@ -1401,7 +1401,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
who,
response.max
);
self.on_demand_core.on_remote_changes_response(OnDemandIn {
self.light_dispatch.on_remote_changes_response(LightDispatchIn {
behaviour: &mut self.behaviour,
peerset: self.peerset_handle.clone(),
}, who, response);
Expand Down Expand Up @@ -1462,7 +1462,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
peer: PeerId,
response: message::BlockResponse<B>
) {
self.on_demand_core.on_remote_body_response(OnDemandIn {
self.light_dispatch.on_remote_body_response(LightDispatchIn {
behaviour: &mut self.behaviour,
peerset: self.peerset_handle.clone(),
}, peer, response);
Expand Down
Loading

0 comments on commit 25f68b3

Please sign in to comment.