Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Commit

Permalink
implements new netcode
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-moser committed Mar 29, 2019
1 parent 77dbb5a commit 107f77a
Show file tree
Hide file tree
Showing 60 changed files with 3,320 additions and 2,540 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ material under section 10.

You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
occurring solely as a consequence of using neighbor-to-neighbor transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@
<scope>compile</scope>
</dependency>

<dependency>
<groupId>net.openhft</groupId>
<artifactId>zero-allocation-hashing</artifactId>
<version>0.8</version>
</dependency>

<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
Expand Down
82 changes: 39 additions & 43 deletions src/main/java/com/iota/iri/Iota.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import com.iota.iri.conf.TipSelConfig;
import com.iota.iri.controllers.TipsViewModel;
import com.iota.iri.controllers.TransactionViewModel;
import com.iota.iri.network.Node;
import com.iota.iri.network.TransactionRequester;
import com.iota.iri.network.UDPReceiver;
import com.iota.iri.network.NeighborRouter;
import com.iota.iri.network.impl.TransactionRequesterWorkerImpl;
import com.iota.iri.network.replicator.Replicator;
import com.iota.iri.network.protocol.pipeline.TxPipeline;
import com.iota.iri.service.TipsSolidifier;
import com.iota.iri.service.ledger.impl.LedgerServiceImpl;
import com.iota.iri.service.milestone.impl.*;
Expand Down Expand Up @@ -36,35 +35,33 @@
import org.slf4j.LoggerFactory;

