Fix issue with not republishing data

This commit is contained in:
Manfred Karrer 2015-12-27 21:27:07 +01:00
parent 485d0e8fd6
commit a4b959df22
3 changed files with 19 additions and 8 deletions

View File

@ -132,6 +132,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
// peer group
peerGroup = new PeerGroup(networkNode);
peerGroup.setSeedNodeAddresses(seedNodeAddresses);
peerGroup.addAuthenticationListener(this);
// P2P network data storage
@ -274,7 +275,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
private void authenticateSeedNode() {
Log.traceCall();
checkNotNull(connectedSeedNode != null, "connectedSeedNode must not be null");
peerGroup.authenticateToSeedNode(connectedSeedNode, seedNodeAddresses);
peerGroup.authenticateToSeedNode(connectedSeedNode);
}

View File

@ -37,8 +37,8 @@ public class PeerGroup implements MessageListener, ConnectionListener {
public static void setMaxConnectionsLowPriority(int maxConnectionsLowPriority) {
MAX_CONNECTIONS_LOW_PRIORITY = maxConnectionsLowPriority;
MAX_CONNECTIONS_NORMAL_PRIORITY = MAX_CONNECTIONS_LOW_PRIORITY + 4;
MAX_CONNECTIONS_HIGH_PRIORITY = MAX_CONNECTIONS_NORMAL_PRIORITY + 4;
MAX_CONNECTIONS_NORMAL_PRIORITY = MAX_CONNECTIONS_LOW_PRIORITY + 6;
MAX_CONNECTIONS_HIGH_PRIORITY = MAX_CONNECTIONS_NORMAL_PRIORITY + 6;
}
static {
@ -273,11 +273,16 @@ public class PeerGroup implements MessageListener, ConnectionListener {
// Authentication to seed node
///////////////////////////////////////////////////////////////////////////////////////////
public void authenticateToSeedNode(Address peerAddress, Set<Address> seedNodeAddresses) {
Log.traceCall();
public void setSeedNodeAddresses(Set<Address> seedNodeAddresses) {
seedNodeAddressesOptional = Optional.of(seedNodeAddresses);
}
public void authenticateToSeedNode(Address peerAddress) {
Log.traceCall();
checkArgument(seedNodeAddressesOptional.isPresent(),
"seedNodeAddresses must be set before calling authenticateToSeedNode");
remainingSeedNodes.remove(peerAddress);
remainingSeedNodes.addAll(seedNodeAddresses);
remainingSeedNodes.addAll(seedNodeAddressesOptional.get());
authenticateToFirstSeedNode(peerAddress);
}
@ -797,7 +802,6 @@ public class PeerGroup implements MessageListener, ConnectionListener {
}
private Optional<ReportedPeer> getAndRemoveNotAuthenticatingReportedPeer() {
Log.traceCall();
Optional<ReportedPeer> reportedPeer = Optional.empty();
List<ReportedPeer> list = new ArrayList<>(reportedPeers);
authenticationHandshakes.keySet().stream().forEach(e -> list.remove(new ReportedPeer(e)));
@ -815,7 +819,6 @@ public class PeerGroup implements MessageListener, ConnectionListener {
private Optional<Address> getAndRemoveNotAuthenticatingSeedNode() {
Log.traceCall();
Optional<Address> seedNode = Optional.empty();
authenticationHandshakes.keySet().stream().forEach(e -> remainingSeedNodes.remove(e));
authenticatedPeers.keySet().stream().forEach(e -> remainingSeedNodes.remove(e));

View File

@ -165,6 +165,13 @@ public class P2PDataStorage implements MessageListener {
if (result) {
map.put(hashOfPayload, protectedData);
// Republished data have a larger sequence number. We set the rePublish flag to enable broadcasting
// even we had the data with the old seq nr. already
if (sequenceNumberMap.containsKey(hashOfPayload) &&
protectedData.sequenceNumber > sequenceNumberMap.get(hashOfPayload))
rePublish = true;
sequenceNumberMap.put(hashOfPayload, protectedData.sequenceNumber);
storage.queueUpForSave(sequenceNumberMap);