-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To ensure we don't think we have a reserved slot on a relay, remove the old tags on startup.
- Loading branch information
1 parent
29b47ad
commit c91d6c2
Showing
6 changed files
with
153 additions
and
26 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
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
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
64 changes: 64 additions & 0 deletions
64
packages/transport-circuit-relay-v2/test/transport/reservation-store.spec.ts
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,64 @@ | ||
import { generateKeyPair } from '@libp2p/crypto/keys' | ||
import { TypedEventEmitter, start } from '@libp2p/interface' | ||
import { defaultLogger } from '@libp2p/logger' | ||
import { peerIdFromPrivateKey } from '@libp2p/peer-id' | ||
import { expect } from 'aegir/chai' | ||
import delay from 'delay' | ||
import { stubInterface } from 'sinon-ts' | ||
import { KEEP_ALIVE_TAG, RELAY_TAG } from '../../src/constants.js' | ||
import { ReservationStore } from '../../src/transport/reservation-store.js' | ||
import type { ComponentLogger, Libp2pEvents, Peer, PeerId, PeerStore, TypedEventTarget } from '@libp2p/interface' | ||
import type { ConnectionManager, TransportManager } from '@libp2p/interface-internal' | ||
import type { StubbedInstance } from 'sinon-ts' | ||
|
||
export interface StubbedReservationStoreComponents { | ||
peerId: PeerId | ||
connectionManager: StubbedInstance<ConnectionManager> | ||
transportManager: StubbedInstance<TransportManager> | ||
peerStore: StubbedInstance<PeerStore> | ||
events: TypedEventTarget<Libp2pEvents> | ||
logger: ComponentLogger | ||
} | ||
|
||
describe('transport reservation-store', () => { | ||
let store: ReservationStore | ||
let components: StubbedReservationStoreComponents | ||
|
||
beforeEach(async () => { | ||
const privateKey = await generateKeyPair('Ed25519') | ||
|
||
components = { | ||
peerId: peerIdFromPrivateKey(privateKey), | ||
connectionManager: stubInterface(), | ||
transportManager: stubInterface(), | ||
peerStore: stubInterface(), | ||
events: new TypedEventEmitter(), | ||
logger: defaultLogger() | ||
} | ||
|
||
store = new ReservationStore(components) | ||
}) | ||
|
||
it('should remove relay tags on start', async () => { | ||
const peer: Peer = { | ||
id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')), | ||
addresses: [], | ||
metadata: new Map(), | ||
tags: new Map([[RELAY_TAG, { value: 1 }]]), | ||
protocols: [] | ||
} | ||
|
||
components.peerStore.all.resolves([peer]) | ||
|
||
await start(store) | ||
|
||
await delay(100) | ||
|
||
expect(components.peerStore.merge.calledWith(peer.id, { | ||
tags: { | ||
[RELAY_TAG]: undefined, | ||
[KEEP_ALIVE_TAG]: undefined | ||
} | ||
})).to.be.true() | ||
}) | ||
}) |