Skip to content

Commit

Permalink
Use getSingleThreadListeningExecutor, cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
chimp1984 committed Oct 7, 2020
1 parent fcd3454 commit fc0082a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
13 changes: 5 additions & 8 deletions p2p/src/main/java/bisq/network/p2p/P2PService.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public void onTorNodeReady() {

if (!seedNodesAvailable) {
isBootstrapped = true;
// As we do not expect a updated data request response we start here listening
// As we do not expect a updated data request response we start here with addHashMapChangedListenerAndApply
addHashMapChangedListenerAndApply();
p2pServiceListeners.stream().forEach(P2PServiceListener::onNoSeedNodeAvailable);
}
Expand Down Expand Up @@ -351,7 +351,7 @@ public void onUpdatedDataReceived() {
if (!isBootstrapped) {
isBootstrapped = true;
// Only now we start listening and processing. The p2PDataStorage is our cache for data we have received
// so far.
// after the hidden service was ready.
addHashMapChangedListenerAndApply();
p2pServiceListeners.stream().forEach(P2PServiceListener::onUpdatedDataReceived);
p2PDataStorage.onBootstrapComplete();
Expand Down Expand Up @@ -458,7 +458,7 @@ private void processSingleMailboxEntry(Collection<ProtectedMailboxStorageEntry>
// We run the batch processing of all mailbox messages we have received at startup in a thread to not block the UI.
// For about 1000 messages decryption takes about 1 sec.
private void threadedBatchProcessMailboxEntries(Collection<ProtectedMailboxStorageEntry> protectedMailboxStorageEntries) {
ListeningExecutorService executor = Utilities.getSingleThreadExecutor("processMailboxEntry-" + new Random().nextInt(1000));
ListeningExecutorService executor = Utilities.getSingleThreadListeningExecutor("processMailboxEntry-" + new Random().nextInt(1000));
long ts = System.currentTimeMillis();
ListenableFuture<Set<Tuple2<ProtectedMailboxStorageEntry, DecryptedMessageWithPubKey>>> future = executor.submit(() -> {
var decryptedEntries = getDecryptedEntries(protectedMailboxStorageEntries);
Expand Down Expand Up @@ -557,7 +557,6 @@ private void doSendEncryptedDirectMessage(@NotNull NodeAddress peersNodeAddress,

// Prefix is not needed for direct messages but as old code is doing the verification we still need to
// send it if peer has not updated.
// TODO persist capability
PrefixedSealedAndSignedMessage sealedMsg = getPrefixedSealedAndSignedMessage(peersNodeAddress,
pubKeyRing,
message);
Expand Down Expand Up @@ -615,12 +614,10 @@ public void sendEncryptedMailboxMessage(NodeAddress peer, PubKeyRing peersPubKey
return;
}

checkNotNull(peer,
"PeerAddress must not be null (sendEncryptedMailboxMessage)");
checkNotNull(peer, "PeerAddress must not be null (sendEncryptedMailboxMessage)");
checkNotNull(networkNode.getNodeAddress(),
"My node address must not be null at sendEncryptedMailboxMessage");
checkArgument(!keyRing.getPubKeyRing().equals(peersPubKeyRing),
"We got own keyring instead of that from peer");
checkArgument(!keyRing.getPubKeyRing().equals(peersPubKeyRing), "We got own keyring instead of that from peer");

if (!isBootstrapped())
throw new NetworkNotReadyException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public final class PrefixedSealedAndSignedMessage extends NetworkEnvelope implem
private final NodeAddress senderNodeAddress;
private final SealedAndSigned sealedAndSigned;

// From v1.4.0 on that can be an empty byte array. We cannot use null as not updated nodes would get a nullPointer
// at protobuf serialisation.
// From v1.4.0 on addressPrefixHash can be an empty byte array.
// We cannot make it nullable as not updated nodes would get a nullPointer exception at protobuf serialisation.
private final byte[] addressPrefixHash;

private final String uid;
Expand Down Expand Up @@ -75,7 +75,8 @@ public protobuf.NetworkEnvelope toProtoNetworkEnvelope() {
.build();
}

public static PrefixedSealedAndSignedMessage fromProto(protobuf.PrefixedSealedAndSignedMessage proto, int messageVersion) {
public static PrefixedSealedAndSignedMessage fromProto(protobuf.PrefixedSealedAndSignedMessage proto,
int messageVersion) {
return new PrefixedSealedAndSignedMessage(NodeAddress.fromProto(proto.getNodeAddress()),
SealedAndSigned.fromProto(proto.getSealedAndSigned()),
proto.getAddressPrefixHash().toByteArray(),
Expand Down
1 change: 0 additions & 1 deletion p2p/src/main/java/bisq/network/p2p/network/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -911,5 +911,4 @@ private String getSenderNodeAddressAsString(NetworkEnvelope networkEnvelope) {
NodeAddress nodeAddress = getSenderNodeAddress(networkEnvelope);
return nodeAddress == null ? "null" : nodeAddress.getFullAddress();
}

}
2 changes: 1 addition & 1 deletion p2p/src/main/java/bisq/network/p2p/peers/PeerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public boolean peerHasCapability(NodeAddress peersNodeAddress, Capability capabi
.orElse(false);
}

// TODO persist Capabilities
// TODO get Capabilities from peers
public Optional<Capabilities> findPeersCapabilities(NodeAddress peersNodeAddress) {
return networkNode.getConfirmedConnections().stream()
.filter(c -> c.getPeersNodeAddressProperty().get() != null)
Expand Down

0 comments on commit fc0082a

Please sign in to comment.