Пример #1
0
 public override object Register(string meshId, PeerNodeAddress nodeAddress, TimeSpan timeout)
 {
     if (this.opened)
     {
         long scopeId = -1L;
         bool flag    = false;
         if (nodeAddress.IPAddresses.Count == 0)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("MustRegisterMoreThanZeroAddresses")));
         }
         foreach (IPAddress address in nodeAddress.IPAddresses)
         {
             if (address.IsIPv6LinkLocal)
             {
                 if (scopeId == -1L)
                 {
                     scopeId = address.ScopeId;
                 }
                 else if (scopeId != address.ScopeId)
                 {
                     flag = true;
                     break;
                 }
             }
         }
         List <IPAddress> list = new List <IPAddress>();
         foreach (IPAddress address2 in nodeAddress.IPAddresses)
         {
             if (!flag || (!address2.IsIPv6LinkLocal && !address2.IsIPv6SiteLocal))
             {
                 list.Add(address2);
             }
         }
         if (list.Count == 0)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("AmbiguousConnectivitySpec")));
         }
         ReadOnlyCollection <IPAddress> ipAddresses = new ReadOnlyCollection <IPAddress>(list);
         this.meshId      = meshId;
         this.nodeAddress = new PeerNodeAddress(nodeAddress.EndpointAddress, ipAddresses);
         RegisterInfo        registerInfo = new RegisterInfo(this.clientId, meshId, this.nodeAddress);
         IPeerResolverClient proxy        = this.GetProxy();
         try
         {
             proxy.OperationTimeout = timeout;
             RegisterResponseInfo info2 = proxy.Register(registerInfo);
             this.registrationId = info2.RegistrationId;
             this.timer.Set(info2.RegistrationLifetime);
             this.defaultLifeTime = info2.RegistrationLifetime;
             proxy.Close();
         }
         finally
         {
             proxy.Abort();
         }
     }
     return(this.registrationId);
 }
        void RegistrationExpired(object state)
        {
            if (!opened)
            {
                return;
            }

            try
            {
                IPeerResolverClient proxy = GetProxy();
                RefreshResponseInfo response;
                try
                {
                    int oldValue = Interlocked.Exchange(ref this.updateSuccessful, 1);
                    if (oldValue == 0)
                    {
                        SendUpdate(new UpdateInfo(this.registrationId, this.clientId, this.meshId, this.nodeAddress), ServiceDefaults.SendTimeout);
                        return;
                    }

                    RefreshInfo info = new RefreshInfo(this.meshId, this.registrationId);
                    response = proxy.Refresh(info);

                    if (response.Result == RefreshResult.RegistrationNotFound)
                    {
                        RegisterInfo         registerInfo     = new RegisterInfo(clientId, meshId, nodeAddress);
                        RegisterResponseInfo registerResponse = proxy.Register(registerInfo);
                        registrationId       = registerResponse.RegistrationId;
                        this.defaultLifeTime = registerResponse.RegistrationLifetime;
                    }
                    else
                    {
                        Fx.Assert(response.Result == RefreshResult.Success, "Unrecognized value!!");
                    }
                    proxy.Close();
                }
                finally
                {
                    proxy.Abort();
                    timer.Set(this.defaultLifeTime);
                }
            }
            catch (CommunicationException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
            }
        }
 public virtual RegisterResponseInfo Register(RegisterInfo registerInfo)
 {
     if (registerInfo == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("registerInfo", System.ServiceModel.SR.GetString("PeerNullRegistrationInfo"));
     }
     this.ThrowIfClosed("Register");
     if (!registerInfo.HasBody() || string.IsNullOrEmpty(registerInfo.MeshId))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("registerInfo", System.ServiceModel.SR.GetString("PeerInvalidMessageBody", new object[] { registerInfo }));
     }
     return(this.Register(registerInfo.ClientId, registerInfo.MeshId, registerInfo.NodeAddress));
 }
        public virtual RegisterResponseInfo Register(RegisterInfo registerInfo)
        {
            if (registerInfo == null)
            {
                throw new ArgumentException("Register info cannot be null.");
            }

            if (!opened)
            {
                throw new InvalidOperationException("The service has never been opened or it was closed previously.");
            }

            return(client.Register(registerInfo));
        }
        public virtual RegisterResponseInfo Register(RegisterInfo registerInfo)
        {
            if (registerInfo == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("registerInfo", SR.GetString(SR.PeerNullRegistrationInfo));
            }

            ThrowIfClosed("Register");

            if (!registerInfo.HasBody() || String.IsNullOrEmpty(registerInfo.MeshId))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("registerInfo", SR.GetString(SR.PeerInvalidMessageBody, registerInfo));
            }
            return(Register(registerInfo.ClientId, registerInfo.MeshId, registerInfo.NodeAddress));
        }
