void AttachedNode_StateChanged(Protocol.Node node, Protocol.NodeState oldState) { if (node.State == Protocol.NodeState.HandShaked) { SetBloomFilter(); } }
void AttachedNode_MessageReceived(Protocol.Node node, Protocol.IncomingMessage message) { var merkleBlock = message.Message.Payload as MerkleBlockPayload; if (merkleBlock != null) { if (!CheckFPRate(merkleBlock)) { return; } foreach (var txId in merkleBlock.Object.PartialMerkleTree.GetMatchedTransactions()) { _TransactionsToBlock.AddOrUpdate(txId, merkleBlock.Object, (k, v) => merkleBlock.Object); var tx = _Tracker.GetKnownTransaction(txId); if (tx != null) { Notify(tx, merkleBlock.Object); } } var h = merkleBlock.Object.Header.GetHash(); uint256 unused; if (_InFlight.TryRemove(h, out unused)) { if (_InFlight.Count == 0) { UpdateCurrentProgress(h); StartScan(unused); } } } var pong = message.Message.Payload as PongPayload; if (pong != null) { var ping = _RunningPing; if (ping != null && pong.Nonce == ping.Nonce) { _RunningPing = null; _FilterState = SPV.FilterState.Loaded; foreach (var item in _OnFilterLoaded) { item(); } _OnFilterLoaded = new ConcurrentBag <Action>(); } } var notfound = message.Message.Payload as NotFoundPayload; if (notfound != null) { foreach (var txid in notfound) { uint256 unusued; if (_InFlight.TryRemove(txid.Hash, out unusued)) { if (_InFlight.Count == 0) { StartScan(null); } } } } var invs = message.Message.Payload as InvPayload; if (invs != null) { foreach (var inv in invs) { if ((inv.Type & InventoryType.MSG_BLOCK) != 0) { node.SendMessageAsync(new GetDataPayload(new InventoryVector(InventoryType.MSG_FILTERED_BLOCK, inv.Hash))); } if ((inv.Type & InventoryType.MSG_TX) != 0) { node.SendMessageAsync(new GetDataPayload(inv)); } } } var txPayload = message.Message.Payload as TxPayload; if (txPayload != null) { var tx = txPayload.Object; MerkleBlock blk; var h = tx.GetHash(); _TransactionsToBlock.TryGetValue(h, out blk); Notify(tx, blk); } }
void AttachedNode_MessageReceived(Protocol.Node node, Protocol.IncomingMessage message) { var merkleBlock = message.Message.Payload as MerkleBlockPayload; if (merkleBlock != null) { foreach (var txId in merkleBlock.Object.PartialMerkleTree.GetMatchedTransactions()) { _TransactionsToBlock.AddOrUpdate(txId, merkleBlock.Object, (k, v) => merkleBlock.Object); var tx = _Tracker.GetKnownTransaction(txId); if (tx != null) { Notify(tx, merkleBlock.Object); } } var h = merkleBlock.Object.Header.GetHash(); uint256 unused; if (_InFlight.TryRemove(h, out unused)) { if (_InFlight.Count == 0) { _LastSeen = h; var chained = _Chain.GetBlock(h); _CurrentProgress = chained == null ? _CurrentProgress : chained.GetLocator(); StartScan(unused); } } } var pong = message.Message.Payload as PongPayload; if (pong != null) { var ping = _RunningPing; if (ping != null && pong.Nonce == ping.Nonce) { _RunningPing = null; if (_PlannedScan) { _PlannedScan = false; StartScan(null); } } } var notfound = message.Message.Payload as NotFoundPayload; if (notfound != null) { foreach (var txid in notfound) { uint256 unusued; if (_InFlight.TryRemove(txid.Hash, out unusued)) { if (_InFlight.Count == 0) { StartScan(null); } } } } var invs = message.Message.Payload as InvPayload; if (invs != null) { foreach (var inv in invs) { if (inv.Type == InventoryType.MSG_BLOCK) { node.SendMessageAsync(new GetDataPayload(new InventoryVector(InventoryType.MSG_FILTERED_BLOCK, inv.Hash))); } if (inv.Type == InventoryType.MSG_TX) { node.SendMessageAsync(new GetDataPayload(inv)); } } } var txPayload = message.Message.Payload as TxPayload; if (txPayload != null) { var tx = txPayload.Object; MerkleBlock blk; var h = tx.GetHash(); _TransactionsToBlock.TryGetValue(h, out blk); Notify(tx, blk); } }