Skip to content

Commit

Permalink
feat(network): add dameon network config
Browse files Browse the repository at this point in the history
add new network config, update other package affected by the change
  • Loading branch information
gfanton committed Jul 31, 2019
1 parent 4354b66 commit 04d1cfe
Show file tree
Hide file tree
Showing 21 changed files with 828 additions and 952 deletions.
85 changes: 36 additions & 49 deletions client/packages/bridge/service/daemon/daemon.pb.json
Expand Up @@ -112,9 +112,39 @@
},
"NetworkConfig": {
"fields": {
"json": {
"type": "string",
"peerCache": {
"type": "bool",
"id": 1
},
"identity": {
"type": "string",
"id": 2
},
"bootstrap": {
"rule": "repeated",
"type": "string",
"id": 3
},
"bindP2P": {
"rule": "repeated",
"type": "string",
"id": 5
},
"mdns": {
"type": "bool",
"id": 6
},
"privateNetwork": {
"type": "bool",
"id": 7
},
"swarmKey": {
"type": "string",
"id": 8
},
"mobile": {
"type": "bool",
"id": 9
}
}
},
Expand Down Expand Up @@ -142,7 +172,7 @@
},
"grpcWebBind": {
"type": "string",
"id": 25
"id": 3
},
"hideBanner": {
"type": "bool",
Expand Down Expand Up @@ -183,56 +213,13 @@
"type": "string",
"id": 12
},
"peerCache": {
"type": "bool",
"networkConfig": {
"type": "NetworkConfig",
"id": 13
},
"identity": {
"type": "string",
"id": 14
},
"bootstrap": {
"rule": "repeated",
"type": "string",
"id": 15
},
"noP2P": {
"type": "bool",
"id": 16
},
"bindP2P": {
"rule": "repeated",
"type": "string",
"id": 17
},
"transportP2P": {
"rule": "repeated",
"type": "string",
"id": 18
},
"hop": {
"type": "bool",
"id": 19
},
"ble": {
"type": "bool",
"id": 20
},
"mdns": {
"type": "bool",
"id": 21
},
"dhtServer": {
"type": "bool",
"id": 22
},
"PrivateNetwork": {
"type": "bool",
"id": 23
},
"SwarmKeyPath": {
"type": "string",
"id": 24
"id": 14
}
}
},
Expand Down
165 changes: 113 additions & 52 deletions client/packages/screen/Settings/Devtools/Network/Config.js
Expand Up @@ -4,6 +4,12 @@ import { withBridgeContext } from '@berty/bridge/Context'

import { Header, Loader, Menu } from '@berty/component'

const transports = {
TCP: '/ip4/0.0.0.0/tcp/0',
BLE: '/ble/00000000-0000-0000-0000-000000000000',
QUIC: '/ip4/0.0.0.0/udp/0/quic',
}

