Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle situation where wireguard netlink returns invalid data #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wgnlpy/wireguardinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, messages, spill_private_key, spill_preshared_keys):
for message in messages:
wgp = lambda p: WireGuardPeer(p, spill_preshared_keys)
for peer in map(wgp, message.get_attr('WGDEVICE_A_PEERS') or []):
assert peer.public_key not in self.peers
if peer.public_key in self.peers: continue
self.peers[peer.public_key] = peer

def __repr__(self):
Expand Down
5 changes: 4 additions & 1 deletion wgnlpy/wireguardpeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def __init__(self, peer, spill_preshared_keys=False):
self.endpoint = peer.get_attr('WGPEER_A_ENDPOINT')
self.persistent_keepalive_interval = peer.get_attr('WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL')
self.last_handshake_time = peer.get_attr('WGPEER_A_LAST_HANDSHAKE_TIME')
if not self.last_handshake_time > 0:
try:
if not self.last_handshake_time > 0:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a try+except, you could also check if whether the variable has a None value:

if self.last_handshake_time is None or not self.last_handshake_time > 0:

self.last_handshake_time = None
except TypeError:
self.last_handshake_time = None
self.rx_bytes = peer.get_attr('WGPEER_A_RX_BYTES')
self.tx_bytes = peer.get_attr('WGPEER_A_TX_BYTES')
Expand Down