2019-07-24 18:42:02 +00:00
|
|
|
import React from 'react';
|
|
|
|
import Cristal from 'react-cristal'
|
|
|
|
|
|
|
|
class ConnMgr extends React.Component {
|
2019-07-24 20:34:40 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.connect = this.connect.bind(this)
|
|
|
|
}
|
|
|
|
|
2019-07-24 21:28:51 +00:00
|
|
|
async connect(action, from, to) {
|
2019-07-24 20:34:40 +00:00
|
|
|
if (action) {
|
2019-07-24 21:28:51 +00:00
|
|
|
const fromNd = this.props.nodes[from]
|
|
|
|
const toNd = this.props.nodes[to]
|
|
|
|
|
|
|
|
const toPeerInfo = await toNd.conn.call('Filecoin.NetAddrsListen', [])
|
|
|
|
|
|
|
|
console.log("conn")
|
|
|
|
await fromNd.conn.call('Filecoin.NetConnect', [toPeerInfo])
|
2019-07-24 20:34:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 18:42:02 +00:00
|
|
|
render() {
|
2019-07-24 20:34:40 +00:00
|
|
|
const nodes = this.props.nodes
|
|
|
|
let keys = Object.keys(nodes)
|
|
|
|
|
|
|
|
const rows = keys.filter((_, i) => i > 0).map((k, i) => {
|
|
|
|
const cols = keys.filter((_, j) => i >= j).map((kt, i) => {
|
2019-07-24 21:28:51 +00:00
|
|
|
return (<td><input key={k + "-" + kt} type="checkbox" onChange={e => this.connect(e.target.checked, k, kt)}/></td>)
|
2019-07-24 20:34:40 +00:00
|
|
|
})
|
|
|
|
return (
|
|
|
|
<tr><td>{k}</td>{cols}</tr>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2019-07-24 18:42:02 +00:00
|
|
|
return(
|
|
|
|
<Cristal title="Connection Manager">
|
2019-07-24 20:34:40 +00:00
|
|
|
<table>
|
|
|
|
<thead><tr><td></td>{keys.slice(0, -1).map((i) => (<td>{i}</td>))}</tr></thead>
|
|
|
|
<tbody>{rows}</tbody>
|
|
|
|
</table>
|
2019-07-24 18:42:02 +00:00
|
|
|
</Cristal>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ConnMgr
|