summaryrefslogtreecommitdiffhomepage
path: root/tunnel/tools/libwg-go
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2023-05-24 22:48:37 +0200
committerMikael Magnusson <mikma@users.sourceforge.net>2023-06-01 21:08:03 +0200
commitf5a5d9ff45e689c573d2144c2c0880218baef6ac (patch)
treec6d93205712bdbe2b094fba0ca8bb6bdaa7b37a8 /tunnel/tools/libwg-go
parent48f3b6e67c8a9f6018455873721fb4fef09489fb (diff)
WIP: tunnel: implement gRPC based wgSetConfig
Diffstat (limited to 'tunnel/tools/libwg-go')
-rw-r--r--tunnel/tools/libwg-go/api-android.go5
-rw-r--r--tunnel/tools/libwg-go/service.go27
2 files changed, 32 insertions, 0 deletions
diff --git a/tunnel/tools/libwg-go/api-android.go b/tunnel/tools/libwg-go/api-android.go
index 943ba628..5d9e8b96 100644
--- a/tunnel/tools/libwg-go/api-android.go
+++ b/tunnel/tools/libwg-go/api-android.go
@@ -54,6 +54,11 @@ type TunnelHandle struct {
var tunnelHandles map[int32]TunnelHandle
+func GetTunnel(handle int32) (tunnelHandle TunnelHandle, ok bool) {
+ tunnelHandle, ok = tunnelHandles[handle]
+ return
+}
+
func init() {
tunnelHandles = make(map[int32]TunnelHandle)
signals := make(chan os.Signal)
diff --git a/tunnel/tools/libwg-go/service.go b/tunnel/tools/libwg-go/service.go
index 30fe650b..f5460486 100644
--- a/tunnel/tools/libwg-go/service.go
+++ b/tunnel/tools/libwg-go/service.go
@@ -226,6 +226,33 @@ func (e *LibwgServiceImpl) Reverse(stream gen.Libwg_ReverseServer) error {
return nil
}
+func (e *LibwgServiceImpl) IpcSet(ctx context.Context, req *gen.IpcSetRequest) (*gen.IpcSetResponse, error) {
+ tunnel, ok := GetTunnel(req.GetTunnel().GetHandle())
+ if !ok {
+ r := &gen.IpcSetResponse{
+ Error: &gen.Error{
+ Message: fmt.Sprintf("Invalid tunnel"),
+ },
+ }
+ return r, nil
+ }
+
+ err := tunnel.device.IpcSet(req.GetConfig())
+ if err != nil {
+ r := &gen.IpcSetResponse{
+ Error: &gen.Error{
+ Message: fmt.Sprintf("IpcSet failed: %v", err),
+ },
+ }
+ return r, nil
+ }
+
+ r := &gen.IpcSetResponse{
+ }
+
+ return r, nil
+}
+
func (e *LibwgServiceImpl) Dhcp(ctx context.Context, req *gen.DhcpRequest) (*gen.DhcpResponse, error) {
var relayAddr netip.Addr
var sourceAddr netip.Addr