pond: Fix storage node connection handling

This commit is contained in:
Łukasz Magiera 2019-09-09 18:01:53 +02:00
parent 19ec43d7fd
commit ed1f604346
4 changed files with 45 additions and 6 deletions

View File

@ -204,6 +204,27 @@ func (api *api) SpawnStorage(fullNodeRepo string) (nodeInfo, error) {
return info, nil 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) { func (api *api) CreateRandomFile(size int64) (string, error) {
tf, err := ioutil.TempFile(os.TempDir(), "pond-random-") tf, err := ioutil.TempFile(os.TempDir(), "pond-random-")
if err != nil { if err != nil {

View File

@ -79,8 +79,8 @@ class FullNode extends React.Component {
this.loadInfo() this.loadInfo()
} }
async startStorageMiner() { startStorageMiner() {
this.props.mountWindow((onClose) => <StorageNodeInit fullRepo={this.props.node.Repo} fullConn={this.props.client} pondClient={this.props.pondClient} onClose={onClose} mountWindow={this.props.mountWindow}/>) this.props.spawnStorageNode(this.props.node.Repo, this.props.client)
} }
async add1k(to) { async add1k(to) {

View File

@ -7,6 +7,7 @@ import StorageNode from "./StorageNode";
import {Client} from "rpc-websockets"; import {Client} from "rpc-websockets";
import pushMessage from "./chain/send"; import pushMessage from "./chain/send";
import Logs from "./Logs"; import Logs from "./Logs";
import StorageNodeInit from "./StorageNodeInit";
class NodeList extends React.Component { class NodeList extends React.Component {
constructor(props) { constructor(props) {
@ -21,6 +22,7 @@ class NodeList extends React.Component {
// This binding is necessary to make `this` work in the callback // This binding is necessary to make `this` work in the callback
this.spawnNode = this.spawnNode.bind(this) this.spawnNode = this.spawnNode.bind(this)
this.spawnStorageNode = this.spawnStorageNode.bind(this)
this.connMgr = this.connMgr.bind(this) this.connMgr = this.connMgr.bind(this)
this.consensus = this.consensus.bind(this) this.consensus = this.consensus.bind(this)
this.transfer1kFrom1 = this.transfer1kFrom1.bind(this) this.transfer1kFrom1 = this.transfer1kFrom1.bind(this)
@ -49,12 +51,18 @@ class NodeList extends React.Component {
client={client} client={client}
pondClient={this.props.client} pondClient={this.props.client}
give1k={this.transfer1kFrom1} give1k={this.transfer1kFrom1}
mountWindow={this.props.mountWindow}/>) mountWindow={this.props.mountWindow}
spawnStorageNode={this.spawnStorageNode}
/>)
} else { } else {
const fullId = await this.props.client.call('Pond.FullID', [node.ID])
this.props.mountWindow((onClose) => this.props.mountWindow((onClose) =>
<StorageNode node={{...node}} <StorageNode node={{...node}}
pondClient={this.props.client} pondClient={this.props.client}
mountWindow={this.props.mountWindow}/>) 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}})) 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) => <StorageNodeInit node={nodePromise} fullRepo={fullRepo} fullConn={fullConn} pondClient={this.props.client} onClose={onClose} mountWindow={this.props.mountWindow}/>)
let node = await nodePromise
await this.mountNode(node)
//this.setState(state => ({nodes: {...state.nodes, [node.ID]: node}}))
}
connMgr() { connMgr() {
this.setState({showConnMgr: true}) this.setState({showConnMgr: true})
} }

View File

@ -4,10 +4,10 @@ import StorageNode from "./StorageNode";
class StorageNodeInit extends React.Component { class StorageNodeInit extends React.Component {
async componentDidMount() { 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.onClose()
this.props.mountWindow((onClose) => <StorageNode node={info} fullRepo={this.props.fullRepo} fullConn={this.props.fullConn} pondClient={this.props.pondClient} onClose={onClose} mountWindow={this.props.mountWindow}/>) //this.props.mountWindow((onClose) => <StorageNode node={info} fullRepo={this.props.fullRepo} fullConn={this.props.fullConn} pondClient={this.props.pondClient} onClose={onClose} mountWindow={this.props.mountWindow}/>)
} }
render() { render() {