Esempio n. 1
0
 public void Welcome(WelcomeInfo welcome)
 {
     if (WelcomeReceived != null)
     {
         WelcomeReceived(welcome);
     }
     connect_handle.Set();
 }
        void IPeerServiceContract.Welcome(WelcomeInfo welcomeInfo)
        {
            IPeerNeighbor neighbor = this.GetNeighbor();

            if (neighbor != null)
            {
                this.connector.Welcome(neighbor, welcomeInfo);
            }
        }
 private void SendWelcome(IPeerNeighbor neighbor)
 {
     if (this.state == State.Opened)
     {
         Referral[]  referrals    = this.maintainer.GetReferrals();
         WelcomeInfo typedMessage = new WelcomeInfo(this.config.NodeId, referrals);
         Message     message      = this.WelcomeInfoMessageConverter.ToMessage(typedMessage, MessageVersion.Soap12WSAddressing10);
         this.SendMessageToNeighbor(neighbor, message, new PeerMessageHelpers.CleanupCallback(this.OnConnectFailure));
     }
 }
Esempio n. 4
0
        void SendWelcome(IPeerNeighbor neighbor)
        {
            // We do not attempt to send the message if PeerConnector is not open
            if (state == State.Opened)
            {
                // Get referrals from the maintainer
                Referral[] referrals = maintainer.GetReferrals();

                WelcomeInfo welcomeInfo = new WelcomeInfo(this.config.NodeId, referrals);
                Message     message     = WelcomeInfoMessageConverter.ToMessage(welcomeInfo, MessageVersion.Soap12WSAddressing10);
                SendMessageToNeighbor(neighbor, message, OnConnectFailure);
            }
        }
 public void Welcome(IPeerNeighbor neighbor, WelcomeInfo welcomeInfo)
 {
     if (this.state == State.Opened)
     {
         PeerCloseReason none = PeerCloseReason.None;
         if ((!neighbor.IsInitiator || !welcomeInfo.HasBody()) || ((neighbor.State != PeerNeighborState.Connecting) && (neighbor.State != PeerNeighborState.Closed)))
         {
             none = PeerCloseReason.InvalidNeighbor;
         }
         else if (this.RemoveTimer(neighbor))
         {
             PeerCloseReason reason2;
             IPeerNeighbor   neighbor2;
             string          action = "http://schemas.microsoft.com/net/2006/05/peer/Refuse";
             this.ValidateNeighbor(neighbor, welcomeInfo.NodeId, out neighbor2, out reason2, out action);
             if (neighbor != neighbor2)
             {
                 if (this.maintainer.AddReferrals(welcomeInfo.Referrals, neighbor))
                 {
                     if (!neighbor.TrySetState(PeerNeighborState.Connected) && (neighbor.State < PeerNeighborState.Faulted))
                     {
                         throw Fx.AssertAndThrow("Neighbor state expected to be >= Faulted; it is " + neighbor.State.ToString());
                     }
                     if (neighbor2 != null)
                     {
                         this.SendTerminatingMessage(neighbor2, action, reason2);
                         this.neighborManager.CloseNeighbor(neighbor2, reason2, PeerCloseInitiator.LocalNode);
                     }
                 }
                 else
                 {
                     none = PeerCloseReason.InvalidNeighbor;
                 }
             }
             else
             {
                 none = reason2;
             }
         }
         if (none != PeerCloseReason.None)
         {
             this.SendTerminatingMessage(neighbor, "http://schemas.microsoft.com/net/2006/05/peer/Disconnect", none);
             this.neighborManager.CloseNeighbor(neighbor, none, PeerCloseInitiator.LocalNode);
         }
     }
 }
        void SendWelcome(IPeerNeighbor neighbor)
        {
            // We do not attempt to send the message if PeerConnector is not open
            if (state == State.Opened)
            {
                // Get referrals from the maintainer
                Referral[] referrals = maintainer.GetReferrals();

                WelcomeInfo welcomeInfo = new WelcomeInfo(this.config.NodeId, referrals);
                Message message = WelcomeInfoMessageConverter.ToMessage(welcomeInfo, MessageVersion.Soap12WSAddressing10);
                SendMessageToNeighbor(neighbor, message, OnConnectFailure);
            }
        }
        // Process Welcome message from the neighbor
        public void Welcome(IPeerNeighbor neighbor, WelcomeInfo welcomeInfo)
        {
            // Don't bother processing the message if Connector has closed
            if (this.state != State.Opened)
                return;

            PeerCloseReason closeReason = PeerCloseReason.None;

            // Welcome message should only be received when neighbor is the initiator
            // and is in connecting state --we accept in closed state to account for
            // timeouts.
            if (!neighbor.IsInitiator || !welcomeInfo.HasBody() || (neighbor.State != PeerNeighborState.Connecting &&
                neighbor.State != PeerNeighborState.Closed))
            {
                closeReason = PeerCloseReason.InvalidNeighbor;
            }
            // Remove the entry from timer table for this neighbor. If entry is still present,
            // RemoveTimer returns true. Otherwise, neighbor is already being closed and 
            // welcome message will be ignored.
            else if (RemoveTimer(neighbor))
            {
                // It is allowed for a node to have more than MaxNeighbours when processing a welcome message
                // Determine if neighbor should be accepted.
                PeerCloseReason closeReason2;
                IPeerNeighbor neighborToClose;
                string action = PeerStrings.RefuseAction;
                ValidateNeighbor(neighbor, welcomeInfo.NodeId, out neighborToClose, out closeReason2, out action);

                if (neighbor != neighborToClose)
                {
                    // Neighbor should be accepted AddReferrals validates the referrals, 
                    // if they are valid then the neighbor is accepted.
                    if (this.maintainer.AddReferrals(welcomeInfo.Referrals, neighbor))
                    {
                        if (!neighbor.TrySetState(PeerNeighborState.Connected))
                        {
                            if (!(neighbor.State >= PeerNeighborState.Faulted))
                            {
                                throw Fx.AssertAndThrow("Neighbor state expected to be >= Faulted; it is " + neighbor.State.ToString());
                            }
                        }

                        if (neighborToClose != null)
                        {
                            // The other neighbor should be closed
                            SendTerminatingMessage(neighborToClose, action, closeReason2);
                            this.neighborManager.CloseNeighbor(neighborToClose, closeReason2, PeerCloseInitiator.LocalNode);
                        }
                    }
                    else
                    {
                        // Referrals were invalid this node is suspicous
                        closeReason = PeerCloseReason.InvalidNeighbor;
                    }
                }
                else
                {
                    closeReason = closeReason2;
                }
            }

            if (closeReason != PeerCloseReason.None)
            {
                SendTerminatingMessage(neighbor, PeerStrings.DisconnectAction, closeReason);
                this.neighborManager.CloseNeighbor(neighbor, closeReason, PeerCloseInitiator.LocalNode);
            }
        }
 public void Welcome(IPeerNeighbor neighbor, WelcomeInfo welcomeInfo)
 {
     if (this.state == State.Opened)
     {
         PeerCloseReason none = PeerCloseReason.None;
         if ((!neighbor.IsInitiator || !welcomeInfo.HasBody()) || ((neighbor.State != PeerNeighborState.Connecting) && (neighbor.State != PeerNeighborState.Closed)))
         {
             none = PeerCloseReason.InvalidNeighbor;
         }
         else if (this.RemoveTimer(neighbor))
         {
             PeerCloseReason reason2;
             IPeerNeighbor neighbor2;
             string action = "http://schemas.microsoft.com/net/2006/05/peer/Refuse";
             this.ValidateNeighbor(neighbor, welcomeInfo.NodeId, out neighbor2, out reason2, out action);
             if (neighbor != neighbor2)
             {
                 if (this.maintainer.AddReferrals(welcomeInfo.Referrals, neighbor))
                 {
                     if (!neighbor.TrySetState(PeerNeighborState.Connected) && (neighbor.State < PeerNeighborState.Faulted))
                     {
                         throw Fx.AssertAndThrow("Neighbor state expected to be >= Faulted; it is " + neighbor.State.ToString());
                     }
                     if (neighbor2 != null)
                     {
                         this.SendTerminatingMessage(neighbor2, action, reason2);
                         this.neighborManager.CloseNeighbor(neighbor2, reason2, PeerCloseInitiator.LocalNode);
                     }
                 }
                 else
                 {
                     none = PeerCloseReason.InvalidNeighbor;
                 }
             }
             else
             {
                 none = reason2;
             }
         }
         if (none != PeerCloseReason.None)
         {
             this.SendTerminatingMessage(neighbor, "http://schemas.microsoft.com/net/2006/05/peer/Disconnect", none);
             this.neighborManager.CloseNeighbor(neighbor, none, PeerCloseInitiator.LocalNode);
         }
     }
 }
 private void SendWelcome(IPeerNeighbor neighbor)
 {
     if (this.state == State.Opened)
     {
         Referral[] referrals = this.maintainer.GetReferrals();
         WelcomeInfo typedMessage = new WelcomeInfo(this.config.NodeId, referrals);
         Message message = this.WelcomeInfoMessageConverter.ToMessage(typedMessage, MessageVersion.Soap12WSAddressing10);
         this.SendMessageToNeighbor(neighbor, message, new PeerMessageHelpers.CleanupCallback(this.OnConnectFailure));
     }
 }
