-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into zcash-script-v5-tx
- Loading branch information
Showing
9 changed files
with
558 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,10 +31,7 @@ jobs: | |
|
||
- uses: actions-rs/[email protected] | ||
with: | ||
# Pinned to workaround issue making cargo-llvm-cov fail, see | ||
# https://github.com/taiki-e/cargo-llvm-cov/issues/128 | ||
# TODO: restore to just `nightly` after it's fixed | ||
toolchain: nightly-2022-01-14 | ||
toolchain: nightly | ||
override: true | ||
profile: minimal | ||
components: llvm-tools-preview | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! The peer message sender channel. | ||
use futures::{Sink, SinkExt}; | ||
|
||
use zebra_chain::serialization::SerializationError; | ||
|
||
use crate::{constants::REQUEST_TIMEOUT, protocol::external::Message, PeerError}; | ||
|
||
/// A wrapper type for a peer connection message sender. | ||
/// | ||
/// Used to apply a timeout to send messages. | ||
#[derive(Clone, Debug)] | ||
pub struct PeerTx<Tx> { | ||
/// A channel for sending Zcash messages to the connected peer. | ||
/// | ||
/// This channel accepts [`Message`]s. | ||
inner: Tx, | ||
} | ||
|
||
impl<Tx> PeerTx<Tx> | ||
where | ||
Tx: Sink<Message, Error = SerializationError> + Unpin, | ||
{ | ||
/// Sends `msg` on `self.inner`, returning a timeout error if it takes too long. | ||
pub async fn send(&mut self, msg: Message) -> Result<(), PeerError> { | ||
tokio::time::timeout(REQUEST_TIMEOUT, self.inner.send(msg)) | ||
.await | ||
.map_err(|_| PeerError::ConnectionSendTimeout)? | ||
.map_err(Into::into) | ||
} | ||
} | ||
|
||
impl<Tx> From<Tx> for PeerTx<Tx> { | ||
fn from(tx: Tx) -> Self { | ||
PeerTx { inner: tx } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.