Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
fix: event emitter and discovery and routing interfaces (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored Apr 30, 2021
1 parent 27c3871 commit 93ddaa4
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 22 deletions.
13 changes: 8 additions & 5 deletions src/content-routing/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
export = ContentRouting;

import PeerId from 'peer-id'
import Multiaddr from 'multiaddr'
import { Multiaddr } from 'multiaddr'
import CID from 'cids'

declare class ContentRouting {
constructor (options: Object);
export interface ContentRoutingFactory {
new (options?: any): ContentRouting;
}

export interface ContentRouting {
provide (cid: CID): Promise<void>;
findProviders (cid: CID, options: Object): AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>;
}

export default ContentRouting;
17 changes: 10 additions & 7 deletions src/peer-discovery/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
export = PeerDiscovery;
import { EventEmitter } from 'events';

import events from 'events';

declare class PeerDiscovery extends events.EventEmitter {
constructor (options: Object);
start (): Promise<void>;
stop (): Promise<void>;
export interface PeerDiscoveryFactory {
new (options?: any): PeerDiscovery;
tag: string;
}

export interface PeerDiscovery extends EventEmitter {
start(): void|Promise<void>;
stop(): void|Promise<void>;
}

export default PeerDiscovery;
13 changes: 8 additions & 5 deletions src/peer-routing/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
export = PeerRouting;

import PeerId from 'peer-id'
import Multiaddr from 'multiaddr'
import { Multiaddr } from 'multiaddr'

export interface PeerRoutingFactory {
new (options?: any): PeerRouting;
}

declare class PeerRouting {
constructor (options?: Object);
export interface PeerRouting {
findPeer (peerId: PeerId, options?: Object): Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>;
getClosestPeers(key: Uint8Array, options?: Object): AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>;
}

export default PeerRouting;
2 changes: 1 addition & 1 deletion src/pubsub/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const debug = require('debug')
const EventEmitter = require('events')
const { EventEmitter } = require('events')
const errcode = require('err-code')

const { pipe } = require('it-pipe')
Expand Down
2 changes: 1 addition & 1 deletion src/pubsub/peer-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const debug = require('debug')
const log = Object.assign(debug('libp2p-pubsub:peer-streams'), {
error: debug('libp2p-pubsub:peer-streams:err')
})
const EventEmitter = require('events')
const { EventEmitter } = require('events')

const lp = require('it-length-prefixed')
const pushable = require('it-pushable')
Expand Down
2 changes: 1 addition & 1 deletion src/transport/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BufferList from 'bl'
import events from 'events'
import Multiaddr from 'multiaddr'
import { Multiaddr } from 'multiaddr'
import Connection from '../connection/connection'
import { Sink } from '../stream-muxer/types'

Expand Down
4 changes: 2 additions & 2 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type SelectFn = function (Uint8Array, Uint8Array[]): number
export type ValidateFn = function (Uint8Array, Uint8Array): Promise<void>
export type SelectFn = (key: Uint8Array, records: Uint8Array[]) => number
export type ValidateFn = (a: Uint8Array, b: Uint8Array) => Promise<void>

export type DhtSelectors = { [key: string]: SelectFn }
export type DhtValidators = { [key: string]: { func: ValidateFn } }

0 comments on commit 93ddaa4

Please sign in to comment.