-
Notifications
You must be signed in to change notification settings - Fork 90
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
Fix/1982 #2051
Conversation
) { | ||
super() | ||
} | ||
|
||
private dialPeer = async (peerAddress: string) => { | ||
if (this.dialedPeers.has(peerAddress)) { | ||
console.log(`Peer ${peerAddress} already dialed, not dialing`) // TODO: remove log | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work with min/max connections? Once a peer has been dialed, are they never dialed again? Would that mean we might run out of peers to dial if enough peers disconnect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every dialed peer is added to libp2p's internal address book. Autodialer checks connections every X minutes. Technically (according to code) if number of connections falls below set minConnections (e.g everyone disconnect from us) autodialer should look up peers in libp2p peerStore and try to open connections again.
dialTimeout: 120_000, | ||
maxParallelDials: 10, | ||
autoDial: true, // It's a default but let's set it to have explicit information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea!
packages/common/src/sortPeers.ts
Outdated
@@ -9,6 +9,9 @@ This is the very simple algorithm for evaluating the most wanted peers. | |||
4. We end up with mix of last seen and most uptime descending array of peers, the it is enchanced to libp2p address. | |||
*/ | |||
export const sortPeers = (peersAddresses: string[], stats: NetworkStats[]): string[] => { | |||
peersAddresses = peersAddresses.filter(add => | |||
add.match(/^\/dns4\/[a-z0-9]{56}.onion\/tcp\/80\/ws\/p2p\/[a-zA-Z0-9]{46}$/g) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this filter helpful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2027 (comment) the second part of my comment is connected with that. Because of this we have invalid addresses (only peerIds) saved in localdb. This is added to filter them out.
packages/common/src/sortPeers.ts
Outdated
@@ -9,6 +9,9 @@ This is the very simple algorithm for evaluating the most wanted peers. | |||
4. We end up with mix of last seen and most uptime descending array of peers, the it is enchanced to libp2p address. | |||
*/ | |||
export const sortPeers = (peersAddresses: string[], stats: NetworkStats[]): string[] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets' change a name to filterAndSortPeers or something
} | ||
|
||
public async processOneItem() { | ||
if (!this.isActive) return | ||
// if (!this.isActive) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover?
Pull Request Checklist
(Optional) Mobile checklist
Please ensure you completed the following checks if you did any changes to the mobile package: