mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-23 14:01:35 +00:00
refactor: pubsub (#467)
* feat: peer-store v0 * chore: apply suggestions from code review Co-Authored-By: Jacob Heun <jacobheun@gmail.com> * chore: address review * refactor: pubsub subsystem * chore: address review * chore: use topology interface * chore: address review * chore: address review * chore: simplify tests
This commit is contained in:
@ -5,9 +5,9 @@ const debug = require('debug')
|
||||
const log = debug('libp2p:peer-store')
|
||||
log.error = debug('libp2p:peer-store:error')
|
||||
|
||||
const Topology = require('libp2p-interfaces/src/topology')
|
||||
const { Connection } = require('libp2p-interfaces/src/connection')
|
||||
const PeerInfo = require('peer-info')
|
||||
const Toplogy = require('./connection-manager/topology')
|
||||
|
||||
/**
|
||||
* Responsible for notifying registered protocols of events in the network.
|
||||
@ -106,17 +106,16 @@ class Registrar {
|
||||
|
||||
/**
|
||||
* Register handlers for a set of multicodecs given
|
||||
* @param {Object} topologyProps properties for topology
|
||||
* @param {Array<string>|string} topologyProps.multicodecs
|
||||
* @param {Object} topologyProps.handlers
|
||||
* @param {function} topologyProps.handlers.onConnect
|
||||
* @param {function} topologyProps.handlers.onDisconnect
|
||||
* @param {Topology} topology protocol topology
|
||||
* @return {string} registrar identifier
|
||||
*/
|
||||
register (topologyProps) {
|
||||
// Create multicodec topology
|
||||
register (topology) {
|
||||
assert(
|
||||
Topology.isTopology(topology),
|
||||
'topology must be an instance of interfaces/topology')
|
||||
|
||||
// Create topology
|
||||
const id = (parseInt(Math.random() * 1e9)).toString(36) + Date.now()
|
||||
const topology = new Toplogy(topologyProps)
|
||||
|
||||
this.topologies.set(id, topology)
|
||||
|
||||
|
Reference in New Issue
Block a user