void IPeerServiceContract.LinkUtility(UtilityInfo utilityInfo) { IPeerNeighbor neighbor = this.GetNeighbor(); if (neighbor != null) { this.flooder.ProcessLinkUtility(neighbor, utilityInfo); } }
public static void ProcessLinkUtility(IPeerNeighbor neighbor, UtilityInfo umessage) { UtilityExtension extension = neighbor.Extensions.Find <UtilityExtension>(); if (extension != null) { extension.ProcessLinkUtility(umessage.Useful, umessage.Total); } }
static public void ProcessLinkUtility(IPeerNeighbor neighbor, UtilityInfo umessage) { Fx.Assert(neighbor != null, "Neighbor must have a value"); UtilityExtension ext = neighbor.Extensions.Find <UtilityExtension>(); if (ext != null) { ext.ProcessLinkUtility(umessage.Useful, umessage.Total); } }
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 Exception HandleSendException(IPeerNeighbor host, Exception e, UtilityInfo umessage) { if ((!(e is ObjectDisposedException) && !(e is TimeoutException)) && !(e is CommunicationException)) { return(e); } if (e.InnerException is QuotaExceededException) { throw Fx.AssertAndThrow("insufficient quota for sending messages!"); } lock (this.ThisLock) { this.inTotal += umessage.Total; this.inUseful += umessage.Useful; } return(null); }
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(); } } } }
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); } }
public AsyncUtilityState(Message message, UtilityInfo info) { this.message = message; this.info = info; }