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

worker: use get_attr and prevent TypeError #57

Merged
merged 1 commit into from
Sep 7, 2021
Merged
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
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