Skip to content

Commit

Permalink
Fixed issue causing frequent disconnects (found by szisti)
Browse files Browse the repository at this point in the history
When sending or requesting more than 1000 online accounts, peers would be disconnected with an EOF or connection reset error due to an intentional null response. This response has been removed and it will instead now only send the first 1000 accounts, which prevents the disconnections from occurring.

In theory, these accounts should be in a different order on each node, so the 1000 limit should still result in a fairly even propagation of accounts. However, we may want to consider increasing this limit, to maximise the propagation speed.

Thanks to szisti for tracking this one down.
  • Loading branch information
archived-2 committed Jun 11, 2021
1 parent a43993e commit e3923b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.qortal.data.network.OnlineAccountData;
import org.qortal.transform.Transformer;
Expand All @@ -25,7 +26,7 @@ public GetOnlineAccountsMessage(List<OnlineAccountData> onlineAccounts) {
private GetOnlineAccountsMessage(int id, List<OnlineAccountData> onlineAccounts) {
super(id, MessageType.GET_ONLINE_ACCOUNTS);

this.onlineAccounts = onlineAccounts;
this.onlineAccounts = onlineAccounts.stream().limit(MAX_ACCOUNT_COUNT).collect(Collectors.toList());
}

public List<OnlineAccountData> getOnlineAccounts() {
Expand All @@ -35,12 +36,9 @@ public List<OnlineAccountData> getOnlineAccounts() {
public static Message fromByteBuffer(int id, ByteBuffer bytes) throws UnsupportedEncodingException {
final int accountCount = bytes.getInt();

if (accountCount > MAX_ACCOUNT_COUNT)
return null;

List<OnlineAccountData> onlineAccounts = new ArrayList<>(accountCount);

for (int i = 0; i < accountCount; ++i) {
for (int i = 0; i < Math.min(MAX_ACCOUNT_COUNT, accountCount); ++i) {
long timestamp = bytes.getLong();

byte[] publicKey = new byte[Transformer.PUBLIC_KEY_LENGTH];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.qortal.data.network.OnlineAccountData;
import org.qortal.transform.Transformer;
Expand All @@ -25,7 +26,7 @@ public OnlineAccountsMessage(List<OnlineAccountData> onlineAccounts) {
private OnlineAccountsMessage(int id, List<OnlineAccountData> onlineAccounts) {
super(id, MessageType.ONLINE_ACCOUNTS);

this.onlineAccounts = onlineAccounts;
this.onlineAccounts = onlineAccounts.stream().limit(MAX_ACCOUNT_COUNT).collect(Collectors.toList());
}

public List<OnlineAccountData> getOnlineAccounts() {
Expand All @@ -35,12 +36,9 @@ public List<OnlineAccountData> getOnlineAccounts() {
public static Message fromByteBuffer(int id, ByteBuffer bytes) throws UnsupportedEncodingException {
final int accountCount = bytes.getInt();

if (accountCount > MAX_ACCOUNT_COUNT)
return null;

List<OnlineAccountData> onlineAccounts = new ArrayList<>(accountCount);

for (int i = 0; i < accountCount; ++i) {
for (int i = 0; i < Math.min(MAX_ACCOUNT_COUNT, accountCount); ++i) {
long timestamp = bytes.getLong();

byte[] signature = new byte[Transformer.SIGNATURE_LENGTH];
Expand Down

0 comments on commit e3923b7

Please sign in to comment.