Skip to content

Commit

Permalink
Merge pull request #293 from nervosnetwork/upgrade-tokio-1.0
Browse files Browse the repository at this point in the history
Upgrade tokio 1.0
  • Loading branch information
driftluo committed Mar 17, 2021
2 parents abecd4f + f60aa7e commit 48841d0
Show file tree
Hide file tree
Showing 88 changed files with 537 additions and 4,506 deletions.
57 changes: 14 additions & 43 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
FLATC := flatc
CFBC := cfbc
MOLC := moleculec
MOLC_VERSION := 0.6.0

FBS_FILES := \
src/protocol_select/protocol_select.fbs \
secio/src/handshake/handshake.fbs \
MOLC_VERSION := 0.7.0

MOL_FILES := \
src/protocol_select/protocol_select.mol \
tentacle/src/protocol_select/protocol_select.mol \
secio/src/handshake/handshake.mol \

FLATC_RUST_FILES := $(patsubst %.fbs,%_generated.rs,${FBS_FILES})
FLATBUFFERS_VERIFIER_FILES := $(patsubst %.fbs,%_generated_verifier.rs,${FBS_FILES})
MOL_RUST_FILES := $(patsubst %.mol,%_mol.rs,${MOL_FILES})

Change_Work_Path := cd tentacle
Expand All @@ -21,61 +13,40 @@ fmt:
cargo fmt --all -- --check

clippy:
$(Change_Work_Path) && RUSTFLAGS='-F warnings' cargo clippy --all --tests --features molc,ws,unstable -- -D clippy::let_underscore_must_use
$(Change_Work_Path) && RUSTFLAGS='-F warnings' cargo clippy --all --tests --features flatc,unstable -- -D clippy::let_underscore_must_use
$(Change_Work_Path) && RUSTFLAGS='-F warnings' cargo clippy --all --tests --features ws,unstable -- -D clippy::let_underscore_must_use

test:
$(Change_Work_Path) && RUSTFLAGS='-F warnings' RUST_BACKTRACE=full cargo test --all --features molc,ws,unstable
$(Change_Work_Path) && RUSTFLAGS='-F warnings' RUST_BACKTRACE=full cargo test --all --features flatc,unstable
$(Change_Work_Path) && RUSTFLAGS='-F warnings' RUST_BACKTRACE=full cargo test --all --features ws,unstable

fuzz:
cargo +nightly fuzz run secio_crypto_decrypt_cipher -- -max_total_time=60
cargo +nightly fuzz run secio_crypto_encrypt_cipher -- -max_total_time=60
cargo +nightly fuzz run yamux_frame_codec -- -max_total_time=60

build:
$(Change_Work_Path) && RUSTFLAGS='-F warnings' cargo build --all --features molc,ws
$(Change_Work_Path) && RUSTFLAGS='-F warnings' cargo build --all --features molc,ws,unstable
$(Change_Work_Path) && RUSTFLAGS='-F warnings' cargo build --all --features flatc,unstable
$(Change_Work_Path) && RUSTFLAGS='-F warnings' cargo build --all --features ws
$(Change_Work_Path) && RUSTFLAGS='-F warnings' cargo build --all --features ws,unstable

examples:
$(Change_Work_Path) && cargo build --examples --all --features molc,unstable
$(Change_Work_Path) && cargo build --examples --all --features flatc,unstable
$(Change_Work_Path) && cargo build --examples --all --features unstable

