Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Howto access dataCount for wireguard? #417

Description

@MattF42

Summary

Howto access dataCount for wireguard connections?

Steps to reproduce

import TunnelKitManager
import TunnelKitWireGuard
import TunnelKitWireGuardAppExtension
#if os(iOS) || os(watchOS) || os(tvOS)
import SVProgressHUD
#endif
import Combine

struct WireGuardView: View {
    let vpn: NetworkExtensionVPN
    
    var body: some View {       
 [SNIP]
}

private extension WireGuardView {
    var formView: some View {
   [SNIP]
}
var buttonView: some View {
[SNIP]
}


func connect(sub: String, usa: Int) {
        if(self.vpnStatus == .disconnected) {
            if let index = subscrArr.firstIndex(of: sub) {
                let parsed = sub.replacingOccurrences(of: ".conf", with: "")
                var title = "MyVPN " + parsed
                var serverArr = endPointArr[index].components(separatedBy: ":")
                
                guard let cfg = WireGuard.DemoConfiguration.make(params: .init(
                    title: title,
                    appGroup: appGroup,
                    clientPrivateKey: privKeyArr[index],
                    clientAddress: addressArr[index],
                    serverPublicKey: pubKeyArr[index],
                    serverAddress: serverArr[0],
                    serverPort: serverArr[1]
                )) else {
                    print("Configuration incomplete")
                    return
                }
              
                Task {
                    try await vpn.reconnect(
                        TunnelIdentifier.wireGuard,
                        configuration: cfg,
                        extra: nil,
                        after: .seconds(2)
                    )
                }
                executeRepeatedly()
            } else {
                print("Element not found")
            }
        } else {
            Task {
                await vpn.disconnect()
            }
        }
        
        
    }
    
    private func executeRepeatedly() {
        DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { [weak self] in
            print(self?.cfg.dataCount ?? "error1")  // **Value of type 'WireGuardView' has no member 'cfg'**
            // self.TunnelKitProvider.Configuration.dataCount(in:)
            // print(self?.Configuration.DataCount ?? "error1")
            self?.executeRepeatedly()
        }
    }

    func disconnect(counter: Int) {
       //  statusString = "Disconnected"
        Task {
            await vpn.disconnect()
        }
    }
}

What is the current bug behavior?

print(self?.cfg.dataCount ?? "error1") // <-- Value of type 'WireGuardView' has no member 'cfg'

The VPN connects successfully. appGroup is correctly updated to reflect my fork of the Demo codebase.
It's not a bug, but I can not seem to work out the correct way to call dataCount for the wireguard connection :(

What is the expected correct behavior?

Please help providing the correct method to access dataCount for wireguard connection

Relevant logs and/or screenshots

N/A

Possible fixes suggested remediation

Documented sample code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions