Skip to content

Commit

Permalink
fix: increase providers validity to 48 hours (#2801)
Browse files Browse the repository at this point in the history
Increase provider record validity duration based on spec as discussed in #2785

---------

Co-authored-by: Daniel N <[email protected]>
Co-authored-by: Alex Potsides <[email protected]>
  • Loading branch information
3 people authored Nov 16, 2024
1 parent 3098232 commit 4329553
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
14 changes: 5 additions & 9 deletions packages/kad-dht/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
// MaxRecordAge specifies the maximum time that any node will hold onto a record
// from the time its received. This does not apply to any other forms of validity that
// the record may contain.
// For example, a record may contain an ipns entry with an EOL saying its valid
// until the year 2020 (a great time in the future). For that record to stick around
// it must be rebroadcasted more frequently than once every 'MaxRecordAge'

import { KEEP_ALIVE } from '@libp2p/interface'

export const second = 1000
Expand All @@ -15,12 +8,15 @@ export const MAX_RECORD_AGE = 36 * hour

export const PROTOCOL = '/ipfs/kad/1.0.0'

export const PROVIDERS_VALIDITY = 24 * hour
/**
* @see https://github.com/libp2p/specs/blob/master/kad-dht/README.md#content-provider-advertisement-and-discovery
*/
export const PROVIDERS_VALIDITY = 48 * hour

export const PROVIDERS_CLEANUP_INTERVAL = hour

// Re-run the provide operation when the expiry of our provider records is within this amount
export const REPROVIDE_THRESHOLD = 2 * hour
export const REPROVIDE_THRESHOLD = 24 * hour

// How many reprovide operations to run at once
export const REPROVIDE_CONCURRENCY = 10
Expand Down
18 changes: 9 additions & 9 deletions packages/kad-dht/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,15 @@ export interface ProvidersInit {
*/
cacheSize?: number
/**
* How often invalid records are cleaned. (in seconds)
* How often invalid records are cleaned in seconds
*
* @default 5400
* @default 5_400
*/
cleanupInterval?: number
/**
* How long is a provider valid for. (in seconds)
* How long is a provider valid for in seconds
*
* @default 86400
* @default 86_400
*/
provideValidity?: number
}
Expand All @@ -370,28 +370,28 @@ export interface ReProvideInit {
/**
* How long to let the re-provide queue grow
*
* @default 16384
* @default 16_384
*/
maxQueueSize?: number

/**
* How long before the record expiry to re-provide in ms
*
* @default 7200000
* @default 86_400_000 (24 hours)
*/
threshold?: number

/**
* How often to check which records need reproviding in ms
* How often to check which records need re-providing in ms
*
* @default 3600000
* @default 3_600_000 (1 hour)
*/
interval?: number

/**
* How long provider records are valid for in ms
*
* @default 86400000
* @default 172_800_000 (48 hours)
*/
validity?: number
}
Expand Down

0 comments on commit 4329553

Please sign in to comment.