Refactoring

This commit is contained in:
chimp1984 2020-08-24 00:37:14 -05:00
parent badc872533
commit c4932829fe
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3
5 changed files with 12 additions and 7 deletions

View File

@ -156,7 +156,7 @@ public abstract class StateNetworkService<Msg extends NewStateHashMessage,
public void broadcastMyStateHash(StH myStateHash) {
NewStateHashMessage newStateHashMessage = getNewStateHashMessage(myStateHash);
broadcaster.broadcast(newStateHashMessage, networkNode.getNodeAddress(), null);
broadcaster.broadcast(newStateHashMessage, networkNode.getNodeAddress());
}
public void requestHashes(int fromHeight, String peersAddress) {

View File

@ -105,7 +105,7 @@ public class FullNodeNetworkService implements MessageListener, PeerManager.List
log.info("Publish new block at height={} and block hash={}", block.getHeight(), block.getHash());
RawBlock rawBlock = RawBlock.fromBlock(block);
NewBlockBroadcastMessage newBlockBroadcastMessage = new NewBlockBroadcastMessage(rawBlock);
broadcaster.broadcast(newBlockBroadcastMessage, networkNode.getNodeAddress(), null);
broadcaster.broadcast(newBlockBroadcastMessage, networkNode.getNodeAddress());
}

View File

@ -238,7 +238,7 @@ public class LiteNodeNetworkService implements MessageListener, ConnectionListen
log.debug("We received a new message from peer {} and broadcast it to our peers. extBlockId={}",
connection.getPeersNodeAddressOptional().orElse(null), extBlockId);
receivedBlocks.add(extBlockId);
broadcaster.broadcast(newBlockBroadcastMessage, connection.getPeersNodeAddressOptional().orElse(null), null);
broadcaster.broadcast(newBlockBroadcastMessage, connection.getPeersNodeAddressOptional().orElse(null));
listeners.forEach(listener -> listener.onNewBlockReceived(newBlockBroadcastMessage));
} else {
log.debug("We had that message already and do not further broadcast it. extBlockId={}", extBlockId);

View File

@ -54,6 +54,11 @@ public class Broadcaster implements BroadcastHandler.ResultHandler {
// API
///////////////////////////////////////////////////////////////////////////////////////////
public void broadcast(BroadcastMessage message,
@Nullable NodeAddress sender) {
broadcast(message, sender, null);
}
public void broadcast(BroadcastMessage message,
@Nullable NodeAddress sender,
@Nullable BroadcastHandler.Listener listener) {

View File

@ -529,7 +529,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
// Broadcast the payload if requested by caller
if (allowBroadcast)
broadcaster.broadcast(new AddPersistableNetworkPayloadMessage(payload), sender, null);
broadcaster.broadcast(new AddPersistableNetworkPayloadMessage(payload), sender);
return true;
}
@ -675,7 +675,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
sequenceNumberMapStorage.queueUpForSave(SequenceNumberMap.clone(sequenceNumberMap), 1000);
// Always broadcast refreshes
broadcaster.broadcast(refreshTTLMessage, sender, null);
broadcaster.broadcast(refreshTTLMessage, sender);
return true;
}
@ -725,9 +725,9 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
printData("after remove");
if (protectedStorageEntry instanceof ProtectedMailboxStorageEntry) {
broadcaster.broadcast(new RemoveMailboxDataMessage((ProtectedMailboxStorageEntry) protectedStorageEntry), sender, null);
broadcaster.broadcast(new RemoveMailboxDataMessage((ProtectedMailboxStorageEntry) protectedStorageEntry), sender);
} else {
broadcaster.broadcast(new RemoveDataMessage(protectedStorageEntry), sender, null);
broadcaster.broadcast(new RemoveDataMessage(protectedStorageEntry), sender);
}
return true;