Esempio n. 10
0
        // Process Welcome message from the neighbor
        public void Welcome(IPeerNeighbor neighbor, WelcomeInfo welcomeInfo)
        {
            // Don't bother processing the message if Connector has closed
            if (this.state != State.Opened)
            {
                return;
            }

            PeerCloseReason closeReason = PeerCloseReason.None;

            // Welcome message should only be received when neighbor is the initiator
            // and is in connecting state --we accept in closed state to account for
            // timeouts.
            if (!neighbor.IsInitiator || !welcomeInfo.HasBody() || (neighbor.State != PeerNeighborState.Connecting &&
                                                                    neighbor.State != PeerNeighborState.Closed))
            {
                closeReason = PeerCloseReason.InvalidNeighbor;
            }
            // Remove the entry from timer table for this neighbor. If entry is still present,
            // RemoveTimer returns true. Otherwise, neighbor is already being closed and
            // welcome message will be ignored.
            else if (RemoveTimer(neighbor))
            {
                // It is allowed for a node to have more than MaxNeighbours when processing a welcome message
                // Determine if neighbor should be accepted.
                PeerCloseReason closeReason2;
                IPeerNeighbor   neighborToClose;
                string          action = PeerStrings.RefuseAction;
                ValidateNeighbor(neighbor, welcomeInfo.NodeId, out neighborToClose, out closeReason2, out action);

                if (neighbor != neighborToClose)
                {
                    // Neighbor should be accepted AddReferrals validates the referrals,
                    // if they are valid then the neighbor is accepted.
                    if (this.maintainer.AddReferrals(welcomeInfo.Referrals, neighbor))
                    {
                        if (!neighbor.TrySetState(PeerNeighborState.Connected))
                        {
                            if (!(neighbor.State >= PeerNeighborState.Faulted))
                            {
                                throw Fx.AssertAndThrow("Neighbor state expected to be >= Faulted; it is " + neighbor.State.ToString());
                            }
                        }

                        if (neighborToClose != null)
                        {
                            // The other neighbor should be closed
                            SendTerminatingMessage(neighborToClose, action, closeReason2);
                            this.neighborManager.CloseNeighbor(neighborToClose, closeReason2, PeerCloseInitiator.LocalNode);
                        }
                    }
                    else
                    {
                        // Referrals were invalid this node is suspicous
                        closeReason = PeerCloseReason.InvalidNeighbor;
                    }
                }
                else
                {
                    closeReason = closeReason2;
                }
            }

            if (closeReason != PeerCloseReason.None)
            {
                SendTerminatingMessage(neighbor, PeerStrings.DisconnectAction, closeReason);
                this.neighborManager.CloseNeighbor(neighbor, closeReason, PeerCloseInitiator.LocalNode);
            }
        }
 void IPeerServiceContract.Welcome(WelcomeInfo welcomeInfo)
 {
     IPeerNeighbor neighbor = this.GetNeighbor();
     if (neighbor != null)
     {
         this.connector.Welcome(neighbor, welcomeInfo);
     }
 }