summaryrefslogtreecommitdiffhomepage
path: root/tunnel/tools/libwg-go/api-android.go
diff options
context:
space:
mode:
Diffstat (limited to 'tunnel/tools/libwg-go/api-android.go')
-rw-r--r--tunnel/tools/libwg-go/api-android.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/tunnel/tools/libwg-go/api-android.go b/tunnel/tools/libwg-go/api-android.go
index d47c5d76..e3e97c67 100644
--- a/tunnel/tools/libwg-go/api-android.go
+++ b/tunnel/tools/libwg-go/api-android.go
@@ -7,6 +7,7 @@ package main
// #cgo LDFLAGS: -llog
// #include <android/log.h>
+// extern void wgOnEvent(void *eventHandler, const char *event);
import "C"
import (
@@ -48,6 +49,7 @@ func (l AndroidLogger) Printf(format string, args ...interface{}) {
type TunnelHandle struct {
device *device.Device
uapi net.Listener
+ eventHandler unsafe.Pointer
}
var tunnelHandles map[int32]TunnelHandle
@@ -73,7 +75,7 @@ func init() {
}
//export wgTurnOn
-func wgTurnOn(interfaceName string, tunFd int32, settings string) int32 {
+func wgTurnOn(interfaceName string, tunFd int32, settings string, eventHandler unsafe.Pointer) int32 {
tag := cstring("WireGuard/GoBackend/" + interfaceName)
logger := &device.Logger{
Verbosef: AndroidLogger{level: C.ANDROID_LOG_DEBUG, tag: tag}.Printf,
@@ -142,21 +144,23 @@ func wgTurnOn(interfaceName string, tunFd int32, settings string) int32 {
device.Close()
return -1
}
- tunnelHandles[i] = TunnelHandle{device: device, uapi: uapi}
+ tunnelHandles[i] = TunnelHandle{device: device, uapi: uapi, eventHandler: eventHandler}
return i
}
//export wgTurnOff
-func wgTurnOff(tunnelHandle int32) {
+func wgTurnOff(tunnelHandle int32) unsafe.Pointer {
handle, ok := tunnelHandles[tunnelHandle]
if !ok {
- return
+ return nil
}
+ eventHandler := handle.eventHandler
delete(tunnelHandles, tunnelHandle)
if handle.uapi != nil {
handle.uapi.Close()
}
handle.device.Close()
+ return eventHandler
}
//export wgGetSocketV4