Пример #6
0
 private void RegistrationExpired(object state)
 {
     if (this.opened)
     {
         try
         {
             IPeerResolverClient proxy = this.GetProxy();
             try
             {
                 if (Interlocked.Exchange(ref this.updateSuccessful, 1) == 0)
                 {
                     this.SendUpdate(new UpdateInfo(this.registrationId, this.clientId, this.meshId, this.nodeAddress), ServiceDefaults.SendTimeout);
                 }
                 else
                 {
                     RefreshInfo refreshInfo = new RefreshInfo(this.meshId, this.registrationId);
                     if (proxy.Refresh(refreshInfo).Result == RefreshResult.RegistrationNotFound)
                     {
                         RegisterInfo         registerInfo = new RegisterInfo(this.clientId, this.meshId, this.nodeAddress);
                         RegisterResponseInfo info4        = proxy.Register(registerInfo);
                         this.registrationId  = info4.RegistrationId;
                         this.defaultLifeTime = info4.RegistrationLifetime;
                     }
                     proxy.Close();
                 }
             }
             finally
             {
                 proxy.Abort();
                 this.timer.Set(this.defaultLifeTime);
             }
         }
         catch (CommunicationException exception)
         {
             DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
         }
         catch (Exception exception2)
         {
             if (Fx.IsFatal(exception2))
             {
                 throw;
             }
             DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information);
         }
     }
 }
