diff --git a/ZitiTunneler/MainWindow.xaml b/ZitiTunneler/MainWindow.xaml
index 58f28557..7a992a2c 100644
--- a/ZitiTunneler/MainWindow.xaml
+++ b/ZitiTunneler/MainWindow.xaml
@@ -120,7 +120,7 @@
-
+
@@ -132,7 +132,7 @@
-
+
diff --git a/ZitiTunneler/MainWindow.xaml.cs b/ZitiTunneler/MainWindow.xaml.cs
index 1ba26818..4ab94de8 100644
--- a/ZitiTunneler/MainWindow.xaml.cs
+++ b/ZitiTunneler/MainWindow.xaml.cs
@@ -75,27 +75,30 @@ namespace ZitiTunneler {
private void MainWindow1_Loaded(object sender, RoutedEventArgs e) {
var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
- _maxHeight = Math.Ceiling(.80*desktopWorkingArea.Height);
- this.Left = desktopWorkingArea.Right-this.Width-_right;
- this.Top = desktopWorkingArea.Bottom-this.Height-_bottom;
+ this.Left = desktopWorkingArea.Right - this.Width - _right;
+ this.Top = desktopWorkingArea.Bottom - this.Height - _bottom;
// add a new service client
serviceClient = new Client();
serviceClient.OnTunnelStatusUpdate += ServiceClient_OnTunnelStatusUpdated;
+ serviceClient.OnMetricsUpdate += ServiceClient_OnMetricsUpdate;
Application.Current.Properties.Add("ServiceClient", serviceClient);
Application.Current.Properties.Add("Identities", new List());
MainMenu.OnAttachmentChange += AttachmentChanged;
try {
LoadStatusFromService();
- // MessageBox.Show("identites are returned from the server. Any that were 'on' will have services. any off won't. Update the toggles to show if they are on or off");
- } catch(Exception ex) {
+ } catch (Exception ex) {
NoServiceView.Visibility = Visibility.Visible;
- //probably some kind of problem with the service...
- // MessageBox.Show("oh my goodness - problem with the service. Almost certainly means the service is NOT RUNNING... Jeremy make this pretty.\n" + ex.Message);
}
LoadIdentities();
IdentityMenu.OnForgot += IdentityForgotten;
}
+ private void ServiceClient_OnMetricsUpdate(object sender, Metrics e) {
+ this.Dispatcher.Invoke(() => {
+ DownloadSpeed.Content = (e.Down / 1000).ToString();
+ UploadSpeed.Content = (e.Up / 1000).ToString();
+ });
+ }
private void ServiceClient_OnTunnelStatusUpdated(object sender, TunnelStatus e) {
}
@@ -126,7 +129,8 @@ namespace ZitiTunneler {
}
private void LoadStatusFromService() {
- TunnelStatus status = serviceClient.GetStatus().Status;
+ var s = serviceClient.GetStatus();
+ TunnelStatus status = s.Status;
if (status != null) {
NoServiceView.Visibility = Visibility.Collapsed;
if (status.Active) {
diff --git a/ZitiTunneler/ServiceClient/ClientImpl.cs b/ZitiTunneler/ServiceClient/ClientImpl.cs
index 5065a197..d816a362 100644
--- a/ZitiTunneler/ServiceClient/ClientImpl.cs
+++ b/ZitiTunneler/ServiceClient/ClientImpl.cs
@@ -61,23 +61,6 @@ namespace ZitiTunneler.ServiceClient
{
//establish the named pipe to the service
setupPipe();
-
- Task.Run(() => {
- Console.WriteLine("THREAD BEGINS");
- NamedPipeClientStream eventClient = new NamedPipeClientStream(localPipeServer, eventPipe, PipeDirection.In);
- eventClient.Connect();
- StreamReader eventReader = new StreamReader(eventClient);
- while (true)
- {
- var r = read("event: ", eventReader);
- if (eventReader.EndOfStream)
- {
- break;
- }
- Debug.WriteLine(r.Payload);
- }
- Console.WriteLine("THREAD DONE");
- });
}
PipeSecurity CreateSystemIOPipeSecurity()
{
@@ -123,6 +106,23 @@ namespace ZitiTunneler.ServiceClient
ipcWriter = null;
pipeClient = null;
}
+
+ Task.Run(() => {
+ Console.WriteLine("THREAD BEGINS");
+ NamedPipeClientStream eventClient = new NamedPipeClientStream(localPipeServer, eventPipe, PipeDirection.In);
+ eventClient.Connect();
+ StreamReader eventReader = new StreamReader(eventClient);
+ while (true)
+ {
+ var r = read("event: ", eventReader);
+ if (eventReader.EndOfStream)
+ {
+ break;
+ }
+ MetricsUpdate(r.Payload.Metrics);
+ }
+ Console.WriteLine("THREAD DONE");
+ });
}
}
diff --git a/ZitiTunneler/ServiceClient/DataStructures.cs b/ZitiTunneler/ServiceClient/DataStructures.cs
index 10efb41d..7fbd0917 100644
--- a/ZitiTunneler/ServiceClient/DataStructures.cs
+++ b/ZitiTunneler/ServiceClient/DataStructures.cs
@@ -108,8 +108,8 @@ namespace ZitiTunneler.ServiceClient
public class Metrics
{
public int TotalBytes { get; set; }
- public double Upload { get; set; }
- public double Download { get; set; }
+ public double Up { get; set; }
+ public double Down { get; set; }
}
public class Identity
diff --git a/ZitiUWPSolution.sln b/ZitiUWPSolution.sln
index b46309d4..3f850bd9 100644
--- a/ZitiUWPSolution.sln
+++ b/ZitiUWPSolution.sln
@@ -20,29 +20,18 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
- Debug|ARM = Debug|ARM
- Debug|ARM64 = Debug|ARM64
- Debug|x64 = Debug|x64
- Debug|x86 = Debug|x86
+ Debug|Default = Debug|Default
Release|Any CPU = Release|Any CPU
- Release|ARM = Release|ARM
- Release|ARM64 = Release|ARM64
- Release|x64 = Release|x64
- Release|x86 = Release|x86
+ Release|Default = Release|Default
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FA4291EA-A97E-4854-959F-91EE7B330B37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA4291EA-A97E-4854-959F-91EE7B330B37}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {FA4291EA-A97E-4854-959F-91EE7B330B37}.Debug|ARM.ActiveCfg = Debug|Any CPU
- {FA4291EA-A97E-4854-959F-91EE7B330B37}.Debug|ARM.Build.0 = Debug|Any CPU
- {FA4291EA-A97E-4854-959F-91EE7B330B37}.Debug|ARM64.ActiveCfg = Debug|Any CPU
- {FA4291EA-A97E-4854-959F-91EE7B330B37}.Debug|ARM64.Build.0 = Debug|Any CPU
- {FA4291EA-A97E-4854-959F-91EE7B330B37}.Debug|x64.ActiveCfg = Debug|Any CPU
- {FA4291EA-A97E-4854-959F-91EE7B330B37}.Debug|x64.Build.0 = Debug|Any CPU
- {FA4291EA-A97E-4854-959F-91EE7B330B37}.Debug|x86.ActiveCfg = Debug|Any CPU
- {FA4291EA-A97E-4854-959F-91EE7B330B37}.Debug|x86.Build.0 = Debug|Any CPU
+ {FA4291EA-A97E-4854-959F-91EE7B330B37}.Debug|Default.ActiveCfg = Debug|Any CPU
+ {FA4291EA-A97E-4854-959F-91EE7B330B37}.Debug|Default.Build.0 = Debug|Any CPU
{FA4291EA-A97E-4854-959F-91EE7B330B37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA4291EA-A97E-4854-959F-91EE7B330B37}.Release|Any CPU.Build.0 = Release|Any CPU
+<<<<<<< HEAD
{FA4291EA-A97E-4854-959F-91EE7B330B37}.Release|ARM.ActiveCfg = Release|Any CPU
{FA4291EA-A97E-4854-959F-91EE7B330B37}.Release|ARM.Build.0 = Release|Any CPU
{FA4291EA-A97E-4854-959F-91EE7B330B37}.Release|ARM64.ActiveCfg = Release|Any CPU
@@ -103,6 +92,18 @@ Global
{5D4B2918-2168-4278-A3C9-3C67BB807217}.Release|ARM64.ActiveCfg = Release
{5D4B2918-2168-4278-A3C9-3C67BB807217}.Release|x64.ActiveCfg = Release
{5D4B2918-2168-4278-A3C9-3C67BB807217}.Release|x86.ActiveCfg = Release
+=======
+ {FA4291EA-A97E-4854-959F-91EE7B330B37}.Release|Default.ActiveCfg = Release|Any CPU
+ {FA4291EA-A97E-4854-959F-91EE7B330B37}.Release|Default.Build.0 = Release|Any CPU
+ {F620947D-5C32-4A6F-BEAA-4DCBB2032668}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F620947D-5C32-4A6F-BEAA-4DCBB2032668}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F620947D-5C32-4A6F-BEAA-4DCBB2032668}.Debug|Default.ActiveCfg = Debug|Any CPU
+ {F620947D-5C32-4A6F-BEAA-4DCBB2032668}.Debug|Default.Build.0 = Debug|Any CPU
+ {F620947D-5C32-4A6F-BEAA-4DCBB2032668}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F620947D-5C32-4A6F-BEAA-4DCBB2032668}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F620947D-5C32-4A6F-BEAA-4DCBB2032668}.Release|Default.ActiveCfg = Release|Any CPU
+ {F620947D-5C32-4A6F-BEAA-4DCBB2032668}.Release|Default.Build.0 = Release|Any CPU
+>>>>>>> origin/bug-fixing
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -110,4 +111,16 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {196E91E3-8AF1-41B3-9BD5-002BC225B6E3}
EndGlobalSection
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|ARM = Debug|ARM
+ Debug|ARM64 = Debug|ARM64
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|ARM = Release|ARM
+ Release|ARM64 = Release|ARM64
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
EndGlobal
diff --git a/wintun-testing/cziti/ctun.go b/wintun-testing/cziti/ctun.go
index 96e9cbf1..9f979d51 100644
--- a/wintun-testing/cziti/ctun.go
+++ b/wintun-testing/cziti/ctun.go
@@ -26,7 +26,7 @@ extern void readIdle(uv_prepare_t *idler);
extern void call_on_packet(void *packet, ssize_t len, packet_cb cb, void *ctx);
-extern void dnsHandler(tunneler_io_context tio, void *ctx, addr_t src, uint16_t sport, void *data, ssize_t len);
+
*/
import "C"
import (
@@ -227,7 +227,6 @@ func (t *tunnel) runWriteLoop() {
}
}
}
-
}
func (t *tunnel) AddIntercept(service string, host string, port int, ctx unsafe.Pointer) {
@@ -237,23 +236,3 @@ func (t *tunnel) AddIntercept(service string, host string, port int, ctx unsafe.
C.CString(service), C.CString(host), C.int(port))
log.Debug("intercept added", res)
}
-
-// extern void dnsHandler(tunneler_io_context tio, void *ctx, addr_t src, uint16_t sport, void *data, ssize_t len);
-//export dnsHandler
-func dnsHandler(tio C.tunneler_io_context, ctx unsafe.Pointer, src C.addr_t, sport C.uint16_t, b unsafe.Pointer, bl C.ssize_t) {
- /*
- reply, err := processDNSquery(C.GoBytes(b, C.int(bl)))
-
- if err == nil {
- replyC := C.CBytes(reply)
- rc := C.NF_udp_send(tio, src, sport, replyC, C.ssize_t(len(reply)))
- C.free(replyC)
- if rc != 0 {
- log.Debug("NF_udp_reply rc=", rc)
- }
- } else {
- log.Debug("dns message error", err)
- }
-
- */
-}
diff --git a/wintun-testing/cziti/cziti-cli/main.go b/wintun-testing/cziti/cziti-cli/main.go
index d829da63..760bf930 100644
--- a/wintun-testing/cziti/cziti-cli/main.go
+++ b/wintun-testing/cziti/cziti-cli/main.go
@@ -92,12 +92,9 @@ func load(args []string) error {
return fmt.Errorf("path to configfile required")
}
- if ctx, err := cziti.LoadZiti(args[0]); err != nil {
- return err
- } else {
- fmt.Printf("successfully loaded %s@%s\n", ctx.Name(), ctx.Controller())
- contexts = append(contexts, ctx)
- }
+ ctx := cziti.LoadZiti(args[0])
+ fmt.Printf("successfully loaded %s@%s\n", ctx.Name(), ctx.Controller())
+ contexts = append(contexts, ctx)
return nil
}
diff --git a/wintun-testing/cziti/sdk.go b/wintun-testing/cziti/sdk.go
index 7445c538..612fe748 100644
--- a/wintun-testing/cziti/sdk.go
+++ b/wintun-testing/cziti/sdk.go
@@ -3,9 +3,12 @@ package cziti
/*
#cgo windows LDFLAGS: -l libziti.imp -luv -lws2_32 -lpsapi
+#include
+
#include "sdk.h"
extern void initCB(nf_context nf, int status, void *ctx);
extern void serviceCB(nf_context nf, ziti_service*, int status, void *ctx);
+
*/
import "C"
import (
@@ -169,7 +172,7 @@ func LoadZiti(cfg string) *CZitiCtx {
ctx.options.config = C.CString(cfg)
ctx.options.init_cb = C.nf_init_cb(C.initCB)
ctx.options.service_cb = C.nf_service_cb(C.serviceCB)
- ctx.options.refresh_interval = C.int(600)
+ ctx.options.refresh_interval = C.long(600)
ctx.options.config_types = C.all_configs
//ctx.options.ctx = unsafe.Pointer(&ctx)
@@ -188,3 +191,11 @@ func LoadZiti(cfg string) *CZitiCtx {
return res
}
+
+func GetTransferRates(ctx *CZitiCtx) (int64, int64) { //extern void NF_get_transfer_rates(nf_context nf, double* up, double* down);
+ var up, down C.double
+ C.NF_get_transfer_rates(ctx.nf, &up, &down)
+ log.Tracef("Up: %v Down %v", up, down)
+
+ return int64(up), int64(down)
+}
\ No newline at end of file
diff --git a/wintun-testing/go.mod b/wintun-testing/go.mod
index 70695225..73c27e15 100644
--- a/wintun-testing/go.mod
+++ b/wintun-testing/go.mod
@@ -14,6 +14,7 @@ require (
github.com/netfoundry/ziti-foundation v0.9.8
github.com/netfoundry/ziti-sdk-golang v0.11.16
github.com/sirupsen/logrus v1.5.0
+ github.com/spf13/cobra v0.0.5
github.com/tebeka/strftime v0.1.4 // indirect
github.com/tv42/topic v0.0.0-20130729201830-aa72cbe81b48
golang.org/x/sys v0.0.0-20200406113430-c6e801f48ba2
diff --git a/wintun-testing/go.sum b/wintun-testing/go.sum
index 26f50c29..33b578ae 100644
--- a/wintun-testing/go.sum
+++ b/wintun-testing/go.sum
@@ -32,6 +32,7 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
+github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4=
@@ -93,9 +94,11 @@ github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s
github.com/speps/go-hashids v2.0.0+incompatible/go.mod h1:P7hqPzMdnZOfyIk+xrlG1QaSMw+gCBdHKsBDnhpaZvc=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
+github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
+github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
diff --git a/wintun-testing/ziti-tunnel/cmd/root.go b/wintun-testing/ziti-tunnel/cmd/root.go
new file mode 100644
index 00000000..c95fef8b
--- /dev/null
+++ b/wintun-testing/ziti-tunnel/cmd/root.go
@@ -0,0 +1,27 @@
+package cmd
+
+import (
+ "fmt"
+ "github.com/spf13/cobra"
+ "os"
+ "path/filepath"
+)
+var exeName, _ = os.Executable()
+var rootCmd = &cobra.Command{
+ Use: filepath.Base(exeName) ,
+ Short: "Runs the ziti-tunnel as a service",
+ Long: `This program provides access to a ziti-based network.
+ When executed without parameters it is expected that this application is running as a service`,
+ Run: func(cmd *cobra.Command, args []string) {
+ // Do Stuff Here
+ fmt.Println("i am in command")
+ },
+}
+
+func Execute() {
+ if err := rootCmd.Execute(); err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+
+}
diff --git a/wintun-testing/ziti-tunnel/cmd/root_addidentity.go b/wintun-testing/ziti-tunnel/cmd/root_addidentity.go
new file mode 100644
index 00000000..28460aec
--- /dev/null
+++ b/wintun-testing/ziti-tunnel/cmd/root_addidentity.go
@@ -0,0 +1,20 @@
+package cmd
+
+import (
+"fmt"
+
+"github.com/spf13/cobra"
+)
+
+func init() {
+ rootCmd.AddCommand(addIdCmd)
+}
+
+var addIdCmd = &cobra.Command{
+ Use: "addId",
+ Short: "Adds the provided jwt file to the running service",
+ Hidden: true,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("Adds the provided jwt file to the running service")
+ },
+}
diff --git a/wintun-testing/ziti-tunnel/cmd/root_debug.go b/wintun-testing/ziti-tunnel/cmd/root_debug.go
new file mode 100644
index 00000000..ec9ff0db
--- /dev/null
+++ b/wintun-testing/ziti-tunnel/cmd/root_debug.go
@@ -0,0 +1,20 @@
+package cmd
+
+import (
+"fmt"
+
+"github.com/spf13/cobra"
+)
+
+func init() {
+ rootCmd.AddCommand(debugCmd)
+}
+
+var debugCmd = &cobra.Command{
+ Use: "debug",
+ Short: "Runs the program interactively instead of expecting to be run as a service. Used in debugging",
+ Hidden: true,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("Runs the program interactively instead of expecting to be run as a service. Used in debugging")
+ },
+}
diff --git a/wintun-testing/ziti-tunnel/cmd/root_disable_id.go b/wintun-testing/ziti-tunnel/cmd/root_disable_id.go
new file mode 100644
index 00000000..94c8b46a
--- /dev/null
+++ b/wintun-testing/ziti-tunnel/cmd/root_disable_id.go
@@ -0,0 +1,20 @@
+package cmd
+
+import (
+"fmt"
+
+"github.com/spf13/cobra"
+)
+
+func init() {
+ rootCmd.AddCommand(disableIdCmd)
+}
+
+var disableIdCmd = &cobra.Command{
+ Use: "disable",
+ Short: "Disables any identity in the running service using the provided fingerprint",
+ Hidden: true,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("Disables any identity in the running service using the provided fingerprint")
+ },
+}
diff --git a/wintun-testing/ziti-tunnel/cmd/root_enable_id.go b/wintun-testing/ziti-tunnel/cmd/root_enable_id.go
new file mode 100644
index 00000000..ebdbeee2
--- /dev/null
+++ b/wintun-testing/ziti-tunnel/cmd/root_enable_id.go
@@ -0,0 +1,20 @@
+package cmd
+
+import (
+"fmt"
+
+"github.com/spf13/cobra"
+)
+
+func init() {
+ rootCmd.AddCommand(enableIdCmd)
+}
+
+var enableIdCmd = &cobra.Command{
+ Use: "enable",
+ Short: "Enables any identity in the running service using the provided fingerprint",
+ Hidden: true,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("Enables any identity in the running service using the provided fingerprint")
+ },
+}
diff --git a/wintun-testing/ziti-tunnel/cmd/root_removeidentity.go b/wintun-testing/ziti-tunnel/cmd/root_removeidentity.go
new file mode 100644
index 00000000..92444aa7
--- /dev/null
+++ b/wintun-testing/ziti-tunnel/cmd/root_removeidentity.go
@@ -0,0 +1,20 @@
+package cmd
+
+import (
+"fmt"
+
+"github.com/spf13/cobra"
+)
+
+func init() {
+ rootCmd.AddCommand(removeIdCmd)
+}
+
+var removeIdCmd = &cobra.Command{
+ Use: "removeId",
+ Short: "Removes any identity from the running service using the provided fingerprint",
+ Hidden: true,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("Removes any identity from the running service using the provided fingerprint")
+ },
+}
diff --git a/wintun-testing/ziti-tunnel/cmd/root_svc.go b/wintun-testing/ziti-tunnel/cmd/root_svc.go
new file mode 100644
index 00000000..decfbd6f
--- /dev/null
+++ b/wintun-testing/ziti-tunnel/cmd/root_svc.go
@@ -0,0 +1,20 @@
+package cmd
+
+import (
+"fmt"
+
+"github.com/spf13/cobra"
+)
+
+func init() {
+ rootCmd.AddCommand(serviceCmd)
+}
+
+var serviceCmd = &cobra.Command{
+ Use: "service",
+ Short: "Expects to run the program as a service",
+ Hidden: true,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("print or return the version here")
+ },
+}
diff --git a/wintun-testing/ziti-tunnel/cmd/root_svc_install.go b/wintun-testing/ziti-tunnel/cmd/root_svc_install.go
new file mode 100644
index 00000000..ed838e84
--- /dev/null
+++ b/wintun-testing/ziti-tunnel/cmd/root_svc_install.go
@@ -0,0 +1,20 @@
+package cmd
+
+import (
+"fmt"
+
+"github.com/spf13/cobra"
+)
+
+func init() {
+ serviceCmd.AddCommand(installCmd)
+}
+
+var installCmd = &cobra.Command{
+ Use: "install",
+ Short: "Installs the executable as a service.",
+ Long: `When installing as a service using this function make sure not to move the executable. The path to the executing program will be used in the service`,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("install this thing as a service")
+ },
+}
diff --git a/wintun-testing/ziti-tunnel/cmd/root_svc_remove.go b/wintun-testing/ziti-tunnel/cmd/root_svc_remove.go
new file mode 100644
index 00000000..4a0a64a2
--- /dev/null
+++ b/wintun-testing/ziti-tunnel/cmd/root_svc_remove.go
@@ -0,0 +1,20 @@
+package cmd
+
+import (
+"fmt"
+
+"github.com/spf13/cobra"
+)
+
+func init() {
+ serviceCmd.AddCommand(removeCmd)
+}
+
+var removeCmd = &cobra.Command{
+ Use: "remove",
+ Short: "Removes the executable as a service.",
+ Long: `When removing the service make sure the path and service name have not changed`,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("remove this thing as a service")
+ },
+}
diff --git a/wintun-testing/ziti-tunnel/cmd/root_svc_start.go b/wintun-testing/ziti-tunnel/cmd/root_svc_start.go
new file mode 100644
index 00000000..4de6e9c1
--- /dev/null
+++ b/wintun-testing/ziti-tunnel/cmd/root_svc_start.go
@@ -0,0 +1,19 @@
+package cmd
+
+import (
+"fmt"
+
+"github.com/spf13/cobra"
+)
+
+func init() {
+ serviceCmd.AddCommand(startCmd)
+}
+
+var startCmd = &cobra.Command{
+ Use: "start",
+ Short: "Tries to start the service",
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("Tries to start the service")
+ },
+}
diff --git a/wintun-testing/ziti-tunnel/cmd/root_svc_status.go b/wintun-testing/ziti-tunnel/cmd/root_svc_status.go
new file mode 100644
index 00000000..6bcac35a
--- /dev/null
+++ b/wintun-testing/ziti-tunnel/cmd/root_svc_status.go
@@ -0,0 +1,20 @@
+package cmd
+
+import (
+"fmt"
+
+"github.com/spf13/cobra"
+)
+
+func init() {
+ serviceCmd.AddCommand(statusCmd)
+}
+
+var statusCmd = &cobra.Command{
+ Use: "status",
+ Short: "Prints the status of the service",
+ Hidden: true,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("Prints the status of the service")
+ },
+}
diff --git a/wintun-testing/ziti-tunnel/cmd/root_svc_stop.go b/wintun-testing/ziti-tunnel/cmd/root_svc_stop.go
new file mode 100644
index 00000000..ac400f52
--- /dev/null
+++ b/wintun-testing/ziti-tunnel/cmd/root_svc_stop.go
@@ -0,0 +1,19 @@
+package cmd
+
+import (
+"fmt"
+
+"github.com/spf13/cobra"
+)
+
+func init() {
+ serviceCmd.AddCommand(stopCmd)
+}
+
+var stopCmd = &cobra.Command{
+ Use: "stop",
+ Short: "Tries to stop the service",
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("try to stop the service")
+ },
+}
diff --git a/wintun-testing/ziti-tunnel/cmd/version.go b/wintun-testing/ziti-tunnel/cmd/version.go
new file mode 100644
index 00000000..3e0ef436
--- /dev/null
+++ b/wintun-testing/ziti-tunnel/cmd/version.go
@@ -0,0 +1,20 @@
+package cmd
+
+import (
+"fmt"
+
+"github.com/spf13/cobra"
+)
+
+func init() {
+ rootCmd.AddCommand(versionCmd)
+}
+
+var versionCmd = &cobra.Command{
+ Use: "version",
+ Short: "Print the version of the current executable",
+ Long: ``,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("print or return the version here")
+ },
+}
diff --git a/wintun-testing/ziti-tunnel/dto/dtos.go b/wintun-testing/ziti-tunnel/dto/dtos.go
index 2a34b3dd..c1e6950a 100644
--- a/wintun-testing/ziti-tunnel/dto/dtos.go
+++ b/wintun-testing/ziti-tunnel/dto/dtos.go
@@ -4,6 +4,7 @@ import (
idcfg "github.com/netfoundry/ziti-sdk-golang/ziti/config"
"github.com/netfoundry/ziti-sdk-golang/ziti/enroll"
"log"
+ "wintun-testing/cziti"
"wintun-testing/ziti-tunnel/config"
)
@@ -28,9 +29,11 @@ type Identity struct {
Metrics Metrics
Connected bool `json:"-"`
+ NFContext *cziti.CZitiCtx `json:"-"`
}
type Metrics struct {
- TotalBytes int64
+ Up int64
+ Down int64
}
type CommandMsg struct {
Function string
diff --git a/wintun-testing/ziti-tunnel/main.go b/wintun-testing/ziti-tunnel/main.go
index 2dd05b87..8a4d4851 100644
--- a/wintun-testing/ziti-tunnel/main.go
+++ b/wintun-testing/ziti-tunnel/main.go
@@ -18,7 +18,16 @@ var log = globals.Logger()
func main() {
globals.InitLogger("debug")
- // passing no arguments is an indicator that this is excpecting to be run 'as a service'.
+ //if len(os.Args) < 2 {
+ // // if no args supplied - expect to run as service
+ // os.Args = append(os.Args, "service")
+ //}
+ //cmd.Execute()
+ //if true {
+ // os.Exit(0)
+ //}
+
+ // passing no arguments is an indicator that this is expecting to be run 'as a service'.
// using arg count instead of svc.IsAnInteractiveSession() as svc.IsAnInteractiveSession()
// seems to return false even when run in an interactive shell as via `psexec -i -s cmd.exe`
hasArgs := len(os.Args) > 1
diff --git a/wintun-testing/ziti-tunnel/service/ipc.go b/wintun-testing/ziti-tunnel/service/ipc.go
index df6861b3..d4b8cad9 100644
--- a/wintun-testing/ziti-tunnel/service/ipc.go
+++ b/wintun-testing/ziti-tunnel/service/ipc.go
@@ -30,17 +30,17 @@ type Pipes struct {
events net.Listener
}
-func(p *Pipes) Close() {
+func (p *Pipes) Close() {
p.ipc.Close()
p.logs.Close()
p.events.Close()
}
-func SubMain(ops <- chan string, changes chan<- svc.Status) error {
+func SubMain(ops <-chan string, changes chan<- svc.Status) error {
defer close(top.Broadcast)
log.Info("============================== service begins ==============================")
- _ = globals.Elog.Info(InformationEvent, SvcName + " starting. log file located at " + config.LogFile())
+ _ = globals.Elog.Info(InformationEvent, SvcName+" starting. log file located at "+config.LogFile())
// create a channel for notifying any connections that they are to be interrupted
interrupt = make(chan struct{})
@@ -52,7 +52,7 @@ func SubMain(ops <- chan string, changes chan<- svc.Status) error {
defer pipes.Close()
// wire in a log file for csdk troubleshooting
- logFile, err := os.OpenFile(config.Path() + "cziti.log", os.O_WRONLY | os.O_TRUNC | os.O_APPEND | os.O_CREATE, 0644)
+ logFile, err := os.OpenFile(config.Path()+"cziti.log", os.O_WRONLY|os.O_TRUNC|os.O_APPEND|os.O_CREATE, 0644)
if err != nil {
log.Warnf("could not open cziti.log for writing. no debug information will be captured.")
} else {
@@ -70,13 +70,41 @@ func SubMain(ops <- chan string, changes chan<- svc.Status) error {
setTunnelState(true)
+ // setup metrics notifier
+ every5s := time.NewTicker(5 * time.Second)
+
+ every5sDone := make(chan bool)
+ go func() {
+ for {
+ select {
+ case <-every5sDone:
+ return
+ case <-every5s.C:
+ stat := rst
+ for _, a := range activeIds {
+ up, down := cziti.GetTransferRates(a.NFContext)
+ top.Broadcast <- dto.ZitiTunnelStatus{
+ Status: nil,
+ Metrics: &dto.Metrics{
+ Up: up,
+ Down: down,
+ },
+ }
+ }
+ }
+ }
+ }()
+
// notify the service is running
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
- _ = globals.Elog.Info(InformationEvent, SvcName + " status set to running")
+ _ = globals.Elog.Info(InformationEvent, SvcName+" status set to running")
log.Info(SvcName + " status set to running. starting cancel loop")
waitForStopRequest(ops)
+ // stop the metrics ticker
+ every5sDone <- true
+
pipes.shutdownConnections()
windns.ResetDNS()
@@ -87,7 +115,7 @@ func SubMain(ops <- chan string, changes chan<- svc.Status) error {
return nil
}
-func waitForStopRequest(ops <- chan string) {
+func waitForStopRequest(ops <-chan string) {
loop:
for {
@@ -139,13 +167,13 @@ func openPipes() (*Pipes, error) {
log.Infof("events listener ready pipe: %s", eventsPipeName())
return &Pipes{
- ipc: ipc,
- logs: logs,
+ ipc: ipc,
+ logs: logs,
events: events,
}, nil
}
-func(p *Pipes) shutdownConnections() {
+func (p *Pipes) shutdownConnections() {
log.Info("waiting for all connections to close...")
for i := 0; i < connections; i++ {
@@ -205,7 +233,7 @@ func accept(p net.Listener, serveFunction func(net.Conn)) {
return
}
wg.Add(1)
- connections ++
+ connections++
log.Debugf("accepting a new client")
go serveFunction(c)
@@ -218,7 +246,7 @@ func serveIpc(conn net.Conn) {
done := make(chan struct{})
defer close(done) // ensure that goroutine exits
- defer wg.Done() // count down whenever the function exits
+ defer wg.Done() // count down whenever the function exits
go func() {
select {
@@ -294,11 +322,6 @@ func serveIpc(conn net.Conn) {
onOff := cmd.Payload["OnOff"].(bool)
fingerprint := cmd.Payload["Fingerprint"].(string)
toggleIdentity(enc, fingerprint, onOff)
-
- top.Broadcast <- dto.ZitiTunnelStatus{
- Status: rts.ToStatus(),
- Metrics: nil,
- }
default:
log.Warnf("Unknown operation: %s. Returning error on pipe", cmd.Function)
respondWithError(enc, "Something unexpected has happened", UNKNOWN_ERROR, nil)
@@ -360,7 +383,7 @@ func serveEvents(conn net.Conn) {
status, ok := msg.(dto.ZitiTunnelStatus)
if !ok {
log.Errorf("message received couldn't be converted to status? %v", status)
- break
+ break
}
respond(o, dto.Response{Payload: status})
_, err := w.WriteString("\n")
@@ -375,8 +398,6 @@ func serveEvents(conn net.Conn) {
break
}
_ = w.Flush()
-
- log.Infof("got %v", msg)
}
log.Info("exiting serve events")
}
@@ -567,6 +588,7 @@ func connectIdentity(id *dto.Identity) {
//tell the c sdk to use the file from the id and connect
log.Debugf("loading identity %s with fingerprint %s", id.Name, id.FingerPrint)
rts.LoadIdentity(id)
+ activeIds[id.FingerPrint] = id
} else {
log.Debugf("id [%s] is already connected - not reconnecting", id.Name)
}
@@ -622,3 +644,23 @@ func respond(out *json.Encoder, thing interface{}) {
//leave for debugging j.Encode(thing)
_ = out.Encode(thing)
}
+
+func pipeName(path string) string {
+ if !Debug {
+ return pipeBase + path
+ } else {
+ return pipeBase /*+ `debug\`*/ + path
+ }
+}
+
+func ipcPipeName() string {
+ return pipeName("ipc")
+}
+
+func logsPipeName() string {
+ return pipeName("logs")
+}
+
+func eventsPipeName() string {
+ return pipeName("events")
+}
\ No newline at end of file
diff --git a/wintun-testing/ziti-tunnel/service/package-variables.go b/wintun-testing/ziti-tunnel/service/package-variables.go
index d2e9f349..85f5ec4c 100644
--- a/wintun-testing/ziti-tunnel/service/package-variables.go
+++ b/wintun-testing/ziti-tunnel/service/package-variables.go
@@ -1,26 +1,3 @@
package service
-import (
- "time"
- "wintun-testing/ziti-tunnel/globals"
-)
-
-const (
- NF_GROUP_NAME = "NetFoundry Tunneler Users"
- TunName = "ZitiTUN"
-)
-
-var TunStarted time.Time
-var log = globals.Logger()
-
-const Ipv4ip = "169.254.1.1"
-const Ipv4mask = 24
-const Ipv4dns = "127.0.0.1" // use lo -- don't pass DNS queries through tunneler SDK
-
-// IPv6 CIDR fe80:6e66:7a69:7469::/64
-// : nf : zi : ti ::
-const ipv6pfx = "fe80:6e66:7a69:7469"
-const ipv6ip = "1"
-const ipv6mask = 64
-const Ipv6dns = "::1" // must be in "ipv6ip/ipv6mask" CIDR block
diff --git a/wintun-testing/ziti-tunnel/service/pkg-vars.go b/wintun-testing/ziti-tunnel/service/pkg-vars.go
index 6f1cf1ab..017e8ed5 100644
--- a/wintun-testing/ziti-tunnel/service/pkg-vars.go
+++ b/wintun-testing/ziti-tunnel/service/pkg-vars.go
@@ -4,12 +4,14 @@ import (
"github.com/tv42/topic"
"golang.org/x/sys/windows/svc"
"sync"
+ "time"
+ "wintun-testing/ziti-tunnel/dto"
+ "wintun-testing/ziti-tunnel/globals"
)
var pipeBase = `\\.\pipe\NetFoundry\tunneler\`
-//var tunStatus = RuntimeState{}
-//var state = dto.TunnelStatusa{}
+var activeIds = make(map[string]*dto.Identity)
var rts = RuntimeState{}
var interrupt chan struct{}
@@ -17,6 +19,11 @@ var wg sync.WaitGroup
var connections int
var Debug bool
+var top = topic.New()
+
+var TunStarted time.Time
+var log = globals.Logger()
+
const (
SUCCESS = 0
COULD_NOT_WRITE_FILE = 1
@@ -55,24 +62,18 @@ const (
System = "(A;;FA;;;SY)"
BuiltinAdmins = "(A;;FA;;;BA)"
LocalService = "(A;;FA;;;LS)"
+
+ NF_GROUP_NAME = "NetFoundry Tunneler Users"
+ TunName = "ZitiTUN"
+
+ Ipv4ip = "169.254.1.1"
+ Ipv4mask = 24
+ Ipv4dns = "127.0.0.1" // use lo -- don't pass DNS queries through tunneler SDK
+
+ // IPv6 CIDR fe80:6e66:7a69:7469::/64
+ // : nf : zi : ti ::
+ ipv6pfx = "fe80:6e66:7a69:7469"
+ ipv6ip = "1"
+ ipv6mask = 64
+ Ipv6dns = "::1" // must be in "ipv6ip/ipv6mask" CIDR block
)
-
-func pipeName(path string) string {
- if !Debug {
- return pipeBase + path
- } else {
- return pipeBase + `debug\` + path
- }
-}
-
-var top = topic.New()
-
-func ipcPipeName() string {
- return pipeName("ipc")
-}
-func logsPipeName() string {
- return pipeName("logs")
-}
-func eventsPipeName() string {
- return pipeName("events")
-}
diff --git a/wintun-testing/ziti-tunnel/service/state.go b/wintun-testing/ziti-tunnel/service/state.go
index 6f3ee794..f4cf2a3f 100644
--- a/wintun-testing/ziti-tunnel/service/state.go
+++ b/wintun-testing/ziti-tunnel/service/state.go
@@ -164,6 +164,8 @@ func (t *RuntimeState) LoadIdentity(id *dto.Identity) {
}
log.Infof("loading identity %s with fingerprint %s", id.Name, id.FingerPrint)
ctx := cziti.LoadZiti(id.Path())
+ id.NFContext = ctx
+
id.Connected = true
if ctx == nil {
log.Warnf("connecting to identity with fingerprint [%s] did not error but no context was returned", id.FingerPrint)
@@ -171,7 +173,7 @@ func (t *RuntimeState) LoadIdentity(id *dto.Identity) {
}
log.Infof("successfully loaded %s@%s", ctx.Name(), ctx.Controller())
- log.Debug("name changed from %s to %s", id.Name, ctx.Name())
+ log.Debugf("name changed from %s to %s", id.Name, ctx.Name())
id.Name = ctx.Name()
if ctx.Services != nil {