Skip to content

Commit

Permalink
add register_os_pipe(), register_callback() and ste_callback_timeout(…
Browse files Browse the repository at this point in the history
…) methods to TransportConfig trait; remove register_channel() method from Transport trait
  • Loading branch information
Maxime2 committed Aug 14, 2019
1 parent 621c4af commit 792849a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ edition = "2018"
libcommon-rs = { git = "https://github.com/Fantom-foundation/libcommon-rs" }
serde = "1.0.97"
bincode = "1.0.1"
os_pipe = "0.8.0"
30 changes: 24 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//#![feature(generic_associated_types)]
use crate::errors::Result;
use libcommon_rs::peer::{PeerId, PeerList};
use os_pipe::PipeWriter;
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::sync::mpsc::Sender;
Expand All @@ -10,11 +11,34 @@ pub trait TransportConfiguration<Data> {
// creates new transport configuration with specified network
// address for incoming messages listener
fn new(set_bind_net_addr: String) -> Self;

// register a sending-half of std::sync::mpsc::channel which is used to push
// all received messages to.
// Several channels can be registered, they will be pushed in
// the order of registration.
fn register_channel(&mut self, sender: Sender<Data>) -> Result<()>;

// Register a PipeWriter of os_pipe::pipe; which is used to push
// all received data blocks to.
// Several pipes can be registered, they will be pushed in
// the order of registration.
fn register_os_pipe(&mut self, sender: PipeWriter) -> Result<()>;

// register a callback function which is called when data is received.
// Several callback functions can be registered, they will be called in
// the order of registration.
// The callback function must return True when transaction is processed successfully
// and False otherwise. The same callback function will be called with the same data
// until callback function return True; a pause between consecutive calls of the
// callback function with the same block will be made for the value of milliseconds
// set by set_callback_timeout() function of the TRansportConfiguration trait;
// default value of the timeout is implementation defined.
fn register_callback(&mut self, callback: fn(data: Data) -> bool) -> Result<()>;

// Set timeout in milliseconds between consecutive calls of the callback
// function with the same data received.
fn set_callback_timeout(&mut self, timeout: u64);

// set bind network address for incoming messages listener
fn set_bind_net_addr(&mut self, address: String) -> Result<()>;
}
Expand Down Expand Up @@ -45,12 +69,6 @@ where

// broadcast specified message to all peers
fn broadcast(&mut self, peers: &mut Pl, data: Data) -> Result<()>;

// register a sending-half of std::sync::mpsc::channel which is used to push
// all received messages to.
// Several channels can be registered, they will be pushed in
// the order of registration.
fn register_channel(&mut self, sender: Sender<Data>) -> Result<()>;
}

pub mod errors;
Expand Down

0 comments on commit 792849a

Please sign in to comment.