diff --git a/lotuspond/api.go b/lotuspond/api.go index 6b547e7a4..3e3b75c4f 100644 --- a/lotuspond/api.go +++ b/lotuspond/api.go @@ -204,6 +204,27 @@ func (api *api) SpawnStorage(fullNodeRepo string) (nodeInfo, error) { return info, nil } +func (api *api) FullID(id int32) (int32, error) { + api.runningLk.Lock() + defer api.runningLk.Unlock() + + stor, ok := api.running[id] + if !ok { + return 0, xerrors.New("storage node not found") + } + + if !stor.meta.Storage { + return 0, xerrors.New("node is not a storage node") + } + + for id, n := range api.running { + if n.meta.Repo == stor.meta.FullNode { + return id, nil + } + } + return 0, xerrors.New("node not found") +} + func (api *api) CreateRandomFile(size int64) (string, error) { tf, err := ioutil.TempFile(os.TempDir(), "pond-random-") if err != nil { diff --git a/lotuspond/front/src/FullNode.js b/lotuspond/front/src/FullNode.js index fcdc6c5be..59b23ff08 100644 --- a/lotuspond/front/src/FullNode.js +++ b/lotuspond/front/src/FullNode.js @@ -79,8 +79,8 @@ class FullNode extends React.Component { this.loadInfo() } - async startStorageMiner() { - this.props.mountWindow((onClose) => ) + startStorageMiner() { + this.props.spawnStorageNode(this.props.node.Repo, this.props.client) } async add1k(to) { diff --git a/lotuspond/front/src/NodeList.js b/lotuspond/front/src/NodeList.js index 97b1aac4d..7399530aa 100644 --- a/lotuspond/front/src/NodeList.js +++ b/lotuspond/front/src/NodeList.js @@ -7,6 +7,7 @@ import StorageNode from "./StorageNode"; import {Client} from "rpc-websockets"; import pushMessage from "./chain/send"; import Logs from "./Logs"; +import StorageNodeInit from "./StorageNodeInit"; class NodeList extends React.Component { constructor(props) { @@ -21,6 +22,7 @@ class NodeList extends React.Component { // This binding is necessary to make `this` work in the callback this.spawnNode = this.spawnNode.bind(this) + this.spawnStorageNode = this.spawnStorageNode.bind(this) this.connMgr = this.connMgr.bind(this) this.consensus = this.consensus.bind(this) this.transfer1kFrom1 = this.transfer1kFrom1.bind(this) @@ -49,12 +51,18 @@ class NodeList extends React.Component { client={client} pondClient={this.props.client} give1k={this.transfer1kFrom1} - mountWindow={this.props.mountWindow}/>) + mountWindow={this.props.mountWindow} + spawnStorageNode={this.spawnStorageNode} + />) } else { + const fullId = await this.props.client.call('Pond.FullID', [node.ID]) + this.props.mountWindow((onClose) => ) + fullConn={this.state.nodes[fullId].conn} + mountWindow={this.props.mountWindow} + />) } }) } @@ -96,6 +104,16 @@ class NodeList extends React.Component { this.setState(state => ({nodes: {...state.nodes, [node.ID]: node}})) } + async spawnStorageNode(fullRepo, fullConn) { + let nodePromise = this.props.client.call('Pond.SpawnStorage', [fullRepo]) + + this.props.mountWindow((onClose) => ) + let node = await nodePromise + await this.mountNode(node) + + //this.setState(state => ({nodes: {...state.nodes, [node.ID]: node}})) + } + connMgr() { this.setState({showConnMgr: true}) } diff --git a/lotuspond/front/src/StorageNodeInit.js b/lotuspond/front/src/StorageNodeInit.js index 674e8c601..45e802ec3 100644 --- a/lotuspond/front/src/StorageNodeInit.js +++ b/lotuspond/front/src/StorageNodeInit.js @@ -4,10 +4,10 @@ import StorageNode from "./StorageNode"; class StorageNodeInit extends React.Component { async componentDidMount() { - const info = await this.props.pondClient.call('Pond.SpawnStorage', [this.props.fullRepo]) + const info = await this.props.node this.props.onClose() - this.props.mountWindow((onClose) => ) + //this.props.mountWindow((onClose) => ) } render() {