This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree 3 files changed +45
-7
lines changed 3 files changed +45
-7
lines changed Original file line number Diff line number Diff line change 59
59
"form-data" : " ^2.1.2" ,
60
60
"fs-pull-blob-store" : " ^0.4.1" ,
61
61
"gulp" : " ^3.9.1" ,
62
- "interface-ipfs-core" : " ^0.21 .0" ,
62
+ "interface-ipfs-core" : " ^0.22 .0" ,
63
63
"left-pad" : " ^1.1.3" ,
64
64
"lodash" : " ^4.17.2" ,
65
65
"ncp" : " ^2.0.0" ,
Original file line number Diff line number Diff line change @@ -9,17 +9,41 @@ const OFFLINE_ERROR = require('../utils').OFFLINE_ERROR
9
9
10
10
module . exports = function swarm ( self ) {
11
11
return {
12
- peers : promisify ( ( callback ) => {
12
+ peers : promisify ( ( opts , callback ) => {
13
+ if ( typeof opts === 'function' ) {
14
+ callback = opts
15
+ opts = { }
16
+ }
17
+
13
18
if ( ! self . isOnline ( ) ) {
14
19
return callback ( OFFLINE_ERROR )
15
20
}
16
21
22
+ const verbose = opts . v || opts . verbose
23
+ // TODO: return latency and streams when verbose is set
24
+ // we currently don't have this information
25
+
17
26
const peers = self . _libp2pNode . peerBook . getAll ( )
18
- const mas = flatMap ( Object . keys ( peers ) , ( id ) => {
19
- return peers [ id ] . multiaddrs
27
+ const keys = Object . keys ( peers )
28
+
29
+ const peerList = flatMap ( keys , ( id ) => {
30
+ const peer = peers [ id ]
31
+
32
+ return peer . multiaddrs . map ( ( addr ) => {
33
+ const res = {
34
+ addr : addr ,
35
+ peer : peers [ id ]
36
+ }
37
+
38
+ if ( verbose ) {
39
+ res . latency = 'unknown'
40
+ }
41
+
42
+ return res
43
+ } )
20
44
} )
21
45
22
- callback ( null , mas )
46
+ callback ( null , peerList )
23
47
} ) ,
24
48
25
49
// all the addrs we know
Original file line number Diff line number Diff line change @@ -26,8 +26,11 @@ exports.parseAddrs = (request, reply) => {
26
26
27
27
exports . peers = {
28
28
handler : ( request , reply ) => {
29
+ const rawVerbose = request . query . v || request . query . verbose
30
+ const verbose = rawVerbose === 'true'
29
31
const ipfs = request . server . app . ipfs
30
- ipfs . swarm . peers ( ( err , peers ) => {
32
+
33
+ ipfs . swarm . peers ( { verbose : verbose } , ( err , peers ) => {
31
34
if ( err ) {
32
35
log . error ( err )
33
36
return reply ( {
@@ -37,7 +40,18 @@ exports.peers = {
37
40
}
38
41
39
42
return reply ( {
40
- Strings : peers . map ( ( addr ) => addr . toString ( ) )
43
+ Peers : peers . map ( ( p ) => {
44
+ const res = {
45
+ Peer : p . peer . id . toB58String ( ) ,
46
+ Addr : p . addr . toString ( )
47
+ }
48
+
49
+ if ( verbose ) {
50
+ res . Latency = p . latency
51
+ }
52
+
53
+ return res
54
+ } )
41
55
} )
42
56
} )
43
57
}
You can’t perform that action at this time.
0 commit comments