-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
14 changed files
with
1,343 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
|
||
# Project specific | ||
3rd | ||
local_conf | ||
|
||
# Rust | ||
|
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,109 @@ | ||
on: [pull_request] | ||
|
||
name: if-watch | ||
|
||
jobs: | ||
ci: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
toolchain: | ||
- rust: stable | ||
#- rust: nightly | ||
platform: | ||
- target: x86_64-unknown-linux-gnu | ||
host: ubuntu-latest | ||
cross: false | ||
|
||
- target: x86_64-apple-darwin | ||
host: macos-latest | ||
cross: false | ||
|
||
- target: x86_64-pc-windows-msvc | ||
host: windows-latest | ||
cross: false | ||
|
||
- target: armv7-linux-androideabi | ||
host: ubuntu-latest | ||
cross: true | ||
- target: aarch64-linux-android | ||
host: ubuntu-latest | ||
cross: true | ||
|
||
- target: aarch64-apple-ios | ||
host: macos-latest | ||
cross: true | ||
env: | ||
RUST_BACKTRACE: 1 | ||
CARGO_INCREMENTAL: 0 | ||
LLVM_CONFIG_PATH: /usr/local/opt/llvm/bin/llvm-config | ||
NDK_HOME: /usr/local/lib/android/sdk/ndk-bundle | ||
|
||
runs-on: ${{ matrix.platform.host }} | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v2 | ||
|
||
- name: Cache cargo folder | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.cargo | ||
key: ${{ matrix.platform.target }}-cargo-${{ matrix.toolchain.rust }} | ||
|
||
- name: Install dependencies ubuntu | ||
if: matrix.platform.host == 'ubuntu-latest' | ||
run: sudo apt-get install llvm-dev | ||
|
||
- name: Install dependencies macos | ||
if: matrix.platform.host == 'macos-latest' | ||
run: brew install llvm | ||
|
||
- name: Install dependencies windows | ||
if: matrix.platform.host == 'windows-latest' | ||
run: choco install llvm | ||
|
||
- name: Install rust toolchain | ||
uses: hecrj/setup-rust-action@v1 | ||
with: | ||
rust-version: ${{ matrix.toolchain.rust }} | ||
targets: ${{ matrix.platform.target }} | ||
|
||
- name: Install cargo-apk | ||
if: contains(matrix.platform.target, 'android') | ||
run: cargo install cargo-apk | ||
|
||
- name: Build | ||
if: contains(matrix.platform.target, 'android') == false | ||
run: cargo build --workspace --all-features --target ${{ matrix.platform.target }} | ||
|
||
- name: Build android | ||
if: contains(matrix.platform.target, 'android') | ||
run: cargo apk build --target ${{ matrix.platform.target }} --all-features | ||
|
||
- name: Rust tests | ||
if: matrix.platform.cross == false | ||
run: cargo test --workspace --all-features | ||
|
||
lint-rust: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v2 | ||
|
||
- name: Cache cargo folder | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.cargo | ||
key: lint-cargo | ||
|
||
- name: Install rust toolchain | ||
uses: hecrj/setup-rust-action@v1 | ||
with: | ||
rust-version: stable | ||
components: clippy, rustfmt | ||
|
||
- name: cargo fmt | ||
run: cargo fmt --all -- --check | ||
|
||
- name: cargo clippy | ||
run: cargo clippy --workspace --all-features --examples --tests -- -D warnings |
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,2 @@ | ||
/target | ||
Cargo.lock |
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,71 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [3.2.0] | ||
|
||
### Fixed | ||
|
||
- Update `async-io`, `if-addrs` crates. | ||
See [PR 33](https://github.com/mxinden/if-watch/pull/33). | ||
|
||
## [3.1.0] | ||
|
||
### Fixed | ||
|
||
- Update `windows` crate. | ||
See [PR 32](https://github.com/mxinden/if-watch/pull/32). | ||
|
||
## [3.0.1] | ||
|
||
### Fixed | ||
|
||
- For all architectures running the fallback option (e.g. Android) reverse the logic when checking if a recorded interface still exists in the new list to avoid reporting all interfaces as down and then up in the same resync(). | ||
See [PR 31]. | ||
|
||
[PR 31]: https://github.com/mxinden/if-watch/pull/31 | ||
|
||
## [3.0.0] | ||
|
||
### Changed | ||
- Feature gate async runtime, allowing opting between Tokio or smol. For every OS each `IfWatcher` is | ||
under the `tokio` or `smol` module. This makes it a breaking change as there | ||
is no more a default implementation. See [PR 27](https://github.com/mxinden/if-watch/pull/27). | ||
|
||
## [2.0.0] | ||
|
||
### Changed | ||
- Add `IfWatcher::poll_if_event`. Implement `Stream` instead of `Future` for `IfWatcher`. | ||
See [PR 23] and [PR 25]. | ||
- Make `IfWatcher::new` synchronous. See [PR 24]. | ||
|
||
[PR 23]: https://github.com/mxinden/if-watch/pull/23 | ||
[PR 24]: https://github.com/mxinden/if-watch/pull/24 | ||
[PR 25]: https://github.com/mxinden/if-watch/pull/25 | ||
|
||
## [1.1.1] | ||
|
||
### Fixed | ||
- Update to `rtnetlink` `v0.10`. See [PR 19]. | ||
|
||
[PR 19]: https://github.com/mxinden/if-watch/pull/19 | ||
|
||
## [1.1.0] | ||
### Added | ||
- Return socket closure as error. See [PR 15]. | ||
|
||
### Fixed | ||
- Update to `windows` `v0.34`. See [PR 16]. | ||
|
||
[PR 15]: https://github.com/mxinden/if-watch/pull/15 | ||
[PR 16]: https://github.com/mxinden/if-watch/pull/16 | ||
|
||
## [1.0.0] - 2022-01-12 | ||
### Added | ||
- macos/ios backend | ||
|
||
### Changed | ||
- linux backend rewritten to use rtnetlink | ||
- windows backend rewritten to use windows crate instead of winapi |
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,50 @@ | ||
[package] | ||
name = "if-watch" | ||
version = "3.2.0" | ||
authors = ["David Craven <[email protected]>", "Parity Technologies Limited <[email protected]>"] | ||
edition = "2021" | ||
keywords = ["asynchronous", "routing"] | ||
license = "MIT OR Apache-2.0" | ||
description = "crossplatform asynchronous network watcher" | ||
repository = "https://github.com/mxinden/if-watch" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "lib"] | ||
|
||
[features] | ||
default = ["tokio"] | ||
tokio = ["dep:tokio", "rtnetlink/tokio_socket"] | ||
smol = ["dep:smol", "rtnetlink/smol_socket"] | ||
|
||
[dependencies] | ||
fnv = "1.0.7" | ||
futures = "0.3.19" | ||
ipnet = "2.3.1" | ||
log = "0.4.14" | ||
|
||
[target.'cfg(target_os = "linux")'.dependencies] | ||
rtnetlink = { version = "0.10.0", default-features = false } | ||
|
||
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] | ||
core-foundation = "0.9.2" | ||
if-addrs = "0.10.0" | ||
system-configuration = "0.6.0" | ||
tokio = { version = "1.21.2", features = ["rt"], optional = true } | ||
smol = { version = "1.2.5", optional = true } | ||
|
||
[target.'cfg(target_os = "windows")'.dependencies] | ||
if-addrs = "0.10.0" | ||
windows = { version = "0.51.0", features = ["Win32_NetworkManagement_IpHelper", "Win32_Foundation", "Win32_NetworkManagement_Ndis", "Win32_Networking_WinSock"] } | ||
|
||
[target.'cfg(not(any(target_os = "ios", target_os = "linux", target_os = "macos", target_os = "windows")))'.dependencies] | ||
async-io = "2.0.0" | ||
if-addrs = "0.10.0" | ||
|
||
[dev-dependencies] | ||
env_logger = "0.10.0" | ||
smol = "1.2.5" | ||
tokio = { version = "1.21.2", features = ["rt", "macros"] } | ||
|
||
[[example]] | ||
name = "if_watch" | ||
required-features = ["smol"] |
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,16 @@ | ||
# Cross platform asynchronous network watcher | ||
|
||
```sh | ||
cargo run --example if_watch | ||
Got event Ok(Up(127.0.0.1/8)) | ||
Got event Ok(Up(192.168.6.65/24)) | ||
Got event Ok(Up(::1/128)) | ||
Got event Ok(Up(2a01:8b81:7000:9700:cef9:e4ff:fe9e:b23b/64)) | ||
Got event Ok(Up(fe80::cef9:e4ff:fe9e:b23b/64)) | ||
``` | ||
|
||
Supported platforms at the moment are: | ||
Linux, Windows and Android with a fallback for Macos and ios that polls for changes every 10s. | ||
|
||
## License | ||
MIT OR Apache-2.0 |
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,13 @@ | ||
use futures::StreamExt; | ||
use if_watch::smol::IfWatcher; | ||
|
||
fn main() { | ||
env_logger::init(); | ||
smol::block_on(async { | ||
let mut set = IfWatcher::new().unwrap(); | ||
loop { | ||
let event = set.select_next_some().await; | ||
println!("Got event {:?}", event); | ||
} | ||
}); | ||
} |
Oops, something went wrong.