This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-17
lines changed Expand file tree Collapse file tree 1 file changed +14
-17
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const promisify = require ( 'promisify-es6' )
4
+ const mafmt = require ( 'mafmt' )
4
5
5
6
module . exports = function id ( self ) {
6
7
return promisify ( ( opts , callback ) => {
7
8
if ( typeof opts === 'function' ) {
8
9
callback = opts
9
10
opts = { }
10
11
}
11
- if ( ! self . _peerInfo ) { // because of split second warmup
12
- setTimeout ( ready , 100 )
13
- } else {
14
- ready ( )
15
- }
16
12
17
- function ready ( ) {
18
- callback ( null , {
19
- id : self . _peerInfo . id . toB58String ( ) ,
20
- publicKey : self . _peerInfo . id . pubKey . bytes . toString ( 'base64' ) ,
21
- addresses : self . _peerInfo . multiaddrs . map ( ( ma ) => {
22
- const addr = ma . toString ( ) + '/ipfs/' + self . _peerInfo . id . toB58String ( )
23
- return addr
24
- } ) . sort ( ) ,
25
- agentVersion : 'js-ipfs' ,
26
- protocolVersion : '9000'
27
- } )
28
- }
13
+ setImmediate ( ( ) => callback ( null , {
14
+ id : self . _peerInfo . id . toB58String ( ) ,
15
+ publicKey : self . _peerInfo . id . pubKey . bytes . toString ( 'base64' ) ,
16
+ addresses : self . _peerInfo . multiaddrs . map ( ( ma ) => {
17
+ if ( mafmt . IPFS . matches ( ma ) ) {
18
+ return ma . toString ( )
19
+ } else {
20
+ return ma . toString ( ) + '/ipfs/' + self . _peerInfo . id . toB58String ( )
21
+ }
22
+ } ) . sort ( ) ,
23
+ agentVersion : 'js-ipfs' ,
24
+ protocolVersion : '9000'
25
+ } ) )
29
26
} )
30
27
}
You can’t perform that action at this time.
0 commit comments