Skip to content

Commit

Permalink
chore: remove redundant interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Jun 16, 2023
1 parent 6f7845a commit acbc997
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 50 deletions.
38 changes: 0 additions & 38 deletions packages/interface-libp2p-internal/src/registrar/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Connection, Stream } from '@libp2p/interface-libp2p/connection'
import type { Topology } from '@libp2p/interface-libp2p/topology'
import type { PeerId } from '@libp2p/interface-peer-id'

export interface IncomingStreamData {
stream: Stream
Expand Down Expand Up @@ -70,40 +69,3 @@ export interface Registrar {
*/
getTopologies: (protocol: string) => Topology[]
}

export interface onConnectHandler {
(peerId: PeerId, conn: Connection): void
}

export interface onDisconnectHandler {
(peerId: PeerId, conn?: Connection): void
}

export interface TopologyInit {
/**
* minimum needed connections
*/
min?: number

/**
* maximum needed connections
*/
max?: number

/**
* Invoked when a new peer is connects that supports the configured
* protocol
*/
onConnect?: onConnectHandler

/**
* Invoked when a peer that supports the configured protocol disconnects
*/
onDisconnect?: onDisconnectHandler
}

export const topologySymbol = Symbol.for('@libp2p/topology')

export function isTopology (other: any): other is Topology {
return other != null && Boolean(other[topologySymbol])
}
6 changes: 0 additions & 6 deletions packages/interface-libp2p/src/topology/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,3 @@ export interface Topology {
onConnect?: (peerId: PeerId, conn: Connection) => void
onDisconnect?: (peerId: PeerId) => void
}

export const topologySymbol = Symbol.for('@libp2p/topology')

export function isTopology (other: any): other is Topology {
return other != null && Boolean(other[topologySymbol])
}
7 changes: 1 addition & 6 deletions packages/libp2p/src/registrar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CodeError } from '@libp2p/interface-libp2p/errors'
import { isTopology, type StreamHandlerOptions, type StreamHandlerRecord, type Registrar, type StreamHandler } from '@libp2p/interface-libp2p-internal/registrar'
import { logger } from '@libp2p/logger'
import merge from 'merge-options'
import { codes } from './errors.js'
Expand All @@ -8,6 +7,7 @@ import type { EventEmitter } from '@libp2p/interface-libp2p/events'
import type { PeerStore } from '@libp2p/interface-libp2p/peer-store'
import type { Topology } from '@libp2p/interface-libp2p/topology'
import type { ConnectionManager } from '@libp2p/interface-libp2p-internal/connection-manager'
import type { StreamHandlerOptions, StreamHandlerRecord, Registrar, StreamHandler } from '@libp2p/interface-libp2p-internal/registrar'
import type { PeerId } from '@libp2p/interface-peer-id'

const log = logger('libp2p:registrar')
Expand Down Expand Up @@ -117,11 +117,6 @@ export class DefaultRegistrar implements Registrar {
* Register handlers for a set of multicodecs given
*/
async register (protocol: string, topology: Topology): Promise<string> {
if (!isTopology(topology)) {
log.error('topology must be an instance of interfaces/topology')
throw new CodeError('topology must be an instance of interfaces/topology', codes.ERR_INVALID_PARAMETERS)
}

// Create topology
const id = `${(Math.random() * 1e9).toString(36)}${Date.now()}`

Expand Down

0 comments on commit acbc997

Please sign in to comment.