Skip to content

Commit 3639df0

Browse files
kornstar11dbcfd
authored andcommitted
some work on making BridgeStream take streams instead of futures (#7)
* Stable Libs Switch to stable libs and stable formatting. Introduce BridgeStream to combine streams
1 parent abba512 commit 3639df0

10 files changed

+237
-141
lines changed

Cargo.toml

+6-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2018"
66
# - Update CHANGELOG.md.
77
# - Update doc URL.
88
# - Create "v0.1.x" git tag.
9-
version = "0.1.0-alpha.1"
9+
version = "0.1.0"
1010
license = "MIT"
1111
readme = "README.md"
1212
description = """
@@ -20,19 +20,17 @@ repository = "https://github.com/dbcfd/pcap-async"
2020
[dependencies]
2121
byteorder = "1.3"
2222
failure = "0.1"
23-
failure_derive = "0.1"
24-
futures-preview = { version ="0.3.0-alpha.19" }
23+
futures = "0.3"
2524
libc = "0.2"
2625
log = "0.4"
27-
pin-project = "0.4.0-alpha.9"
28-
pcap-sys = { git = "https://github.com/protectwise/pcap-sys.git", tag = "v0.3.0" }
29-
tokio-executor = "=0.2.0-alpha.6"
30-
tokio-timer = "0.3.0-alpha.6"
26+
pin-project = "0.4"
27+
pcap-sys = "0.1"
28+
tokio = { version = "0.2", features = ["blocking", "rt-threaded", "time"] }
3129

3230
[dev-dependencies]
3331
criterion = "0.2"
3432
env_logger = "0.6"
35-
tokio = "=0.2.0-alpha.6"
33+
tokio = { version = "0.2", features = ["macros", "rt-core"] }
3634

3735
[lib]
3836
path = "src/lib.rs"

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ First, add this to your `Cargo.toml`:
2424

2525
```toml
2626
[dependencies]
27-
channel-async = "0.1.0-alpha.1"
27+
pcap-async = "0.1"
2828
```
2929

3030
Next, add this to your crate:
@@ -36,7 +36,7 @@ use pcap_async::{Config, Handle, PacketStream};
3636
#[tokio::main]
3737
async fn main() {
3838
let handle = Handle::lookup().expect("No handle created");
39-
let mut provider = PacketProvider::new(Config::default(), handle)
39+
let mut provider = PacketStream::new(Config::default(), handle)
4040
.expect("Could not create provider")
4141
.fuse();
4242
while let Some(packets) = provider.next().await {

benches/bench_capture.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
33
use futures::StreamExt;
44
use log::*;
5-
use pcap_async::{Config, Handle, PacketStream, BridgeStream};
5+
use pcap_async::{BridgeStream, Config, Handle, PacketStream};
66
use std::path::PathBuf;
77

88
fn bench_stream_from_large_file(b: &mut Bencher) {
@@ -15,7 +15,7 @@ fn bench_stream_from_large_file(b: &mut Bencher) {
1515
info!("Benchmarking against {:?}", pcap_path.clone());
1616

1717
b.iter(|| {
18-
let rt = tokio::runtime::Runtime::new().expect("Failed to create runtime");
18+
let mut rt = tokio::runtime::Runtime::new().expect("Failed to create runtime");
1919

2020
let clone_path = pcap_path.clone();
2121

@@ -63,7 +63,7 @@ fn bench_stream_next_from_large_file_bridge(b: &mut Bencher) {
6363
info!("Benchmarking against {:?}", pcap_path.clone());
6464

6565
b.iter(|| {
66-
let rt = tokio::runtime::Runtime::new().expect("Failed to create runtime");
66+
let mut rt = tokio::runtime::Runtime::new().expect("Failed to create runtime");
6767

6868
let clone_path = pcap_path.clone();
6969

@@ -76,8 +76,9 @@ fn bench_stream_next_from_large_file_bridge(b: &mut Bencher) {
7676
let mut cfg = Config::default();
7777
cfg.with_max_packets_read(5000);
7878

79-
let packet_provider = BridgeStream::new(Config::default(), vec![handle1.clone(), handle2.clone()])
80-
.expect("Failed to build");
79+
let packet_provider =
80+
BridgeStream::new(Config::default(), vec![handle1.clone(), handle2.clone()])
81+
.expect("Failed to build");
8182
let fut_packets = async move {
8283
let mut packet_provider = packet_provider.boxed();
8384
let mut packets = vec![];
@@ -106,7 +107,7 @@ fn bench_stream_next_from_large_file(b: &mut Bencher) {
106107
info!("Benchmarking against {:?}", pcap_path.clone());
107108

108109
b.iter(|| {
109-
let rt = tokio::runtime::Runtime::new().expect("Failed to create runtime");
110+
let mut rt = tokio::runtime::Runtime::new().expect("Failed to create runtime");
110111

111112
let clone_path = pcap_path.clone();
112113

@@ -136,7 +137,8 @@ fn bench_stream_next_from_large_file(b: &mut Bencher) {
136137
}
137138

138139
fn bench_stream_next_bridge(c: &mut Criterion) {
139-
let benchmark = criterion::Benchmark::new("4sics-bridge", bench_stream_next_from_large_file_bridge);
140+
let benchmark =
141+
criterion::Benchmark::new("4sics-bridge", bench_stream_next_from_large_file_bridge);
140142

141143
c.bench(
142144
"stream_next",
@@ -159,7 +161,12 @@ fn bench_stream_next(c: &mut Criterion) {
159161
);
160162
}
161163

162-
criterion_group!(benches, bench_stream, bench_stream_next, bench_stream_next_bridge);
164+
criterion_group!(
165+
benches,
166+
bench_stream,
167+
bench_stream_next,
168+
bench_stream_next_bridge
169+
);
163170

164171
// Benchmark: cargo bench --verbose
165172

lefthook.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ format:
44
1_install:
55
run: rustup component add rustfmt
66
2_cargo_fmt:
7-
run: cargo +nightly fmt --all
7+
run: cargo +${RUST_VERSION:-stable} fmt --all
88

99
pre-push:
1010
piped: true
1111
commands:
1212
1_install:
1313
run: rustup component add rustfmt
1414
2_fmt:
15-
run: cargo +nightly fmt --all -- --check
15+
run: cargo +${RUST_VERSION:-stable} fmt --all -- --check

0 commit comments

Comments
 (0)