internal ZitiService(ZitiIdentity id, ZitiContext context, IntPtr ziti_service)
 {
     this.Identity             = id;
     zitiContext               = context;
     this.nativeServicePointer = ziti_service;
     nativeService             = Marshal.PtrToStructure <ziti_service>(ziti_service);
 }
Exemple #2
0
        /// <summary>
        /// The only constructor for <see cref="ZitiConnection"/>. A valid <see cref="ZitiService"/> and
        /// <see cref="ZitiContext"/> must be provided.
        /// </summary>
        /// <param name="service">The <see cref="ZitiService"/> to construct a <see cref="ZitiConnection"/> with</param>
        /// <param name="context"></param>
        /// <param name="connectionContext">Additional context that needs to be stored along with the <see cref="ZitiConnection"/></param>
        public ZitiConnection(ZitiService service, ZitiContext context, object connectionContext)
        {
            this.Service      = service;
            ConnectionContext = connectionContext;

            //make initialze a connection in native code
            Native.API.ziti_conn_init(context.nativeZitiContext, out nativeConnection, GCHandle.ToIntPtr(nativeConnContext));
            zitiContext = context;
        }
Exemple #3
0
 public static void CheckStatus(ZitiContext zitiContext, ZitiStatus status, object initContext)
 {
     status.Check();
 }
        private void ziti_event_cb(IntPtr ziti_context, IntPtr ziti_event_t)
        {
            int type = Native.NativeHelperFunctions.ziti_event_type_from_pointer(ziti_event_t);

            switch (type)
            {
            case ZitiEventFlags.ZitiContextEvent:
                NativeContext  = ziti_context;
                WrappedContext = new ZitiContext(ziti_context);

                Native.ziti_context_event ziti_context_event = Marshal.PtrToStructure <Native.ziti_context_event>(ziti_event_t);
                var          vptr = Native.API.ziti_get_controller_version(ziti_context);
                ziti_version v    = Marshal.PtrToStructure <ziti_version>(vptr);
                IntPtr       ptr  = Native.API.ziti_get_controller(ziti_context);
                string       name = Marshal.PtrToStringUTF8(ptr);

                ZitiContextEvent evt = new ZitiContextEvent()
                {
                    Name        = name,
                    Status      = (ZitiStatus)ziti_context_event.ctrl_status,
                    StatusError = Marshal.PtrToStringUTF8(ziti_context_event.err),
                    Version     = v,
                    Identity    = this,
                };
                InitOpts.ZitiContextEvent(evt);

                lock (this) {
                    Monitor.Pulse(this);
                    isInitialized = true;
                }

                break;

            case ZitiEventFlags.ZitiRouterEvent:
                Native.ziti_router_event ziti_router_event = Marshal.PtrToStructure <Native.ziti_router_event>(ziti_event_t);

                ZitiRouterEvent routerEvent = new ZitiRouterEvent()
                {
                    Name    = Marshal.PtrToStringUTF8(ziti_router_event.name),
                    Type    = (RouterEventType)ziti_router_event.status,
                    Version = Marshal.PtrToStringUTF8(ziti_router_event.version),
                };
                InitOpts.ZitiRouterEvent(routerEvent);
                break;

            case ZitiEventFlags.ZitiServiceEvent:
                Native.ziti_service_event ziti_service_event = Marshal.PtrToStructure <Native.ziti_service_event>(ziti_event_t);

                ZitiServiceEvent serviceEvent = new ZitiServiceEvent()
                {
                    nativeRemovedList = ziti_service_event.removed,
                    nativeChangedList = ziti_service_event.changed,
                    nativeAddedList   = ziti_service_event.added,
                    ziti_ctx          = ziti_context,
                    Context           = this.ApplicationContext,
                    id = this,
                };

                if (isStreaming)
                {
                    foreach (var removed in serviceEvent.Removed())
                    {
                        services.Remove(removed.Id);
                    }
                    foreach (var changed in serviceEvent.Changed())
                    {
                        services[changed.Id] = changed;
                    }
                    foreach (var added in serviceEvent.Added())
                    {
                        services[added.Id] = added;
                    }

                    streamLock.Release();
                }

                InitOpts.ZitiServiceEvent(serviceEvent);

                break;

            default:
                Logger.Warn("UNEXPECTED ZitiEventFlags [{0}]! Please report.", type);
                break;
            }
        }