public override void ProcessLinkUtility(IPeerNeighbor neighbor, UtilityInfo utilityInfo) { if (!PeerNeighborStateHelper.IsConnected(neighbor.State)) { neighbor.Abort(PeerCloseReason.InvalidNeighbor, PeerCloseInitiator.LocalNode); } else { try { UtilityExtension.ProcessLinkUtility(neighbor, utilityInfo); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } if (PeerFlooderBase <Message, UtilityInfo> .CloseNeighborIfKnownException(base.neighborManager, exception, neighbor) != null) { throw; } DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information); } } }
public override void ProcessLinkUtility(IPeerNeighbor neighbor, UtilityInfo utilityInfo) { if (!PeerNeighborStateHelper.IsConnected(neighbor.State)) { neighbor.Abort(PeerCloseReason.InvalidNeighbor, PeerCloseInitiator.LocalNode); return; } try { UtilityExtension.ProcessLinkUtility(neighbor, utilityInfo); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (null != CloseNeighborIfKnownException(neighborManager, e, neighbor)) { throw; } DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); } }
void SendUtilityMessage(uint useful, uint total) { IPeerNeighbor host = owner; if (host == null || !PeerNeighborStateHelper.IsConnected(host.State) || total == 0) { return; } UtilityInfo umessage = new UtilityInfo(useful, total); IAsyncResult result = null; Message message = MessageConverter.ToMessage(umessage, MessageVersion.Soap12WSAddressing10); bool fatal = false; try { result = host.BeginSend(message, Fx.ThunkCallback(new AsyncCallback(UtilityMessageSent)), new AsyncUtilityState(message, umessage)); if (result.CompletedSynchronously) { host.EndSend(result); EventHandler handler = UtilityInfoSent; if (handler != null) { handler(this, EventArgs.Empty); } } } catch (Exception e) { if (Fx.IsFatal(e)) { fatal = true; throw; } if (null != HandleSendException(host, e, umessage)) { throw; } DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); } finally { if (!fatal && (result == null || result.CompletedSynchronously)) { message.Close(); } } }
private void UtilityMessageSent(IAsyncResult result) { if ((result != null) && (result.AsyncState != null)) { IPeerNeighbor owner = this.owner; if (((owner != null) && PeerNeighborStateHelper.IsConnected(owner.State)) && !result.CompletedSynchronously) { AsyncUtilityState asyncState = (AsyncUtilityState)result.AsyncState; Message message = asyncState.message; UtilityInfo umessage = asyncState.info; bool flag = false; if (umessage == null) { throw Fx.AssertAndThrow("expecting a UtilityInfo message in the AsyncState!"); } try { owner.EndSend(result); } catch (Exception exception) { if (Fx.IsFatal(exception)) { flag = true; throw; } if (this.HandleSendException(owner, exception, umessage) != null) { throw; } DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information); } finally { if (!flag) { message.Close(); } } EventHandler utilityInfoSent = this.UtilityInfoSent; if (utilityInfoSent != null) { utilityInfoSent(this, EventArgs.Empty); } } } }
private void SendUtilityMessage(uint useful, uint total) { IPeerNeighbor owner = this.owner; if (((owner != null) && PeerNeighborStateHelper.IsConnected(owner.State)) && (total != 0)) { UtilityInfo typedMessage = new UtilityInfo(useful, total); IAsyncResult result = null; Message message = this.MessageConverter.ToMessage(typedMessage, MessageVersion.Soap12WSAddressing10); bool flag = false; try { result = owner.BeginSend(message, Fx.ThunkCallback(new AsyncCallback(this.UtilityMessageSent)), new AsyncUtilityState(message, typedMessage)); if (result.CompletedSynchronously) { owner.EndSend(result); EventHandler utilityInfoSent = this.UtilityInfoSent; if (utilityInfoSent != null) { utilityInfoSent(this, EventArgs.Empty); } } } catch (Exception exception) { if (Fx.IsFatal(exception)) { flag = true; throw; } if (this.HandleSendException(owner, exception, typedMessage) != null) { throw; } DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information); } finally { if (!flag && ((result == null) || result.CompletedSynchronously)) { message.Close(); } } } }
protected virtual IAsyncResult FloodMessageToNeighbors(MessageBuffer messageBuffer, TimeSpan timeout, AsyncCallback callback, object state, int index, MessageHeader hopHeader, IPeerNeighbor except, EventHandler OnMessageSentCallback) { Interlocked.Increment(ref this.messageSequence); FloodAsyncResult fresult = new FloodAsyncResult(this.neighborManager, timeout, callback, state); fresult.OnMessageSent += OnMessageSentCallback; foreach (IPeerNeighbor neighbor in this.Neighbors) { if (!neighbor.Equals(except) && PeerNeighborStateHelper.IsConnected(neighbor.State)) { Message message = messageBuffer.CreateMessage(); if (index != -1) { message.Headers.ReplaceAt(index, hopHeader); } if (PeerNeighborStateHelper.IsConnected(neighbor.State)) { this.BeginSendHelper(neighbor, timeout, message, fresult); } } } fresult.MarkEnd(true); return(fresult); }
protected virtual IAsyncResult FloodMessageToNeighbors(MessageBuffer messageBuffer, TimeSpan timeout, AsyncCallback callback, object state, int index, MessageHeader hopHeader, IPeerNeighbor except, EventHandler OnMessageSentCallback) { long temp = Interlocked.Increment(ref messageSequence); FloodAsyncResult fresult = new FloodAsyncResult(this.neighborManager, timeout, callback, state); fresult.OnMessageSent += OnMessageSentCallback; List <IPeerNeighbor> neighbors = this.Neighbors; foreach (IPeerNeighbor neighbor in neighbors) { if (neighbor.Equals(except)) { continue; } // Don't do anything if the neighbor is not connected if (PeerNeighborStateHelper.IsConnected(neighbor.State)) { Message fmessage = messageBuffer.CreateMessage(); if (index != -1) { fmessage.Headers.ReplaceAt(index, hopHeader); } // Don't do anything if the neighbor is not connected if (PeerNeighborStateHelper.IsConnected(neighbor.State)) { BeginSendHelper(neighbor, timeout, fmessage, fresult); } } } fresult.MarkEnd(true); return(fresult); }
void UtilityMessageSent(IAsyncResult result) { if (result == null || result.AsyncState == null) { return; } IPeerNeighbor host = this.owner; if (host == null || !PeerNeighborStateHelper.IsConnected(host.State)) { return; } if (result.CompletedSynchronously) { return; } AsyncUtilityState state = (AsyncUtilityState)result.AsyncState; Fx.Assert(state != null, "IAsyncResult.AsyncState does not contain AsyncUtilityState"); Message message = state.message; UtilityInfo umessage = state.info; bool fatal = false; if (!(umessage != null)) { throw Fx.AssertAndThrow("expecting a UtilityInfo message in the AsyncState!"); } try { host.EndSend(result); } catch (Exception e) { if (Fx.IsFatal(e)) { fatal = true; throw; } if (null != HandleSendException(host, e, umessage)) { throw; } DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); } finally { if (!fatal) { Fx.Assert(!result.CompletedSynchronously, "result.CompletedSynchronously"); message.Close(); } } EventHandler handler = UtilityInfoSent; if (handler != null) { handler(this, EventArgs.Empty); } }