lotus/lotuspond/front/src/StorageNode.js

146 lines
4.3 KiB
JavaScript
Raw Normal View History

2019-07-30 23:18:21 +00:00
import React from 'react';
2019-07-31 18:20:05 +00:00
import { Client } from 'rpc-websockets'
2019-08-10 01:54:45 +00:00
import Address from "./Address";
2019-09-19 14:27:01 +00:00
import Window from "./Window";
2019-07-31 18:20:05 +00:00
const stateConnected = 'connected'
const stateConnecting = 'connecting'
const stateGettingToken = 'getting-token'
let sealCodes = [
2019-09-24 10:30:48 +00:00
"Unknown",
"Pending",
"Failed",
"Sealing",
"Sealed",
2019-07-31 18:20:05 +00:00
]
2019-07-30 23:18:21 +00:00
class StorageNode extends React.Component {
2019-07-31 18:20:05 +00:00
constructor(props) {
super(props)
this.state = {
state: stateGettingToken,
id: "~",
mining: false,
statusCounts: [0, 0, 0, 0, 0]
2019-07-31 18:20:05 +00:00
}
this.loadInfo = this.loadInfo.bind(this)
this.sealGarbage = this.sealGarbage.bind(this)
2019-09-17 12:53:43 +00:00
this.stop = this.stop.bind(this)
2019-07-31 18:20:05 +00:00
this.connect()
}
async connect() {
const token = await this.props.pondClient.call('Pond.TokenFor', [this.props.node.ID])
this.setState(() => ({
state: stateConnecting,
token: token,
}))
const client = new Client(`ws://127.0.0.1:${this.props.node.ApiPort}/rpc/v0?token=${token}`)
client.on('open', async () => {
this.setState(() => ({
state: stateConnected,
client: client,
version: {Version: "~version~"},
id: "~peerid~",
peers: -1,
balances: []
}))
const id = await this.state.client.call("Filecoin.ID", [])
this.setState(() => ({id: id}))
// this.props.onConnect(client, id) // TODO: dedupe connecting part
2019-09-17 12:53:43 +00:00
let updates = setInterval(this.loadInfo, 1050)
client.on('close', () => clearInterval(updates))
2019-07-31 18:20:05 +00:00
})
console.log(token) // todo: use
}
async loadInfo() {
const version = await this.state.client.call("Filecoin.Version", [])
const peers = await this.state.client.call("Filecoin.NetPeers", [])
2019-08-10 01:54:45 +00:00
const [actor] = await this.state.client.call("Filecoin.ActorAddresses", [])
2019-07-31 18:20:05 +00:00
2019-09-19 16:17:49 +00:00
const stActor = await this.props.fullConn.call('Filecoin.StateGetActor', [actor, null])
const actorState = await this.props.fullConn.call('Filecoin.StateReadState', [stActor, null])
this.setState({version: version, peers: peers.length, actor: actor, actorState: actorState})
2019-07-31 18:20:05 +00:00
await this.stagedList()
}
async stagedList() {
let stagedList = await this.state.client.call("Filecoin.SectorsStagedList", [])
let staged = await stagedList
.map(sector => this.state.client.call("Filecoin.SectorsStatus", [sector.SectorID]))
.reduce(async (p, n) => [...await p, await n], Promise.resolve([]))
let statusCounts = staged.reduce((p, n) => p.map((e, i) => e + (i === n.State ? 1 : 0) ), [0, 0, 0, 0, 0])
2019-07-31 18:20:05 +00:00
this.setState({staged, statusCounts})
}
async sealGarbage() {
await this.state.client.call("Filecoin.StoreGarbageData", [])
}
sealStaged = async () => {
await this.state.client.call("Filecoin.SectorsStagedSeal", [])
}
2019-09-17 12:53:43 +00:00
async stop() {
await this.props.stop()
}
2019-07-30 23:18:21 +00:00
render() {
2019-07-31 18:20:05 +00:00
let runtime = <div></div>
2019-08-10 01:54:45 +00:00
if (this.state.actor) {
2019-07-31 18:20:05 +00:00
const sealGarbage = <a href="#" onClick={this.sealGarbage}>[Seal Garbage]</a>
const sealStaged = <a href="#" onClick={this.sealStaged}>[Seal Staged]</a>
2019-07-31 18:20:05 +00:00
runtime = (
<div>
<div>v{this.state.version.Version}, <abbr title={this.state.id}>{this.state.id.substr(-8)}</abbr>, {this.state.peers} peers</div>
<div>Repo: LOTUS_STORAGE_PATH={this.props.node.Repo}</div>
<div>
{sealGarbage} {sealStaged}
2019-07-31 18:20:05 +00:00
</div>
2019-08-10 01:54:45 +00:00
<div>
<Address client={this.props.fullConn} addr={this.state.actor} mountWindow={this.props.mountWindow}/>
2019-09-19 16:17:49 +00:00
<span>&nbsp;<abbr title="Proving period end">PPE:</abbr> <b>{this.state.actorState.State.ProvingPeriodEnd}</b></span>
2019-08-10 01:54:45 +00:00
</div>
2019-09-16 21:25:23 +00:00
<div>{this.state.statusCounts.map((c, i) => <span key={i}>{sealCodes[i]}: {c} | </span>)}</div>
2019-07-31 18:20:05 +00:00
<div>
2019-09-16 21:25:23 +00:00
{this.state.staged ? this.state.staged.map((s, i) => (
2019-09-24 10:30:48 +00:00
<div key={i}>{s.SectorID} {sealCodes[s.State]}</div>
2019-09-16 21:25:23 +00:00
)) : <div/>}
2019-07-31 18:20:05 +00:00
</div>
</div>
)
}
2019-09-19 14:27:01 +00:00
return <Window
2019-07-31 18:20:05 +00:00
title={"Storage Miner Node " + this.props.node.ID}
2019-09-17 12:53:43 +00:00
initialPosition={{x: this.props.node.ID*30, y: this.props.node.ID * 30}}
onClose={this.stop} >
2019-07-30 23:18:21 +00:00
<div className="CristalScroll">
2019-07-31 18:20:05 +00:00
<div className="StorageNode">
{runtime}
2019-07-30 23:18:21 +00:00
</div>
</div>
2019-09-19 14:27:01 +00:00
</Window>
2019-07-30 23:18:21 +00:00
}
}
export default StorageNode