forked from ipfs/ipfs-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouting.js
55 lines (48 loc) · 1.04 KB
/
routing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React, {Component} from 'react'
import {
Row, Col
}
from 'react-bootstrap'
import debug from 'debug'
import DHTGraph from '../views/dhtgraph'
import {idToAngle} from '../utils/common'
const log = debug('pages:routing')
export
default class Routing extends Component {
state = {
peers: []
};
static displayName = 'Routing';
static propTypes = {
ipfs: React.PropTypes.object
};
componentDidMount () {
this.props.ipfs.id((err, id) => {
if (err) return console.error(err)
this.props.ipfs.swarm.peers((err, res) => {
if (err) return console.error(err)
let peers = res.Peers || []
peers.push(id)
peers = peers.map((peer) => {
return {
pos: idToAngle(peer.ID),
id: peer.ID
}
})
log('peers', peers)
this.setState({
peers
})
})
})
}
render () {
return (
<Row>
<Col sm={10} smOffset={1}>
<DHTGraph peers={this.state.peers} />
</Col>
</Row>
)
}
}