features-check:
# remove yamux default features
sed -i 's/"tokio-timer"//g' yamux/Cargo.toml
$(Change_Work_Path) && cargo build --features molc,unstable
$(Change_Work_Path) && cargo build --features molc,tokio-runtime,generic-timer,unstable --no-default-features
$(Change_Work_Path) && cargo build --features molc,async-runtime,generic-timer,unstable --no-default-features
$(Change_Work_Path) && cargo build --features molc,async-runtime,async-timer,unstable --no-default-features
$(Change_Work_Path) && cargo build --features unstable
$(Change_Work_Path) && cargo build --features tokio-runtime,generic-timer,unstable --no-default-features
$(Change_Work_Path) && cargo build --features async-runtime,generic-timer,unstable --no-default-features
$(Change_Work_Path) && cargo build --features async-runtime,async-timer,unstable --no-default-features
# required wasm32-unknown-unknown target
$(Change_Work_Path) && cargo build --features molc,wasm-timer,unstable --no-default-features --target=wasm32-unknown-unknown
$(Change_Work_Path) && cargo build --features wasm-timer,unstable --no-default-features --target=wasm32-unknown-unknown
git checkout .

bench_p2p:
cd bench && cargo run --release --features molc
cd bench && cargo run --release --features flatc
cd bench && cargo run --release

ci: fmt clippy test examples bench_p2p features-check
git diff --exit-code Cargo.lock

check-cfbc-version:
test "$$($(CFBC) --version)" = 0.1.9

%_generated_verifier.rs: %.fbs check-cfbc-version
$(FLATC) -b --schema -o $(shell dirname $@) $<
$(CFBC) -o $(shell dirname $@) $*.bfbs
rm -f $*_builder.rs $*.bfbs

%_generated.rs: %.fbs
$(FLATC) -r -o $(shell dirname $@) $<

gen-fb: $(FLATC_RUST_FILES) $(FLATBUFFERS_VERIFIER_FILES)

clean-fb:
rm -f $(FLATC_RUST_FILES) $(FLATBUFFERS_VERIFIER_FILES)

check-moleculec-version:
test "$$(${MOLC} --version | awk '{ print $$2 }' | tr -d ' ')" = ${MOLC_VERSION}

Expand All @@ -88,4 +59,4 @@ clean-mol:
rm -f $(MOL_RUST_FILES)


.PHONY: fmt clippy test fuzz build examples ci gen-fb clean-fb check-cfbc-version check-moleculec-version gen-mol clean-mol
.PHONY: fmt clippy test fuzz build examples ci check-moleculec-version gen-mol clean-mol
15 changes: 4 additions & 11 deletions bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,10 @@ path = "./src/main.rs"

[dependencies]
p2p = { path = "../tentacle", package = "tentacle" }
rand = "0.6.1"
rand = "0.7.1"
futures = { version = "0.3.0" }
tokio = { version = "0.2.0", features = ["time", "io-util", "tcp", "dns", "rt-threaded", "blocking"] }
tokio-util = { version = "0.3.0", features = ["codec"] }
tokio = { version = "1.0.0", features = ["time", "io-util", "net", "rt-multi-thread"] }
tokio-util = { version = "0.6.0", features = ["codec"] }
crossbeam-channel = "0.3.6"
env_logger = "0.6.0"
bytes = "0.5.0"

