cfxcore/pos/state_sync/
network.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8//! Interface between State Sync and Network layers.
9
10use crate::pos::state_sync::{
11    chunk_request::GetChunkRequest, chunk_response::GetChunkResponse,
12    error::Error,
13};
14use diem_types::PeerId;
15/*use network::{
16    peer_manager::{ConnectionRequestSender, PeerManagerRequestSender},
17    protocols::network::{NetworkEvents, NetworkSender, NewNetworkSender},
18    ProtocolId,
19};*/
20use serde::{Deserialize, Serialize};
21
22/// State sync network messages
23#[derive(Clone, Debug, Deserialize, Serialize)]
24pub enum StateSyncMessage {
25    GetChunkRequest(Box<GetChunkRequest>),
26    GetChunkResponse(Box<GetChunkResponse>),
27}
28
29/*
30/// The interface from Network to StateSync layer.
31///
32/// `StateSyncEvents` is a `Stream` of `PeerManagerNotification` where the
33/// raw `Bytes` direct-send messages are deserialized into `StateSyncMessage`
34/// types. `StateSyncEvents` is a thin wrapper around a
35/// `channel::Receiver<PeerManagerNotification>`.
36pub type StateSyncEvents = NetworkEvents<StateSyncMessage>;
37*/
38
39/// The interface from StateSync to Networking layer.
40///
41/// This is a thin wrapper around a `NetworkSender<StateSyncMessage>`, so it
42/// is easy to clone and send off to a separate task. For example, the rpc
43/// requests return Futures that encapsulate the whole flow, from sending the
44/// request to remote, to finally receiving the response and deserializing. It
45/// therefore makes the most sense to make the rpc call on a separate async
46/// task, which requires the `StateSyncSender` to be `Clone` and `Send`.
47#[derive(Clone)]
48pub struct StateSyncSender {
49    //inner: NetworkSender<StateSyncMessage>,
50}
51
52/*
53impl NewNetworkSender for StateSyncSender {
54    fn new(
55        peer_mgr_reqs_tx: PeerManagerRequestSender,
56        connection_reqs_tx: ConnectionRequestSender,
57    ) -> Self {
58        Self {
59            inner: NetworkSender::new(peer_mgr_reqs_tx, connection_reqs_tx),
60        }
61    }
62}*/
63
64impl StateSyncSender {
65    pub fn send_to(
66        &mut self, _recipient: PeerId, _message: StateSyncMessage,
67    ) -> Result<(), Error> {
68        Ok(())
69        /*let protocol = ProtocolId::StateSyncDirectSend;
70        Ok(self.inner.send_to(recipient, protocol, message)?)*/
71    }
72}
73
74/*
75/// Configuration for the network endpoints to support state sync.
76pub fn network_endpoint_config() -> (
77    Vec<ProtocolId>,
78    Vec<ProtocolId>,
79    QueueStyle,
80    usize,
81    Option<&'static IntCounterVec>,
82) {
83    (
84        vec![],
85        vec![ProtocolId::StateSyncDirectSend],
86        QueueStyle::LIFO,
87        STATE_SYNC_MAX_BUFFER_SIZE,
88        Some(&counters::PENDING_STATE_SYNC_NETWORK_EVENTS),
89    )
90}
91*/