-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rosenet-node, rosenet-relay): limit relays count for nodes
Connecting to a lot of relays can significantly affect pubsub network traffic. For 40 nodes, 3 relay per node seems a good balance between traffic, delivery and performance. This number may change in the future, though. Also prevent relays from broadcasting their addresses over discovery network. If not disable, it totally negates the point of limiting relays count to 3.
- Loading branch information
1 parent
d7f66e7
commit c1e3008
Showing
3 changed files
with
23 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Sample `size` elements from `array` randomly | ||
* @param array | ||
* @param size | ||
*/ | ||
const sample = <T>(array: T[], size: number): T[] => | ||
array | ||
.map((value) => ({ value, sort: Math.random() })) | ||
.sort((a, b) => a.sort - b.sort) | ||
.map(({ value }) => value) | ||
.slice(0, size); | ||
|
||
export default sample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters