File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed
interface-compliance-tests/src/pubsub Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 1
- import { isStartable , start , stop } from '@libp2p/interface'
1
+ import { isPubSub , isStartable , start , stop } from '@libp2p/interface'
2
2
import { expect } from 'aegir/chai'
3
3
import delay from 'delay'
4
4
import pDefer from 'p-defer'
@@ -39,6 +39,10 @@ export default (common: TestSetup<PubSub, PubSubArgs>): void => {
39
39
mockNetwork . reset ( )
40
40
} )
41
41
42
+ it ( 'is a PubSub implementation' , ( ) => {
43
+ expect ( isPubSub ( pubsub ) ) . to . be . true ( )
44
+ } )
45
+
42
46
it ( 'can start correctly' , async ( ) => {
43
47
if ( ! isStartable ( pubsub ) ) {
44
48
return
Original file line number Diff line number Diff line change @@ -268,3 +268,16 @@ export interface PeerStreamEvents {
268
268
'stream:outbound' : CustomEvent < never >
269
269
'close' : CustomEvent < never >
270
270
}
271
+
272
+ /**
273
+ * All Pubsub implementations must use this symbol as the name of a property
274
+ * with a boolean `true` value
275
+ */
276
+ export const pubSubSymbol = Symbol . for ( '@libp2p/pubsub' )
277
+
278
+ /**
279
+ * Returns true if the passed argument is a PubSub implementation
280
+ */
281
+ export function isPubSub ( obj ?: any ) : obj is PubSub {
282
+ return Boolean ( obj ?. [ pubSubSymbol ] )
283
+ }
Original file line number Diff line number Diff line change 32
32
* ```
33
33
*/
34
34
35
- import { serviceDependencies } from '@libp2p/interface'
35
+ import { pubSubSymbol , serviceDependencies } from '@libp2p/interface'
36
36
import { PubSubBaseProtocol , type PubSubComponents } from '@libp2p/pubsub'
37
37
import { toString } from 'uint8arrays/to-string'
38
38
import { SimpleTimeCache } from './cache.js'
@@ -78,6 +78,8 @@ export class FloodSub extends PubSubBaseProtocol {
78
78
} )
79
79
}
80
80
81
+ readonly [ pubSubSymbol ] = true
82
+
81
83
readonly [ Symbol . toStringTag ] = '@libp2p/floodsub'
82
84
83
85
readonly [ serviceDependencies ] : string [ ] = [
You can’t perform that action at this time.
0 commit comments