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

limit the frequency of findnode messages #91

Open
zeusoo001 opened this issue Feb 28, 2025 · 4 comments
Open

limit the frequency of findnode messages #91

zeusoo001 opened this issue Feb 28, 2025 · 4 comments

Comments

@zeusoo001
Copy link

Background

Currently, the neighbor discovery algorithm runs once every 7.2 seconds (KademliaOptions.DISCOVER_CYCLE), and each time it sends a findnode message to 24 different nodes. So theoretically, a findnode message can be sent to the same node at most once within 7.2s. However, there is no frequency limit when processing findnode messages. The code is as follows:

public void handleFindNode(FindNodeMessage msg) {
  List<Node> closest = kadService.getTable().getClosestNodes(msg.getTargetId());
  sendNeighbours(closest, msg.getTimestamp());
}

To avoid unnecessary network bandwidth consumption, the frequency of findnode messages needs to be limited.

Rationale

To avoid network bandwidth consumption caused by high-frequency neighbor requests, it is necessary to limit the frequency of neighbor requests. The minimum time request interval for each channel can be set to KademliaOptions.DISCOVER_CYCLE / 2. The findnode message is replied to at most once within the minimum time interval.

@jakamobiii
Copy link

It is indeed necessary to do a strict check of the message. How to implement this function?

@zeusoo001
Copy link
Author

@jakamobiii Add a field to record the time when the findnode message is received.

private long rcvFindNodeMsgTime;

If the next request time is less than the threshold (which can be set to KademliaOptions.DISCOVER_CYCLE / 2), no neighbors message will be responded to.

  1. Check whether the time of receiving the findnode message exceeds the threshold, and return directly if it exceeds.
  2. Update the value of rcvFindNodeMsgTime.
public void handleFindNode(FindNodeMessage msg) {
  long now = System.currentTimeMillis();
  if (now - rcvFindNodeMsgTime < threshold) {
    return;
  }
  rcvFindNodeMsgTime = now;
  List<Node> closest = kadService.getTable().getClosestNodes(msg.getTargetId());
  sendNeighbours(closest, msg.getTimestamp());
}

@jakamobiii
Copy link

Good, which version will support this feature?

@zeusoo001
Copy link
Author

@jakamobiii The next version v2.2.6 will support this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants