public virtual ResolveResponseInfo Resolve(ResolveInfo resolveInfo) { if (resolveInfo == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("resolveInfo", System.ServiceModel.SR.GetString("PeerNullResolveInfo")); } this.ThrowIfClosed("Resolve"); if (!resolveInfo.HasBody()) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("resolveInfo", System.ServiceModel.SR.GetString("PeerInvalidMessageBody", new object[] { resolveInfo })); } int num = 0; int num2 = 0; int maxAddresses = resolveInfo.MaxAddresses; ResolveResponseInfo info = new ResolveResponseInfo(); List <PeerNodeAddress> list = new List <PeerNodeAddress>(); List <RegistrationEntry> entryList = null; MeshEntry meshEntry = this.GetMeshEntry(resolveInfo.MeshId, false); if (meshEntry != null) { LiteLock liteLock = null; try { LiteLock.Acquire(out liteLock, meshEntry.Gate); entryList = meshEntry.EntryList; if (entryList.Count <= maxAddresses) { foreach (RegistrationEntry entry3 in entryList) { list.Add(entry3.Address); } } else { Random random = new Random(); while (num < maxAddresses) { num2 = random.Next(entryList.Count); RegistrationEntry entry = entryList[num2]; PeerNodeAddress item = entry.Address; if (!list.Contains(item)) { list.Add(item); } num++; } } } finally { LiteLock.Release(liteLock); } } info.Addresses = list.ToArray(); return(info); }
public virtual ResolveResponseInfo Resolve(ResolveInfo resolveInfo) { if (resolveInfo == null) { throw new ArgumentException("Resolve info cannot be null."); } if (!opened) { throw new InvalidOperationException("The service has never been opened or it was closed previously."); } return(client.Resolve(resolveInfo)); }
public static void Main () { BasicHttpBinding binding = new BasicHttpBinding (); EndpointAddress ea = new EndpointAddress ( new Uri ("http://localhost:8080/ChatServer")); IPeerResolverContract proxy = ChannelFactory<IPeerResolverContract>.CreateChannel (binding, ea); try { Guid guid = Guid.NewGuid (); Console.WriteLine (guid); ResolveInfo ri = new ResolveInfo ( guid, "net.p2p://chatMesh/ChatServer", 1); ResolveResponseInfo rri = proxy.Resolve (ri); Console.WriteLine ("Response: {0}", rri); } catch (Exception e) { Console.WriteLine (e.Message); } }
public ResolveResponseInfo Resolve(ResolveInfo resolveInfo) { var r = resolveInfo; log.WriteLine("REQUEST: Resolve (Mesh: {0}, Client: {1}, MaxAddresses: {2})", r.MeshId, r.ClientId, r.MaxAddresses); Mesh mesh; var rr = new ResolveResponseInfo(); if (!mesh_map.TryGetValue(r.MeshId, out mesh)) { return(rr); } // FIXME: find out how to use the argument ClientId. // So far, it is used to filter out the registered node from the same ClientId. foreach (var node in mesh.TakeWhile(n => n.ClientId != r.ClientId)) { rr.Addresses.Add(node.Address); if (rr.Addresses.Count == r.MaxAddresses) { break; } } return(rr); }
public override ReadOnlyCollection <PeerNodeAddress> Resolve(string meshId, int maxAddresses, TimeSpan timeout) { ResolveResponseInfo info = null; IList <PeerNodeAddress> addresses = null; List <PeerNodeAddress> list2 = new List <PeerNodeAddress>(); if (this.opened) { ResolveInfo resolveInfo = new ResolveInfo(this.clientId, meshId, maxAddresses); try { IPeerResolverClient proxy = this.GetProxy(); try { proxy.OperationTimeout = timeout; info = proxy.Resolve(resolveInfo); proxy.Close(); } finally { proxy.Abort(); } if ((info != null) && (info.Addresses != null)) { addresses = info.Addresses; } } catch (CommunicationException exception) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information); } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } this.opened = false; throw; } } if (addresses != null) { foreach (PeerNodeAddress address in addresses) { bool flag = true; long scopeId = -1L; if (address != null) { foreach (IPAddress address2 in address.IPAddresses) { if (address2.IsIPv6LinkLocal) { if (scopeId == -1L) { scopeId = address2.ScopeId; } else if (scopeId != address2.ScopeId) { flag = false; break; } } } if (flag) { list2.Add(address); } } } } return(new ReadOnlyCollection <PeerNodeAddress>(list2)); }
// Query the resolver service for addresses associated with a mesh ID public override ReadOnlyCollection<PeerNodeAddress> Resolve(string meshId, int maxAddresses, TimeSpan timeout) { ResolveResponseInfo result = null; IList<PeerNodeAddress> addresses = null; List<PeerNodeAddress> output_addresses = new List<PeerNodeAddress>(); if (opened) { ResolveInfo info = new ResolveInfo(clientId, meshId, maxAddresses); try { IPeerResolverClient proxy = GetProxy(); try { proxy.OperationTimeout = timeout; result = proxy.Resolve(info); proxy.Close(); } finally { proxy.Abort(); } // If addresses couldn't be obtained, return empty collection if (result != null && result.Addresses != null) addresses = result.Addresses; } catch (CommunicationException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); } catch (Exception e) { if (Fx.IsFatal(e)) throw; opened = false; throw; } } if (addresses != null) { foreach (PeerNodeAddress nodeaddr in addresses) { bool valid = true; long scopeId = -1; if (nodeaddr == null) continue; foreach (IPAddress addr in nodeaddr.IPAddresses) { if (addr.IsIPv6LinkLocal) { if (scopeId == -1) { scopeId = addr.ScopeId; } else if (scopeId != addr.ScopeId) { valid = false; break; } } } if (valid) { output_addresses.Add(nodeaddr); } } } return new ReadOnlyCollection<PeerNodeAddress>(output_addresses); }
public virtual new ResolveResponseInfo Resolve(ResolveInfo resolveInfo) { return default(ResolveResponseInfo); }
public override ResolveResponseInfo Resolve (ResolveInfo resolveInfo) { ResolveResponseInfo rri = new ResolveResponseInfo (); if (ControlShape) { lock (mesh_lock) { if (nodes_count == 0) rri.Addresses = new PeerNodeAddress [0]; else if (unique_node != null) { Node n = unique_node; rri.Addresses = new PeerNodeAddress [] {n.Address}; } Console.WriteLine ("Resolve: {0}", resolveInfo.MeshId); } } else rri = base.Resolve (resolveInfo); return rri; }
public virtual new ResolveResponseInfo Resolve(ResolveInfo resolveInfo) { return(default(ResolveResponseInfo)); }
public virtual ResolveResponseInfo Resolve(ResolveInfo resolveInfo) { if (resolveInfo == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("resolveInfo", SR.GetString(SR.PeerNullResolveInfo)); } ThrowIfClosed("Resolve"); if (!resolveInfo.HasBody()) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("resolveInfo", SR.GetString(SR.PeerInvalidMessageBody, resolveInfo)); } int currentCount = 0; int index = 0; int maxEntries = resolveInfo.MaxAddresses; ResolveResponseInfo response = new ResolveResponseInfo(); List<PeerNodeAddress> results = new List<PeerNodeAddress>(); List<RegistrationEntry> entries = null; PeerNodeAddress address; RegistrationEntry entry; MeshEntry meshEntry = GetMeshEntry(resolveInfo.MeshId, false); if (meshEntry != null) { LiteLock ll = null; try { LiteLock.Acquire(out ll, meshEntry.Gate); entries = meshEntry.EntryList; if (entries.Count <= maxEntries) { foreach (RegistrationEntry e in entries) { results.Add(e.Address); } } else { Random random = new Random(); while (currentCount < maxEntries) { index = random.Next(entries.Count); entry = entries[index]; Fx.Assert(entry.State == RegistrationState.OK, "A deleted registration is still around!"); address = entry.Address; if (!results.Contains(address)) results.Add(address); currentCount++; } } } finally { LiteLock.Release(ll); } } response.Addresses = results.ToArray(); return response; }
public virtual ResolveResponseInfo Resolve(ResolveInfo resolveInfo) { if (resolveInfo == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("resolveInfo", SR.GetString(SR.PeerNullResolveInfo)); } ThrowIfClosed("Resolve"); if (!resolveInfo.HasBody()) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("resolveInfo", SR.GetString(SR.PeerInvalidMessageBody, resolveInfo)); } int currentCount = 0; int index = 0; int maxEntries = resolveInfo.MaxAddresses; ResolveResponseInfo response = new ResolveResponseInfo(); List <PeerNodeAddress> results = new List <PeerNodeAddress>(); List <RegistrationEntry> entries = null; PeerNodeAddress address; RegistrationEntry entry; MeshEntry meshEntry = GetMeshEntry(resolveInfo.MeshId, false); if (meshEntry != null) { LiteLock ll = null; try { LiteLock.Acquire(out ll, meshEntry.Gate); entries = meshEntry.EntryList; if (entries.Count <= maxEntries) { foreach (RegistrationEntry e in entries) { results.Add(e.Address); } } else { Random random = new Random(); while (currentCount < maxEntries) { index = random.Next(entries.Count); entry = entries[index]; Fx.Assert(entry.State == RegistrationState.OK, "A deleted registration is still around!"); address = entry.Address; if (!results.Contains(address)) { results.Add(address); } currentCount++; } } } finally { LiteLock.Release(ll); } } response.Addresses = results.ToArray(); return(response); }
// Query the resolver service for addresses associated with a mesh ID public override ReadOnlyCollection <PeerNodeAddress> Resolve(string meshId, int maxAddresses, TimeSpan timeout) { ResolveResponseInfo result = null; IList <PeerNodeAddress> addresses = null; List <PeerNodeAddress> output_addresses = new List <PeerNodeAddress>(); if (opened) { ResolveInfo info = new ResolveInfo(clientId, meshId, maxAddresses); try { IPeerResolverClient proxy = GetProxy(); try { proxy.OperationTimeout = timeout; result = proxy.Resolve(info); proxy.Close(); } finally { proxy.Abort(); } // If addresses couldn't be obtained, return empty collection if (result != null && result.Addresses != null) { addresses = result.Addresses; } } catch (CommunicationException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } opened = false; throw; } } if (addresses != null) { foreach (PeerNodeAddress nodeaddr in addresses) { bool valid = true; long scopeId = -1; if (nodeaddr == null) { continue; } foreach (IPAddress addr in nodeaddr.IPAddresses) { if (addr.IsIPv6LinkLocal) { if (scopeId == -1) { scopeId = addr.ScopeId; } else if (scopeId != addr.ScopeId) { valid = false; break; } } } if (valid) { output_addresses.Add(nodeaddr); } } } return(new ReadOnlyCollection <PeerNodeAddress>(output_addresses)); }
public virtual ResolveResponseInfo Resolve(ResolveInfo resolveInfo) { if (resolveInfo == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("resolveInfo", System.ServiceModel.SR.GetString("PeerNullResolveInfo")); } this.ThrowIfClosed("Resolve"); if (!resolveInfo.HasBody()) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("resolveInfo", System.ServiceModel.SR.GetString("PeerInvalidMessageBody", new object[] { resolveInfo })); } int num = 0; int num2 = 0; int maxAddresses = resolveInfo.MaxAddresses; ResolveResponseInfo info = new ResolveResponseInfo(); List<PeerNodeAddress> list = new List<PeerNodeAddress>(); List<RegistrationEntry> entryList = null; MeshEntry meshEntry = this.GetMeshEntry(resolveInfo.MeshId, false); if (meshEntry != null) { LiteLock liteLock = null; try { LiteLock.Acquire(out liteLock, meshEntry.Gate); entryList = meshEntry.EntryList; if (entryList.Count <= maxAddresses) { foreach (RegistrationEntry entry3 in entryList) { list.Add(entry3.Address); } } else { Random random = new Random(); while (num < maxAddresses) { num2 = random.Next(entryList.Count); RegistrationEntry entry = entryList[num2]; PeerNodeAddress item = entry.Address; if (!list.Contains(item)) { list.Add(item); } num++; } } } finally { LiteLock.Release(liteLock); } } info.Addresses = list.ToArray(); return info; }
public override ReadOnlyCollection<PeerNodeAddress> Resolve(string meshId, int maxAddresses, TimeSpan timeout) { ResolveResponseInfo info = null; IList<PeerNodeAddress> addresses = null; List<PeerNodeAddress> list2 = new List<PeerNodeAddress>(); if (this.opened) { ResolveInfo resolveInfo = new ResolveInfo(this.clientId, meshId, maxAddresses); try { IPeerResolverClient proxy = this.GetProxy(); try { proxy.OperationTimeout = timeout; info = proxy.Resolve(resolveInfo); proxy.Close(); } finally { proxy.Abort(); } if ((info != null) && (info.Addresses != null)) { addresses = info.Addresses; } } catch (CommunicationException exception) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information); } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } this.opened = false; throw; } } if (addresses != null) { foreach (PeerNodeAddress address in addresses) { bool flag = true; long scopeId = -1L; if (address != null) { foreach (IPAddress address2 in address.IPAddresses) { if (address2.IsIPv6LinkLocal) { if (scopeId == -1L) { scopeId = address2.ScopeId; } else if (scopeId != address2.ScopeId) { flag = false; break; } } } if (flag) { list2.Add(address); } } } } return new ReadOnlyCollection<PeerNodeAddress>(list2); }
public virtual ResolveResponseInfo Resolve (ResolveInfo resolveInfo) { if (resolveInfo == null) throw new ArgumentException ("Resolve info cannot be null."); if (! opened) throw new InvalidOperationException ("The service has never been opened or it was closed previously."); return client.Resolve (resolveInfo); }