-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a04850
commit 6ac0462
Showing
8 changed files
with
121 additions
and
2 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
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,24 @@ | ||
use super::PushStream; | ||
use crate::data::BottleInSea; | ||
use crate::data::Peer; | ||
use crate::error::Error; | ||
use async_trait::async_trait; | ||
use futures::stream::Stream; | ||
|
||
/// Interface for the blockchain node to exchange "bottle in the sea" messages. | ||
#[async_trait] | ||
pub trait BottleInSeaService { | ||
/// The type of outbound asynchronous streams returned by the | ||
/// `subscription` method. | ||
type SubscriptionStream: Stream<Item = Result<BottleInSea, Error>> + Send + Sync; | ||
|
||
/// Called by the protocol implementation to establish a | ||
/// bidirectional subscription stream. | ||
/// The inbound stream is passed to the asynchronous method, | ||
/// which resolves to the outbound stream. | ||
async fn bottle_in_sea_subscription( | ||
&self, | ||
subscriber: Peer, | ||
stream: PushStream<BottleInSea>, | ||
) -> Result<Self::SubscriptionStream, Error>; | ||
} |
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,34 @@ | ||
/// A "bottle in the sea" raw message. | ||
#[derive(Clone)] | ||
pub struct BottleInSea(Box<[u8]>); | ||
|
||
impl BottleInSea { | ||
#[inline] | ||
pub fn from_bytes<B: Into<Box<[u8]>>>(bytes: B) -> Self { | ||
Self(bytes.into()) | ||
} | ||
|
||
#[inline] | ||
pub fn as_bytes(&self) -> &[u8] { | ||
&self.0 | ||
} | ||
|
||
#[inline] | ||
pub fn into_bytes(self) -> Vec<u8> { | ||
self.0.into() | ||
} | ||
} | ||
|
||
impl AsRef<[u8]> for BottleInSea { | ||
#[inline] | ||
fn as_ref(&self) -> &[u8] { | ||
self.as_bytes() | ||
} | ||
} | ||
|
||
impl From<BottleInSea> for Vec<u8> { | ||
#[inline] | ||
fn from(block: BottleInSea) -> Self { | ||
block.into_bytes() | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
pub mod block; | ||
pub mod bottle; | ||
pub mod fragment; | ||
pub mod gossip; | ||
pub mod p2p; | ||
|
||
pub use block::{Block, BlockEvent, BlockId, BlockIds, Header}; | ||
pub use bottle::BottleInSea; | ||
pub use fragment::{Fragment, FragmentId, FragmentIds}; | ||
pub use gossip::Gossip; | ||
pub use p2p::{Peer, Peers}; |
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