rscamper 0.2.2

Rust interface to scamper network measurement tool
Documentation
// rscamper - Rust wrapper for scamper mux connections
//
// Copyright (C) 2026 Dimitrios Giakatos
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.

use crate::ffi::libscamperctrl::{self, ScamperMuxT};
use crate::vp::ScamperVp;

/// A multiplexor that provides access to many scamper VPs via a single socket.
pub struct ScamperMux {
    pub(crate) inner: *mut ScamperMuxT,
}

impl ScamperMux {
    pub(crate) unsafe fn from_ptr(ptr: *mut ScamperMuxT) -> Option<Self> {
        if ptr.is_null() { return None; }
        Some(ScamperMux { inner: ptr })
    }

    /// Return the list of vantage points available via this mux.
    pub fn vps(&self) -> Vec<ScamperVp> {
        let mut vps = Vec::new();
        let vpset = unsafe { libscamperctrl::scamper_vpset_get(self.inner) };
        if vpset.is_null() { return vps; }
        let count = unsafe { libscamperctrl::scamper_vpset_vp_count(vpset) };
        for i in 0..count {
            let vp_ptr = unsafe { libscamperctrl::scamper_vpset_vp_get(vpset, i) };
            if let Some(vp) = unsafe { ScamperVp::from_ptr(vp_ptr) } {
                vps.push(vp);
            }
        }
        unsafe { libscamperctrl::scamper_vpset_free(vpset) };
        vps
    }
}

unsafe impl Send for ScamperMux {}
unsafe impl Sync for ScamperMux {}