mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-23 22:11:35 +00:00
chore: apply suggestions from code review
Co-Authored-By: Jacob Heun <jacobheun@gmail.com>
This commit is contained in:
16
src/index.js
16
src/index.js
@ -11,7 +11,7 @@ const PeerId = require('peer-id')
|
||||
const peerRouting = require('./peer-routing')
|
||||
const contentRouting = require('./content-routing')
|
||||
const pubsub = require('./pubsub')
|
||||
const getPeerId = require('./get-peer-id')
|
||||
const getPeer = require('./get-peer')
|
||||
const { validate: validateConfig } = require('./config')
|
||||
const { codes } = require('./errors')
|
||||
|
||||
@ -293,11 +293,13 @@ class Libp2p extends EventEmitter {
|
||||
* @returns {Promise<Connection|*>}
|
||||
*/
|
||||
async dialProtocol (peer, protocols, options) {
|
||||
const peerId = getPeerId(peer, this.peerStore)
|
||||
let connection = this.registrar.getConnection(peerId)
|
||||
const { id, multiaddrs } = getPeer(peer, this.peerStore)
|
||||
let connection = this.registrar.getConnection(id)
|
||||
|
||||
if (!connection) {
|
||||
connection = await this.dialer.connectToPeer(peer, options)
|
||||
} else {
|
||||
this.peerStore.addressBook.add(id, multiaddrs)
|
||||
}
|
||||
|
||||
// If a protocol was provided, create a new stream
|
||||
@ -314,9 +316,9 @@ class Libp2p extends EventEmitter {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async hangUp (peer) {
|
||||
const peerId = getPeerId(peer)
|
||||
const { id } = getPeer(peer)
|
||||
|
||||
const connections = this.registrar.connections.get(peerId.toB58String())
|
||||
const connections = this.registrar.connections.get(id.toB58String())
|
||||
|
||||
if (!connections) {
|
||||
return
|
||||
@ -335,9 +337,9 @@ class Libp2p extends EventEmitter {
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
ping (peer) {
|
||||
const peerId = getPeerId(peer)
|
||||
const { id } = getPeer(peer)
|
||||
|
||||
return ping(this, peerId)
|
||||
return ping(this, id)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user