libtransport in Rust.
use libtransport::TransportReceiver;
use libtransport::TransportSender;
use libtransport_tcp::receiver::TCPreceiver;
use libtransport_tcp::sender::TCPsender;
use libtransport_http::receiver::HTTPreceiver;
use libtransport_http::sender::HTTPsender;
let (transport_type, reply_bind_address) = {
let cfg = config.read().unwrap();
(cfg.transport_type.clone(), cfg.reply_addr.clone())
};
let mut sync_req_sender = {
match transport_type {
libtransport::TransportType::TCP => {
TCPsender::<P, SyncReq<P>, errors::Error, peer::DAGPeerList<P, PK>>::new().unwrap()
}
libtransport::TransportType::HTTP => {
HTTPsender::<P, SyncReq<P>, errors::Error, peer::DAGPeerList<P, PK>>::new().unwrap()
}
libtransport::TransportType::Unknown => panic!("unknown transport"),
}
};
let mut sync_reply_receiver = {
match transport_type {
libtransport::TransportType::TCP => {
let x: TCPreceiver<P, SyncReply<D, P, PK, Sig>, Error, DAGPeerList<P, PK>> =
TCPreceiver::new(reply_bind_address).unwrap();
x
}
libtransport::TransportType::HTTP => {
let x: HTTPreceiver<P, SyncReply<D, P, PK, Sig>, Error, DAGPeerList<P, PK>> =
TCPreceiver::new(reply_bind_address).unwrap();
x
}
libtransport::TransportType::Unknown => panic!("unknown transport"),
}
};
match sync_req_sender.send(peer.request_addr, request) {
Ok(()) => {}
Err(e) => error!("error sending sync request: {:?}", e),
}
block_on(async {
if let Some(sync_reply) = sync_reply_receiver.next().await {
debug!(
"{} Sync Reply from {}",
sync_reply.to.clone(),
sync_reply.from.clone()
);
// do processing here for sync_reply received
}
});
https://github.com/Fantom-foundation/fantom-rfcs
Install the latest version of Rust. We tend to use nightly versions. CLI tool for installing Rust.
We use rust-clippy linters to improve code quality.
There are plenty of IDEs and other Rust development tools to consider.
# Install Rust (nightly)
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain nightly
# Install cargo-make (cross-platform feature-rich reimplementation of Make)
$ cargo install --force cargo-make
# Install rustfmt (Rust formatter)
$ rustup component add rustfmt
# Install clippy (Rust linter)
$ rustup component add clippy
# Clone this repo
$ git clone https://github.com/Fantom-foundation/libtransport && cd libtransport
# Run tests
$ cargo test
# Format, build and test
$ cargo make