use of org.aion.p2p.impl1.P2pMgr in project aion by aionnetwork.
the class AionHub method initializeHub.
private void initializeHub(CfgAion _cfgAion, AionBlockchainImpl _blockchain, PendingTxCallback pendingTxCallback, NetworkBestBlockCallback networkBestBlockCallback, TransactionBroadcastCallback transactionBroadcastCallback, boolean forTest) {
this.cfg = _cfgAion;
// load event manager before init blockchain instance
loadEventMgr(forTest);
registerBlockEvents();
// the current unit tests require passing in a different repository instance
// during normal execution we need to instantiate the repository
// for this reason we pass in null when a new instance is required
this.blockchain = _blockchain == null ? new AionBlockchainImpl(cfg, eventMgr, forTest) : _blockchain;
try {
this.blockchain.load(cfg.getGenesis(), genLOG);
} catch (IllegalStateException e) {
genLOG.error("Found database corruption, please re-import your database by using ./aion.sh -n <network> --redo-import", e);
System.exit(SystemExitCodes.DATABASE_CORRUPTION);
}
this.startingBlock = this.blockchain.getBestBlock();
if (blockchain.forkUtility.is040ForkActive(blockchain.getBestBlock().getNumber())) {
TransactionTypeRule.allowAVMContractTransaction();
}
this.mempool = new AionPendingStateImpl(blockchain, cfg.getConsensus().getEnergyStrategy().getUpperBound(), cfg.getTx().getTxPendingTimeout(), cfg.getTx().getPoolBackup(), cfg.getTx().isSeedMode(), cfg.getTx().getPoolDump(), pendingTxCallback, networkBestBlockCallback, transactionBroadcastCallback, forTest);
if (cfg.getTx().isSeedMode()) {
genLOG.info("Seed node mode enabled!");
}
/*
* p2p hook up start sync mgr needs to be initialed after loadBlockchain()
* method
*/
CfgNetP2p cfgNetP2p = this.cfg.getNet().getP2p();
this.chainId = this.cfg.getNet().getId();
// there are two p2p implementation , now just point to impl1.
this.p2pMgr = new P2pMgr(AionLoggerFactory.getLogger(LogEnum.P2P.name()), AionLoggerFactory.getLogger(LogEnum.SURVEY.name()), this.chainId, Version.KERNEL_VERSION, this.cfg.getId(), cfgNetP2p.getIp(), cfgNetP2p.getPort(), this.cfg.getNet().getNodes(), cfgNetP2p.getDiscover(), cfgNetP2p.getMaxTempNodes(), cfgNetP2p.getMaxActiveNodes(), cfgNetP2p.getBootlistSyncOnly(), cfgNetP2p.getErrorTolerance());
this.syncMgr = new SyncMgr(blockchain, p2pMgr, eventMgr, cfg.getSync().getShowStatus(), cfg.getSync().getShowStatistics(), cfg.getNet().getP2p().getMaxActiveNodes());
ChainConfiguration chainConfig = new ChainConfiguration();
this.propHandler = new BlockPropagationHandler(1024, this.blockchain, syncMgr.getSyncStats(), p2pMgr, chainConfig.createBlockHeaderValidator(), cfg.getNet().getP2p().inSyncOnlyMode(), apiVersion, mempool);
registerCallback();
if (!forTest) {
p2pMgr.run();
}
if (!AionBlockchainImpl.enableFullSyncCheck) {
this.pow = new AionPoW();
this.pow.init(blockchain, mempool, eventMgr, syncMgr);
}
SelfNodeStatusCallback callback = new SelfNodeStatusCallback(p2pMgr);
callback.updateBlockStatus(blockchain.getBestBlock().getNumber(), blockchain.getBestBlock().getHash(), blockchain.getTotalDifficulty());
blockchain.setNodeStatusCallback(callback);
blockchain.setBestBlockImportCallback(new BestBlockImportCallback(mempool));
}
use of org.aion.p2p.impl1.P2pMgr in project aion by aionnetwork.
the class P2pMgrTest method newTwoNodeSetup.
public Map.Entry<P2pMgr, P2pMgr> newTwoNodeSetup() {
String ip = "127.0.0.1";
String id1 = UUID.randomUUID().toString();
String id2 = UUID.randomUUID().toString();
int port1 = 30303;
int port2 = 30304;
// we want node 1 to connect to node 2
String[] nodes = new String[] { "p2p://" + id2 + "@" + ip + ":" + port2 };
// to guarantee they don't receive the same port
System.out.println("connector on: " + TestUtilities.formatAddr(id1, ip, port1));
P2pMgr connector = new P2pMgr(p2pLOG, surveyLog, 0, "", id1, ip, port1, nodes, false, 128, 128, false, 50);
System.out.println("receiver on: " + TestUtilities.formatAddr(id2, ip, port2));
P2pMgr receiver = new P2pMgr(p2pLOG, surveyLog, 0, "", id2, ip, port2, new String[0], false, 128, 128, false, 50);
return Map.entry(connector, receiver);
}
use of org.aion.p2p.impl1.P2pMgr in project aion by aionnetwork.
the class P2pMgrTest method testIgnoreSameNodeIdAsSelf.
@Test
public void testIgnoreSameNodeIdAsSelf() {
String[] nodes = new String[] { "p2p://" + nodeId1 + "@" + ip2 + ":" + port2 };
P2pMgr p2p = new P2pMgr(p2pLOG, surveyLog, 0, "", nodeId1, ip1, port1, nodes, false, 128, 128, false, 50);
assertEquals(p2p.getTempNodesCount(), 0);
}
use of org.aion.p2p.impl1.P2pMgr in project aion by aionnetwork.
the class P2pMgrTest method testTempNodes.
@Test
public void testTempNodes() {
// the ip and port are not used in the id hash calculation, therefore the UUID must differ
String[] nodes = new String[] { "p2p://" + UUID.randomUUID() + "@" + ip1 + ":" + port2, "p2p://" + UUID.randomUUID() + "@" + ip2 + ":" + port1, "p2p://" + UUID.randomUUID() + "@" + ip2 + ":" + port2 };
P2pMgr p2p = new P2pMgr(p2pLOG, surveyLog, 0, "", nodeId1, ip1, port1, nodes, false, 128, 128, false, 50);
assertEquals(3, p2p.getTempNodesCount());
}
use of org.aion.p2p.impl1.P2pMgr in project aion by aionnetwork.
the class LastThousands method test.
@Ignore
@Test
public void test() throws InterruptedException {
String nodeId = UUID.randomUUID().toString();
String ip = "127.0.0.1";
int port = 30303;
int max = 1000;
int maxPort = port + max;
String[] testerP2p = new String[] { "p2p://" + nodeId + "@" + ip + ":" + port };
P2pMgr tester = new P2pMgr(p2pLOG, surveyLog, 0, "", nodeId, ip, port, new String[] {}, false, max, max, false, 50);
List<P2pMgr> examiners = new ArrayList<>();
for (int i = port + 1; i <= maxPort; i++) {
if (checkPort(ip, i)) {
System.out.println("examiner " + i);
P2pMgr examiner = new P2pMgr(p2pLOG, surveyLog, 0, "", UUID.randomUUID().toString(), ip, i, testerP2p, false, max, max, false, 50);
examiners.add(examiner);
}
}
System.out.println("examiners " + examiners.size());
tester.run();
for (P2pMgr examiner : examiners) {
examiner.run();
}
Thread.sleep(3000);
for (P2pMgr examiner : examiners) {
assertEquals(1, examiner.getActiveNodes().size());
}
for (P2pMgr examiner : examiners) {
assertEquals(max, tester.getActiveNodes().size());
}
tester.shutdown();
for (P2pMgr examiner : examiners) {
examiner.shutdown();
}
}
Aggregations