Skip to content

Commit

Permalink
Rewrite the pinger library
Browse files Browse the repository at this point in the history
  • Loading branch information
orf committed Dec 16, 2024
1 parent 703db5f commit 5429c9a
Show file tree
Hide file tree
Showing 18 changed files with 622 additions and 367 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
if: github.event_name == 'tag' || github.ref_name == 'master'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
Expand All @@ -57,7 +58,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
push: true
push: ${{ github.event_name == 'tag' || github.ref_name == 'master' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: |
Expand Down
20 changes: 2 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
include:
Expand Down Expand Up @@ -69,25 +70,8 @@ jobs:
name: build-${{ matrix.name }}
path: ${{ matrix.name }}

test_alpine:
name: Test in Alpine
runs-on: ubuntu-latest
container:
image: alpine:latest
steps:
- uses: actions/checkout@v4
- run: apk add --no-cache libgcc gcc musl-dev bash curl

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
prefix-key: alpine-build-
- name: Run tests
run: cargo test

cross_builds:
name: Cross-build
name: ${{ matrix.target }}
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
113 changes: 101 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 24 additions & 17 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
[target."armv7-linux-androideabi"]
pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]

[target."armv7-unknown-linux-gnueabihf"]
pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]

[target."armv7-unknown-linux-musleabihf"]
pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]
#[target."armv7-linux-androideabi"]
#pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]
#
#[target."armv7-unknown-linux-gnueabihf"]
#pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]
#
#[target."armv7-unknown-linux-musleabihf"]
#pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]
#
#[target."aarch64-linux-android"]
#pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]
#
#[target."aarch64-unknown-linux-gnu"]
#pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]
#
#[target."aarch64-unknown-linux-musl"]
#pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]
#
#[target."x86_64-unknown-linux-musl"]
#pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]
#

[target."aarch64-linux-android"]
[build]
pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]

[target."aarch64-unknown-linux-gnu"]
pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]

[target."aarch64-unknown-linux-musl"]
pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]

[target."x86_64-unknown-linux-musl"]
pre-build = ["apt-get update && apt-get install --assume-yes iputils-ping"]
[build.env]
passthrough = ["CI", "GITHUB_ACTIONS"]
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ RUN apt-get update \
&& apt-get install -y iputils-ping \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /usr/local/cargo/bin/gping /usr/local/bin/gping
COPY --link --from=builder /usr/local/cargo/bin/gping /usr/local/bin/gping

ENTRYPOINT ["gping"]
4 changes: 2 additions & 2 deletions gping/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() -> shadow_rs::SdResult<()> {
shadow_rs::new()
fn main() {
shadow_rs::ShadowBuilder::builder().build().unwrap();
}
5 changes: 3 additions & 2 deletions gping/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crossterm::{
};
use dns_lookup::lookup_host;
use itertools::{Itertools, MinMaxResult};
use pinger::{ping_with_interval, PingResult};
use pinger::{ping, PingOptions, PingResult};
use std::io;
use std::io::BufWriter;
use std::iter;
Expand Down Expand Up @@ -310,7 +310,8 @@ fn start_ping_thread(
) -> Result<JoinHandle<Result<()>>> {
let interval = Duration::from_millis((watch_interval.unwrap_or(0.2) * 1000.0) as u64);
// Pump ping messages into the queue
let stream = ping_with_interval(host, interval, interface)?;
let ping_opts = PingOptions::new(host, interval, interface);
let stream = ping(ping_opts)?;
Ok(thread::spawn(move || -> Result<()> {
while !kill_event.load(Ordering::Acquire) {
match stream.recv() {
Expand Down
14 changes: 9 additions & 5 deletions pinger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ description = "A small cross-platform library to execute the ping command and pa
repository = "https://github.com/orf/pinger/"

[dependencies]
anyhow = "1.0.94"
thiserror = "2.0.6"
rand = "0.8.5"
lazy-regex = "3.1.0"
thiserror = "2.0.7"
lazy-regex = "3.3.0"
rand = { version = "0.8.5", optional = true }

[target.'cfg(windows)'.dependencies]
winping = "0.10.1"
dns-lookup = "2.0.0"

[dev-dependencies]
os_info = "3.9.0"
ntest = "0.9.3"
anyhow = "1.0.94"

[features]
default = []
fake-ping = ["rand"]
Loading

0 comments on commit 5429c9a

Please sign in to comment.