From 97ca8e9358e8ed5ee043c6b6fcc57a3d4d0817eb Mon Sep 17 00:00:00 2001 From: Guilhem Fanton Date: Thu, 25 Jul 2019 18:37:00 +0200 Subject: [PATCH] feat(client): update congfig --- client/package-lock.json | 18 +- .../bridge/service/daemon/daemon.pb.json | 4 +- .../Settings/Devtools/Network/Config.js | 48 ++-- core/cmd/berty/daemon.go | 221 +++++++++--------- core/cmd/berty/root.go | 2 +- core/daemon/daemon.pb.go | 158 ++++++------- core/daemon/daemon.proto | 2 +- core/daemon/network.go | 7 +- core/daemon/run.go | 4 +- core/daemon/service.go | 12 +- core/go.mod | 4 +- core/go.sum | 1 + core/manager/account/p2p.go | 7 +- core/node/network.go | 2 +- core/platform/desktop/main.go | 29 ++- core/platform/mobile/core/bridge.go | 27 ++- core/platform/mobile/core/config.go | 2 +- 17 files changed, 298 insertions(+), 250 deletions(-) diff --git a/client/package-lock.json b/client/package-lock.json index 0ec350268f..8d5f2846f3 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -5213,14 +5213,14 @@ }, "dependencies": { "caniuse-lite": { - "version": "1.0.30000987", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000987.tgz", - "integrity": "sha512-O3VrjtRMTxoU5Cn5/QSmXeIR1gkVps4j9jqfIm4FLaQ5JzqBlVjMUG1xWnoYFv8N+H3Lp++aa05TekyIbjHL7g==" + "version": "1.0.30000988", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000988.tgz", + "integrity": "sha512-lPj3T8poYrRc/bniW5SQPND3GRtSrQdUM/R4mCYTbZxyi3jQiggLvZH4+BYUuX0t4TXjU+vMM7KFDQg+rSzZUQ==" }, "electron-to-chromium": { - "version": "1.3.205", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.205.tgz", - "integrity": "sha512-VV+f2FVeFI5D/slUD7A3V1lTMDkQTUGWYH2dZGAijIutN5Aga4Fn/Hv4Gc+60OpXFVLYIq5HpXb2cG6NrGGQaA==" + "version": "1.3.207", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.207.tgz", + "integrity": "sha512-RIgAnfqbjZNECBLjslfy4cIYvcPl3GAXmnENrcoo0TZ8fGkyEEAealAbO7MoevW4xYUPe+e68cWAj6eP0DmMHw==" }, "node-releases": { "version": "1.1.26", @@ -18456,9 +18456,9 @@ } }, "rc-calendar": { - "version": "9.15.4", - "resolved": "https://registry.npmjs.org/rc-calendar/-/rc-calendar-9.15.4.tgz", - "integrity": "sha512-+3gS00OO6OfNL7R9vI/YOY86oZ1NKRiK74CzVinJ6qm1PhQobr8IfSdli3cdj6vib9i1MKVn7xRSgUpgJ0rKhA==", + "version": "9.15.5", + "resolved": "https://registry.npmjs.org/rc-calendar/-/rc-calendar-9.15.5.tgz", + "integrity": "sha512-nvoEXk5P0DADt5b7FHlKiXKj+IhoWawQGSkb5soa6gXQIfoqQJ5+zB2Ogy7k1RxNbxQu4iIkEW/a3+HObVRDdA==", "requires": { "babel-runtime": "6.x", "classnames": "2.x", diff --git a/client/packages/bridge/service/daemon/daemon.pb.json b/client/packages/bridge/service/daemon/daemon.pb.json index 1686e0cc1c..e31d4f5882 100644 --- a/client/packages/bridge/service/daemon/daemon.pb.json +++ b/client/packages/bridge/service/daemon/daemon.pb.json @@ -138,8 +138,8 @@ "type": "bool", "id": 7 }, - "swarmKey": { - "type": "string", + "ipfs": { + "type": "bool", "id": 8 }, "mobile": { diff --git a/client/packages/screen/Settings/Devtools/Network/Config.js b/client/packages/screen/Settings/Devtools/Network/Config.js index 83a464ecd8..bdb199a138 100644 --- a/client/packages/screen/Settings/Devtools/Network/Config.js +++ b/client/packages/screen/Settings/Devtools/Network/Config.js @@ -1,6 +1,7 @@ import { Switch } from 'react-native' import React, { PureComponent } from 'react' import { withBridgeContext } from '@berty/bridge/Context' +import { withNavigation } from 'react-navigation' import { Header, Loader, Menu } from '@berty/component' @@ -10,6 +11,7 @@ const transports = { QUIC: '/ip4/0.0.0.0/udp/0/quic', } +@withNavigation class Network extends PureComponent { static navigationOptions = ({ navigation }) => { const updating = @@ -49,36 +51,54 @@ class Network extends PureComponent { saveConfig = async config => { const { bridge } = this.props - this.props.navigation.setParams({ updating: true }) try { await bridge.daemon.updateNetworkConfig(this.state) } catch (err) { console.error(err) } + + // get config back to be sure to reflect config from the back + try { + const updatedConfig = await bridge.daemon.getNetworkConfig({}) + this.setState(updatedConfig) + } catch (err) { + console.error(err) + } + + console.warn(this.state) + this.props.navigation.setParams({ updating: false }) } - isTransportEnable = (matchPatern) => { - return this.state.bindP2P.reduce((acc, currentTransport) => { - return acc || currentTransport.indexOf(matchPatern) >= 0 + isTransportEnable = matchPatern => { + let enable = false + + this.state.bindP2P.forEach(transport => { + enable = enable || transport.indexOf(matchPatern) >= 0 }) + + return enable } - removeTransport = (matchPatern) => { - return this.state.bindP2P.filter((currentTransport) => { - return currentTransport.indexOf(matchPatern) >= 0 + removeTransport = matchPatern => { + return this.state.bindP2P.filter(currentTransport => { + return currentTransport.indexOf(matchPatern) < 0 }) } - addTransport = (transport) => { + addTransport = transport => { return this.state.bindP2P.concat(transport) } render() { - if (this.state == null) { + if ( + this.state == null || + this.props.navigation.getParam('updating', false) + ) { return } + return ( @@ -88,7 +108,7 @@ class Network extends PureComponent { this.updateConfig({ mobile })} + onValueChange={mobile => this.updateConfig({ mobile })} /> } /> @@ -100,8 +120,8 @@ class Network extends PureComponent { customRight={ this.updateConfig({ Mdns })} + value={this.state.mdns} + onValueChange={mdns => this.updateConfig({ mdns })} /> } /> @@ -134,7 +154,7 @@ class Network extends PureComponent { value={this.isTransportEnable('quic')} onValueChange={enable => { if (enable) { - const bindP2P = this.addTransport(transports.TCP) + const bindP2P = this.addTransport(transports.QUIC) this.updateConfig({ bindP2P }) } else { const bindP2P = this.removeTransport('quic') @@ -152,7 +172,7 @@ class Network extends PureComponent { value={this.isTransportEnable('ble')} onValueChange={enable => { if (enable) { - const bindP2P = this.addTransport(transports.TCP) + const bindP2P = this.addTransport(transports.BLE) this.updateConfig({ bindP2P }) } else { const bindP2P = this.removeTransport('ble') diff --git a/core/cmd/berty/daemon.go b/core/cmd/berty/daemon.go index 6d5a179629..4efa93b807 100644 --- a/core/cmd/berty/daemon.go +++ b/core/cmd/berty/daemon.go @@ -96,7 +96,7 @@ func daemonSetupFlags(flags *pflag.FlagSet, opts *daemonOptions) { flags.BoolVar(&opts.PrivateNetwork, "private-network", true, "enable private network with the default swarm key") flags.BoolVar(&opts.ipfs, "ipfs", false, "connect to ipfs network (override private-network & boostrap)") flags.BoolVar(&opts.peerCache, "cache-peer", true, "if false, network will ask the dht every time he need to send an envelope (emit)") - flags.StringSliceVar(&opts.bindP2P, "bind-p2p", []string{}, "p2p listening address") + flags.StringSliceVar(&opts.bindP2P, "bind-p2p", nil, "p2p listening address") // flags.StringSliceVar(&opts.bindP2P, "bind-p2p", []string{"/ip4/0.0.0.0/tcp/0"}, "p2p listening address") _ = viper.BindPFlags(flags) } @@ -121,6 +121,120 @@ func newDaemonCommand() *cobra.Command { return cmd } +func runDaemon(opts *daemonOptions) error { + sqlConfig := &daemon.SQLConfig{ + Name: opts.sql.name, + Key: opts.sql.key, + } + + if opts.ipfs { + logger().Warn("Connecting to ipfs network") + opts.bootstrap = network.BootstrapIpfs + opts.PrivateNetwork = false + } + + if opts.bindP2P == nil { + opts.bindP2P = []string{ + "/ip4/0.0.0.0/udp/0/quic", + "/ip4/0.0.0.0/tcp/0", + "/ble/00000000-0000-0000-0000-000000000000", + } + } + + networkConfig := &daemon.NetworkConfig{ + PeerCache: opts.peerCache, + Identity: opts.identity, + Bootstrap: opts.bootstrap, + BindP2P: opts.bindP2P, + Mdns: opts.mdns, + PrivateNetwork: opts.PrivateNetwork, + Mobile: opts.mobile, + Ipfs: opts.ipfs, + } + + config := &daemon.Config{ + SqlOpts: sqlConfig, + GrpcBind: opts.grpcBind, + GrpcWebBind: opts.grpcWebBind, + HideBanner: opts.hideBanner, + DropDatabase: opts.dropDatabase, + InitOnly: opts.initOnly, + WithBot: opts.withBot, + Notification: opts.notification, + ApnsCerts: opts.apnsCerts, + ApnsDevVoipCerts: opts.apnsDevVoipCerts, + FcmAPIKeys: opts.fcmAPIKeys, + PrivateKeyFile: opts.privateKeyFile, + NoP2P: opts.noP2P, + NetworkConfig: networkConfig, + } + + startRequest := &daemon.StartRequest{ + Nickname: opts.nickname, + } + + dlogger := zap.L().Named("daemon.grpc") + // serverStreamOpts := []grpc.StreamServerInterceptor{ + // // grpc_auth.StreamServerInterceptor(myAuthFunction), + // grpc_ctxtags.StreamServerInterceptor(), + // grpc_zap.StreamServerInterceptor(dlogger), + // grpc_recovery.StreamServerInterceptor(grpc_recovery.WithRecoveryHandler(errorcodes.RecoveryHandler)), + // errorcodes.StreamServerInterceptor(), + // } + serverUnaryOpts := []grpc.UnaryServerInterceptor{ + // grpc_auth.UnaryServerInterceptor(myAuthFunction), + grpc_ctxtags.UnaryServerInterceptor(), + grpc_zap.UnaryServerInterceptor(dlogger), + grpc_recovery.UnaryServerInterceptor(grpc_recovery.WithRecoveryHandler(errorcodes.RecoveryHandler)), + errorcodes.UnaryServerInterceptor(), + } + + interceptors := []grpc.ServerOption{ + // grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(serverStreamOpts...)), + grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(serverUnaryOpts...)), + } + + // set storage path + if err := deviceinfo.SetStoragePath(opts.sql.path); err != nil { + return err + } + + d := daemon.New() + if opts.notification { + d.Notification = notification.NewDesktopNotification() + } + + if _, err := d.Initialize(context.Background(), config); err != nil { + return err + } + + if _, err := d.Start(context.Background(), startRequest); err != nil { + return err + } + + if opts.daemonWebBind != "" { + go func() { + if err := serveWeb(d, opts.daemonWebBind, interceptors...); err != nil { + logger().Error("serve web", zap.Error(err)) + } + }() + } + + if opts.daemonGRPCBind != "" { + go func() { + if err := serveGrpc(d, opts.daemonGRPCBind, interceptors...); err != nil { + logger().Error("serve web", zap.Error(err)) + } + }() + } + + if !opts.initOnly { + select {} + } + + return nil +} + func serveWeb(d *daemon.Daemon, bind string, interceptors ...grpc.ServerOption) error { gs := grpc.NewServer(interceptors...) daemon.RegisterDaemonServer(gs, d) @@ -227,108 +341,3 @@ func serveGrpc(d *daemon.Daemon, bind string, interceptors ...grpc.ServerOption) return gs.Serve(listener) } - -func runDaemon(opts *daemonOptions) error { - sqlConfig := &daemon.SQLConfig{ - Name: opts.sql.name, - Key: opts.sql.key, - } - - if opts.ipfs { - logger().Warn("Connecting to ipfs network") - opts.bootstrap = network.BootstrapIpfs - opts.PrivateNetwork = false - } - - networkConfig := &daemon.NetworkConfig{ - PeerCache: opts.peerCache, - Identity: opts.identity, - Bootstrap: opts.bootstrap, - BindP2P: opts.bindP2P, - Mdns: opts.mdns, - PrivateNetwork: opts.PrivateNetwork, - Mobile: opts.mobile, - } - - config := &daemon.Config{ - SqlOpts: sqlConfig, - GrpcBind: opts.grpcBind, - GrpcWebBind: opts.grpcWebBind, - HideBanner: opts.hideBanner, - DropDatabase: opts.dropDatabase, - InitOnly: opts.initOnly, - WithBot: opts.withBot, - Notification: opts.notification, - ApnsCerts: opts.apnsCerts, - ApnsDevVoipCerts: opts.apnsDevVoipCerts, - FcmAPIKeys: opts.fcmAPIKeys, - PrivateKeyFile: opts.privateKeyFile, - NoP2P: opts.noP2P, - NetworkConfig: networkConfig, - } - - startRequest := &daemon.StartRequest{ - Nickname: opts.nickname, - } - - dlogger := zap.L().Named("daemon.grpc") - // serverStreamOpts := []grpc.StreamServerInterceptor{ - // // grpc_auth.StreamServerInterceptor(myAuthFunction), - // grpc_ctxtags.StreamServerInterceptor(), - // grpc_zap.StreamServerInterceptor(dlogger), - // grpc_recovery.StreamServerInterceptor(grpc_recovery.WithRecoveryHandler(errorcodes.RecoveryHandler)), - // errorcodes.StreamServerInterceptor(), - // } - serverUnaryOpts := []grpc.UnaryServerInterceptor{ - // grpc_auth.UnaryServerInterceptor(myAuthFunction), - grpc_ctxtags.UnaryServerInterceptor(), - grpc_zap.UnaryServerInterceptor(dlogger), - grpc_recovery.UnaryServerInterceptor(grpc_recovery.WithRecoveryHandler(errorcodes.RecoveryHandler)), - errorcodes.UnaryServerInterceptor(), - } - - interceptors := []grpc.ServerOption{ - // grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(serverStreamOpts...)), - grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(serverUnaryOpts...)), - } - - // set storage path - if err := deviceinfo.SetStoragePath(opts.sql.path); err != nil { - return err - } - - d := daemon.New() - if opts.notification { - d.Notification = notification.NewDesktopNotification() - } - - if _, err := d.Initialize(context.Background(), config); err != nil { - return err - } - - if _, err := d.Start(context.Background(), startRequest); err != nil { - return err - } - - if opts.daemonWebBind != "" { - go func() { - if err := serveWeb(d, opts.daemonWebBind, interceptors...); err != nil { - logger().Error("serve web", zap.Error(err)) - } - }() - } - - if opts.daemonGRPCBind != "" { - go func() { - if err := serveGrpc(d, opts.daemonGRPCBind, interceptors...); err != nil { - logger().Error("serve web", zap.Error(err)) - } - }() - } - - if !opts.initOnly { - select {} - } - - return nil -} diff --git a/core/cmd/berty/root.go b/core/cmd/berty/root.go index 8b61e345cd..e76c58e406 100644 --- a/core/cmd/berty/root.go +++ b/core/cmd/berty/root.go @@ -56,7 +56,7 @@ func newRootCommand() *cobra.Command { defaultJaegerName := os.Getenv("USER") + "@" + os.Getenv("HOST") cmd.PersistentFlags().BoolP("help", "h", false, "Print usage") cmd.PersistentFlags().StringP("log-level", "", "info", "log level (debug, info, warn, error)") - cmd.PersistentFlags().StringP("log-namespaces", "", "core.*", "logger namespaces to enable (supports wildcard)") + cmd.PersistentFlags().StringP("log-namespaces", "", "core.*,network*", "logger namespaces to enable (supports wildcard)") cmd.PersistentFlags().StringP("log-dir", "", "/tmp/berty-logs", "local log files directory") cmd.PersistentFlags().StringP("jaeger-address", "", "127.0.0.1:6831", "ip address / hostname and port of jaeger-agent: :") cmd.PersistentFlags().StringP("jaeger-name", "", defaultJaegerName, "tracer name") diff --git a/core/daemon/daemon.pb.go b/core/daemon/daemon.pb.go index b725dcf133..2138ccf156 100644 --- a/core/daemon/daemon.pb.go +++ b/core/daemon/daemon.pb.go @@ -263,7 +263,7 @@ type NetworkConfig struct { BindP2P []string `protobuf:"bytes,5,rep,name=bindP2P,proto3" json:"bindP2P,omitempty"` Mdns bool `protobuf:"varint,6,opt,name=mdns,proto3" json:"mdns,omitempty"` PrivateNetwork bool `protobuf:"varint,7,opt,name=privateNetwork,proto3" json:"privateNetwork,omitempty"` - SwarmKey string `protobuf:"bytes,8,opt,name=swarmKey,proto3" json:"swarmKey,omitempty"` + Ipfs bool `protobuf:"varint,8,opt,name=ipfs,proto3" json:"ipfs,omitempty"` Mobile bool `protobuf:"varint,9,opt,name=mobile,proto3" json:"mobile,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -345,11 +345,11 @@ func (m *NetworkConfig) GetPrivateNetwork() bool { return false } -func (m *NetworkConfig) GetSwarmKey() string { +func (m *NetworkConfig) GetIpfs() bool { if m != nil { - return m.SwarmKey + return m.Ipfs } - return "" + return false } func (m *NetworkConfig) GetMobile() bool { @@ -676,62 +676,61 @@ func init() { func init() { proto.RegisterFile("daemon/daemon.proto", fileDescriptor_622b4ce7acb47fee) } var fileDescriptor_622b4ce7acb47fee = []byte{ - // 867 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0xcd, 0x6e, 0x23, 0x45, - 0x10, 0xb6, 0x89, 0x7f, 0x2b, 0x4e, 0x36, 0xf4, 0x46, 0x61, 0x14, 0xc0, 0x44, 0x2d, 0x84, 0xa2, - 0x3d, 0x78, 0x95, 0x84, 0xc3, 0x2e, 0x48, 0x48, 0xb1, 0x03, 0xde, 0x28, 0x81, 0x35, 0x63, 0xb1, - 0x48, 0xdc, 0xda, 0x33, 0x95, 0xa4, 0x89,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, 0x3f, - 0x1a, 0x3c, 0xac, 0x61, 0x63, 0xd2, 0xd1, 0xc3, 0x02, 0x3e, 0x87, 0x0d, 0x6b, 0xf4, 0x2e, 0xf1, - 0x5e, 0xc0, 0xe3, 0x1f, 0xa2, 0xf0, 0xee, 0x29, 0x4a, 0xaf, 0xc7, 0xdb, 0xae, 0x42, 0xb9, 0xa7, - 0xfe, 0xfe, 0xef, 0xb7, 0xdd, 0xea, 0x1f, 0xb7, 0xdd, 0xea, 0x9f, 0xb7, 0xdd, 0xea, 0x6f, 0x7f, - 0x75, 0x2b, 0x3f, 0xed, 0x24, 0x6a, 0x84, 0xc1, 0xd5, 0xd3, 0x40, 0xc7, 0x98, 0xfe, 0xed, 0x98, - 0x34, 0xdc, 0xff, 0x8e, 0xa3, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x05, 0x3d, 0x22, 0xae, 0x8e, - 0x08, 0x00, 0x00, + // 863 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0x5f, 0x6f, 0x1b, 0x45, + 0x10, 0xb7, 0x89, 0xff, 0x4e, 0x9c, 0x34, 0x6c, 0xa3, 0x70, 0x0a, 0x60, 0xa2, 0x15, 0x42, 0x51, + 0x1f, 0x5c, 0x25, 0xe1, 0xa1, 0x05, 0x09, 0x29, 0x76, 0xc0, 0x8d, 0x1a, 0xa8, 0x39, 0x8b, 0x22, + 0xf1, 0xb6, 0xbe, 0x1b, 0x27, 0x4b, 0xec, 0xdd, 0xeb, 0xed, 0xb8, 0x95, 0x79, 0xe4, 0x53, 0xf0, + 0x91, 0x78, 0xe4, 0x23, 0xa0, 0xf0, 0x84, 0xc4, 0x87, 0x40, 0xbb, 0x77, 0xe7, 0xdc, 0x99, 0x4b, + 0x45, 0xfa, 0xe4, 0x9d, 0xdf, 0xcd, 0x6f, 0x66, 0x77, 0x7e, 0xb3, 0xb3, 0x86, 0x87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xff, 0xb8, 0xe9, 0x56, 0xff, 0xbc, 0xe9, 0x56, 0x7f, 0xfb, 0xab, 0x5b, 0xf9, 0x69, + 0x2f, 0x71, 0x23, 0x0c, 0xae, 0x1e, 0x07, 0x3a, 0xc6, 0xf4, 0xef, 0xc6, 0xa4, 0xe1, 0xfe, 0x6f, + 0x9c, 0xfc, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x87, 0x6e, 0x30, 0x70, 0x86, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1568,11 +1567,15 @@ func (m *NetworkConfig) MarshalTo(dAtA []byte) (int, error) { } i++ } - if len(m.SwarmKey) > 0 { - dAtA[i] = 0x42 + if m.Ipfs { + dAtA[i] = 0x40 + i++ + if m.Ipfs { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } i++ - i = encodeVarintDaemon(dAtA, i, uint64(len(m.SwarmKey))) - i += copy(dAtA[i:], m.SwarmKey) } if m.Mobile { dAtA[i] = 0x48 @@ -1964,9 +1967,8 @@ func (m *NetworkConfig) Size() (n int) { if m.PrivateNetwork { n += 2 } - l = len(m.SwarmKey) - if l > 0 { - n += 1 + l + sovDaemon(uint64(l)) + if m.Ipfs { + n += 2 } if m.Mobile { n += 2 @@ -2676,10 +2678,10 @@ func (m *NetworkConfig) Unmarshal(dAtA []byte) error { } m.PrivateNetwork = bool(v != 0) case 8: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SwarmKey", wireType) + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Ipfs", wireType) } - var stringLen uint64 + var v int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowDaemon @@ -2689,24 +2691,12 @@ func (m *NetworkConfig) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + v |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthDaemon - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthDaemon - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SwarmKey = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex + m.Ipfs = bool(v != 0) case 9: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Mobile", wireType) diff --git a/core/daemon/daemon.proto b/core/daemon/daemon.proto index 848db1b195..e1b35f3ed5 100644 --- a/core/daemon/daemon.proto +++ b/core/daemon/daemon.proto @@ -50,7 +50,7 @@ message NetworkConfig { repeated string bindP2P = 5; bool mdns = 6; bool privateNetwork = 7; - string swarmKey = 8; + bool ipfs = 8; // @TODO: implement me bool mobile = 9; } diff --git a/core/daemon/network.go b/core/daemon/network.go index e7647ea603..6a0bd5769f 100644 --- a/core/daemon/network.go +++ b/core/daemon/network.go @@ -11,11 +11,16 @@ func NewHost(ctx context.Context, cfg *NetworkConfig) (*host.BertyHost, error) { // base config opts := []host.Option{ host.WithMetricsReporter(), // @TODO: opt this? - host.WithSwarmKey(cfg.SwarmKey), host.WithIdentity(cfg.Identity), host.WithListeners(cfg.BindP2P...), } + if cfg.PrivateNetwork { + opts = append(opts, host.WithSwarmKey(host.DefaultSwarmKey)) + } else { + opts = append(opts, host.WithSwarmKey("")) + } + if cfg.Mobile { opts = append(opts, host.WithMobileMode()) } diff --git a/core/daemon/run.go b/core/daemon/run.go index 61696bd341..d7efd8d00f 100644 --- a/core/daemon/run.go +++ b/core/daemon/run.go @@ -50,7 +50,9 @@ func (d *Daemon) daemon(ctx context.Context, cfg *Config, accountName string) er } if !cfg.NoP2P { - accountOptions = append(accountOptions, account.WithNetwork(NewNetworkDriver(ctx, cfg.NetworkConfig))) + accountOptions = append(accountOptions, account.WithNetwork( + NewNetworkDriver(ctx, cfg.NetworkConfig), + )) } else { accountOptions = append(accountOptions, account.WithEnqueurNetwork()) } diff --git a/core/daemon/service.go b/core/daemon/service.go index c460a02211..f658341752 100644 --- a/core/daemon/service.go +++ b/core/daemon/service.go @@ -224,12 +224,18 @@ func (d *Daemon) StopLocalGRPC(context.Context, *Void) (*Void, error) { func (d *Daemon) UpdateNetworkConfig(ctx context.Context, nc *NetworkConfig) (*Void, error) { currentAccount, _ := account.Get(d.rootContext, d.accountName) - - newHost, err := NewHost(ctx, nc) + newHost, err := NewHost(d.rootContext, nc) if err != nil { return nil, err } - currentAccount.UpdateNetworkHost(ctx, newHost) + go func() { + if err := currentAccount.UpdateNetworkHost(ctx, newHost); err != nil { + logger().Warn("update network error", zap.Error(err)) + } + }() + + // update config + d.config.NetworkConfig = nc return &Void{}, nil } diff --git a/core/go.mod b/core/go.mod index fa2f3d888f..b800058282 100644 --- a/core/go.mod +++ b/core/go.mod @@ -3,7 +3,7 @@ module berty.tech/core go 1.12 require ( - berty.tech/network v0.0.0-20190725074812-0c668fcbee48 + berty.tech/network v0.0.0 cloud.google.com/go v0.34.0 // indirect github.com/0xAX/notificator v0.0.0-20181105090803-d81462e38c21 github.com/NaySoftware/go-fcm v0.0.0-20180207124314-28fff9381d17 @@ -70,3 +70,5 @@ require ( gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/yaml.v2 v2.2.2 ) + +replace berty.tech/network v0.0.0 => ../network diff --git a/core/go.sum b/core/go.sum index 2f8480ad3f..4c9194eee4 100644 --- a/core/go.sum +++ b/core/go.sum @@ -1,3 +1,4 @@ +berty.tech v0.0.0-20190731133108-4354b6650799 h1:XchAr6IUnZQQAyIbOJvuZJTjy+s/PCKN1mzbk5SF0t8= berty.tech/network v0.0.0-20190705175056-c1e3d7d90ac3 h1:4rXAhaOFt1sQBHzMeTnsY8TnSBCp0sZ5w0CEB/9JhA8= berty.tech/network v0.0.0-20190705175056-c1e3d7d90ac3/go.mod h1:i0xFI/jNEHw9qz0AAgSBlwtitoQKTO3ZdbF2xatrrR4= berty.tech/network v0.0.0-20190712164033-f7a09d9c96f6 h1:1BbutSM5UW2w0/B9rw+XBaTl1M/w2ah1iKq0xP2m/2g= diff --git a/core/manager/account/p2p.go b/core/manager/account/p2p.go index 2f10daa3e3..42b3da33bb 100644 --- a/core/manager/account/p2p.go +++ b/core/manager/account/p2p.go @@ -14,7 +14,12 @@ func (a *Account) UpdateNetworkHost(ctx context.Context, bh *host.BertyHost) err ctx = tracer.Context() a.network.UpdateHost(bh) - return nil + + // update metric + a.node.UseNetworkMetric(ctx, bh.Metric) + a.metric = bh.Metric + + return a.network.Join() } func (a *Account) Network() network.Driver { diff --git a/core/node/network.go b/core/node/network.go index 74b87afdf6..fe2c2833d4 100644 --- a/core/node/network.go +++ b/core/node/network.go @@ -57,7 +57,7 @@ func (n *Node) UseNetworkDriver(ctx context.Context, driver network.Driver) erro // configure network n.networkDriver.OnMessage(n.HandleMessage) n.networkDriver.SetLocalContactID(n.UserID()) - n.networkDriver.Join() + go n.networkDriver.Join() // FIXME: subscribe to every owned device IDs // var devices []entity.Device diff --git a/core/platform/desktop/main.go b/core/platform/desktop/main.go index 0ca7533b83..5788001f05 100644 --- a/core/platform/desktop/main.go +++ b/core/platform/desktop/main.go @@ -9,7 +9,7 @@ import ( "berty.tech/core/daemon" "berty.tech/core/pkg/logmanager" - network_config "berty.tech/network/config" + network_config "berty.tech/network" "go.uber.org/zap" "berty.tech/core/platform/desktop/coreinterface" @@ -52,6 +52,21 @@ func main() { Key: "s3cur3", } + networkConfig := &daemon.NetworkConfig{ + PeerCache: true, + Identity: "", + Bootstrap: network_config.DefaultBootstrap, + BindP2P: []string{ + "/ip4/0.0.0.0/udp/0/quic", + "/ip4/0.0.0.0/tcp/0", + "/ble/00000000-0000-0000-0000-000000000000", + }, + Mdns: true, + PrivateNetwork: true, + Mobile: true, + Ipfs: false, + } + config := &daemon.Config{ SqlOpts: sqlConfig, GrpcBind: ":1337", @@ -65,18 +80,8 @@ func main() { ApnsDevVoipCerts: []string{}, FcmAPIKeys: []string{}, PrivateKeyFile: "", - PeerCache: true, - Identity: "", - Bootstrap: network_config.DefaultBootstrap, NoP2P: false, - BindP2P: []string{}, - TransportP2P: []string{}, - Hop: true, - Ble: true, - Mdns: true, - DhtServer: true, - PrivateNetwork: true, - SwarmKeyPath: "", + NetworkConfig: networkConfig, } // Init diff --git a/core/platform/mobile/core/bridge.go b/core/platform/mobile/core/bridge.go index 0935196c22..66b852ee47 100644 --- a/core/platform/mobile/core/bridge.go +++ b/core/platform/mobile/core/bridge.go @@ -8,7 +8,7 @@ import ( "berty.tech/core/daemon" "berty.tech/core/pkg/deviceinfo" "berty.tech/core/pkg/errorcodes" - network_config "berty.tech/network" + "berty.tech/network" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap" @@ -34,6 +34,20 @@ var sqlConfig = &daemon.SQLConfig{ Key: "s3cur3", } +var networkConfig = &daemon.NetworkConfig{ + PeerCache: true, + Bootstrap: network.DefaultBootstrap, + BindP2P: []string{ + "/ip4/0.0.0.0/udp/0/quic", + "/ip4/0.0.0.0/tcp/0", + "/ble/00000000-0000-0000-0000-000000000000", + }, + Mdns: true, + Identity: "", + PrivateNetwork: true, + Mobile: true, +} + var config = &daemon.Config{ SqlOpts: sqlConfig, GrpcBind: ":1337", @@ -47,18 +61,7 @@ var config = &daemon.Config{ ApnsDevVoipCerts: []string{}, FcmAPIKeys: []string{}, PrivateKeyFile: "", - PeerCache: true, - Identity: "", - Bootstrap: network_config.DefaultBootstrap, NoP2P: false, - BindP2P: []string{}, - TransportP2P: []string{}, - Hop: false, - Ble: false, - Mdns: true, - DhtServer: false, - PrivateNetwork: true, - SwarmKeyPath: "", } type NativeBridge interface { diff --git a/core/platform/mobile/core/config.go b/core/platform/mobile/core/config.go index bf4481f95c..445d5428cc 100644 --- a/core/platform/mobile/core/config.go +++ b/core/platform/mobile/core/config.go @@ -1,6 +1,6 @@ package core -import "berty.tech/network/protocol/ble" +import "berty.tech/network/transport/ble" // This file contain the configuration by default