forked from Qortal/qortal
Only add an entry to directConnectionInfo if one with this peer-signature combination doesn't already exist.
This commit is contained in:
parent
0418c831e6
commit
76b8ba91dd
@ -483,7 +483,7 @@ public class ArbitraryDataFileListManager {
|
|||||||
|
|
||||||
// Keep track of the source peer, for direct connections
|
// Keep track of the source peer, for direct connections
|
||||||
if (arbitraryDataFileListMessage.getPeerAddress() != null) {
|
if (arbitraryDataFileListMessage.getPeerAddress() != null) {
|
||||||
ArbitraryDataFileManager.getInstance().directConnectionInfo.add(
|
ArbitraryDataFileManager.getInstance().addDirectConnectionInfoIfUnique(
|
||||||
new ArbitraryDirectConnectionInfo(signature, arbitraryDataFileListMessage.getPeerAddress(), hashes, now));
|
new ArbitraryDirectConnectionInfo(signature, arbitraryDataFileListMessage.getPeerAddress(), hashes, now));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public class ArbitraryDataFileManager extends Thread {
|
|||||||
/**
|
/**
|
||||||
* List to keep track of peers potentially available for direct connections, based on recent requests
|
* List to keep track of peers potentially available for direct connections, based on recent requests
|
||||||
*/
|
*/
|
||||||
public List<ArbitraryDirectConnectionInfo> directConnectionInfo = Collections.synchronizedList(new ArrayList<>());
|
private List<ArbitraryDirectConnectionInfo> directConnectionInfo = Collections.synchronizedList(new ArrayList<>());
|
||||||
|
|
||||||
|
|
||||||
public static int MAX_FILE_HASH_RESPONSES = 1000;
|
public static int MAX_FILE_HASH_RESPONSES = 1000;
|
||||||
@ -293,6 +293,23 @@ public class ArbitraryDataFileManager extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an ArbitraryDirectConnectionInfo item, but only if one with this peer-signature combination
|
||||||
|
* doesn't already exist.
|
||||||
|
* @param connectionInfo - the direct connection info to add
|
||||||
|
*/
|
||||||
|
public void addDirectConnectionInfoIfUnique(ArbitraryDirectConnectionInfo connectionInfo) {
|
||||||
|
boolean peerAlreadyExists;
|
||||||
|
synchronized (directConnectionInfo) {
|
||||||
|
peerAlreadyExists = directConnectionInfo.stream()
|
||||||
|
.anyMatch(i -> Arrays.equals(i.getSignature(), connectionInfo.getSignature())
|
||||||
|
&& Objects.equals(i.getPeerAddress(), connectionInfo.getPeerAddress()));
|
||||||
|
}
|
||||||
|
if (!peerAlreadyExists) {
|
||||||
|
directConnectionInfo.add(connectionInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void removeDirectConnectionInfo(ArbitraryDirectConnectionInfo connectionInfo) {
|
private void removeDirectConnectionInfo(ArbitraryDirectConnectionInfo connectionInfo) {
|
||||||
this.directConnectionInfo.remove(connectionInfo);
|
this.directConnectionInfo.remove(connectionInfo);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user