예제 #1
0
 public void Initialize(PluginInitializationContext context)
 {
     context.AddDispatchInterceptor(
         async(request, current, next) =>
     {
         current.Context["DispatchPlugin"] = "1";
         OutgoingResponseFrame response    = await next(request, current);
         if (request.Protocol == Protocol.Ice2)
         {
             response.AddBinaryContextEntry(100, 100, (ostr, v) => ostr.WriteInt(v));
         }
         return(response);
     });
 }
예제 #2
0
            public override void Initialize(PluginInitializationContext context)
            {
                var one = (BasePluginFail?)_communicator.GetPlugin("PluginOneFail");

                TestHelper.Assert(one != null);
                _one = one;
                TestHelper.Assert(_one.isInitialized());
                var three = (BasePluginFail?)_communicator.GetPlugin("PluginThreeFail");

                TestHelper.Assert(three != null);
                _three = three;
                TestHelper.Assert(!_three.isInitialized());
                _initialized = true;
            }
예제 #3
0
 public void Initialize(PluginInitializationContext context)
 {
     context.AddInvocationInterceptor(
         async(target, request, next) =>
     {
         if (request.Protocol == Protocol.Ice2)
         {
             request.ContextOverride["InvocationPlugin"] = "1";
         }
         IncomingResponseFrame response = await next(target, request);
         if (response.Protocol == Protocol.Ice2 && response.ResultType == ResultType.Success)
         {
             TestHelper.Assert(
                 response.BinaryContext.TryGetValue(100, out ReadOnlyMemory <byte> value) &&
                 value.Read(istr => istr.ReadInt()) == 100);
         }
         return(response);
     });
 }
예제 #4
0
        public void Initialize(PluginInitializationContext context)
        {
            const string defaultIPv4Endpoint = "udp -h 239.255.0.1 -p 4061";
            const string defaultIPv6Endpoint = "udp -h \"ff15::1\" -p 4061";

            if (_communicator.GetProperty("IceDiscovery.Multicast.Endpoints") == null)
            {
                _communicator.SetProperty("IceDiscovery.Multicast.Endpoints",
                                          $"{defaultIPv4Endpoint}:{defaultIPv6Endpoint}");
            }

            string?lookupEndpoints = _communicator.GetProperty("IceDiscovery.Lookup");

            if (lookupEndpoints == null)
            {
                List <string> endpoints      = new ();
                List <string> ipv4Interfaces = Network.GetInterfacesForMulticast("0.0.0.0", Network.EnableIPv4);
                List <string> ipv6Interfaces = Network.GetInterfacesForMulticast("::0", Network.EnableIPv6);

                endpoints.AddRange(ipv4Interfaces.Select(i => $"{defaultIPv4Endpoint} --interface \"{i}\""));
                endpoints.AddRange(ipv6Interfaces.Select(i => $"{defaultIPv6Endpoint} --interface \"{i}\""));

                lookupEndpoints = string.Join(":", endpoints);
            }

            if (_communicator.GetProperty("IceDiscovery.Reply.Endpoints") == null)
            {
                _communicator.SetProperty("IceDiscovery.Reply.Endpoints", "udp -h \"::0\" -p 0");
            }

            if (_communicator.GetProperty("IceDiscovery.Locator.Endpoints") == null)
            {
                _communicator.SetProperty("IceDiscovery.Locator.AdapterId", Guid.NewGuid().ToString());
            }

            _multicastAdapter = _communicator.CreateObjectAdapter("IceDiscovery.Multicast");
            _replyAdapter     = _communicator.CreateObjectAdapter("IceDiscovery.Reply");
            _locatorAdapter   = _communicator.CreateObjectAdapter("IceDiscovery.Locator");

            // Setup locator registry.
            var locatorRegistryServant          = new LocatorRegistry(_communicator);
            ILocatorRegistryPrx locatorRegistry =
                _locatorAdapter.AddWithUUID(locatorRegistryServant, ILocatorRegistryPrx.Factory);

            ILookupPrx lookup =
                ILookupPrx.Parse($"IceDiscovery/Lookup -d:{lookupEndpoints}", _communicator).Clone(clearRouter: true);

            // Add lookup Ice object
            var lookupServant = new Lookup(locatorRegistryServant, _communicator);

            _multicastAdapter.Add("IceDiscovery/Lookup", lookupServant);

            // Setup locator on the communicator.
            _locator = _locatorAdapter.AddWithUUID(new Locator(locatorRegistry, lookup, _replyAdapter),
                                                   ILocatorPrx.Factory);

            _defaultLocator = _communicator.DefaultLocator;
            _communicator.DefaultLocator = _locator;

            _multicastAdapter.Activate();
            _replyAdapter.Activate();
            _locatorAdapter.Activate();
        }
예제 #5
0
        public void Initialize(PluginInitializationContext context)
        {
            const string defaultIPv4Endpoint = "udp -h 239.255.0.1 -p 4061";
            const string defaultIPv6Endpoint = "udp -h \"ff15::1\" -p 4061";

            string?lookupEndpoints = _communicator.GetProperty($"{_name}.Lookup");

            if (lookupEndpoints == null)
            {
                List <string> endpoints      = new ();
                List <string> ipv4Interfaces = Network.GetInterfacesForMulticast("0.0.0.0", Network.EnableIPv4);
                List <string> ipv6Interfaces = Network.GetInterfacesForMulticast("::0", Network.EnableIPv6);

                endpoints.AddRange(ipv4Interfaces.Select(i => $"{defaultIPv4Endpoint} --interface \"{i}\""));
                endpoints.AddRange(ipv6Interfaces.Select(i => $"{defaultIPv6Endpoint} --interface \"{i}\""));

                lookupEndpoints = string.Join(":", endpoints);
            }

            if (_communicator.GetProperty($"{_name}.Reply.Endpoints") == null)
            {
                _communicator.SetProperty($"{_name}.Reply.Endpoints", "udp -h \"::0\" -p 0");
            }
            _communicator.SetProperty($"{_name}.Reply.ProxyOptions", "-d");

            if (_communicator.GetProperty($"{_name}.Locator.Endpoints") == null)
            {
                _communicator.SetProperty($"{_name}.Locator.AdapterId", Guid.NewGuid().ToString());
            }

            _replyAdapter   = _communicator.CreateObjectAdapter(_name + ".Reply");
            _locatorAdapter = _communicator.CreateObjectAdapter(_name + ".Locator");

            // We don't want those adapters to be registered with the locator so clear their locator.
            _replyAdapter.Locator   = null;
            _locatorAdapter.Locator = null;

            var lookupPrx = ILookupPrx.Parse($"IceLocatorDiscovery/Lookup -d:{lookupEndpoints}", _communicator);

            lookupPrx = lookupPrx.Clone(clearRouter: false);

            var             lookupReplyId   = new Identity(Guid.NewGuid().ToString(), "");
            ILookupReplyPrx locatorReplyPrx = _replyAdapter.CreateProxy(lookupReplyId, ILookupReplyPrx.Factory);

            Debug.Assert(locatorReplyPrx.InvocationMode == InvocationMode.Datagram);

            _defaultLocator = _communicator.DefaultLocator;

            string instanceName = _communicator.GetProperty($"{_name}.InstanceName") ?? "";
            var    locatorId    = new Identity("Locator", instanceName.Length > 0 ? instanceName : Guid.NewGuid().ToString());

            _locatorServant = new Locator(_name, lookupPrx, _communicator, instanceName, locatorReplyPrx);

            _locator = _locatorAdapter.Add(locatorId, _locatorServant, ILocatorPrx.Factory);
            _communicator.DefaultLocator = _locator;

            _replyAdapter.Add(lookupReplyId, new LookupReply(_locatorServant));

            _replyAdapter.Activate();
            _locatorAdapter.Activate();
        }