[features]
default = []
# use flatbuffer to handshake
flatc = [ "p2p/flatc" ]
# use molecule to handshake
molc = [ "p2p/molc" ]
bytes = "1.0.0"
10 changes: 5 additions & 5 deletions bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn create_meta(id: ProtocolId) -> (ProtocolMeta, crossbeam_channel::Receiver<Not
})
.service_handle(move || {
if id == ProtocolId::default() {
ProtocolHandle::Neither
ProtocolHandle::None
} else {
let handle = Box::new(PHandle {
connected_count: 0,
Expand All @@ -105,7 +105,7 @@ pub fn init() {
let mut service = create(true, meta, ());
let control = service.control().clone();
thread::spawn(move || {
let mut rt = tokio::runtime::Runtime::new().unwrap();
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async move {
let listen_addr = service
.listen("/ip4/127.0.0.1/tcp/0".parse().unwrap())
Expand All @@ -123,7 +123,7 @@ pub fn init() {
let (meta, client_receiver) = create_meta(1.into());

thread::spawn(|| {
let mut rt = tokio::runtime::Runtime::new().unwrap();
let rt = tokio::runtime::Runtime::new().unwrap();
let mut service = create(true, meta, ());
rt.block_on(async move {
let listen_addr = addr_receiver.await.unwrap();
Expand Down Expand Up @@ -153,7 +153,7 @@ pub fn init() {
let mut service = create(false, meta, ());
let control = service.control().clone();
thread::spawn(move || {
let mut rt = tokio::runtime::Runtime::new().unwrap();
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async move {
let listen_addr = service
.listen("/ip4/127.0.0.1/tcp/0".parse().unwrap())
Expand All @@ -171,7 +171,7 @@ pub fn init() {
let (meta, client_receiver) = create_meta(ProtocolId::new(1));

thread::spawn(move || {
let mut rt = tokio::runtime::Runtime::new().unwrap();
let rt = tokio::runtime::Runtime::new().unwrap();
let mut service = create(false, meta, ());
rt.block_on(async move {
let listen_addr = addr_receiver.await.unwrap();
Expand Down
6 changes: 3 additions & 3 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.3"
tentacle-secio = { path = "../secio", features = ["molc"] }
tentacle-secio = { path = "../secio" }
tokio-yamux = { path = "../yamux" }
rand = "0.7"
bytes = "0.5.0"
tokio-util = { version = "0.3.0", features = ["codec"] }
bytes = "1.0.0"
tokio-util = { version = "0.6.0", features = ["codec"] }

# Prevent this from interfering with workspaces
[workspace]
Expand Down
4 changes: 2 additions & 2 deletions multiaddr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
unsigned-varint = "0.3"
bytes = "0.5"
unsigned-varint = "0.6"
bytes = "1.0"
bs58 = "0.3.0"
sha2 = "0.9.0"
serde = "1"
Expand Down
23 changes: 7 additions & 16 deletions protocols/discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,20 @@ categories = ["network-programming", "asynchronous"]
edition = "2018"

[package.metadata.docs.rs]
features = [ "molc" ]
features = []
all-features = false
no-default-features = true

[dependencies]
p2p = { path = "../..", version = "0.3.0", package = "tentacle" }
bytes = "0.5.0"
p2p = { path = "../../tentacle", version = "0.3.0", package = "tentacle" }
bytes = "1.0"
futures = { version = "0.3.0" }
tokio = { version = "0.2.0", features = ["time", "io-util", "tcp", "dns", "stream"] }
tokio-util = { version = "0.3.0", features = ["codec"] }
tokio = { version = "1.0.0", features = ["time", "io-util", "net"] }
tokio-util = { version = "0.6.0", features = ["codec"] }
log = "0.4"
rand = "0.6.1"
rand = "0.7"
bloom-filters = "0.1"
flatbuffers = { version = "0.6.0", optional = true }
flatbuffers-verifier = { version = "0.2.0", optional = true }
molecule = { version = "0.5.0", optional = true }
molecule = { version = "0.7.0" }

[dev-dependencies]
env_logger = "0.6"

[features]
default = []
# use flatbuffer to handshake
flatc = [ "flatbuffers", "flatbuffers-verifier", "p2p/flatc" ]
# use molecule to handshake
molc = [ "molecule", "p2p/molc" ]
10 changes: 0 additions & 10 deletions protocols/discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ mod addr;
mod protocol;
mod state;

#[cfg(feature = "flatc")]
#[rustfmt::skip]
#[allow(clippy::all)]
mod protocol_generated;
#[cfg(feature = "flatc")]
#[rustfmt::skip]
#[allow(clippy::all)]
#[allow(dead_code)]
mod protocol_generated_verifier;
#[cfg(feature = "molc")]
#[rustfmt::skip]
#[allow(clippy::all)]
#[allow(dead_code)]
Expand Down
29 changes: 0 additions & 29 deletions protocols/discovery/src/protocol.fbs

This file was deleted.

Loading

0 comments on commit 48841d0

Please sign in to comment.