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 void ResolveResponseInfo ()
	{
		var ser = new DataContractSerializer (typeof (ResolveResponseInfo));
		var rri = new ResolveResponseInfo ();
		var pna = new PeerNodeAddress (
			new EndpointAddress ("http://localhost:8080"),
			new ReadOnlyCollection<IPAddress> (new IPAddress [0]));
		rri.Addresses = new List<PeerNodeAddress> ();
		rri.Addresses.Add (pna);
		var sw = new StringWriter ();
		using (var xw = XmlWriter.Create (sw))
			ser.WriteObject (xw, rri);
		rri = (ResolveResponseInfo) ser.ReadObject (XmlReader.Create (new StringReader (sw.ToString ())));
	}
Exemple #3
0
        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);
        }
Exemple #4
0
        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));
        }
Exemple #5
0
		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 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;
 }