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

Better peer sorting and updated initial diallng #2427

Merged
merged 2 commits into from
Apr 12, 2024

Conversation

islathehut
Copy link
Collaborator

Pull Request Checklist

  • I have linked this PR to a related GitHub issue.
  • I have added a description of the change (and Github issue number, if any) to the root CHANGELOG.md.

(Optional) Mobile checklist

Please ensure you completed the following checks if you did any changes to the mobile package:

  • I have run e2e tests for mobile
  • I have updated base screenshots for visual regression tests

@@ -517,7 +517,7 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
agent: this.socksProxyAgent,
localAddress: this.libp2pService.createLibp2pAddress(onionAddress, peerId.toString()),
targetPort: this.ports.libp2pHiddenService,
peers: peers ?? [],
peers: peers ? peers.slice(1) : [],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to avoid the self-dialing we normally see.

): string[] => {
peersAddresses = filterValidAddresses(peersAddresses)
const currentlyConnected = [...stats].filter(peer => peer.connectionTime === 0)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a peer connects we set the connectionTime to zero so peers with that value present should be currently connected (or connected the last time we were online). This means for invitation links the peers are more likely to be online and when we go offline, if we went offline recently, we're more likely to try connecting to online peers (this becomes less likely the longer a user is offline but that's true for connection time filtering, too).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be saving who we were last connected to, whenever we shut down, or periodically?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is something I also considered, you can give libp2p a datastore so it can persist the peer data it had on shutdown.

private processItem: (arg: T) => Promise<any>
private readonly logger = Logger(ProcessInChunksService.name)
constructor() {
super()
}

public init(data: T[], processItem: (arg: T) => Promise<any>, chunkSize: number = DEFAULT_CHUNK_SIZE) {
this.data = data
this.logger(`Initializing process-in-chunks.service with peers ${JSON.stringify(data, null, 2)}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to address this now, but eventually we want to sanitize addresses like onion addresses or peerid's from the logs.

): string[] => {
peersAddresses = filterValidAddresses(peersAddresses)
const currentlyConnected = [...stats].filter(peer => peer.connectionTime === 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be saving who we were last connected to, whenever we shut down, or periodically?

@islathehut islathehut merged commit 67b5c27 into develop Apr 12, 2024
15 of 19 checks passed
@@ -121,7 +122,7 @@ afterEach(async () => {
})

describe('Connections manager', () => {
it('saves peer stats when peer has been disconnected', async () => {
it.only('saves peer stats when peer has been disconnected', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only here in purpose?

islathehut pushed a commit that referenced this pull request Apr 12, 2024
* Better peer sorting and updated initial diallng

* Update tests
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

Successfully merging this pull request may close these issues.

3 participants