예제 #6
0
        public void Initialize(PluginInitializationContext context)
        {
            bool ipv4       = _communicator.GetPropertyAsBool("Ice.IPv4") ?? true;
            bool preferIPv6 = _communicator.GetPropertyAsBool("Ice.PreferIPv6Address") ?? false;

            string address;

            if (ipv4 && !preferIPv6)
            {
                address = _communicator.GetProperty($"{_name}.Address") ?? "239.255.0.1";
            }
            else
            {
                address = _communicator.GetProperty($"{_name}.Address") ?? "ff15::1";
            }
            int    port = _communicator.GetPropertyAsInt($"{_name}.Port") ?? 4061;
            string intf = _communicator.GetProperty($"{_name}.Interface") ?? "";

            string lookupEndpoints = _communicator.GetProperty($"{_name}.Lookup") ?? "";

            if (lookupEndpoints.Length == 0)
            {
                int           ipVersion  = ipv4 && !preferIPv6 ? Network.EnableIPv4 : Network.EnableIPv6;
                List <string> interfaces = Network.GetInterfacesForMulticast(intf, ipVersion);
                lookupEndpoints = string.Join(":", interfaces.Select(
                                                  intf => $"udp -h \"{address}\" -p {port} --interface \"{intf}\""));
            }

            if (_communicator.GetProperty($"{_name}.Reply.Endpoints") == null)
            {
                _communicator.SetProperty($"{_name}.Reply.Endpoints",
                                          intf.Length == 0 ? "udp -h *" : $"udp -h \"{intf}\"");
            }

            if (_communicator.GetProperty($"{_name}.Locator.Endpoints") == null)
            {
                _communicator.SetProperty($"{_name}.Locator.AdapterId", Guid.NewGuid().ToString());
            }

            _replyAdapter   = _communicator.CreateObjectAdapter(_name + ".Reply");
            _locatorAdapter = _communicator.CreateObjectAdapter(_name + ".Locator");

            // We don't want those adapters to be registered with the locator so clear their locator.
            _replyAdapter.Locator   = null;
            _locatorAdapter.Locator = null;

            var lookupPrx = ILookupPrx.Parse($"IceLocatorDiscovery/Lookup -d:{lookupEndpoints}", _communicator);

            lookupPrx = lookupPrx.Clone(clearRouter: false);

            ILocatorPrx voidLocator = _locatorAdapter.AddWithUUID(new VoidLocator(), ILocatorPrx.Factory);

            var             lookupReplyId   = new Identity(Guid.NewGuid().ToString(), "");
            ILookupReplyPrx?locatorReplyPrx = _replyAdapter.CreateProxy(lookupReplyId, ILookupReplyPrx.Factory).Clone(
                invocationMode: InvocationMode.Datagram);

            _defaultLocator = _communicator.DefaultLocator;

            string instanceName = _communicator.GetProperty($"{_name}.InstanceName") ?? "";
            var    locatorId    = new Identity("Locator", instanceName.Length > 0 ? instanceName : Guid.NewGuid().ToString());

            _locator    = new Locator(_name, lookupPrx, _communicator, instanceName, voidLocator, locatorReplyPrx);
            _locatorPrx = _locatorAdapter.Add(locatorId, _locator, ILocatorPrx.Factory);
            _communicator.DefaultLocator = _locatorPrx;

            _replyAdapter.Add(lookupReplyId, new LookupReply(_locator));

            _replyAdapter.Activate();
            _locatorAdapter.Activate();
        }
