本文整理汇总了C#中Node.SendMessageAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Node.SendMessageAsync方法的具体用法?C# Node.SendMessageAsync怎么用?C# Node.SendMessageAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node
的用法示例。
在下文中一共展示了Node.SendMessageAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AttachedNode_MessageReceived
void AttachedNode_MessageReceived(Node node, IncomingMessage message)
{
var getaddr = message.Message.Payload as GetAddrPayload;
if(getaddr != null)
{
node.SendMessageAsync(new AddrPayload(AddressManager.GetAddr().Take(1000).ToArray()));
}
var addr = message.Message.Payload as AddrPayload;
if(addr != null)
{
AddressManager.Add(addr.Addresses, node.RemoteSocketAddress);
}
}
示例2: AttachedNode_MessageReceived
void AttachedNode_MessageReceived(Node node, IncomingMessage message)
{
var filterload = message.Message.Payload as FilterLoadPayload;
if(filterload != null)
{
_Filter = filterload.Object;
}
var filteradd = message.Message.Payload as FilterAddPayload;
if(filteradd != null)
{
_Filter.Insert(filteradd.Data);
}
var getdata = message.Message.Payload as GetDataPayload;
if(getdata != null)
{
foreach(var inv in getdata.Inventory)
{
if(inv.Type == InventoryType.MSG_FILTERED_BLOCK && _Filter != null)
{
var merkle = new MerkleBlock(_Blocks[inv.Hash], _Filter);
AttachedNode.SendMessageAsync(new MerkleBlockPayload(merkle));
foreach(var tx in merkle.PartialMerkleTree.GetMatchedTransactions())
{
if(_Known.TryAdd(tx, tx))
{
AttachedNode.SendMessageAsync(new InvPayload(InventoryType.MSG_TX, tx));
}
}
}
var found = FindTransaction(inv.Hash);
if(inv.Type == InventoryType.MSG_TX && found != null)
AttachedNode.SendMessageAsync(new TxPayload(found));
}
}
var mempool = message.Message.Payload as MempoolPayload;
if(mempool != null)
{
foreach(var tx in _Builder.Mempool)
{
BroadcastCore(tx.Value);
}
}
var invs = message.Message.Payload as InvPayload;
if(invs != null)
{
node.SendMessageAsync(new GetDataPayload(invs.ToArray()));
}
var txPayload = message.Message.Payload as TxPayload;
if(txPayload != null)
{
if(!_ReceivedTransactions.TryAdd(txPayload.Object.GetHash(), txPayload.Object))
{
node.SendMessageAsync(new RejectPayload()
{
Hash = txPayload.Object.GetHash(),
Code = RejectCode.DUPLICATE,
Message = "tx"
});
}
else
{
foreach(var other in Nodes.Where(n => n != node))
{
other.SendMessageAsync(new InvPayload(txPayload.Object));
}
}
}
}
示例3: AttachedNode_MessageReceived
void AttachedNode_MessageReceived(Node node, IncomingMessage message)
{
if(!PingVersion())
return;
var ping = message.Message.Payload as PingPayload;
if(ping != null && Mode.HasFlag(PingPongMode.RespondPong))
{
node.SendMessageAsync(new PongPayload()
{
Nonce = ping.Nonce
});
}
var pong = message.Message.Payload as PongPayload;
if(pong != null &&
Mode.HasFlag(PingPongMode.SendPing) &&
_CurrentPing != null &&
_CurrentPing.Nonce == pong.Nonce)
{
Latency = DateTimeOffset.UtcNow - _DateSent;
ClearCurrentPing();
}
}
示例4: AttachedNode_MessageReceived
void AttachedNode_MessageReceived(Node node, IncomingMessage message)
{
TxPayload txPayload = message.Message.Payload as TxPayload;
if(txPayload != null)
{
Transaction tx;
var hash = txPayload.Object.GetHash();
if(_Wallet._BroadcastedTransaction.TryRemove(hash, out tx))
{
_Broadcasting.TryRemove(hash, out tx);
_Wallet.OnTransactionBroadcasted(tx, node);
}
}
RejectPayload reject = message.Message.Payload as RejectPayload;
if(reject != null)
{
Transaction tx;
if(_Broadcasting.TryRemove(reject.Hash, out tx))
{
_Wallet.OnTransactionRejected(tx, node);
}
}
GetDataPayload getData = message.Message.Payload as GetDataPayload;
if(getData != null)
{
foreach(var inventory in getData.Inventory.Where(i => i.Type == InventoryType.MSG_TX))
{
Transaction tx;
if(_Broadcasting.TryRemove(inventory.Hash, out tx))
node.SendMessageAsync(new TxPayload(tx));
}
}
}
示例5: AttachedNode_MessageReceived
void AttachedNode_MessageReceived(Node node, IncomingMessage message)
{
InvPayload invPayload = message.Message.Payload as InvPayload;
if(invPayload != null)
{
foreach(var hash in invPayload.Where(i => i.Type == InventoryType.MSG_TX).Select(i => i.Hash))
{
var tx = GetTransaction(hash, true);
if(tx != null)
tx.State = BroadcastState.Accepted;
Transaction unused;
if(_BroadcastHub.BroadcastedTransaction.TryRemove(hash, out unused))
{
_BroadcastHub.OnTransactionBroadcasted(tx.Transaction);
}
}
}
RejectPayload reject = message.Message.Payload as RejectPayload;
if(reject != null && reject.Message == "tx")
{
var tx = GetTransaction(reject.Hash, true);
if(tx != null)
tx.State = BroadcastState.Rejected;
Transaction tx2;
if(_BroadcastHub.BroadcastedTransaction.TryRemove(reject.Hash, out tx2))
{
_BroadcastHub.OnTransactionRejected(tx2, reject);
}
}
GetDataPayload getData = message.Message.Payload as GetDataPayload;
if(getData != null)
{
foreach(var inventory in getData.Inventory.Where(i => i.Type == InventoryType.MSG_TX))
{
var tx = GetTransaction(inventory.Hash, false);
if(tx != null)
{
tx.State = BroadcastState.Broadcasted;
var ping = new PingPayload();
tx.PingValue = ping.Nonce;
_PingToTransaction.TryAdd(tx.PingValue, tx);
node.SendMessageAsync(new TxPayload(tx.Transaction));
node.SendMessageAsync(ping);
}
}
}
PongPayload pong = message.Message.Payload as PongPayload;
if(pong != null)
{
var tx = GetTransaction(pong.Nonce, true);
if(tx != null)
{
tx.State = BroadcastState.Accepted;
Transaction unused;
if(_BroadcastHub.BroadcastedTransaction.TryRemove(tx.Transaction.GetHash(), out unused))
{
_BroadcastHub.OnTransactionBroadcasted(tx.Transaction);
}
}
}
}