1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use crate::{
chunk_request::GetChunkRequest, chunk_response::GetChunkResponse, counters, error::Error,
};
use channel::message_queues::QueueStyle;
use diem_metrics::IntCounterVec;
use diem_types::PeerId;
use network::{
peer_manager::{ConnectionRequestSender, PeerManagerRequestSender},
protocols::network::{NetworkEvents, NetworkSender, NewNetworkSender},
ProtocolId,
};
use serde::{Deserialize, Serialize};
const STATE_SYNC_MAX_BUFFER_SIZE: usize = 1;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum StateSyncMessage {
GetChunkRequest(Box<GetChunkRequest>),
GetChunkResponse(Box<GetChunkResponse>),
}
pub type StateSyncEvents = NetworkEvents<StateSyncMessage>;
#[derive(Clone)]
pub struct StateSyncSender {
inner: NetworkSender<StateSyncMessage>,
}
impl NewNetworkSender for StateSyncSender {
fn new(
peer_mgr_reqs_tx: PeerManagerRequestSender,
connection_reqs_tx: ConnectionRequestSender,
) -> Self {
Self {
inner: NetworkSender::new(peer_mgr_reqs_tx, connection_reqs_tx),
}
}
}
impl StateSyncSender {
pub fn send_to(&mut self, recipient: PeerId, message: StateSyncMessage) -> Result<(), Error> {
let protocol = ProtocolId::StateSyncDirectSend;
Ok(self.inner.send_to(recipient, protocol, message)?)
}
}
pub fn network_endpoint_config() -> (
Vec<ProtocolId>,
Vec<ProtocolId>,
QueueStyle,
usize,
Option<&'static IntCounterVec>,
) {
(
vec![],
vec![ProtocolId::StateSyncDirectSend],
QueueStyle::LIFO,
STATE_SYNC_MAX_BUFFER_SIZE,
Some(&counters::PENDING_STATE_SYNC_NETWORK_EVENTS),
)
}