Skip to content

Commit f395258

Browse files
committed
Refactor WHITE_LIST to WHITELIST
1 parent aac55a1 commit f395258

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

ts/constants.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -223,18 +223,18 @@ export const ERR_TOPIC_VALIDATOR_IGNORE = 'ERR_TOPIC_VALIDATOR_IGNORE'
223223

224224
/**
225225
* If peer score is better than this, we accept messages from this peer
226-
* within ACCEPT_FROM_WHITE_LIST_DURATION_MS from the last time computing score.
226+
* within ACCEPT_FROM_WHITELIST_DURATION_MS from the last time computing score.
227227
**/
228-
export const ACCEPT_FROM_WHITE_LIST_THRESHOLD_SCORE = 0
228+
export const ACCEPT_FROM_WHITELIST_THRESHOLD_SCORE = 0
229229

230230
/**
231-
* If peer score >= ACCEPT_FROM_WHITE_LIST_THRESHOLD_SCORE, accept up to this
231+
* If peer score >= ACCEPT_FROM_WHITELIST_THRESHOLD_SCORE, accept up to this
232232
* number of messages from that peer.
233233
*/
234-
export const ACCEPT_FROM_WHITE_LIST_MAX_MESSAGES = 128
234+
export const ACCEPT_FROM_WHITELIST_MAX_MESSAGES = 128
235235

236236
/**
237-
* If peer score >= ACCEPT_FROM_WHITE_LIST_THRESHOLD_SCORE, accept messages from
237+
* If peer score >= ACCEPT_FROM_WHITELIST_THRESHOLD_SCORE, accept messages from
238238
* this peer up to this time duration.
239239
*/
240-
export const ACCEPT_FROM_WHITE_LIST_DURATION_MS = 1000
240+
export const ACCEPT_FROM_WHITELIST_DURATION_MS = 1000

ts/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import PeerId = require('peer-id')
1717
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1818
// @ts-ignore
1919
import Envelope = require('libp2p/src/record/envelope')
20-
import { ACCEPT_FROM_WHITE_LIST_DURATION_MS, ACCEPT_FROM_WHITE_LIST_MAX_MESSAGES, ACCEPT_FROM_WHITE_LIST_THRESHOLD_SCORE } from './constants'
20+
import { ACCEPT_FROM_WHITELIST_DURATION_MS, ACCEPT_FROM_WHITELIST_MAX_MESSAGES, ACCEPT_FROM_WHITELIST_THRESHOLD_SCORE } from './constants'
2121

2222
interface GossipInputOptions {
2323
emitSelf: boolean
@@ -85,7 +85,7 @@ interface GossipOptions extends GossipInputOptions {
8585
scoreThresholds: PeerScoreThresholds
8686
}
8787

88-
interface AcceptFromWhiteListEntry {
88+
interface AcceptFromWhitelistEntry {
8989
/** number of messages accepted since recomputing the peer's score */
9090
messagesAccepted: number
9191
/** have to recompute score after this time */
@@ -96,7 +96,7 @@ class Gossipsub extends Pubsub {
9696
peers: Map<string, PeerStreams>
9797
direct: Set<string>
9898
seenCache: SimpleTimeCache
99-
acceptFromWhitelist: Map<string, AcceptFromWhiteListEntry>
99+
acceptFromWhitelist: Map<string, AcceptFromWhitelistEntry>
100100
topics: Map<string, Set<string>>
101101
mesh: Map<string, Set<string>>
102102
fanout: Map<string, Set<string>>
@@ -194,7 +194,7 @@ class Gossipsub extends Pubsub {
194194
/**
195195
* Map of peer id and AcceptRequestWhileListEntry
196196
*
197-
* @type {Map<string, AcceptFromWhiteListEntry}
197+
* @type {Map<string, AcceptFromWhitelistEntry}
198198
*/
199199
this.acceptFromWhitelist = new Map()
200200

@@ -475,19 +475,19 @@ class Gossipsub extends Pubsub {
475475
const entry = this.acceptFromWhitelist.get(id)
476476

477477
if (entry &&
478-
entry.messagesAccepted < ACCEPT_FROM_WHITE_LIST_MAX_MESSAGES &&
478+
entry.messagesAccepted < ACCEPT_FROM_WHITELIST_MAX_MESSAGES &&
479479
entry.acceptUntil >= now) {
480480
entry.messagesAccepted += 1
481481
return true
482482
}
483483

484484
const score = this.score.score(id)
485-
if (score >= ACCEPT_FROM_WHITE_LIST_THRESHOLD_SCORE) {
485+
if (score >= ACCEPT_FROM_WHITELIST_THRESHOLD_SCORE) {
486486
// peer is unlikely to be able to drop its score to `graylistThreshold`
487487
// after 128 messages or 1s
488488
this.acceptFromWhitelist.set(id, {
489489
messagesAccepted: 0,
490-
acceptUntil: now + ACCEPT_FROM_WHITE_LIST_DURATION_MS
490+
acceptUntil: now + ACCEPT_FROM_WHITELIST_DURATION_MS
491491
})
492492
} else {
493493
this.acceptFromWhitelist.delete(id)

0 commit comments

Comments
 (0)