Skip to content

added get stats function for indicator connection#35

Open
Bellukchips wants to merge 3 commits into
Caqil:mainfrom
Bellukchips:added_getStats_indicator
Open

added get stats function for indicator connection#35
Bellukchips wants to merge 3 commits into
Caqil:mainfrom
Bellukchips:added_getStats_indicator

Conversation

@Bellukchips

Copy link
Copy Markdown

No description provided.

@StanislausPN

Copy link
Copy Markdown

Hi there, may you please update indicator connection for iOS?

@Bellukchips

Copy link
Copy Markdown
Author

Sorry, i cannot update indicator for ios, because i dont have device mac

@StanislausPN

Copy link
Copy Markdown

Ah, OK then.
But, is it possible to add getStats to the native swift?

@Bellukchips

Copy link
Copy Markdown
Author

Yes, it is very possible. On android I added a function to get statistics and on ios it should work too

@StanislausPN

StanislausPN commented Feb 2, 2025

Copy link
Copy Markdown

Hello @Bellukchips
Could you please explain me what method “getTransferData” is call from?

Because i had this error

wireguard_flutter/android/src/main/kotlin/billion/group/wireguard_flutter/WireguardFlutterPlugin.kt:296:58 Unresolved reference: getTransferData
wireguard_flutter/android/src/main/kotlin/billion/group/wireguard_flutter/WireguardFlutterPlugin.kt:308:56 Unresolved reference: getTransferData
private fun getDownloadData(result: Result) {
        scope.launch(Dispatchers.IO) {
            try {
                val downloadData = futureBackend.await().getTransferData(tunnel(tunnelName)).rxBytes
                flutterSuccess(result, downloadData)
            } catch (e: Throwable) {
                Log.e(TAG, "getDownloadData - ERROR - ${e.message}")
                flutterError(result, e.message.toString())
            }
        }
    }

@Bellukchips

Copy link
Copy Markdown
Author

Sorry, I forgot. The upload and download codes are unused

Just

` private fun handleGetStats(result: MethodChannel.Result) {

    if (tunnelName.isEmpty()) {
        flutterError(result, "Provide tunnel name to get statistics")
        return
    }

    scope.launch(Dispatchers.IO) {
        try {
            val stats = futureBackend.await().getStatistics(tunnel(tunnelName))

            var latestHandshake = 0L

            for (key in stats.peers()) {
                val peerStats = stats.peer(key)
                if (peerStats != null && peerStats.latestHandshakeEpochMillis > latestHandshake) {
                    latestHandshake = peerStats.latestHandshakeEpochMillis
                }
            }
            flutterSuccess(result, Klaxon().toJsonString(
                Stats(stats.totalRx(), stats.totalTx(), latestHandshake)
            ))
        } catch (e: BackendException) {
            Log.e(TAG, "handleGetStats - BackendException - ERROR - ${e.reason}")
            flutterError(result, e.reason.toString())
        } catch (e: Throwable) {
            Log.e(TAG, "handleGetStats - Can't get stats: $e")`

Future<Stats?> getStats() async { try { final result = await _methodChannel.invokeMethod('getStats'); final stats = Stats.fromJson(jsonDecode(result)); return stats; } on Exception catch (e) { throw Exception(e); } }

@StanislausPN

Copy link
Copy Markdown

Okay, that's all right.
Thank you.

For android is already running, and for iOS I have a lot of problems.
The implementation of download upload status and last handshake on iOS is very different from android.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants