aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/service/ipc_client.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-02-25 18:47:12 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-28 08:05:02 +0100
commit3e7d023068e9d82dc07b5b8740e8b76ca946b7d0 (patch)
treef57899e05cc73a1a5153cc6b118bf0bb810a8098 /service/ipc_client.go
parentservice: introduce base of services (diff)
downloadwireguard-windows-3e7d023068e9d82dc07b5b8740e8b76ca946b7d0.tar.xz
wireguard-windows-3e7d023068e9d82dc07b5b8740e8b76ca946b7d0.zip
ipc: add base of IPC
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'service/ipc_client.go')
-rw-r--r--service/ipc_client.go87
1 files changed, 87 insertions, 0 deletions
diff --git a/service/ipc_client.go b/service/ipc_client.go
new file mode 100644
index 00000000..25575014
--- /dev/null
+++ b/service/ipc_client.go
@@ -0,0 +1,87 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
+ */
+
+package service
+
+import (
+ "golang.org/x/sys/windows"
+ "golang.zx2c4.com/wireguard/windows/conf"
+ "net/rpc"
+ "os"
+)
+
+type Tunnel struct {
+ Name string
+}
+
+type TunnelState int
+
+const (
+ TunnelUnknown TunnelState = iota
+ TunnelStarted
+ TunnelStopped
+ TunnelStarting
+ TunnelStopping
+ TunnelDeleting
+)
+
+var rpcClient *rpc.Client
+
+func InitializeIPCClient(reader *os.File, writer *os.File) {
+ rpcClient = rpc.NewClient(&pipeRWC{reader, writer})
+}
+
+func (t *Tunnel) StoredConfig() (c conf.Config, err error) {
+ err = rpcClient.Call("ManagerService.StoredConfig", t.Name, &c)
+ return
+}
+
+func (t *Tunnel) RuntimeConfig() (c conf.Config, err error) {
+ err = rpcClient.Call("ManagerService.RuntimeConfig", t.Name, &c)
+ return
+}
+
+func (t *Tunnel) Start() (TunnelState, error) {
+ var state TunnelState
+ return state, rpcClient.Call("ManagerService.Start", t.Name, &state)
+}
+
+func (t *Tunnel) Stop() (TunnelState, error) {
+ var state TunnelState
+ return state, rpcClient.Call("ManagerService.Stop", t.Name, &state)
+}
+
+func (t *Tunnel) Delete() (TunnelState, error) {
+ var state TunnelState
+ return state, rpcClient.Call("ManagerService.Delete", t.Name, &state)
+}
+
+func (t *Tunnel) State() (TunnelState, error) {
+ var state TunnelState
+ return state, rpcClient.Call("ManagerService.State", t.Name, &state)
+}
+
+func IPCClientNewTunnel(conf *conf.Config) (Tunnel, error) {
+ var tunnel Tunnel
+ return tunnel, rpcClient.Call("ManagerService.Create", *conf, &tunnel)
+}
+
+func IPCClientTunnels() ([]Tunnel, error) {
+ var tunnels []Tunnel
+ return tunnels, rpcClient.Call("ManagerService.Tunnels", 0, &tunnels)
+}
+
+func IPCClientQuit(stopTunnelsOnQuit bool) (bool, error) {
+ var alreadyQuit bool
+ return alreadyQuit, rpcClient.Call("ManagerService.Quit", stopTunnelsOnQuit, &alreadyQuit)
+}
+
+func IPCClientRegisterAsNotificationThread() error {
+ return rpcClient.Call("ManagerService.RegisterAsNotificationThread", windows.GetCurrentThreadId(), nil)
+}
+
+func IPCClientUnregisterAsNotificationThread() error {
+ return rpcClient.Call("ManagerService.UnregisterAsNotificationThread", windows.GetCurrentThreadId(), nil)
+}