Skip to content

Commit

Permalink
fix(network): NET-1360 Reattempt handshakes if neighbor count is 0 an…
Browse files Browse the repository at this point in the history
…d contacts exist (#2786)

## Summary

Fix a problem with small streams (around 2 nodes) where if initial
handshakes fail the nodes never discover each other.
  • Loading branch information
juslesan authored Oct 14, 2024
1 parent ba26853 commit 9325a50
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setAbortableTimeout } from '@streamr/utils'
import { Logger, setAbortableTimeout } from '@streamr/utils'
import { NodeList } from '../NodeList'
import { DhtAddress } from '@streamr/dht'

Expand All @@ -15,6 +15,8 @@ interface FindNeighborsSessionOptions {
const INITIAL_WAIT = 100
const INTERVAL = 250

const logger = new Logger(module)

export class NeighborFinder {
private readonly abortController: AbortController
private readonly options: FindNeighborsSessionOptions
Expand All @@ -39,6 +41,9 @@ export class NeighborFinder {
if (this.options.neighbors.size() < this.options.minCount && newExcludes.length < uniqueContactCount) {
// TODO should we catch possible promise rejection?
setAbortableTimeout(() => this.findNeighbors(newExcludes), INTERVAL, this.abortController.signal)
} else if (this.options.neighbors.size() === 0 && uniqueContactCount > 0) {
logger.debug('No neighbors found yet contacts are available, restarting handshaking process')
setAbortableTimeout(() => this.findNeighbors([]), INTERVAL, this.abortController.signal)
} else {
this.running = false
}
Expand Down

0 comments on commit 9325a50

Please sign in to comment.