Пример #7
0
        public RegisterResponseInfo Register(RegisterInfo registerInfo)
        {
            var r = registerInfo;

            log.WriteLine("REQUEST: Register (Mesh: {0}, Client: {1}, NodeAddress: endpoint {2})", r.MeshId, r.ClientId, r.NodeAddress.EndpointAddress);
            Mesh mesh;

            if (!mesh_map.TryGetValue(r.MeshId, out mesh))
            {
                mesh = new Mesh(r.MeshId);

                mesh_map.Add(r.MeshId, mesh);
            }
            var node = RegisterNode(mesh, r.ClientId, r.NodeAddress);

            return(new RegisterResponseInfo()
            {
                RegistrationId = node.RegistrationId
            });
        }
        void RegistrationExpired(object state)
        {
            if (!opened)
                return;

            try
            {
                IPeerResolverClient proxy = GetProxy();
                RefreshResponseInfo response;
                try
                {
                    int oldValue = Interlocked.Exchange(ref this.updateSuccessful, 1);
                    if (oldValue == 0)
                    {
                        SendUpdate(new UpdateInfo(this.registrationId, this.clientId, this.meshId, this.nodeAddress), ServiceDefaults.SendTimeout);
                        return;
                    }

                    RefreshInfo info = new RefreshInfo(this.meshId, this.registrationId);
                    response = proxy.Refresh(info);

                    if (response.Result == RefreshResult.RegistrationNotFound)
                    {
                        RegisterInfo registerInfo = new RegisterInfo(clientId, meshId, nodeAddress);
                        RegisterResponseInfo registerResponse = proxy.Register(registerInfo);
                        registrationId = registerResponse.RegistrationId;
                        this.defaultLifeTime = registerResponse.RegistrationLifetime;
                    }
                    else
                    {
                        Fx.Assert(response.Result == RefreshResult.Success, "Unrecognized value!!");
                    }
                    proxy.Close();
                }
                finally
                {
                    proxy.Abort();
                    timer.Set(this.defaultLifeTime);
                }
            }
            catch (CommunicationException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e)) throw;
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
            }
        }
        // Register address for a node participating in a mesh identified by meshId with the resolver service
        public override object Register(string meshId, PeerNodeAddress nodeAddress, TimeSpan timeout)
        {
            if (opened)
            {

                long scopeId = -1;
                bool multipleScopes = false;

                if (nodeAddress.IPAddresses.Count == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.MustRegisterMoreThanZeroAddresses)));
                }

                foreach (IPAddress address in nodeAddress.IPAddresses)
                {
                    if (address.IsIPv6LinkLocal)
                    {
                        if (scopeId == -1)
                        {
                            scopeId = address.ScopeId;
                        }
                        else if (scopeId != address.ScopeId)
                        {
                            multipleScopes = true;
                            break;
                        }
                    }
                }

                List<IPAddress> addresslist = new List<IPAddress>();
                foreach (IPAddress address in nodeAddress.IPAddresses)
                {
                    if (!multipleScopes || (!address.IsIPv6LinkLocal && !address.IsIPv6SiteLocal))
                        addresslist.Add(address);
                }

                if (addresslist.Count == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(SR.GetString(SR.AmbiguousConnectivitySpec)));
                }

                ReadOnlyCollection<IPAddress> addresses = new ReadOnlyCollection<IPAddress>(addresslist);
                this.meshId = meshId;
                this.nodeAddress = new PeerNodeAddress(nodeAddress.EndpointAddress, addresses);
                RegisterInfo info = new RegisterInfo(clientId, meshId, this.nodeAddress);
                IPeerResolverClient proxy = GetProxy();
                try
                {
                    proxy.OperationTimeout = timeout;
                    RegisterResponseInfo response = proxy.Register(info);
                    this.registrationId = response.RegistrationId;
                    timer.Set(response.RegistrationLifetime);
                    this.defaultLifeTime = response.RegistrationLifetime;
                    proxy.Close();
                }
                finally
                {
                    proxy.Abort();
                }
            }
            return registrationId;
        }
 public virtual new RegisterResponseInfo Register(RegisterInfo registerInfo)
 {
     return(default(RegisterResponseInfo));
 }
        // Register address for a node participating in a mesh identified by meshId with the resolver service
        public override object Register(string meshId, PeerNodeAddress nodeAddress, TimeSpan timeout)
        {
            if (opened)
            {
                long scopeId        = -1;
                bool multipleScopes = false;

                if (nodeAddress.IPAddresses.Count == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.MustRegisterMoreThanZeroAddresses)));
                }

                foreach (IPAddress address in nodeAddress.IPAddresses)
                {
                    if (address.IsIPv6LinkLocal)
                    {
                        if (scopeId == -1)
                        {
                            scopeId = address.ScopeId;
                        }
                        else if (scopeId != address.ScopeId)
                        {
                            multipleScopes = true;
                            break;
                        }
                    }
                }

                List <IPAddress> addresslist = new List <IPAddress>();
                foreach (IPAddress address in nodeAddress.IPAddresses)
                {
                    if (!multipleScopes || (!address.IsIPv6LinkLocal && !address.IsIPv6SiteLocal))
                    {
                        addresslist.Add(address);
                    }
                }

                if (addresslist.Count == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(SR.GetString(SR.AmbiguousConnectivitySpec)));
                }

                ReadOnlyCollection <IPAddress> addresses = new ReadOnlyCollection <IPAddress>(addresslist);
                this.meshId      = meshId;
                this.nodeAddress = new PeerNodeAddress(nodeAddress.EndpointAddress, addresses);
                RegisterInfo        info  = new RegisterInfo(clientId, meshId, this.nodeAddress);
                IPeerResolverClient proxy = GetProxy();
                try
                {
                    proxy.OperationTimeout = timeout;
                    RegisterResponseInfo response = proxy.Register(info);
                    this.registrationId = response.RegistrationId;
                    timer.Set(response.RegistrationLifetime);
                    this.defaultLifeTime = response.RegistrationLifetime;
                    proxy.Close();
                }
                finally
                {
                    proxy.Abort();
                }
            }
            return(registrationId);
        }
Пример #12
0
		public virtual RegisterResponseInfo Register (RegisterInfo registerInfo)
		{
			if (registerInfo == null)
				throw new ArgumentException ("Register info cannot be null.");
			
			if (! opened)
				throw new InvalidOperationException ("The service has never been opened or it was closed previously.");
			
			return client.Register (registerInfo);
		}