use of org.tron.common.overlay.message.Message in project java-tron by tronprotocol.
the class Wallet method broadcastTransaction.
/**
* Broadcast a transaction.
*/
public boolean broadcastTransaction(Transaction signaturedTransaction) {
TransactionCapsule trx = new TransactionCapsule(signaturedTransaction);
try {
if (trx.validateSignature()) {
Message message = new TransactionMessage(signaturedTransaction);
dbManager.pushTransactions(trx);
p2pnode.broadcast(message);
return true;
}
} catch (ValidateSignatureException e) {
logger.debug(e.getMessage(), e);
} catch (ContractValidateException e) {
logger.debug(e.getMessage(), e);
} catch (ContractExeException e) {
logger.debug(e.getMessage(), e);
} catch (Exception e) {
logger.debug(e.getMessage(), e);
}
return false;
}
use of org.tron.common.overlay.message.Message in project java-tron by tronprotocol.
the class NodeImpl method processAdvBlock.
private void processAdvBlock(PeerConnection peer, BlockCapsule block) {
// TODO: lack the complete flow.
if (!freshBlockId.contains(block.getBlockId())) {
try {
LinkedList<Sha256Hash> trxIds = del.handleBlock(block, false);
freshBlockId.offer(block.getBlockId());
trxIds.forEach(trxId -> advObjToFetch.remove(trxId));
// TODO:save message cache again.
getActivePeer().stream().filter(p -> p.getAdvObjSpreadToUs().containsKey(block.getBlockId())).forEach(p -> {
p.setHeadBlockWeBothHave(block.getBlockId());
p.setHeadBlockTimeWeBothHave(block.getTimeStamp());
});
getActivePeer().forEach(p -> p.cleanInvGarbage());
// rebroadcast
broadcast(new BlockMessage(block));
} catch (BadBlockException e) {
badAdvObj.put(block.getBlockId(), System.currentTimeMillis());
} catch (UnLinkedBlockException e) {
// reSync
startSyncWithPeer(peer);
}
}
}
use of org.tron.common.overlay.message.Message in project java-tron by tronprotocol.
the class NodeImpl method onHandleFetchDataMessage.
private void onHandleFetchDataMessage(PeerConnection peer, FetchInvDataMessage fetchInvDataMsg) {
logger.info("on handle fetch block message");
MessageTypes type = fetchInvDataMsg.getInvMessageType();
// TODO:maybe can use message cache here
final BlockCapsule[] blocks = { del.getGenesisBlock() };
// get data and send it one by one
fetchInvDataMsg.getHashList().forEach(hash -> {
if (del.contain(hash, type)) {
Message msg = del.getData(hash, type);
if (type.equals(MessageTypes.BLOCK)) {
blocks[0] = ((BlockMessage) msg).getBlockCapsule();
}
peer.sendMessage(msg);
} else {
peer.sendMessage(new ItemNotFound());
}
});
if (blocks[0] != null) {
peer.setHeadBlockWeBothHave(blocks[0].getBlockId());
peer.setHeadBlockTimeWeBothHave(blocks[0].getTimeStamp());
}
}
Aggregations