public void SetLookupReply(ILookupReplyPrx lookupReply) { // // Use a lookup reply proxy whose address matches the interface used to send multicast datagrams. // var single = new Endpoint[1]; foreach (ILookupPrx key in new List<ILookupPrx>(_lookups.Keys)) { var endpoint = (UdpEndpoint)key.Endpoints[0]; if (endpoint.McastInterface.Length > 0) { foreach (Endpoint q in lookupReply.Endpoints) { if (q is IPEndpoint && ((IPEndpoint)q).Host.Equals(endpoint.McastInterface)) { single[0] = q; _lookups[key] = lookupReply.Clone(endpoints: single); } } } if (_lookups[key] == null) { // Fallback: just use the given lookup reply proxy if no matching endpoint found. _lookups[key] = lookupReply; } } }
public async ValueTask FindAdapterByIdAsync( string domainId, string adapterId, ILookupReplyPrx reply, Current current, CancellationToken cancel) { if (domainId != _domainId) { return; // Ignore } (IObjectPrx? proxy, bool isReplicaGroup) = _registryServant.FindAdapter(adapterId); if (proxy != null) { // Reply to the multicast request using the given proxy. try { await reply.FoundAdapterByIdAsync(adapterId, proxy, isReplicaGroup, cancel : cancel). ConfigureAwait(false); } catch (Exception ex) { current.Communicator.Logger.Warning( $"IceDiscovery failed to send foundAdapterById to `{reply}':\n{ex}"); } } }
public async ValueTask FindObjectByIdAsync( string domainId, Identity id, string?facet, ILookupReplyPrx reply, Current current, CancellationToken cancel) { if (domainId != _domainId) { return; // Ignore } if (await _registryServant.FindObjectAsync(id, facet, cancel).ConfigureAwait(false) is IObjectPrx proxy) { // Reply to the multicast request using the given proxy. try { await reply.FoundObjectByIdAsync(id, proxy, cancel : cancel).ConfigureAwait(false); } catch (Exception ex) { current.Communicator.Logger.Warning( $"IceDiscovery failed to send foundObjectById to `{reply}':\n{ex}"); } } }
public void SetLookupReply(ILookupReplyPrx lookupReply) { // Use a lookup reply proxy whose address matches the interface used to send multicast datagrams. var single = new Endpoint[1]; foreach (ILookupPrx key in _lookups.Keys.ToArray()) { var endpoint = (UdpEndpoint)key.Endpoints[0]; 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[key] == null) { // Fallback: just use the given lookup reply proxy if no matching endpoint found. _lookups[key] = lookupReply; } } }
setLookupReply(ILookupReplyPrx lookupReply) { // // Use a lookup reply proxy whose adress matches the interface used to send multicast datagrams. // var single = new Endpoint[1]; foreach (var key in new List <ILookupPrx>(_lookups.Keys)) { var info = (UDPEndpointInfo)key.Endpoints[0].getInfo(); if (info.mcastInterface.Length > 0) { foreach (var q in lookupReply.Endpoints) { var r = q.getInfo(); if (r is IPEndpointInfo && ((IPEndpointInfo)r).host.Equals(info.mcastInterface)) { single[0] = q; _lookups[key] = lookupReply.Clone(endpoints: single); } } } if (_lookups[key] == null) { // Fallback: just use the given lookup reply proxy if no matching endpoint found. _lookups[key] = lookupReply; } } }
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(); }
public void FindAdapterById(string domainId, string adapterId, ILookupReplyPrx reply, Current current) { if (!domainId.Equals(_domainId)) { return; // Ignore } bool isReplicaGroup; IObjectPrx proxy = _registry.FindAdapter(adapterId, out isReplicaGroup); if (proxy != null) { // // Reply to the multicast request using the given proxy. // try { reply.FoundAdapterByIdAsync(adapterId, proxy, isReplicaGroup); } catch (LocalException) { // Ignore. } } }
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); }
public void invoke(string domainId, Dictionary <ILookupPrx, ILookupReplyPrx?> lookups) { _lookupCount = lookups.Count; _failureCount = 0; Ice.Identity id = new Ice.Identity(_requestId, ""); foreach (var entry in lookups) { invokeWithLookup(domainId, entry.Key, ILookupReplyPrx.UncheckedCast(entry.Value.Clone(id))); } }
public void Invoke(string domainId, Dictionary <ILookupPrx, ILookupReplyPrx?> lookups) { LookupCount = lookups.Count; FailureCount = 0; var id = new Identity(_requestId, ""); foreach (KeyValuePair <ILookupPrx, ILookupReplyPrx?> entry in lookups) { InvokeWithLookup(domainId, entry.Key, ILookupReplyPrx.UncheckedCast(entry.Value.Clone(id))); } }
private async Task FindLocator(ILookupPrx lookup, ILookupReplyPrx reply) { try { await lookup.FindLocatorAsync(_instanceName, reply).ConfigureAwait(false); } catch (Exception ex) { Exception(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 void FindObjectById(string domainId, Identity id, ILookupReplyPrx reply, Current current) { if (!domainId.Equals(_domainId)) { return; // Ignore } IObjectPrx proxy = _registry.FindObject(id); if (proxy != null) { // // Reply to the mulicast request using the given proxy. // try { reply.FoundObjectByIdAsync(id, proxy); } catch (LocalException) { // Ignore. } } }
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(); }
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); } }
protected abstract void InvokeWithLookup(string domainId, ILookupPrx lookup, ILookupReplyPrx lookupReply);
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(); }