From 6ac06323cd5721758cb49ff22eb1fef3d8308208 Mon Sep 17 00:00:00 2001 From: ziti-ci Date: Mon, 13 Jul 2020 15:31:30 -0400 Subject: [PATCH 1/5] update release notes... --- release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/release-notes.md b/release-notes.md index a551a1dc..7ae9b45f 100644 --- a/release-notes.md +++ b/release-notes.md @@ -7,6 +7,7 @@ * [#61](https://github.com/openziti/desktop-edge-win/issues/61) - identity shutdown needs to be on the uv loop (issue with forgetting identities) * [#63](https://github.com/openziti/desktop-edge-win/issues/63) - when service restarts and UI reconnects clear identities and let the service repopulate the UI * [#65](https://github.com/openziti/desktop-edge-win/issues/65) - set the MTU based on the value reported from the interface + * [#69](https://github.com/openziti/desktop-edge-win/issues/69) - reference counting for identities with access to the same service # Release 0.0.16 From 0927b6f7a8581eb21d89dc0d7e8d8a7a0d6da150 Mon Sep 17 00:00:00 2001 From: ziti-ci Date: Tue, 14 Jul 2020 08:35:24 -0400 Subject: [PATCH 2/5] remove unused time --- service/cziti/sdk.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/service/cziti/sdk.go b/service/cziti/sdk.go index 09d0d17b..1033729d 100644 --- a/service/cziti/sdk.go +++ b/service/cziti/sdk.go @@ -272,7 +272,6 @@ func(c *CZitiCtx) Shutdown() { var logFile *os.File //the current, active log file var logLevel int //set in InitializeCLogger -var lastRollover = time.Now() func InitializeCLogger(level int) { logLevel = level @@ -284,7 +283,6 @@ func InitializeCLogger(level int) { } func initiateRollLog() { - lastRollover = time.Now() async := (*C.uv_async_t)(C.malloc(C.sizeof_uv_async_t)) C.uv_async_init(_impl.libuvCtx.l, async, C.uv_async_cb(C.cron_callback)) C.uv_async_send((*C.uv_async_t)(unsafe.Pointer(async))) From f3ab3ed836426f5c56d411329e32c947a5745092 Mon Sep 17 00:00:00 2001 From: ziti-ci Date: Thu, 16 Jul 2020 07:37:20 -0400 Subject: [PATCH 3/5] return an ip for a service even if it's not going to own the dns intercept --- service/cziti/dns.go | 46 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/service/cziti/dns.go b/service/cziti/dns.go index a17e0b19..d25c3b2b 100644 --- a/service/cziti/dns.go +++ b/service/cziti/dns.go @@ -57,33 +57,37 @@ type ctxService struct { name string } -func (dns *dnsImpl) RegisterService(dnsName string, port uint16, ctx *CZitiCtx, name string) (net.IP, error) { - log.Infof("adding DNS entry for service name %s@%s:%d", name, dnsName, port) +// RegisterService will return the next ip address in the configured range. If the ip address is not +// assigned to a hostname an error will also be returned indicating why. +func (dns *dnsImpl) RegisterService(dnsNameToReg string, port uint16, ctx *CZitiCtx, name string) (net.IP, error) { + log.Infof("adding DNS entry for service name %s@%s:%d", name, dnsNameToReg, port) DnsInit(defaultCidr, defaultMaskBits) - dnsName = dnsName + "." + dnsName := dnsNameToReg + "." key := fmt.Sprint(dnsName, ':', port) - if cs, found := dns.serviceMap[key]; found { - if cs.ctx != ctx || cs.name != name { - return nil, fmt.Errorf( - "service mapping conflict: %s:%d is already mapped for another context", dnsName, port) - } - return dns.hostnameMap[dnsName], nil - } - - dns.serviceMap[key] = ctxService{ - ctx: ctx, - name: name, - } - - if ip, mapped := dns.hostnameMap[dnsName]; mapped { - return ip, nil - } nextAddr := dns.cidr | atomic.AddUint32(&dns.counter, 1) nextIp := make(net.IP, 4) binary.BigEndian.PutUint32(nextIp, nextAddr) - dns.hostnameMap[dnsName] = nextIp - dns.ipMap[nextAddr] = dnsName + + if cs, found := dns.serviceMap[key]; found { + if cs.ctx != ctx || cs.name != name { + return nextIp, fmt.Errorf( + "service mapping conflict: %s:%d is already mapped for another context", dnsNameToReg, port) + } + return nextIp, nil + } else { + dns.serviceMap[key] = ctxService{ + ctx: ctx, + name: name, + } + + if ip, mapped := dns.hostnameMap[dnsName]; mapped { + return ip, nil + } + + dns.hostnameMap[dnsName] = nextIp + dns.ipMap[nextAddr] = dnsName + } return nextIp, nil } From ac61f5708506038c1d6519c81095c65d135ef411 Mon Sep 17 00:00:00 2001 From: ziti-ci Date: Thu, 16 Jul 2020 08:44:40 -0400 Subject: [PATCH 4/5] clean release notes and bump version --- release-notes.md | 11 +++++++++-- version | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/release-notes.md b/release-notes.md index 55a2eace..6cf1e42a 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,10 +1,18 @@ +# Release 0.0.18 + +* What's New + + * [#70](https://github.com/openziti/desktop-edge-win/issues/70) - + +* Bug fixes + * [#59](https://github.com/openziti/desktop-edge-win/issues/59) - + # Release 0.0.17 * What's New * [#70](https://github.com/openziti/desktop-edge-win/issues/70) - added api ApiVersion to TunnelStatusEvent * [#71](https://github.com/openziti/desktop-edge-win/issues/71) - add .log to rolled over log files - * * Bug fixes * [#59](https://github.com/openziti/desktop-edge-win/issues/59) - too many services blocked service from accepting connections from the UI @@ -12,7 +20,6 @@ * [#63](https://github.com/openziti/desktop-edge-win/issues/63) - when service restarts and UI reconnects clear identities and let the service repopulate the UI * [#67](https://github.com/openziti/desktop-edge-win/issues/67) - set the MTU based on the value reported from the interface - # Release 0.0.16 - tracking lost diff --git a/version b/version index cd231804..32786aa4 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.0.17 +0.0.18 From fb9f06061f15a3bf648ef950dcbf73701408a16b Mon Sep 17 00:00:00 2001 From: ziti-ci Date: Thu, 16 Jul 2020 13:35:30 -0400 Subject: [PATCH 5/5] track the ip assigned and send it to the UI as well for display --- DesktopEdge/MainWindow.xaml.cs | 2 +- DesktopEdge/Models/ZitiIdentity.cs | 2 +- DesktopEdge/Models/ZitiService.cs | 49 ++++++++++++++++++--- DesktopEdge/ServiceClient/ClientImpl.cs | 2 - DesktopEdge/ServiceClient/DataStructures.cs | 8 ++-- service/cziti/sdk.go | 16 ++++--- service/ziti-tunnel/service/debug.go | 1 + service/ziti-tunnel/service/ipc.go | 7 +-- 8 files changed, 64 insertions(+), 23 deletions(-) diff --git a/DesktopEdge/MainWindow.xaml.cs b/DesktopEdge/MainWindow.xaml.cs index da6d6f93..073d7a5b 100644 --- a/DesktopEdge/MainWindow.xaml.cs +++ b/DesktopEdge/MainWindow.xaml.cs @@ -230,7 +230,7 @@ namespace ZitiDesktopEdge { } if (e.Action == "added") { - ZitiService zs = new ZitiService(e.Service.Name, e.Service.HostName, e.Service.Port, ""); // CLINT: Gimme an error + ZitiService zs = new ZitiService(e.Service); var svc = found.Services.Find(s => s.Name == zs.Name); if (svc == null) found.Services.Add(zs); else Debug.WriteLine("the service named " + zs.Name + " is already accounted for on this identity."); diff --git a/DesktopEdge/Models/ZitiIdentity.cs b/DesktopEdge/Models/ZitiIdentity.cs index fd3361fa..5ba18ae1 100644 --- a/DesktopEdge/Models/ZitiIdentity.cs +++ b/DesktopEdge/Models/ZitiIdentity.cs @@ -44,7 +44,7 @@ namespace ZitiDesktopEdge.Models { if (id.Services != null) { foreach (var svc in id.Services) { - var zsvc = new ZitiService(svc.Name, svc.HostName, svc.Port, ""); // CLINT: Warning needed + var zsvc = new ZitiService(svc); zid.Services.Add(zsvc); } } diff --git a/DesktopEdge/Models/ZitiService.cs b/DesktopEdge/Models/ZitiService.cs index 4e7ba741..9ed581bb 100644 --- a/DesktopEdge/Models/ZitiService.cs +++ b/DesktopEdge/Models/ZitiService.cs @@ -1,18 +1,55 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Management.Automation.Language; using System.Text; using System.Threading.Tasks; namespace ZitiDesktopEdge.Models { public class ZitiService { public string Name { get; set; } - public string Url { get; set; } - public string Warning { get; set; } - public ZitiService(string Name, string hostname, int port, string warning) { - this.Name = Name; - this.Url = hostname + ":" + port; - this.Warning = warning; + public string AssignedIP { get; set; } + public string Host { get; set; } + public string Port { get; set; } + public bool OwnsIntercept { get; set; } + public string Url + { + get + { + if (this.OwnsIntercept) + { + return Host + ":" + Port; + } else + { + return AssignedIP + ":" + Port; + } + } + } + public string Warning + { + get + { + if (this.OwnsIntercept) + { + return ""; + } + else + { + return $"Another identity is already mapped the specified hostname: {Host}.\nThis service is only available via IP"; + } + } + } + + public ZitiService() { + } + + public ZitiService(ZitiDesktopEdge.ServiceClient.Service svc) + { + this.Name = svc.Name; + this.AssignedIP = svc.AssignedIP; + this.Host = svc.InterceptHost; + this.Port = svc.InterceptPort.ToString(); + this.OwnsIntercept = svc.OwnsIntercept; } } } diff --git a/DesktopEdge/ServiceClient/ClientImpl.cs b/DesktopEdge/ServiceClient/ClientImpl.cs index 428352b4..a656335c 100644 --- a/DesktopEdge/ServiceClient/ClientImpl.cs +++ b/DesktopEdge/ServiceClient/ClientImpl.cs @@ -122,8 +122,6 @@ namespace ZitiDesktopEdge.ServiceClient _extendedDebug = true; } } - //establish the named pipe to the service - setupPipe(); } catch(Exception ex) { diff --git a/DesktopEdge/ServiceClient/DataStructures.cs b/DesktopEdge/ServiceClient/DataStructures.cs index 6de9f0e9..2487e0a6 100644 --- a/DesktopEdge/ServiceClient/DataStructures.cs +++ b/DesktopEdge/ServiceClient/DataStructures.cs @@ -126,8 +126,10 @@ namespace ZitiDesktopEdge.ServiceClient public class Service { public string Name { get; set; } - public string HostName { get; set; } - public UInt16 Port { get; set; } + public string InterceptHost { get; set; } + public UInt16 InterceptPort { get; set; } + public bool OwnsIntercept { get; set; } + public string AssignedIP { get; set; } } public class EnrollmentFlags @@ -173,7 +175,7 @@ namespace ZitiDesktopEdge.ServiceClient writer.WriteLine($" Services:"); foreach (Service s in id.Services) { - writer.WriteLine($" Name: {s.Name} HostName: {s.HostName} Port: {s.Port}"); + writer.WriteLine($" Name: {s.Name} HostName: {s.InterceptHost} Port: {s.InterceptPort}"); } writer.WriteLine("============================================="); } diff --git a/service/cziti/sdk.go b/service/cziti/sdk.go index 2584bb06..c2e9eb6a 100644 --- a/service/cziti/sdk.go +++ b/service/cziti/sdk.go @@ -99,6 +99,7 @@ type Service struct { Id string InterceptHost string InterceptPort uint16 + AssignedIP string } type CZitiCtx struct { @@ -172,13 +173,6 @@ func serviceCB(nf C.ziti_context, service *C.ziti_service, status C.int, data un port = int(c["port"].(float64)) } } - added := Service{ - Name: name, - Id: id, - InterceptHost: host, - InterceptPort: uint16(port), - } - ctx.Services.Store(id, added) if host != "" && port != -1 { ip, err := DNS.RegisterService(host, uint16(port), ctx, name) if err != nil { @@ -189,6 +183,14 @@ func serviceCB(nf C.ziti_context, service *C.ziti_service, status C.int, data un t.AddIntercept(id, name, ip.String(), port, unsafe.Pointer(ctx.zctx)) } } + added := Service{ + Name: name, + Id: id, + InterceptHost: host, + InterceptPort: uint16(port), + AssignedIP: ip.String(), + } + ctx.Services.Store(id, added) ServiceChanges <- ServiceChange{ Operation: ADDED, Service: &added, diff --git a/service/ziti-tunnel/service/debug.go b/service/ziti-tunnel/service/debug.go index bbfe7851..3c04a103 100644 --- a/service/ziti-tunnel/service/debug.go +++ b/service/ziti-tunnel/service/debug.go @@ -28,6 +28,7 @@ func dbg() { events.broadcast <- dto.TunnelStatusEvent{ StatusEvent: dto.StatusEvent{Op: "status"}, Status: r, + ApiVersion: API_VERSION, } svcs := make([]*dto.Service, 2) diff --git a/service/ziti-tunnel/service/ipc.go b/service/ziti-tunnel/service/ipc.go index 7148db11..9da12139 100644 --- a/service/ziti-tunnel/service/ipc.go +++ b/service/ziti-tunnel/service/ipc.go @@ -300,7 +300,7 @@ func accept(p net.Listener, serveFunction func(net.Conn), debug string) { func serveIpc(conn net.Conn) { log.Debug("beginning ipc receive loop") - defer log.Warn("IPC Loop has exited") + defer log.Info("A connected IPC client has disconnected") defer closeConn(conn) //close the connection after this function invoked as go routine exits events.broadcast <- dto.TunnelStatusEvent{ @@ -519,7 +519,7 @@ loop: case msg := <-consumer: err := o.Encode(msg) if err != nil { - log.Infof("exiting from serveEvents - %v", err) + log.Debugf("exiting from serveEvents - %v", err) break loop } _ = w.Flush() @@ -527,7 +527,7 @@ loop: break loop } } - log.Debug("exiting serve events") + log.Info("a connected event client has disconnected") } func reportStatus(out *json.Encoder) { @@ -828,6 +828,7 @@ func acceptServices() { InterceptHost: c.Service.InterceptHost, InterceptPort: c.Service.InterceptPort, Id: c.Service.Id, + AssignedIP: c.Service.AssignedIP, } id.Services = append(id.Services, &svc)