public void TraceEventHelper(TraceEventType severity, int traceCode, string traceDescription, Exception e,
                string action, PeerNeighborState nbrState, PeerNeighborState previousOrAttemptedState)
            {
                if (DiagnosticUtility.ShouldTrace(severity))
                {
                    string attemptedState = null;
                    string previousState = null;
                    PeerNodeAddress listenAddr = null;
                    IPAddress connectIPAddr = null;

                    if (nbrState >= PeerNeighborState.Opened && nbrState <= PeerNeighborState.Connected)
                    {
                        listenAddr = this.ListenAddress;
                        connectIPAddr = this.ConnectIPAddress;
                    }

                    if (traceCode == TraceCode.PeerNeighborStateChangeFailed)
                        attemptedState = previousOrAttemptedState.ToString();
                    else if (traceCode == TraceCode.PeerNeighborStateChanged)
                        previousState = previousOrAttemptedState.ToString();

                    PeerNeighborTraceRecord record = new PeerNeighborTraceRecord(this.nodeId,
                        this.config.NodeId, listenAddr, connectIPAddr, this.GetHashCode(),
                        this.initiator, nbrState.ToString(), previousState, attemptedState, action);

                    if (severity == TraceEventType.Verbose && e != null)
                        severity = TraceEventType.Information; // need to be >= info for exceptions

                    TraceUtility.TraceEvent(severity, traceCode, traceDescription, record, this, e);
                }
            }
            public void TraceClosedEvent(PeerNeighborState previousState)
            {
                if (DiagnosticUtility.ShouldTraceInformation)
                {
                    TraceEventType severity = TraceEventType.Information;

                    // Override tracing severity based on close reason
                    switch (this.closeReason)
                    {
                        case PeerCloseReason.InvalidNeighbor:
                        case PeerCloseReason.DuplicateNodeId:
                            severity = TraceEventType.Error;
                            break;

                        case PeerCloseReason.ConnectTimedOut:
                        case PeerCloseReason.InternalFailure:
                        case PeerCloseReason.Faulted:
                            severity = TraceEventType.Warning;
                            break;
                    }

                    PeerNeighborCloseTraceRecord record = new PeerNeighborCloseTraceRecord(
                        this.nodeId, this.config.NodeId, null, null,
                        this.GetHashCode(), this.initiator,
                        PeerNeighborState.Closed.ToString(), previousState.ToString(), null,
                        this.closeInitiator.ToString(), this.closeReason.ToString()
                    );

                    TraceUtility.TraceEvent(severity, TraceCode.PeerNeighborStateChanged,
                        SR.GetString(SR.TraceCodePeerNeighborStateChanged), record, this, this.closeException);
                }
            }
        private IPeerNeighbor GetNeighbor()
        {
            IPeerNeighbor neighbor = this.getNeighborCallback(OperationContext.Current.GetCallbackChannel <IPeerProxy>());

            if ((neighbor == null) || (neighbor.State == PeerNeighborState.Closed))
            {
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning, 0x40036, System.ServiceModel.SR.GetString("TraceCodePeerNeighborNotFound"), new PeerNodeTraceRecord(this.config.NodeId), OperationContext.Current.IncomingMessage);
                }
                return(null);
            }
            if (DiagnosticUtility.ShouldTraceVerbose)
            {
                PeerNeighborState state            = neighbor.State;
                PeerNodeAddress   listenAddress    = null;
                IPAddress         connectIPAddress = null;
                if ((state >= PeerNeighborState.Opened) && (state <= PeerNeighborState.Connected))
                {
                    listenAddress    = this.config.GetListenAddress(true);
                    connectIPAddress = this.config.ListenIPAddress;
                }
                PeerNeighborTraceRecord extendedData = new PeerNeighborTraceRecord(neighbor.NodeId, this.config.NodeId, listenAddress, connectIPAddress, neighbor.GetHashCode(), neighbor.IsInitiator, state.ToString(), null, null, OperationContext.Current.IncomingMessage.Headers.Action);
                TraceUtility.TraceEvent(TraceEventType.Verbose, 0x4003a, System.ServiceModel.SR.GetString("TraceCodePeerNeighborMessageReceived"), extendedData, this, null);
            }
            return(neighbor);
        }
 // Throws if the new state being set on the neighbor is invalid compared to the 
 // current state (such as setting state to connecting when it is already in
 // disconnected state). Also throws if neighbor is already closed.
 // NOTE: This method should be called within the lock.
 void ThrowIfInvalidState(PeerNeighborState newState)
 {
     if (this.state == PeerNeighborState.Closed)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(
             this.ToString()));
     }
     if (this.state >= newState)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
             SR.GetString(SR.PeerNeighborInvalidState, this.state.ToString(),
             newState.ToString())));
     }
 }
Example #5
0
        IPeerNeighbor GetNeighbor()
        {
            IPeerNeighbor neighbor = (IPeerNeighbor)getNeighborCallback(OperationContext.Current.GetCallbackChannel <IPeerProxy>());

            if (neighbor == null || neighbor.State == PeerNeighborState.Closed)
            {
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.PeerNeighborNotFound,
                                            SR.GetString(SR.TraceCodePeerNeighborNotFound),
                                            new PeerNodeTraceRecord(config.NodeId),
                                            OperationContext.Current.IncomingMessage);
                }
                return(null);
            }

            if (DiagnosticUtility.ShouldTraceVerbose)
            {
                PeerNeighborState state = neighbor.State;

                PeerNodeAddress listenAddr    = null;
                IPAddress       connectIPAddr = null;

                if (state >= PeerNeighborState.Opened && state <= PeerNeighborState.Connected)
                {
                    listenAddr    = config.GetListenAddress(true);
                    connectIPAddr = config.ListenIPAddress;
                }

                PeerNeighborTraceRecord record = new PeerNeighborTraceRecord(neighbor.NodeId,
                                                                             this.config.NodeId, listenAddr, connectIPAddr, neighbor.GetHashCode(),
                                                                             neighbor.IsInitiator, state.ToString(), null, null,
                                                                             OperationContext.Current.IncomingMessage.Headers.Action);

                TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.PeerNeighborMessageReceived, SR.GetString(SR.TraceCodePeerNeighborMessageReceived), record, this, null);
            }

            return(neighbor);
        }