Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove address prefix #4610

Merged
merged 35 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9404e8f
Add NO_ADDRESS_PRE_FIX capability.
chimp1984 Oct 7, 2020
e73a4b4
Cleanups
chimp1984 Oct 7, 2020
6f7dfcf
Make onRemoved default in interface
chimp1984 Oct 7, 2020
40f9cfb
Add methods for getting peers capabilities
chimp1984 Oct 7, 2020
8aec306
Remove verification for address prefix
chimp1984 Oct 7, 2020
9821dd6
Clear capabilitiesListeners at shutdown
chimp1984 Oct 7, 2020
17974f3
Refactor: move SupportedCapabilitiesMessage handling code out to a me…
chimp1984 Oct 7, 2020
1c07be0
Use only node address for equals and hashcode
chimp1984 Oct 7, 2020
bf659a1
Pass supportedCapabilities to PeerManager. Not further processed yet,…
chimp1984 Oct 7, 2020
2523c2e
Use getSingleThreadListeningExecutor, cleanups
chimp1984 Oct 7, 2020
765f9ea
Apply code inspection suggestions
chimp1984 Oct 7, 2020
186a9d6
Add findPeersCapabilities method
chimp1984 Oct 7, 2020
7af16d7
Add getDateAsLong method, add setter for capabilities
chimp1984 Oct 7, 2020
25bfe2d
Add findPeersCapabilities method
chimp1984 Oct 7, 2020
2552675
Replace persistedPeers with peerList
chimp1984 Oct 7, 2020
bf674ea
Use getPersistedPeers for peerList.getList() calls
chimp1984 Oct 7, 2020
cf06930
Update common/src/main/java/bisq/common/app/Capability.java
chimp1984 Oct 7, 2020
983f610
Update p2p/src/main/java/bisq/network/p2p/network/Connection.java
chimp1984 Oct 7, 2020
31e7e26
Fix incorrect handling of decryptedEntries size
chimp1984 Oct 7, 2020
4575516
Refactor: Return early
chimp1984 Oct 7, 2020
ed960ab
Refactor: Rearrange code, remove unused methods, renamings (no functi…
chimp1984 Oct 7, 2020
0686079
Refactor: Rename method
chimp1984 Oct 7, 2020
31ce5cc
Use connection.getPeersNodeAddressOptional().isPresent() instead of c…
chimp1984 Oct 7, 2020
cfda0af
Fix tests
chimp1984 Oct 8, 2020
351db88
Use a hashset instead of list to avoid duplicates. Filter out my own …
chimp1984 Oct 8, 2020
2fd0104
Decrease failedConnectionAttempts onConnection
chimp1984 Oct 8, 2020
f36a173
Fix incorrect collection used in == 1 check
chimp1984 Oct 8, 2020
b748bff
Add isPresent check
chimp1984 Oct 8, 2020
c7f23e8
Do not log size as we don't want to call potentially expensive toProt…
chimp1984 Oct 8, 2020
f53290b
Copy peers in a new hashset to avoid concurrent modification exc at s…
chimp1984 Oct 8, 2020
447235c
Dont reassign param
chimp1984 Oct 8, 2020
c88bc1c
Use custom class MailboxItem instead of Tuple
chimp1984 Oct 8, 2020
c8feef1
Apply code review suggestions
chimp1984 Oct 8, 2020
4f685f8
When updating the capability from a reported peer we check if the rep…
chimp1984 Oct 8, 2020
6e3fdbc
Apply codacy suggestions
chimp1984 Oct 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions common/src/main/java/bisq/common/app/Capabilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public boolean containsAll(Capability... capabilities) {
return this.capabilities.containsAll(Arrays.asList(capabilities));
}

public boolean contains(Capability capability) {
return this.capabilities.contains(capability);
}

public boolean isEmpty() {
return capabilities.isEmpty();
}
Expand Down Expand Up @@ -180,4 +184,18 @@ public String prettyPrint() {
public int size() {
return capabilities.size();
}

// We return true if our capabilities have less capabilities than the parameter value
public boolean hasLess(Capabilities other) {
return findHighestCapability(this) < findHighestCapability(other);
}

// We use the sum of all capabilities. Alternatively we could use the highest entry.
// Neither would support removal of past capabilities, a use case we never had so far and which might have
// backward compatibility issues, so we should treat capabilities as an append-only data structure.
public int findHighestCapability(Capabilities capabilities) {
return (int) capabilities.capabilities.stream()
.mapToLong(e -> (long) e.ordinal())
.sum();
}
}
3 changes: 2 additions & 1 deletion common/src/main/java/bisq/common/app/Capability.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ public enum Capability {
SIGNED_ACCOUNT_AGE_WITNESS, // Supports the signed account age witness feature
MEDIATION, // Supports mediation feature
REFUND_AGENT, // Supports refund agents
TRADE_STATISTICS_HASH_UPDATE // We changed the hash method in 1.2.0 and that requires update to 1.2.2 for handling it correctly, otherwise the seed nodes have to process too much data.
TRADE_STATISTICS_HASH_UPDATE, // We changed the hash method in 1.2.0 and that requires update to 1.2.2 for handling it correctly, otherwise the seed nodes have to process too much data.
NO_ADDRESS_PRE_FIX // At 1.4.0 we removed the prefix filter for mailbox messages. If a peer has that capability we do not sent the prefix.
}
42 changes: 42 additions & 0 deletions common/src/test/java/bisq/common/app/CapabilitiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.junit.Test;

import static bisq.common.app.Capability.DAO_FULL_NODE;
import static bisq.common.app.Capability.SEED_NODE;
import static bisq.common.app.Capability.TRADE_STATISTICS;
import static bisq.common.app.Capability.TRADE_STATISTICS_2;
Expand All @@ -40,6 +41,47 @@ public void testNoCapabilitiesAvailable() {
assertFalse(DUT.containsAll(new Capabilities(SEED_NODE)));
}

@Test
public void testHasLess() {
assertTrue(new Capabilities().hasLess(new Capabilities(SEED_NODE)));
assertFalse(new Capabilities().hasLess(new Capabilities()));
assertFalse(new Capabilities(SEED_NODE).hasLess(new Capabilities()));
assertTrue(new Capabilities(SEED_NODE).hasLess(new Capabilities(DAO_FULL_NODE)));
assertFalse(new Capabilities(DAO_FULL_NODE).hasLess(new Capabilities(SEED_NODE)));

Capabilities all = new Capabilities(
TRADE_STATISTICS,
TRADE_STATISTICS_2,
Capability.ACCOUNT_AGE_WITNESS,
Capability.ACK_MSG,
Capability.PROPOSAL,
Capability.BLIND_VOTE,
Capability.DAO_STATE,
Capability.BUNDLE_OF_ENVELOPES,
Capability.MEDIATION,
Capability.SIGNED_ACCOUNT_AGE_WITNESS,
Capability.REFUND_AGENT,
Capability.TRADE_STATISTICS_HASH_UPDATE
);
Capabilities other = new Capabilities(
TRADE_STATISTICS,
TRADE_STATISTICS_2,
Capability.ACCOUNT_AGE_WITNESS,
Capability.ACK_MSG,
Capability.PROPOSAL,
Capability.BLIND_VOTE,
Capability.DAO_STATE,
Capability.BUNDLE_OF_ENVELOPES,
Capability.MEDIATION,
Capability.SIGNED_ACCOUNT_AGE_WITNESS,
Capability.REFUND_AGENT,
Capability.TRADE_STATISTICS_HASH_UPDATE,
Capability.NO_ADDRESS_PRE_FIX
);

assertTrue(all.hasLess(other));
}

@Test
public void testO() {
Capabilities DUT = new Capabilities(TRADE_STATISTICS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private void connectToNextNode() {
private void connectToAnyFullNode() {
Capabilities required = new Capabilities(Capability.DAO_FULL_NODE);

List<Peer> list = peerManager.getLivePeers(null).stream()
List<Peer> list = peerManager.getLivePeers().stream()
.filter(peer -> peer.getCapabilities().containsAll(required))
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void onConnection(Connection connection) {
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
closeHandler(connection);

if (peerManager.isNodeBanned(closeConnectionReason, connection)) {
if (peerManager.isPeerBanned(closeConnectionReason, connection)) {
connection.getPeersNodeAddressOptional().ifPresent(nodeAddress -> {
seedNodeAddresses.remove(nodeAddress);
removeFromRequestBlocksHandlerMap(nodeAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ static void setSupportedCapabilities(Config config) {
Capability.MEDIATION,
Capability.SIGNED_ACCOUNT_AGE_WITNESS,
Capability.REFUND_AGENT,
Capability.TRADE_STATISTICS_HASH_UPDATE
Capability.TRADE_STATISTICS_HASH_UPDATE,
Capability.NO_ADDRESS_PRE_FIX
);

if (config.daoActivated) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ public void updateMap() {

observableMap.putAll(filtered);
observableMap.values().forEach(this::addAcceptedDisputeAgentToUser);

log.info("Available disputeAgents: {}", observableMap.keySet());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import bisq.network.p2p.DecryptedMessageWithPubKey;
import bisq.network.p2p.MailboxMessage;
import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.P2PService;
import bisq.network.p2p.SendMailboxMessageListener;
import bisq.network.p2p.messaging.DecryptedMailboxListener;

Expand Down Expand Up @@ -77,8 +78,8 @@ protected void onInitialized() {
processModel.getP2PService().addDecryptedDirectMessageListener(this);
}
processModel.getP2PService().addDecryptedMailboxListener(this);
processModel.getP2PService().getMailboxMap().values()
.stream().map(e -> e.second)
processModel.getP2PService().getMailboxItemsByUid().values()
.stream().map(P2PService.MailboxItem::getDecryptedMessageWithPubKey)
.forEach(this::handleDecryptedMessageWithPubKey);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected void execute() {
networkProtoResolver);
DefaultSeedNodeRepository seedNodeRepository = new DefaultSeedNodeRepository(config);
PeerManager peerManager = new PeerManager(networkNode, seedNodeRepository, new ClockWatcher(),
maxConnections, new PersistenceManager<>(storageDir, persistenceProtoResolver, corruptedStorageFileHandler));
new PersistenceManager<>(storageDir, persistenceProtoResolver, corruptedStorageFileHandler), maxConnections);

// init file storage
peerManager.readPersisted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@

public interface DecryptedDirectMessageListener {

void onDirectMessage(DecryptedMessageWithPubKey decryptedMessageWithPubKey, @SuppressWarnings("UnusedParameters") NodeAddress peerNodeAddress);
void onDirectMessage(DecryptedMessageWithPubKey decryptedMessageWithPubKey, NodeAddress peerNodeAddress);
}
Loading