[bisq-network/bisq] Remove address prefix for mailbox messages (#4609)

sqrrm notifications at github.com
Thu Oct 8 12:52:13 UTC 2020


@sqrrm commented on this pull request.

I think we should think about `Optional<>` as a very short stream and use in the same way we use streams. It flows nicely using `ifPresent`, `orElse` and `flatMap` rather than checking `isPresent` and then treating it as a value.

>          Optional<Peer> reportedPeerOptional = reportedPeersClone.stream()
                 .filter(e -> e.getNodeAddress().equals(nodeAddress)).findAny();
         if (reportedPeerOptional.isPresent()) {
             Peer reportedPeer = reportedPeerOptional.get();
             removeReportedPeer(reportedPeer);
-            return reportedPeer;
-        } else {
-            return null;
         }

Easier way
```
        reportedPeersClone.stream()
                .filter(e -> e.getNodeAddress().equals(nodeAddress))
                .findAny()
                .ifPresent(this::removeReportedPeer);
```

> +        if (connection.getPeersNodeAddressOptional().isPresent()) {
+            findPeer(connection.getPeersNodeAddressOptional().get())
+                    .ifPresent(Peer::onConnection);

```suggestion
        connection.getPeersNodeAddressOptional().flatMap(this::findPeer).ifPresent(Peer::onConnection);
```

> +        if (peerManager.isPeerBanned(closeConnectionReason, connection) &&
+                connection.getPeersNodeAddressOptional().isPresent())
             seedNodeAddresses.remove(connection.getPeersNodeAddressOptional().get());

```suggestion
        if (peerManager.isPeerBanned(closeConnectionReason, connection))
            connection.getPeersNodeAddressOptional().ifPresent(seedNodeAddresses::remove);
```

>      ///////////////////////////////////////////////////////////////////////////////////////////
 
     private boolean removePersistedPeer(Peer persistedPeer) {
-        if (persistedPeers.contains(persistedPeer)) {
-            persistedPeers.remove(persistedPeer);
-            peerList.setAll(persistedPeers);
-            persistenceManager.requestPersistence();
+        if (getPersistedPeers().contains(persistedPeer)) {
+            //getPersistedPeers().remove(persistedPeer);

I don't understand why this line is commented out. Seems the peer is not removed as it should now.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/bisq-network/bisq/pull/4609#pullrequestreview-504713019
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20201008/e7f86f1e/attachment.html>


More information about the bisq-github mailing list