/// <summary> /// Pushes a single item to a peer, and combines /// the result locally /// </summary> /// <param name="peer"> /// The peer to push to /// </param> /// <param name="item"> /// The item to push /// </param> private void Push(Peer peer, Item item) { lock(item) { var output = item; if (peer.CallCombine(item, out output)) this.db.Combine(output, out output); else item.Contagion /= 2; } }
/// <summary> /// Handles a peer communication exception, /// bubbling the exception up to any configured /// event handlers /// </summary> /// <param name="peer"> /// The peer raising the exception /// </param> /// <param name="e"> /// The communication exception /// </param> private void HandleException(Peer peer, Exception e) { if (this.OnPeerException != null) this.OnPeerException(peer, e); }
/// <summary> /// Handles peer communication exceptions, /// eagerly removing failed peers from the list /// </summary> /// <param name="peer"> /// The peer causing the failure /// </param> /// <param name="e"> /// The exception that occurred /// </param> private void HandlePeerException(Peer peer, Exception e) { if (peer.ID != this.parentID) this.peers.Remove(peer.ID); }
/// <summary> /// Creates a new peer instance /// </summary> /// <param name="id"> /// The peer's node identifier /// </param> /// <returns> /// The new peer instance /// </returns> public Peer Create(Uri id) { Peer peer = new Peer(id); if (this.OnPeerException != null) peer.OnException += HandleException; return peer; }