예제 #7
0
파일: Plugin.cs 프로젝트: keno1213/ice
        public void Initialize(PluginInitializationContext context)
        {
            bool   ipv4       = _communicator.GetPropertyAsBool("Ice.IPv4") ?? true;
            bool   preferIPv6 = _communicator.GetPropertyAsBool("Ice.PreferIPv6Address") ?? false;
            string address;

            if (ipv4 && !preferIPv6)
            {
                address = _communicator.GetProperty("IceDiscovery.Address") ?? "239.255.0.1";
            }
            else
            {
                address = _communicator.GetProperty("IceDiscovery.Address") ?? "ff15::1";
            }
            int    port = _communicator.GetPropertyAsInt("IceDiscovery.Port") ?? 4061;
            string intf = _communicator.GetProperty("IceDiscovery.Interface") ?? "";

            if (_communicator.GetProperty("IceDiscovery.Multicast.Endpoints") == null)
            {
                if (intf.Length > 0)
                {
                    _communicator.SetProperty("IceDiscovery.Multicast.Endpoints",
                                              $"udp -h \"{address}\" -p {port} --interface \"{intf}\"");
                }
                else
                {
                    _communicator.SetProperty("IceDiscovery.Multicast.Endpoints", $"udp -h \"{address}\" -p {port}");
                }
            }

            string lookupEndpoints = _communicator.GetProperty("IceDiscovery.Lookup") ?? "";

            if (lookupEndpoints.Length == 0)
            {
                int           ipVersion  = ipv4 && !preferIPv6 ? Network.EnableIPv4 : Network.EnableIPv6;
                List <string> interfaces = Network.GetInterfacesForMulticast(intf, ipVersion);
                foreach (string p in interfaces)
                {
                    if (p != interfaces[0])
                    {
                        lookupEndpoints += ":";
                    }
                    lookupEndpoints += $"udp -h \"{address}\" -p {port} --interface \"{p}\"";
                }
            }

            if (_communicator.GetProperty("IceDiscovery.Reply.Endpoints") == null)
            {
                _communicator.SetProperty("IceDiscovery.Reply.Endpoints",
                                          intf.Length == 0 ? "udp -h *" : $"udp -h \"{intf}\"");
            }

            if (_communicator.GetProperty("IceDiscovery.Locator.Endpoints") == null)
            {
                _communicator.SetProperty("IceDiscovery.Locator.AdapterId", Guid.NewGuid().ToString());
            }

            _multicastAdapter = _communicator.CreateObjectAdapter("IceDiscovery.Multicast");
            _replyAdapter     = _communicator.CreateObjectAdapter("IceDiscovery.Reply");
            _locatorAdapter   = _communicator.CreateObjectAdapter("IceDiscovery.Locator");

            // Setup locator registry.
            var locatorRegistry = new LocatorRegistry();
            ILocatorRegistryPrx locatorRegistryPrx =
                _locatorAdapter.AddWithUUID(locatorRegistry, ILocatorRegistryPrx.Factory);

            ILookupPrx lookupPrx =
                ILookupPrx.Parse($"IceDiscovery/Lookup -d:{lookupEndpoints}", _communicator).Clone(clearRouter: true);

            // Add lookup Ice object
            var lookup = new Lookup(locatorRegistry, lookupPrx, _communicator, _replyAdapter);

            _multicastAdapter.Add("IceDiscovery/Lookup", lookup);

            // Setup locator on the communicator.
            _locator        = _locatorAdapter.AddWithUUID(new Locator(lookup, locatorRegistryPrx), ILocatorPrx.Factory);
            _defaultLocator = _communicator.DefaultLocator;
            _communicator.DefaultLocator = _locator;

            _multicastAdapter.Activate();
            _replyAdapter.Activate();
            _locatorAdapter.Activate();
        }
예제 #8
0
 public void Initialize(PluginInitializationContext context) => throw new PluginInitializeFailException();
예제 #9
0
파일: Client.cs 프로젝트: keno1213/ice
 public void Initialize(PluginInitializationContext context) => _initialized = true;
예제 #10
0
 public abstract void Initialize(PluginInitializationContext context);
예제 #11
0
 public void Initialize(PluginInitializationContext context) => context.Logger = new Logger();