Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Houman <houmie@gmail.com>
To: WireGuard mailing list <wireguard@lists.zx2c4.com>
Subject: Is there a Delegate for the Wireguard status in PacketTunnelProvider (iOS)
Date: Sat, 19 Feb 2022 17:34:50 +0000	[thread overview]
Message-ID: <CABBZOsnRAS1bz_hT863E+GAn9D8=OXAvvsnuZhQbxsRZNVToDA@mail.gmail.com> (raw)

Hello,

I wonder if there is a Delegate we could use in PacketTunnelProvider
to observe the state of Wireguard VPN.

For example OpenVPN has something like this:

extension PacketTunnelProvider: OpenVPNAdapterDelegate {
    func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleEvent
event: OpenVPNAdapterEvent, message: String?) {
        switch event {
        case .connected:
        case .disconnected:
        case .reconnecting:
        default:
            break
        }
    }
}

Do we have this in Wireguard?

I know it's possible to subscribe to this NEVPNStatusDidChange in the
main app instead:

override func viewDidLoad() {
    NotificationCenter.default.addObserver(self, selector:
#selector(vpnStatusDidChange(_:)), name:
NSNotification.Name.NEVPNStatusDidChange, object: nil)
}

But this doesn't work well for Third party VPNs that integrate over
the NetworkExtension framework. Even though I have observed this once,
I see multiple connected states being triggered, after connecting a
single time to the VPN.

@objc private func vpnStatusDidChange(_ notification: Notification) {
        let nevpnconn = notification.object as! NEVPNConnection
        let status = nevpnconn.status
        switch status {
        case NEVPNStatus.invalid:
        case NEVPNStatus.disconnected:
        case NEVPNStatus.connecting:
        case NEVPNStatus.connected:
...
}

Any suggestions please?
Thanks,

                 reply	other threads:[~2022-02-19 17:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABBZOsnRAS1bz_hT863E+GAn9D8=OXAvvsnuZhQbxsRZNVToDA@mail.gmail.com' \
    --to=houmie@gmail.com \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).