public bool IsNotSeenBefore(Message message, out byte[] id, out int cacheHit) { cacheHit = -1; id = PeerNodeImplementation.DefaultId; if (message is SecurityVerifiedMessage) { id = (message as SecurityVerifiedMessage).PrimarySignatureValue; } else { System.Xml.UniqueId messageId = PeerMessageHelpers.GetHeaderUniqueId(message.Headers, PeerStrings.MessageId, PeerStrings.Namespace); if (messageId == null) { return(false); } if (messageId.IsGuid) { id = new byte[16]; messageId.TryGetGuid(id, 0); } else { return(false); } } cacheHit = messageIds.AddForLookup(id); if (cacheHit == -1) { return(true); } return(false); }
private int UpdateHopCount(Message message, out MessageHeader hopHeader, out ulong currentValue) { int index = -1; currentValue = ulong.MaxValue; hopHeader = null; try { index = message.Headers.FindHeader("Hops", "http://schemas.microsoft.com/net/2006/05/peer/HopCount"); if (index != -1) { ulong num2; currentValue = PeerMessageHelpers.GetHeaderULong(message.Headers, index); currentValue = num2 = (ulong)(currentValue - 1L); hopHeader = MessageHeader.CreateHeader("Hops", "http://schemas.microsoft.com/net/2006/05/peer/HopCount", num2, false); } } catch (MessageHeaderException exception) { System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning); } catch (CommunicationException exception2) { System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Warning); } catch (SerializationException exception3) { System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Warning); } catch (XmlException exception4) { System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception4, TraceEventType.Warning); } return(index); }
int UpdateHopCount(Message message, out MessageHeader hopHeader, out ulong currentValue) { int index = -1; currentValue = PeerTransportConstants.MaxHopCount; hopHeader = null; try { // If a message contains multiple Hopcounts with our name and namespace or the message can't deserialize to a ulong then ignore the HopCount index = message.Headers.FindHeader(PeerStrings.HopCountElementName, PeerStrings.HopCountElementNamespace); if (index != -1) { currentValue = PeerMessageHelpers.GetHeaderULong(message.Headers, index); hopHeader = MessageHeader.CreateHeader(PeerStrings.HopCountElementName, PeerStrings.HopCountElementNamespace, --currentValue, false); } } catch (MessageHeaderException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning); } catch (CommunicationException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning); } catch (SerializationException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning); } catch (XmlException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning); } Fx.Assert((index == -1) || (hopHeader != null), "Could not successfully create new HopCount Header!"); return(index); }
public bool IsNotSeenBefore(Message message, out byte[] id, out int cacheHit) { cacheHit = -1; id = PeerNodeImplementation.DefaultId; if (message is SecurityVerifiedMessage) { id = (message as SecurityVerifiedMessage).PrimarySignatureValue; } else { UniqueId id2 = PeerMessageHelpers.GetHeaderUniqueId(message.Headers, "MessageID", "http://schemas.microsoft.com/net/2006/05/peer"); if ((id2 != null) && id2.IsGuid) { id = new byte[0x10]; id2.TryGetGuid(id, 0); } else { return(false); } } cacheHit = this.messageIds.AddForLookup(id); return(cacheHit == -1); }
public string SelectOperation(ref Message message) { string action = message.Headers.Action; string str2 = null; byte[] defaultId = PeerNodeImplementation.DefaultId; string str3 = PeerStrings.FindAction(action); Uri via = null; Uri uri2 = null; bool flag = false; PeerMessageProperty property = new PeerMessageProperty(); if (str3 != null) { return(str3); } try { str2 = PeerMessageHelpers.GetHeaderString(message.Headers, "FloodMessage", "http://schemas.microsoft.com/net/2006/05/peer"); via = PeerMessageHelpers.GetHeaderUri(message.Headers, "PeerVia", "http://schemas.microsoft.com/net/2006/05/peer"); uri2 = PeerMessageHelpers.GetHeaderUri(message.Headers, "PeerTo", "http://schemas.microsoft.com/net/2006/05/peer"); } catch (MessageHeaderException exception) { System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning); return("Fault"); } catch (SerializationException exception2) { System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Warning); return("Fault"); } catch (XmlException exception3) { System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Warning); return("Fault"); } property.PeerVia = via; property.PeerTo = uri2; message.Properties.Add("PeerProperty", property); if (!(str2 == "PeerFlooder")) { return(null); } try { if (!this.messageHandler.ValidateIncomingMessage(ref message, via)) { property.SkipLocalChannels = true; flag = true; TurnOffSecurityHeader(message); } if (this.messageHandler.IsNotSeenBefore(message, out defaultId, out property.CacheMiss)) { property.MessageVerified = true; } else if (!flag) { property.SkipLocalChannels = true; } if (defaultId == PeerNodeImplementation.DefaultId) { return("Fault"); } } catch (MessageHeaderException exception4) { System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception4, TraceEventType.Warning); return("Fault"); } catch (SerializationException exception5) { System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception5, TraceEventType.Warning); return("Fault"); } catch (XmlException exception6) { System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception6, TraceEventType.Warning); return("Fault"); } catch (MessageSecurityException exception7) { if (!exception7.ReplayDetected) { return("Fault"); } System.ServiceModel.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception7, TraceEventType.Information); } return("FloodMessage"); }
//this method takes care of closing the message. void SendMessageToNeighbor(IPeerNeighbor neighbor, Message message, PeerMessageHelpers.CleanupCallback cleanupCallback) { bool fatal = false; try { neighbor.Send(message); } catch (Exception e) { if (Fx.IsFatal(e)) { fatal = true; throw; } if (e is CommunicationException || e is QuotaExceededException || e is ObjectDisposedException || e is TimeoutException) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); // Message failed to transmit due to quota exceeding or channel failure if (cleanupCallback != null) { cleanupCallback(neighbor, PeerCloseReason.InternalFailure, e); } } else { throw; } } finally { if (!fatal) message.Close(); } }
private void SendMessageToNeighbor(IPeerNeighbor neighbor, Message message, PeerMessageHelpers.CleanupCallback cleanupCallback) { bool flag = false; try { neighbor.Send(message); } catch (Exception exception) { if (Fx.IsFatal(exception)) { flag = true; throw; } if ((!(exception is CommunicationException) && !(exception is QuotaExceededException)) && (!(exception is ObjectDisposedException) && !(exception is TimeoutException))) { throw; } DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information); if (cleanupCallback != null) { cleanupCallback(neighbor, PeerCloseReason.InternalFailure, exception); } } finally { if (!flag) { message.Close(); } } }
public string SelectOperation(ref Message message) { string action = message.Headers.Action; string demux = null; byte[] id = PeerNodeImplementation.DefaultId; string operation = PeerStrings.FindAction(action); Uri via = null; Uri to = null; bool skipped = false; PeerMessageProperty peerProperty = new PeerMessageProperty(); if (operation != null) { return(operation); } try { demux = PeerMessageHelpers.GetHeaderString(message.Headers, PeerOperationNames.Flood, PeerStrings.Namespace); via = PeerMessageHelpers.GetHeaderUri(message.Headers, PeerStrings.Via, PeerStrings.Namespace); to = PeerMessageHelpers.GetHeaderUri(message.Headers, PeerOperationNames.PeerTo, PeerStrings.Namespace); } catch (MessageHeaderException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning); return(PeerOperationNames.Fault); } catch (SerializationException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning); return(PeerOperationNames.Fault); } catch (XmlException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning); return(PeerOperationNames.Fault); } peerProperty.PeerVia = via; peerProperty.PeerTo = to; message.Properties.Add(PeerStrings.PeerProperty, peerProperty); if (demux == PeerOperationNames.Demuxer) { try { if (!this.messageHandler.ValidateIncomingMessage(ref message, via)) { peerProperty.SkipLocalChannels = true; skipped = true; TurnOffSecurityHeader(message); } if (this.messageHandler.IsNotSeenBefore(message, out id, out peerProperty.CacheMiss)) { peerProperty.MessageVerified = true; } else { if (!skipped) { peerProperty.SkipLocalChannels = true; } } //means that the message doesnt contain legal id if (id == PeerNodeImplementation.DefaultId) { return(PeerOperationNames.Fault); } } catch (MessageHeaderException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning); return(PeerOperationNames.Fault); } catch (SerializationException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning); return(PeerOperationNames.Fault); } catch (XmlException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning); return(PeerOperationNames.Fault); } catch (MessageSecurityException e) { if (!e.ReplayDetected) { return(PeerOperationNames.Fault); } else { DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); } } return(PeerOperationNames.Flood); } else { return(null); } }