This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Converts to typescript - Only named exports - No more CJS, only ESM - Runs tests on all supported environments - Adds auto-publish - Adds dependabot BREAKING CHANGE: switch to named exports, ESM only
- Loading branch information
1 parent
a20824a
commit 5064483
Showing
22 changed files
with
390 additions
and
603 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict' | ||
|
||
/** @type {import('aegir').PartialOptions} */ | ||
module.exports = { | ||
build: { | ||
bundlesizeMax: '143KB', | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
'use strict' | ||
|
||
const Benchmark = require('benchmark') | ||
const crypto = require('crypto') | ||
|
File renamed without changes.
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 was deleted.
Oops, something went wrong.
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,63 @@ | ||
interface SimpleTimeCacheOpts { | ||
validityMs: number | ||
} | ||
|
||
interface CacheValue<T> { | ||
value: T | ||
validUntilMs: number | ||
} | ||
|
||
/** | ||
* This is similar to https://github.com/daviddias/time-cache/blob/master/src/index.js | ||
* for our own need, we don't use lodash throttle to improve performance. | ||
* This gives 4x - 5x performance gain compared to npm TimeCache | ||
*/ | ||
export class SimpleTimeCache<T> { | ||
private entries: Map<string, CacheValue<T>> | ||
private readonly validityMs: number | ||
private lastPruneTime = 0 | ||
|
||
constructor (options: SimpleTimeCacheOpts) { | ||
this.entries = new Map() | ||
this.validityMs = options.validityMs | ||
|
||
// allow negative validityMs so that this does not cache anything, spec test compliance.spec.js | ||
// sends duplicate messages and expect peer to receive all. Application likely uses positive validityMs | ||
} | ||
|
||
put (key: string, value: T): void { | ||
this.entries.set(key, { value, validUntilMs: Date.now() + this.validityMs }) | ||
this.prune() | ||
} | ||
|
||
prune (): void { | ||
const now = Date.now() | ||
if (now - this.lastPruneTime < 200) { | ||
return | ||
} | ||
this.lastPruneTime = now | ||
|
||
for (const [k, v] of this.entries.entries()) { | ||
if (v.validUntilMs < now) { | ||
this.entries.delete(k) | ||
} else { | ||
// sort by insertion order | ||
break | ||
} | ||
} | ||
} | ||
|
||
has (key: string): boolean { | ||
return this.entries.has(key) | ||
} | ||
|
||
get (key: string): T | undefined { | ||
const value = this.entries.get(key) | ||
return (value != null && value.validUntilMs >= Date.now()) ? value.value : undefined | ||
} | ||
|
||
clear (): void { | ||
this.entries = new Map() | ||
this.lastPruneTime = 0 | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
import { logger } from '@libp2p/logger' | ||
|
||
export const log = logger('libp2p:floodsub') | ||
|
||
export const multicodec = '/floodsub/1.0.0' |
Oops, something went wrong.