Closed cmoiccool closed 1 month ago
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
This pull request has been merged in facebookincubator/wireguard_py@add244deaa133b34b879bed89c62ddce4884ecb5.
Description
This pull request enhances the
wireguard_py
library by adding additional peer statistics and making necessary adjustments to support these new attributes. The most important changes include updating thePeer
class to include new fields, modifying thelist_peers
function to display these new statistics, and adjusting the Cython interface to handle the new data.Enhancements to peer statistics:
wireguard_py/wireguard_common.py
: Addedlast_handshake_time
,rx_bytes
, andtx_bytes
as optional fields to thePeer
class.wireguard_py/wgpy.py
: Updated thelist_peers
function to print the new fieldslast_handshake_time
,rx_bytes
, andtx_bytes
if they are notNone
.Adjustments to Cython interface:
wireguard_py/wireguard_py.pxd
: Introduceduint64_t
fromstdint.h
and addedtimespec64
,rx_bytes
, andtx_bytes
to thewg_peer
structure. [1] [2]wireguard_py/wireguard_py.pyx
: Modified thelist_peers
function to assignlast_handshake_time
,rx_bytes
, andtx_bytes
from the C structure to the PythonPeer
object.Motivation and Context
The list_peers method was not returning the last_hanshake_time rx_bytes and tx_bytes returned by the kernel call making it impossible to use it to monitor peer status and statistics: Resolves #3
How Has This Been Tested?
Tests have been realised on an Ubuntu server with active peers on an existing interface with the modified wgpy.py to ensure that peers that have never connected and peers that has already connected have returned either values of 0 when never connected or valid values when already connected when the wgpy.py list-peers was called.
I have also tested with a loop creating up to 40 peers to make sure that the list-peers returns all the created peers.
Screenshots (if appropriate):
Types of changes
Checklist: