Skip to content

Commit

Permalink
worker: use get_attr and prevent TypeError
Browse files Browse the repository at this point in the history
The `WG<XXX>` attributes are no longer present after
svinota/pyroute2@3e48554
so .get_attr has to beed used in order to remain compatible with
pyroute2 >= 0.5.15.

Calling extend on a list with None as argument waill raise a TypeError.
This happens when no peers are added yet (e.g. after a fresh boot)
  • Loading branch information
moepman committed Sep 7, 2021
1 parent 8d4d50e commit b7904b5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions wgkex/worker/netlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,16 @@ def find_stale_wireguard_clients(wg_interface: str) -> List:
(datetime.now() - timedelta(hours=_PEER_TIMEOUT_HOURS)).timestamp()
)
with pyroute2.WireGuard() as wg:
clients = []
all_clients = []
infos = wg.info(wg_interface)
for info in infos:
clients.extend(info.WGDEVICE_A_PEERS.value)
clients = info.get_attr("WGDEVICE_A_PEERS")
if clients is not None:
all_clients.extend(clients)
ret = [
client.WGPEER_A_PUBLIC_KEY.get("value", "").decode("utf-8")
for client in clients
if client.WGPEER_A_LAST_HANDSHAKE_TIME.get("tv_sec", int())
client.get_attr("WGPEER_A_PUBLIC_KEY").decode("utf-8")
for client in all_clients
if client.get_attr("WGPEER_A_LAST_HANDSHAKE_TIME").get("tv_sec", int())
< three_hrs_in_secs
]
return ret

0 comments on commit b7904b5

Please sign in to comment.