private void SendTerminatingMessage(IPeerNeighbor neighbor, string action, PeerCloseReason closeReason)
 {
     if ((this.state == State.Opened) && (closeReason != PeerCloseReason.InvalidNeighbor))
     {
         if (neighbor.TrySetState(PeerNeighborState.Disconnecting))
         {
             Message    message;
             Referral[] referrals = this.maintainer.GetReferrals();
             if (action == "http://schemas.microsoft.com/net/2006/05/peer/Disconnect")
             {
                 DisconnectInfo typedMessage = new DisconnectInfo((DisconnectReason)closeReason, referrals);
                 message = this.DisconnectInfoMessageConverter.ToMessage(typedMessage, MessageVersion.Soap12WSAddressing10);
             }
             else
             {
                 RefuseInfo info2 = new RefuseInfo((RefuseReason)closeReason, referrals);
                 message = this.RefuseInfoMessageConverter.ToMessage(info2, MessageVersion.Soap12WSAddressing10);
             }
             this.SendMessageToNeighbor(neighbor, message, null);
         }
         else if (neighbor.State < PeerNeighborState.Disconnecting)
         {
             throw Fx.AssertAndThrow("Neighbor state expected to be >= Disconnecting; it is " + neighbor.State.ToString());
         }
     }
 }
示例#2
0
        // Process Refuse message from the neighbor
        public void Refuse(IPeerNeighbor neighbor, RefuseInfo refuseInfo)
        {
            // Don't bother processing the message if Connector has closed
            if (this.state != State.Opened)
            {
                return;
            }

            PeerCloseReason  closeReason = PeerCloseReason.InvalidNeighbor;
            IList <Referral> referrals   = null;

            if (refuseInfo.HasBody())
            {
                // Refuse 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 && (neighbor.State == PeerNeighborState.Connecting ||
                                             neighbor.State == PeerNeighborState.Closed))
                {
                    // Remove the entry from timer table for this neighbor
                    RemoveTimer(neighbor);

                    if (PeerConnectorHelper.IsDefined(refuseInfo.Reason))
                    {
                        closeReason = (PeerCloseReason)refuseInfo.Reason;
                        referrals   = refuseInfo.Referrals;
                    }
                }
            }
            // Complete processing of refuse message
            CompleteTerminateMessageProcessing(neighbor, closeReason, referrals);
        }
        void IPeerServiceContract.Refuse(RefuseInfo refuseInfo)
        {
            IPeerNeighbor neighbor = this.GetNeighbor();

            if (neighbor != null)
            {
                this.connector.Refuse(neighbor, refuseInfo);
            }
        }
 public void Refuse(IPeerNeighbor neighbor, RefuseInfo refuseInfo)
 {
     if (this.state == State.Opened)
     {
         PeerCloseReason  invalidNeighbor = PeerCloseReason.InvalidNeighbor;
         IList <Referral> referrals       = null;
         if ((refuseInfo.HasBody() && neighbor.IsInitiator) && ((neighbor.State == PeerNeighborState.Connecting) || (neighbor.State == PeerNeighborState.Closed)))
         {
             this.RemoveTimer(neighbor);
             if (PeerConnectorHelper.IsDefined(refuseInfo.Reason))
             {
                 invalidNeighbor = (PeerCloseReason)refuseInfo.Reason;
                 referrals       = refuseInfo.Referrals;
             }
         }
         this.CompleteTerminateMessageProcessing(neighbor, invalidNeighbor, referrals);
     }
 }
