import { DEFAULT_EVICTION_THRESHOLD_TIME } from '../constants' ; import { P2PEnhancedPeerInfo } from '../types' ; import { evictPeerRandomlyFromBucket , expirePeerFromBucket , PEER_TYPE } from '../utils' ; import { BaseList , Bucket , PeerListConfig } from './base_list' ; export interface NewListConfig extends PeerListConfig { readonly evictionThresholdTime ? : number ; } export class NewList extends BaseList { private readonly _evictionThresholdTime : number ; public constructor ( { evictionThresholdTime , numOfBuckets , bucketSize , secret , peerType , } ) { super ( { secret , numOfBuckets , bucketSize , peerType , } ) ; this . type = PEER_TYPE . NEW_PEER ; this . _evictionThresholdTime = evictionThresholdTime ?? DEFAULT_EVICTION_THRESHOLD_TIME ; } public get newPeerConfig ( ) : NewListConfig { return { ... this . peerListConfig , evictionThresholdTime : this . _evictionThresholdTime , } ; } public makeSpace ( bucket ) { const evictedPeer = expirePeerFromBucket ( bucket , this . _evictionThresholdTime ) ; if ( evictedPeer ) { return evictedPeer ; } return evictPeerRandomlyFromBucket ( bucket ) ; } }