public void Initialize(PluginInitializationContext context) { string address = _communicator.GetProperty($"{_name}.Address") ?? (_communicator.PreferIPv6 ? "ff15::1" : "239.255.0.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 = _communicator.PreferIPv6 ? Network.EnableIPv6 : Network.EnableIPv4; 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(); }
internal Lookup( LocatorRegistry registry, ILookupPrx lookup, Communicator communicator, ObjectAdapter replyAdapter) { _replyAdapter = replyAdapter; _registry = registry; _lookup = lookup; _timeout = communicator.GetPropertyAsTimeSpan("IceDiscovery.Timeout") ?? TimeSpan.FromMilliseconds(300); if (_timeout == Timeout.InfiniteTimeSpan) { _timeout = TimeSpan.FromMilliseconds(300); } _retryCount = communicator.GetPropertyAsInt("IceDiscovery.RetryCount") ?? 3; _latencyMultiplier = communicator.GetPropertyAsInt("IceDiscovery.LatencyMultiplier") ?? 1; if (_latencyMultiplier < 1) { throw new InvalidConfigurationException( "The value of `IceDiscovery.LatencyMultiplier' must be a positive integer greater than 0"); } _domainId = communicator.GetProperty("IceDiscovery.DomainId") ?? ""; // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast // datagram on each endpoint. ILookupReplyPrx lookupReply = _replyAdapter.CreateProxy( "dummy", ILookupReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram); var single = new Endpoint[1]; foreach (Endpoint endpoint in lookup.Endpoints) { // lookup's invocation mode is Datagram Debug.Assert(endpoint.Transport == Transport.UDP); single[0] = endpoint; ILookupPrx?key = lookup.Clone(endpoints: single); if (endpoint["interface"] is string mcastInterface && mcastInterface.Length > 0) { Endpoint?q = lookupReply.Endpoints.FirstOrDefault(e => e.Host == mcastInterface); if (q != null) { single[0] = q; _lookups[key] = lookupReply.Clone(endpoints: single); } } if (!_lookups.ContainsKey(key)) { // Fallback: just use the given lookup reply proxy if no matching endpoint found. _lookups[key] = lookupReply; } } Debug.Assert(_lookups.Count > 0); }
private async Task FindLocator(ILookupPrx lookup, ILookupReplyPrx reply) { try { await lookup.FindLocatorAsync(_instanceName, reply).ConfigureAwait(false); } catch (Exception ex) { Exception(ex); } }
protected override async Task InvokeWithLookup(string domainId, ILookupPrx lookup, ILookupReplyPrx lookupReply) { try { await lookup.FindObjectByIdAsync(domainId, Id, lookupReply).ConfigureAwait(false); } catch (Exception ex) { Lookup.ObjectRequestException(this, ex); } }
internal Locator( string name, ILookupPrx lookup, Communicator communicator, string instanceName, ILocatorPrx voidLocator, ILookupReplyPrx lookupReply) { _lookup = lookup; _timeout = communicator.GetPropertyAsTimeSpan($"{name}.Timeout") ?? TimeSpan.FromMilliseconds(300); if (_timeout == System.Threading.Timeout.InfiniteTimeSpan) { _timeout = TimeSpan.FromMilliseconds(300); } _retryCount = Math.Max(communicator.GetPropertyAsInt($"{name}.RetryCount") ?? 3, 1); _retryDelay = communicator.GetPropertyAsTimeSpan($"{name}.RetryDelay") ?? TimeSpan.FromMilliseconds(2000); _traceLevel = communicator.GetPropertyAsInt($"{name}.Trace.Lookup") ?? 0; _instanceName = instanceName; _warned = false; _locator = lookup.Communicator.DefaultLocator; _voidLocator = voidLocator; // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast // datagram on each endpoint. var single = new Endpoint[1]; foreach (Endpoint endpoint in lookup.Endpoints) { // lookup's invocation mode is Datagram Debug.Assert(endpoint.Transport == Transport.UDP); single[0] = endpoint; ILookupPrx key = lookup.Clone(endpoints: single); if (endpoint["interface"] is string mcastInterface && mcastInterface.Length > 0) { Endpoint?q = lookupReply.Endpoints.FirstOrDefault(e => e.Host == mcastInterface); if (q != null) { single[0] = q; _lookups[key] = lookupReply.Clone(endpoints: single); } } if (!_lookups.ContainsKey(key)) { // Fallback: just use the given lookup reply proxy if no matching endpoint found. _lookups[key] = lookupReply; } } Debug.Assert(_lookups.Count > 0); }
protected override void InvokeWithLookup(string domainId, ILookupPrx lookup, ILookupReplyPrx lookupReply) { lookup.FindObjectByIdAsync(domainId, Id, lookupReply).ContinueWith(task => { try { task.Wait(); } catch (AggregateException ex) { Lookup.ObjectRequestException(this, ex.InnerException); } }, lookup.Scheduler); }
internal Locator( string name, ILookupPrx lookup, Communicator communicator, string instanceName, ILocatorPrx voidLocator, ILookupReplyPrx lookupReply) { _lookup = lookup; _timeout = communicator.GetPropertyAsInt($"{name}.Timeout") ?? 300; if (_timeout < 0) { _timeout = 300; } _retryCount = Math.Max(communicator.GetPropertyAsInt($"{name}.RetryCount") ?? 3, 1); _retryDelay = Math.Max(communicator.GetPropertyAsInt($"{name}.RetryDelay") ?? 2000, 0); _traceLevel = communicator.GetPropertyAsInt($"{name}.Trace.Lookup") ?? 0; _instanceName = instanceName; _warned = false; _locator = lookup.Communicator.DefaultLocator; _voidLocator = voidLocator; // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast // datagram on each endpoint. var single = new Endpoint[1]; foreach (UdpEndpoint endpoint in lookup.Endpoints.Cast <UdpEndpoint>()) { single[0] = endpoint; ILookupPrx key = lookup.Clone(endpoints: single); if (endpoint.McastInterface.Length > 0) { IPEndpoint?q = lookupReply.Endpoints.Cast <IPEndpoint>().FirstOrDefault( e => e is IPEndpoint ipEndpoint && ipEndpoint.Host.Equals(endpoint.McastInterface)); if (q != null) { single[0] = q; _lookups[key] = lookupReply.Clone(endpoints: single); } } if (!_lookups.ContainsKey(key)) { // Fallback: just use the given lookup reply proxy if no matching endpoint found. _lookups[key] = lookupReply; } } Debug.Assert(_lookups.Count > 0); }
internal Lookup(LocatorRegistry registry, ILookupPrx lookup, Communicator communicator, ObjectAdapter replyAdapter) { _replyAdapter = replyAdapter; _registry = registry; _lookup = lookup; _timeout = communicator.GetPropertyAsTimeSpan("IceDiscovery.Timeout") ?? TimeSpan.FromMilliseconds(300); if (_timeout == System.Threading.Timeout.InfiniteTimeSpan) { _timeout = TimeSpan.FromMilliseconds(300); } _retryCount = communicator.GetPropertyAsInt("IceDiscovery.RetryCount") ?? 3; _latencyMultiplier = communicator.GetPropertyAsInt("IceDiscovery.LatencyMultiplier") ?? 1; _domainId = communicator.GetProperty("IceDiscovery.DomainId") ?? ""; // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast // datagram on each endpoint. ILookupReplyPrx lookupReply = _replyAdapter.CreateProxy( "dummy", ILookupReplyPrx.Factory).Clone(invocationMode: InvocationMode.Datagram); var single = new Endpoint[1]; foreach (UdpEndpoint endpoint in lookup.Endpoints.Cast <UdpEndpoint>()) { single[0] = endpoint; ILookupPrx?key = lookup.Clone(endpoints: single); if (endpoint.McastInterface.Length > 0) { Endpoint?q = lookupReply.Endpoints.FirstOrDefault( e => e is IPEndpoint ipEndpoint && ipEndpoint.Host.Equals(endpoint.McastInterface)); if (q != null) { single[0] = q; _lookups[key] = lookupReply.Clone(endpoints: single); } } if (!_lookups.ContainsKey(key)) { // Fallback: just use the given lookup reply proxy if no matching endpoint found. _lookups[key] = lookupReply; } } Debug.Assert(_lookups.Count > 0); }
public LocatorI(string name, ILookupPrx lookup, Communicator communicator, string instanceName, ILocatorPrx voidLocator) { _lookup = lookup; _timeout = communicator.GetPropertyAsInt($"{name}.Timeout") ?? 300; if (_timeout < 0) { _timeout = 300; } _retryCount = communicator.GetPropertyAsInt("${name}.RetryCount") ?? 3; if (_retryCount < 0) { _retryCount = 0; } _retryDelay = communicator.GetPropertyAsInt($"{name}.RetryDelay") ?? 2000; if (_retryDelay < 0) { _retryDelay = 0; } _timer = lookup.Communicator.Timer(); _traceLevel = communicator.GetPropertyAsInt($"{name}.Trace.Lookup") ?? 0; _instanceName = instanceName; _warned = false; _locator = lookup.Communicator.GetDefaultLocator(); _voidLocator = voidLocator; _pending = false; _pendingRetryCount = 0; _failureCount = 0; _warnOnce = true; // // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast // datagram on each endpoint. // var single = new IEndpoint[1]; foreach (IEndpoint endpt in lookup.Endpoints) { single[0] = endpt; _lookups[lookup.Clone(endpoints: single)] = null; } Debug.Assert(_lookups.Count > 0); }
public Lookup(LocatorRegistry registry, ILookupPrx lookup, Communicator communicator) { _registry = registry; _lookup = lookup; _timeout = communicator.GetPropertyAsInt("IceDiscovery.Timeout") ?? 300; _retryCount = communicator.GetPropertyAsInt("IceDiscovery.RetryCount") ?? 3; _latencyMultiplier = communicator.GetPropertyAsInt("IceDiscovery.LatencyMultiplier") ?? 1; _domainId = communicator.GetProperty("IceDiscovery.DomainId") ?? ""; _timer = lookup.Communicator.Timer(); // // Create one lookup proxy per endpoint from the given proxy. We want to send a multicast // datagram on each endpoint. // var single = new Ice.IEndpoint[1]; foreach (IEndpoint endpt in lookup.Endpoints) { single[0] = endpt; _lookups[lookup.Clone(endpoints: single)] = null; } Debug.Assert(_lookups.Count > 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(); }
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(); }
initialize() { bool ipv4 = (_communicator.GetPropertyAsInt("Ice.IPv4") ?? 1) > 0; bool preferIPv6 = _communicator.GetPropertyAsInt("Ice.PreferIPv6Address") > 0; 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 protocol = ipv4 && !preferIPv6 ? IceInternal.Network.EnableIPv4 : IceInternal.Network.EnableIPv6; var interfaces = IceInternal.Network.getInterfacesForMulticast(intf, protocol); foreach (string p in interfaces) { if (p != interfaces[0]) { lookupEndpoints += ":"; } lookupEndpoints += "udp -h \"" + address + "\" -p " + port + " --interface \"" + p + "\""; } } 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.SetLocator(null); _locatorAdapter.SetLocator(null); var lookupPrx = ILookupPrx.Parse($"IceLocatorDiscovery/Lookup -d:{lookupEndpoints}", _communicator); // No colloc optimization or router for the multicast proxy! lookupPrx = lookupPrx.Clone(clearRouter: false, collocationOptimized: false); ILocatorPrx voidLo = _locatorAdapter.Add(new VoidLocatorI()); string instanceName = _communicator.GetProperty($"{_name}.InstanceName") ?? ""; var id = new Identity("Locator", instanceName.Length > 0 ? instanceName : Guid.NewGuid().ToString()); _defaultLocator = _communicator.getDefaultLocator(); _locator = new LocatorI(_name, lookupPrx, _communicator, instanceName, voidLo); _locatorPrx = ILocatorPrx.UncheckedCast( _locatorAdapter.Add((current, incoming) => _locator.Dispatch(current, incoming))); _communicator.setDefaultLocator(_locatorPrx); LookupReply lookupReplyI = new LookupReplyI(_locator); _locator.setLookupReply(_replyAdapter.Add(lookupReplyI).Clone(invocationMode: InvocationMode.Datagram)); _replyAdapter.Activate(); _locatorAdapter.Activate(); }
protected abstract void InvokeWithLookup(string domainId, ILookupPrx lookup, ILookupReplyPrx lookupReply);
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(); }
public void initialize() { bool ipv4 = (_communicator.GetPropertyAsInt("Ice.IPv4") ?? 1) > 0; bool preferIPv6 = _communicator.GetPropertyAsInt("Ice.PreferIPv6Address") > 0; 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) { _communicator.SetProperty("IceDiscovery.Multicast.Endpoints", intf.Length > 0 ? $"udp -h \"{address}\" -p {port} --interface \"{intf}\"" : $"udp -h \"{address}\" -p {port}"); } string lookupEndpoints = _communicator.GetProperty("IceDiscovery.Lookup") ?? ""; if (lookupEndpoints.Length == 0) { int protocol = ipv4 && !preferIPv6 ? IceInternal.Network.EnableIPv4 : IceInternal.Network.EnableIPv6; var interfaces = IceInternal.Network.getInterfacesForMulticast(intf, protocol); 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 locatory registry. // LocatorRegistryI locatorRegistry = new LocatorRegistryI(_communicator); ILocatorRegistryPrx locatorRegistryPrx = _locatorAdapter.Add(locatorRegistry); ILookupPrx lookupPrx = ILookupPrx.Parse("IceDiscovery/Lookup -d:" + lookupEndpoints, _communicator).Clone( clearRouter: true, collocationOptimized: false); // No colloc optimization or router for the multicast proxy! // // Add lookup and lookup reply Ice objects // LookupI lookup = new LookupI(locatorRegistry, lookupPrx, _communicator); _multicastAdapter.Add(lookup, "IceDiscovery/Lookup"); LookupReplyTraits lookupT = default; LookupReplyI lookupReply = new LookupReplyI(lookup); _replyAdapter.AddDefaultServant( (current, incoming) => lookupT.Dispatch(lookupReply, current, incoming), ""); lookup.SetLookupReply(ILookupReplyPrx.UncheckedCast(_replyAdapter.CreateProxy("dummy")).Clone(invocationMode: InvocationMode.Datagram)); // // Setup locator on the communicator. // _locator = _locatorAdapter.Add(new LocatorI(lookup, locatorRegistryPrx)); _defaultLocator = _communicator.getDefaultLocator(); _communicator.setDefaultLocator(_locator); _multicastAdapter.Activate(); _replyAdapter.Activate(); _locatorAdapter.Activate(); }