示例#5
0
        // Send Disconnect or Refuse message
        void SendTerminatingMessage(IPeerNeighbor neighbor, string action, PeerCloseReason closeReason)
        {
            // We do not attempt to send the message if Connector is not open
            // or if the close reason is InvalidNeighbor.
            if (this.state != State.Opened || closeReason == PeerCloseReason.InvalidNeighbor)
            {
                return;
            }

            // Set the neighbor state to disconnecting. TrySetState can fail if the
            // neighbor is already being closed. Disconnect/Refuse msg not sent in that case.
            if (neighbor.TrySetState(PeerNeighborState.Disconnecting))
            {
                // Get referrals from the maintainer
                Referral[] referrals = maintainer.GetReferrals();

                // Build and send the message
                Message message;
                if (action == PeerStrings.DisconnectAction)
                {
                    DisconnectInfo disconnectInfo = new DisconnectInfo((DisconnectReason)closeReason, referrals);
                    message = DisconnectInfoMessageConverter.ToMessage(disconnectInfo, MessageVersion.Soap12WSAddressing10);
                }
                else
                {
                    RefuseInfo refuseInfo = new RefuseInfo((RefuseReason)closeReason, referrals);
                    message = RefuseInfoMessageConverter.ToMessage(refuseInfo, MessageVersion.Soap12WSAddressing10);
                }
                SendMessageToNeighbor(neighbor, message, null);
            }
            else
            if (!(neighbor.State >= PeerNeighborState.Disconnecting))
            {
                throw Fx.AssertAndThrow("Neighbor state expected to be >= Disconnecting; it is " + neighbor.State.ToString());
            }
        }
        // Send Disconnect or Refuse message
        void SendTerminatingMessage(IPeerNeighbor neighbor, string action, PeerCloseReason closeReason)
        {
            // We do not attempt to send the message if Connector is not open
            // or if the close reason is InvalidNeighbor.
            if (this.state != State.Opened || closeReason == PeerCloseReason.InvalidNeighbor)
                return;

            // Set the neighbor state to disconnecting. TrySetState can fail if the 
            // neighbor is already being closed. Disconnect/Refuse msg not sent in that case.
            if (neighbor.TrySetState(PeerNeighborState.Disconnecting))
            {
                // Get referrals from the maintainer
                Referral[] referrals = maintainer.GetReferrals();

                // Build and send the message
                Message message;
                if (action == PeerStrings.DisconnectAction)
                {
                    DisconnectInfo disconnectInfo = new DisconnectInfo((DisconnectReason)closeReason, referrals);
                    message = DisconnectInfoMessageConverter.ToMessage(disconnectInfo, MessageVersion.Soap12WSAddressing10);
                }
                else
                {
                    RefuseInfo refuseInfo = new RefuseInfo((RefuseReason)closeReason, referrals);
                    message = RefuseInfoMessageConverter.ToMessage(refuseInfo, MessageVersion.Soap12WSAddressing10);
                }
                SendMessageToNeighbor(neighbor, message, null);
            }
            else
                if (!(neighbor.State >= PeerNeighborState.Disconnecting))
                {
                    throw Fx.AssertAndThrow("Neighbor state expected to be >= Disconnecting; it is " + neighbor.State.ToString());
                }
        }
        // Process Refuse message from the neighbor
        public void Refuse(IPeerNeighbor neighbor, RefuseInfo refuseInfo)
        {
            // Don't bother processing the message if Connector has closed
            if (this.state != State.Opened)
                return;

            PeerCloseReason closeReason = PeerCloseReason.InvalidNeighbor;
            IList<Referral> referrals = null;

            if (refuseInfo.HasBody())
            {
                // Refuse 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 && (neighbor.State == PeerNeighborState.Connecting ||
                    neighbor.State == PeerNeighborState.Closed))
                {
                    // Remove the entry from timer table for this neighbor
                    RemoveTimer(neighbor);

                    if (PeerConnectorHelper.IsDefined(refuseInfo.Reason))
                    {
                        closeReason = (PeerCloseReason)refuseInfo.Reason;
                        referrals = refuseInfo.Referrals;
                    }
                }
            }
            // Complete processing of refuse message
            CompleteTerminateMessageProcessing(neighbor, closeReason, referrals);
        }
示例#8
0
 public void Refuse(RefuseInfo refuse)
 {
     // FIXME: it should not probably actually throw an error.
     connect_handle.Set();
     throw new InvalidOperationException("Peer connection was refused");
 }
 private void SendTerminatingMessage(IPeerNeighbor neighbor, string action, PeerCloseReason closeReason)
 {
     if ((this.state == State.Opened) && (closeReason != PeerCloseReason.InvalidNeighbor))
     {
         if (neighbor.TrySetState(PeerNeighborState.Disconnecting))
         {
             Message message;
             Referral[] referrals = this.maintainer.GetReferrals();
             if (action == "http://schemas.microsoft.com/net/2006/05/peer/Disconnect")
             {
                 DisconnectInfo typedMessage = new DisconnectInfo((DisconnectReason) closeReason, referrals);
                 message = this.DisconnectInfoMessageConverter.ToMessage(typedMessage, MessageVersion.Soap12WSAddressing10);
             }
             else
             {
                 RefuseInfo info2 = new RefuseInfo((RefuseReason) closeReason, referrals);
                 message = this.RefuseInfoMessageConverter.ToMessage(info2, MessageVersion.Soap12WSAddressing10);
             }
             this.SendMessageToNeighbor(neighbor, message, null);
         }
         else if (neighbor.State < PeerNeighborState.Disconnecting)
         {
             throw Fx.AssertAndThrow("Neighbor state expected to be >= Disconnecting; it is " + neighbor.State.ToString());
         }
     }
 }
 public void Refuse(IPeerNeighbor neighbor, RefuseInfo refuseInfo)
 {
     if (this.state == State.Opened)
     {
         PeerCloseReason invalidNeighbor = PeerCloseReason.InvalidNeighbor;
         IList<Referral> referrals = null;
         if ((refuseInfo.HasBody() && neighbor.IsInitiator) && ((neighbor.State == PeerNeighborState.Connecting) || (neighbor.State == PeerNeighborState.Closed)))
         {
             this.RemoveTimer(neighbor);
             if (PeerConnectorHelper.IsDefined(refuseInfo.Reason))
             {
                 invalidNeighbor = (PeerCloseReason) refuseInfo.Reason;
                 referrals = refuseInfo.Referrals;
             }
         }
         this.CompleteTerminateMessageProcessing(neighbor, invalidNeighbor, referrals);
     }
 }
 void IPeerServiceContract.Refuse(RefuseInfo refuseInfo)
 {
     IPeerNeighbor neighbor = this.GetNeighbor();
     if (neighbor != null)
     {
         this.connector.Refuse(neighbor, refuseInfo);
     }
 }