class Network extends PureComponent {
static navigationOptions = ({ navigation }) => {
const updating =
Expand All @@ -30,8 +36,8 @@ class Network extends PureComponent {
const { bridge } = this.props

const config = await bridge.daemon.getNetworkConfig({})
console.warn(config.json)
this.setState(JSON.parse(config.json))
console.warn(config)
this.setState(config)
this.props.navigation.setParams({
onSave: this.saveConfig.bind(this),
})
Expand All @@ -46,100 +52,154 @@ class Network extends PureComponent {

this.props.navigation.setParams({ updating: true })
try {
await bridge.daemon.updateNetworkConfig({
json: JSON.stringify(this.state),
})
await bridge.daemon.updateNetworkConfig(this.state)
} catch (err) {
console.error(err)
}
this.props.navigation.setParams({ updating: false })
}

isTransportEnable = (matchPatern) => {
return this.state.bindP2P.reduce((acc, currentTransport) => {
return acc || currentTransport.indexOf(matchPatern) >= 0
})
}

removeTransport = (matchPatern) => {
return this.state.bindP2P.filter((currentTransport) => {
return currentTransport.indexOf(matchPatern) >= 0
})
}

addTransport = (transport) => {
return this.state.bindP2P.concat(transport)
}

render() {
if (this.state == null) {
return <Loader message="Loading network configuration ..." />
}
return (
<Menu>
<Menu.Section title="Discovery">
<Menu.Section title="Global">
<Menu.Item
title="Multicast DNS"
title="Mobile Mode"
customRight={
<Switch
justify="end"
value={this.state.MDNS}
onValueChange={MDNS => this.updateConfig({ MDNS })}
value={this.state.mobile}
onValueChange={peerCache => this.updateConfig({ mobile })}
/>
}
/>
</Menu.Section>
<Menu.Section title="Transports" customMarginTop={24}>

<Menu.Section title="Discovery">
<Menu.Item
title="TCP"
title="Multicast DNS"
customRight={
<Switch
justify="end"
value={this.state.TCP}
onValueChange={TCP => this.updateConfig({ TCP })}
value={this.state.Mdns}
onValueChange={MDNS => this.updateConfig({ Mdns })}
/>
}
/>
</Menu.Section>

<Menu.Section title="Transports" customMarginTop={24}>
<Menu.Item
title="QUIC"
title="TCP"
customRight={
<Switch
justify="end"
value={this.state.QUIC}
onValueChange={QUIC => this.updateConfig({ QUIC })}
value={this.isTransportEnable('tcp')}
onValueChange={enable => {
if (enable) {
const bindP2P = this.addTransport(transports.TCP)
this.updateConfig({ bindP2P })
} else {
const bindP2P = this.removeTransport('tcp')
this.updateConfig({ bindP2P })
}
}}
/>
}
/>
<Menu.Item
title="Bluetooth"
title="QUIC"
customRight={
<Switch
justify="end"
value={this.state.BLE}
onValueChange={BLE => this.updateConfig({ BLE })}
value={this.isTransportEnable('quic')}
onValueChange={enable => {
if (enable) {
const bindP2P = this.addTransport(transports.TCP)
this.updateConfig({ bindP2P })
} else {
const bindP2P = this.removeTransport('quic')
this.updateConfig({ bindP2P })
}
}}
/>
}
/>
<Menu.Item
title="Websocket"
title="Bluetooth"
customRight={
<Switch
justify="end"
value={this.state.WS}
onValueChange={WS => this.updateConfig({ WS })}
value={this.isTransportEnable('ble')}
onValueChange={enable => {
if (enable) {
const bindP2P = this.addTransport(transports.TCP)
this.updateConfig({ bindP2P })
} else {
const bindP2P = this.removeTransport('ble')
this.updateConfig({ bindP2P })
}
}}
/>
}
/>
{/* <Menu.Item */}
{/* title="Websocket" */}
{/* customRight={ */}
{/* <Switch */}
{/* justify="end" */}
{/* value={this.state.WS} */}
{/* onValueChange={WS => this.updateConfig({ WS })} */}
{/* /> */}
{/* } */}
{/* /> */}
</Menu.Section>

<Menu.Section title="Connections">
<Menu.Item
title="Peer cache"
customRight={
<Switch
justify="end"
value={this.state.PeerCache}
onValueChange={PeerCache => this.updateConfig({ PeerCache })}
value={this.state.peerCache}
onValueChange={peerCache => this.updateConfig({ peerCache })}
/>
}
/>
</Menu.Section>

<Menu.Section title="Bootstrap">
<Menu.Item
title="Default bootstrap"
customRight={
<Switch
justify="end"
value={this.state.DefaultBootstrap}
onValueChange={DefaultBootstrap =>
this.updateConfig({ DefaultBootstrap })
}
/>
}
/>
{/* <Menu.Item */}
{/* title="Default bootstrap" */}
{/* customRight={ */}
{/* <Switch */}
{/* justify="end" */}
{/* value={this.state.bootstrap} */}
{/* onValueChange={bootstrap => */}
{/* this.updateConfig({ bootstrap }) */}
{/* } */}
{/* /> */}
{/* } */}
{/* /> */}
<Menu.Item
title="IPFS bootstrap (not implem.)"
customRight={<Switch justify="end" disaBLEd value={false} />}
Expand All @@ -149,22 +209,23 @@ class Network extends PureComponent {
onPress={() => {}}
/>
</Menu.Section>
<Menu.Section title="Relay">
<Menu.Item
title="Relay HOP"
customRight={<Switch justify="end" value={this.state.HOP} />}
/>
<Menu.Item
title="DHT Bucket"
customRight={
<Switch
justify="end"
value={this.state.DHT}
onValueChange={DHT => this.updateConfig({ DHT })}
/>
}
/>
</Menu.Section>

{/* <Menu.Section title="Relay"> */}
{/* <Menu.Item */}
{/* title="Relay HOP" */}
{/* customRight={<Switch justify="end" value={this.state.HOP} />} */}
{/* /> */}
{/* <Menu.Item */}
{/* title="DHT Bucket" */}
{/* customRight={ */}
{/* <Switch */}
{/* justify="end" */}
{/* value={this.state.DHT} */}
{/* onValueChange={DHT => this.updateConfig({ DHT })} */}
{/* /> */}
{/* } */}
{/* /> */}
{/* </Menu.Section> */}
</Menu>
)
}
Expand Down

0 comments on commit 04d1cfe

Please sign in to comment.