Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ExchangeServerHandler #72

Merged
merged 20 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license = "Apache-2.0"
[dependencies]
celestia-proto = { workspace = true }
celestia-types = { workspace = true }
tendermint = { workspace = true }
tendermint-proto = { workspace = true }

async-trait = "0.1.73"
Expand Down
7 changes: 5 additions & 2 deletions node/src/exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ const RESPONSE_SIZE_MAXIMUM: usize = 10 * 1024 * 1024;
/// Maximum length of the protobuf length delimiter in bytes
const PROTOBUF_MAX_LENGTH_DELIMITER_LEN: usize = 10;

type RequestType = HeaderRequest;
type ResponseType = Vec<HeaderResponse>;
type ReqRespBehaviour = request_response::Behaviour<HeaderCodec>;
type ReqRespEvent = request_response::Event<HeaderRequest, Vec<HeaderResponse>>;
type ReqRespMessage = request_response::Message<HeaderRequest, Vec<HeaderResponse>>;
type ReqRespEvent = request_response::Event<RequestType, ResponseType>;
type ReqRespMessage = request_response::Message<RequestType, ResponseType>;

pub(crate) struct ExchangeBehaviour<S>
where
Expand Down Expand Up @@ -231,6 +233,7 @@ where
return Poll::Ready(ev);
}
}
let _ = self.server_handler.poll(cx, &mut self.req_resp);
oblique marked this conversation as resolved.
Show resolved Hide resolved

Poll::Pending
}
Expand Down
10 changes: 5 additions & 5 deletions node/src/exchange/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::utils::{OneshotResultSender, OneshotResultSenderExt};

pub(super) struct ExchangeClientHandler<S = ReqRespBehaviour>
where
S: Sender,
S: RequestSender,
{
reqs: HashMap<S::RequestId, State>,
peer_tracker: Arc<PeerTracker>,
Expand All @@ -33,13 +33,13 @@ struct State {
respond_to: OneshotResultSender<Vec<ExtendedHeader>, P2pError>,
}

pub(super) trait Sender {
pub(super) trait RequestSender {
type RequestId: Hash + Eq + Debug;

fn send_request(&mut self, peer: &PeerId, request: HeaderRequest) -> Self::RequestId;
}

impl Sender for ReqRespBehaviour {
impl RequestSender for ReqRespBehaviour {
type RequestId = RequestId;

fn send_request(&mut self, peer: &PeerId, request: HeaderRequest) -> RequestId {
Expand All @@ -49,7 +49,7 @@ impl Sender for ReqRespBehaviour {

impl<S> ExchangeClientHandler<S>
where
S: Sender,
S: RequestSender,
{
pub(super) fn new(peer_tracker: Arc<PeerTracker>) -> Self {
ExchangeClientHandler {
Expand Down Expand Up @@ -880,7 +880,7 @@ mod tests {
peer: PeerId,
}

impl Sender for MockReq {
impl RequestSender for MockReq {
type RequestId = MockReqId;

fn send_request(&mut self, peer: &PeerId, _request: HeaderRequest) -> Self::RequestId {
Expand Down
Loading
Loading