/**
*
* The main class of IRI. This will propagate transactions into and throughout the network.
* This data is stored as a {@link Tangle}, a form of a Directed acyclic graph.
* All incoming data will be stored in one or more implementations of {@link PersistenceProvider}.
*
* <p>
* During initialization, all the Providers can be set to rescan or revalidate their transactions.
* After initialization, an asynchronous process has started which will process inbound and outbound transactions.
* Each full node should be peered with 7-9 other full nodes (neighbors) to function optimally.
* During initialization, all the Providers can be set to rescan or revalidate their transactions.
* After initialization, an asynchronous process has started which will process inbound and outbound transactions.
* Each full node should be peered with 7-9 other full nodes (neighbors) to function optimally.
* </p>
* <p>
* If this node has no Neighbors defined, no data is transferred.
* However, if the node has Neighbors, but no Internet connection,
* synchronization will continue after Internet connection is established.
* Any transactions sent to this node in its local network will then be processed.
* This makes IRI able to run partially offline if an already existing database exists on this node.
* If this node has no Neighbors defined, no data is transferred.
* However, if the node has Neighbors, but no Internet connection,
* synchronization will continue after Internet connection is established.
* Any transactions sent to this node in its local network will then be processed.
* This makes IRI able to run partially offline if an already existing database exists on this node.
* </p>
* <p>
* Validation of a transaction is the process by which other devices choose the transaction.
* This is done via a {@link TipSelector} algorithm, after which the transaction performs
* the necessary proof-of-work in order to cast their vote of confirmation/approval upon those tips. <br/>
*
* As many other transactions repeat this process on top of each other,
* validation of the transaction in question slowly builds up enough verifications.
* Eventually this will reach a minimum acceptable verification threshold.
* This threshold is determined by the recipient of the transaction.
* When this minimum threshold is reached, the transaction is "confirmed".
* Validation of a transaction is the process by which other devices choose the transaction.
* This is done via a {@link TipSelector} algorithm, after which the transaction performs
* the necessary proof-of-work in order to cast their vote of confirmation/approval upon those tips. <br/>
* <p>
* As many other transactions repeat this process on top of each other,
* validation of the transaction in question slowly builds up enough verifications.
* Eventually this will reach a minimum acceptable verification threshold.
* This threshold is determined by the recipient of the transaction.
* When this minimum threshold is reached, the transaction is "confirmed".
* </p>
*
*/
public class Iota {
private static final Logger log = LoggerFactory.getLogger(Iota.class);
Expand Down Expand Up @@ -101,9 +98,8 @@ public class Iota {
public final TransactionValidator transactionValidator;
public final TipsSolidifier tipsSolidifier;
public final TransactionRequester transactionRequester;
public final Node node;
public final UDPReceiver udpReceiver;
public final Replicator replicator;
public final TxPipeline txPipeline;
public final NeighborRouter neighborRouter;
public final IotaConfig configuration;
public final TipsViewModel tipsViewModel;
public final MessageQ messageQ;
Expand All @@ -114,8 +110,8 @@ public class Iota {
*
* @param configuration Information about how this node will be configured.
* @throws TransactionPruningException If the TransactionPruner could not restore its state.
* @throws SnapshotException If the Snapshot fails to initialize.
* This can happen if the snapshot signature is invalid or the file cannot be read.
* @throws SnapshotException If the Snapshot fails to initialize.
* This can happen if the snapshot signature is invalid or the file cannot be read.
*/
public Iota(IotaConfig configuration) throws TransactionPruningException, SnapshotException, SpentAddressesException {
this.configuration = configuration;
Expand All @@ -126,17 +122,19 @@ public Iota(IotaConfig configuration) throws TransactionPruningException, Snapsh
snapshotProvider = new SnapshotProviderImpl();
snapshotService = new SnapshotServiceImpl();
localSnapshotManager = configuration.getLocalSnapshotsEnabled()
? new LocalSnapshotManagerImpl()
: null;
? new LocalSnapshotManagerImpl()
: null;
milestoneService = new MilestoneServiceImpl();
latestMilestoneTracker = new LatestMilestoneTrackerImpl();
latestSolidMilestoneTracker = new LatestSolidMilestoneTrackerImpl();
seenMilestonesRetriever = new SeenMilestonesRetrieverImpl();
milestoneSolidifier = new MilestoneSolidifierImpl();
transactionPruner = configuration.getLocalSnapshotsEnabled() && configuration.getLocalSnapshotsPruningEnabled()
? new AsyncTransactionPruner()
: null;
? new AsyncTransactionPruner()
: null;
transactionRequesterWorker = new TransactionRequesterWorkerImpl();
neighborRouter = new NeighborRouter();
txPipeline = new TxPipeline();

// legacy code
bundleValidator = new BundleValidator();
Expand All @@ -145,10 +143,6 @@ public Iota(IotaConfig configuration) throws TransactionPruningException, Snapsh
tipsViewModel = new TipsViewModel();
transactionRequester = new TransactionRequester(tangle, snapshotProvider, messageQ);
transactionValidator = new TransactionValidator(tangle, snapshotProvider, tipsViewModel, transactionRequester);
node = new Node(tangle, snapshotProvider, transactionValidator, transactionRequester, tipsViewModel,
latestMilestoneTracker, messageQ, configuration);
replicator = new Replicator(node, configuration);
udpReceiver = new UDPReceiver(node, configuration);
tipsSolidifier = new TipsSolidifier(tangle, transactionValidator, tipsViewModel, configuration);
tipsSelector = createTipSelector(configuration);

Expand All @@ -167,7 +161,7 @@ public void init() throws Exception {
initializeTangle();
tangle.init();

if (configuration.isRescanDb()){
if (configuration.isRescanDb()) {
rescanDb();
}

Expand All @@ -180,9 +174,10 @@ public void init() throws Exception {
transactionValidator.init(configuration.isTestnet(), configuration.getMwm());
tipsSolidifier.init();
transactionRequester.init(configuration.getpRemoveRequest());
udpReceiver.init();
replicator.init();
node.init();

txPipeline.start();
Thread gossipThread = new Thread(neighborRouter);
gossipThread.start();

latestMilestoneTracker.start();
latestSolidMilestoneTracker.start();
Expand Down Expand Up @@ -220,7 +215,10 @@ private void injectDependencies() throws SnapshotException, TransactionPruningEx
if (transactionPruner != null) {
transactionPruner.init(tangle, snapshotProvider, spentAddressesService, tipsViewModel, configuration);
}
transactionRequesterWorker.init(tangle, transactionRequester, tipsViewModel, node);
transactionRequesterWorker.init(tangle, transactionRequester, tipsViewModel, neighborRouter);
neighborRouter.init(configuration, tangle, transactionRequester, latestMilestoneTracker, txPipeline);
txPipeline.init(neighborRouter, configuration, transactionValidator, tangle, snapshotProvider, transactionRequester,
tipsViewModel, latestMilestoneTracker);
}

private void rescanDb() throws Exception {
Expand Down Expand Up @@ -268,9 +266,7 @@ public void shutdown() throws Exception {
}

tipsSolidifier.shutdown();
node.shutdown();
udpReceiver.shutdown();
replicator.shutdown();
neighborRouter.shutdown();
transactionValidator.shutdown();
tangle.shutdown();
messageQ.shutdown();
Expand Down
Loading

0 comments on commit 107f77a

Please sign in to comment.