public bool RegisterMessage(DhtMessage message, DhtNode node) { switch (message.CommandType) { case CommandType.UnKnow: return(false); case CommandType.Ping: case CommandType.Find_Node: case CommandType.Announce_Peer: message.MessageId = TypeMapTransactionId[message.CommandType]; return(true); case CommandType.Get_Peers: break; default: return(false); } if (RegisterGetPeersMessage(message.Get <byte[]>("info_hash"), node, out var msgId)) { message.MessageId = msgId; return(true); } return(false); }
public async Task <bool> RegisterMessageAsync(DhtMessage message, DhtNode node) { switch (message.CommandType) { case CommandType.UnKnow: return(false); case CommandType.Ping: case CommandType.Find_Node: case CommandType.Announce_Peer: message.MessageId = TypeMapTransactionId[message.CommandType]; return(true); case CommandType.Get_Peers: break; default: return(false); } var result = await RegisterGetPeersMessageAsync(message.Get <byte[]>("info_hash"), node); if (result.IsOk) { message.MessageId = result.MsgId; return(true); } return(false); }
public bool RequireRegisteredInfo(DhtMessage message, DhtNode node) { if (TransactionIdMapType.ContainsKey(message.MessageId)) { message.CommandType = TransactionIdMapType[message.MessageId]; return(true); } message.CommandType = CommandType.Get_Peers; if (RequireGetPeersRegisteredInfo(message.MessageId, node, out var infoHash)) { message.Data["info_hash"] = infoHash; return(true); } return(false); }
public async Task <bool> RequireRegisteredInfoAsync(DhtMessage message, DhtNode node) { if (TransactionIdMapType.ContainsKey(message.MessageId)) { message.CommandType = TransactionIdMapType[message.MessageId]; return(true); } message.CommandType = CommandType.Get_Peers; var result = await RequireGetPeersRegisteredInfoAsync(message.MessageId, node); if (result.IsOk) { message.Data["info_hash"] = result.InfoHash; return(true); } return(false); }