Skip to content
This repository was archived by the owner on Aug 23, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@
<version>1.3</version>
</dependency>

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

</dependencies>

<build>
Expand Down
21 changes: 8 additions & 13 deletions src/main/java/com/iota/iri/network/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
import com.iota.iri.service.milestone.LatestMilestoneTracker;
import com.iota.iri.service.snapshot.SnapshotProvider;
import com.iota.iri.storage.Tangle;
import net.openhft.hashing.LongHashFunction;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.*;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.*;
import java.util.concurrent.*;
Expand Down Expand Up @@ -75,7 +73,8 @@ public class Node {
private static final SecureRandom rnd = new SecureRandom();


private FIFOCache<ByteBuffer, Hash> recentSeenBytes;
private FIFOCache<Long, Hash> recentSeenBytes;
private LongHashFunction recentSeenBytesHashFunction;

private static AtomicLong recentSeenBytesMissCount = new AtomicLong(0L);
private static AtomicLong recentSeenBytesHitCount = new AtomicLong(0L);
Expand Down Expand Up @@ -127,6 +126,7 @@ public void init() throws Exception {

BROADCAST_QUEUE_SIZE = RECV_QUEUE_SIZE = REPLY_QUEUE_SIZE = configuration.getqSizeNode();
recentSeenBytes = new FIFOCache<>(configuration.getCacheSizeBytes(), configuration.getpDropCacheEntry());
recentSeenBytesHashFunction = LongHashFunction.xx();

parseNeighborsConfig();

Expand Down Expand Up @@ -293,7 +293,7 @@ public void preProcessReceivedData(byte[] receivedData, SocketAddress senderAddr
try {

//Transaction bytes
ByteBuffer digest = getBytesDigest(receivedData);
long digest = getBytesDigest(receivedData);

//check if cached
synchronized (recentSeenBytes) {
Expand All @@ -314,9 +314,6 @@ public void preProcessReceivedData(byte[] receivedData, SocketAddress senderAddr
addReceivedDataToReceiveQueue(receivedTransactionViewModel, neighbor);

}

} catch (NoSuchAlgorithmException e) {
log.error("MessageDigest: " + e);
} catch (final TransactionValidator.StaleTimestampException e) {
log.debug(e.getMessage());
try {
Expand Down Expand Up @@ -516,7 +513,7 @@ public void replyToRequest(Hash requestedHash, Neighbor neighbor) {
try {
sendPacket(sendingPacket, transactionViewModel, neighbor);

ByteBuffer digest = getBytesDigest(transactionViewModel.getBytes());
long digest = getBytesDigest(transactionViewModel.getBytes());
synchronized (recentSeenBytes) {
recentSeenBytes.put(digest, transactionViewModel.getHash());
}
Expand Down Expand Up @@ -767,10 +764,8 @@ public void shutdown() throws InterruptedException {
executor.awaitTermination(6, TimeUnit.SECONDS);
}

private ByteBuffer getBytesDigest(byte[] receivedData) throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.update(receivedData, 0, TransactionViewModel.SIZE);
return ByteBuffer.wrap(digest.digest());
private long getBytesDigest(byte[] receivedData) {
return recentSeenBytesHashFunction.hashBytes(receivedData);
}

// helpers methods
Expand Down