From efb2bb5653365816cb10138926608c0eaa67fd92 Mon Sep 17 00:00:00 2001 From: Godefroy Ponsinet Date: Wed, 31 Oct 2018 10:44:00 +0100 Subject: [PATCH] fix(network): add start method to handle panic in account Signed-off-by: Godefroy Ponsinet --- client/react-native/common/components/App.js | 41 ++-- .../Screens/Settings/Devtools/List.js | 45 +++- .../common/graphql/queries/Panic.js | 16 ++ .../common/graphql/queries/index.js | 1 + .../react-native/common/relay/environment.js | 25 +- client/react-native/common/schema.graphql | 3 + client/react-native/gomobile/core.go | 95 +++---- .../jsonclient/berty.node.service.gen.go | 15 ++ .../node/graphql/graph/generated/generated.go | 69 ++++++ core/api/node/graphql/resolver.go | 3 + core/api/node/graphql/service.gen.graphql | 3 + core/api/node/service.pb.go | 232 ++++++++++-------- core/api/node/service.proto | 5 + core/cmd/berty/daemon.go | 5 +- core/manager/account/account.go | 59 ++++- core/manager/account/options.go | 26 +- core/network/driver.go | 6 +- core/network/p2p/p2p.go | 50 ++-- core/network/p2p/test/p2p_test.go | 11 +- core/node/nodeapi_devtools.go | 4 + core/test/e2e_test.go | 14 +- 21 files changed, 501 insertions(+), 227 deletions(-) create mode 100644 client/react-native/common/graphql/queries/Panic.js diff --git a/client/react-native/common/components/App.js b/client/react-native/common/components/App.js index 10f5fa0483..3174d71841 100644 --- a/client/react-native/common/components/App.js +++ b/client/react-native/common/components/App.js @@ -1,6 +1,11 @@ import React, { PureComponent } from 'react' import Screens from './Screens' -import { NativeModules, Platform, ActivityIndicator, Linking } from 'react-native' +import { + NativeModules, + Platform, + ActivityIndicator, + Linking, +} from 'react-native' import { Flex } from './Library' import { subscriptions } from '../graphql' import { SafeAreaView, NavigationActions } from 'react-navigation' @@ -18,11 +23,7 @@ export default class App extends PureComponent { async componentDidMount () { try { await CoreModule.start() - } catch (e) { - console.warn(e) - } - - try { + await CoreModule.getPort() subscriptions.eventStream.subscribe({ iterator: function * () { try { @@ -52,11 +53,13 @@ export default class App extends PureComponent { subscriptions.eventStream.dispose() } - Linking.getInitialURL().then(url => { - if (url !== null) { - this.handleOpenURL({ url }) - } - }).catch(() => {}) + Linking.getInitialURL() + .then(url => { + if (url !== null) { + this.handleOpenURL({ url }) + } + }) + .catch(() => {}) if (this._handleOpenURL === undefined) { this._handleOpenURL = this.handleOpenURL.bind(this) @@ -86,14 +89,18 @@ export default class App extends PureComponent { const urlParts = url.split('/') - if (urlParts.length === 3 && urlParts[0] === 'add-contact' && urlParts[1] === 'public-key') { + if ( + urlParts.length === 3 && + urlParts[0] === 'add-contact' && + urlParts[1] === 'public-key' + ) { console.log('Adding new contact via public key') this.navigation.dispatch( NavigationActions.navigate({ routeName: 'modal/contacts/add/by-public-key', params: { initialKey: urlParts[2] }, - }), + }) ) } } @@ -107,7 +114,13 @@ export default class App extends PureComponent { )} - {success && { this.navigation = nav }} />} + {success && ( + { + this.navigation = nav + }} + /> + )} {Platform.OS === 'ios' && } ) diff --git a/client/react-native/common/components/Screens/Settings/Devtools/List.js b/client/react-native/common/components/Screens/Settings/Devtools/List.js index 9b334b1902..eb855a7ed2 100644 --- a/client/react-native/common/components/Screens/Settings/Devtools/List.js +++ b/client/react-native/common/components/Screens/Settings/Devtools/List.js @@ -3,24 +3,28 @@ import React, { PureComponent } from 'react' import { Flex, Header, Menu, Screen, Text } from '../../../Library' import { colors } from '../../../../constants' +import { queries } from '../../../../graphql' const { CoreModule } = NativeModules export default class List extends PureComponent { static navigationOptions = ({ navigation }) => ({ - header: navigation.getParam('restartDaemon') ? null : ( -
- ), + header: + navigation.getParam('restartDaemon') || + navigation.getParam('panic') ? null : ( +
+ ), tabBarVisible: false, }) state = { restartDaemon: false, + panic: false, } restartDaemon = async () => { @@ -28,6 +32,7 @@ export default class List extends PureComponent { this.setState({ restartDaemon: true }, async () => { try { await CoreModule.restart() + await CoreModule.getPort() this.props.navigation.setParams({ restartDaemon: false, }) @@ -38,10 +43,26 @@ export default class List extends PureComponent { }) } + panic = async () => { + this.props.navigation.setParams({ panic: true }) + this.setState({ panic: true }, async () => { + try { + queries.Panic.fetch() + await CoreModule.getPort() + this.props.navigation.setParams({ + panic: false, + }) + this.setState({ panic: false }) + } catch (err) { + console.error(err) + } + }) + } + render () { const { navigation } = this.props - const { restartDaemon } = this.state - if (restartDaemon) { + const { restartDaemon, panic } = this.state + if (restartDaemon || panic) { return ( @@ -49,7 +70,8 @@ export default class List extends PureComponent { - Daemon is restarting, please wait ... + {restartDaemon && 'Daemon is restarting, please wait ...'} + {panic && 'Daemon has been panicked, please wait ...'} @@ -70,6 +92,7 @@ export default class List extends PureComponent { title='Restart daemon' onPress={this.restartDaemon} /> + fetchQuery(environment, query, variables), +} diff --git a/client/react-native/common/graphql/queries/index.js b/client/react-native/common/graphql/queries/index.js index 093e6dfe20..6190eff1d1 100644 --- a/client/react-native/common/graphql/queries/index.js +++ b/client/react-native/common/graphql/queries/index.js @@ -4,3 +4,4 @@ export Contact from './Contact' export DeviceInfos from './DeviceInfos' export AppVersion from './AppVersion' export EventList from './EventList' +export Panic from './Panic' diff --git a/client/react-native/common/relay/environment.js b/client/react-native/common/relay/environment.js index 331261d9b1..bffa7fd79c 100644 --- a/client/react-native/common/relay/environment.js +++ b/client/react-native/common/relay/environment.js @@ -1,8 +1,9 @@ -import { Environment, Network, RecordSource, Store } from 'relay-runtime' +import { NativeModules, Platform } from 'react-native' import { SubscriptionClient } from 'subscriptions-transport-ws' -import { Platform, NativeModules } from 'react-native' import { installRelayDevTools } from 'relay-devtools' +import { Environment, Network, RecordSource, Store } from 'relay-runtime' + // eslint-disable-next-line if (__DEV__) { installRelayDevTools() @@ -12,7 +13,7 @@ if (__DEV__) { if (Platform.OS === 'web') { const CoreModule = { start: async () => {}, - restart: async () => {}, + restart: async () => console.warn('not implemented in web'), getPort: async () => { const url = new URL(window.location.href) return url.searchParams.get('gql-port') || '8700' @@ -64,26 +65,12 @@ let getIP = () => } }) -const getPortInterval = async resolve => { - try { - const port = await CoreModule.getPort() - resolve(port) - } catch (error) { - console.warn(error) - setTimeout(() => { - getPortInterval(resolve) - }, 1000) - } -} -const getPort = () => new Promise(resolve => getPortInterval(resolve)) - getIP().then(console.log) -getPort().then(console.log) export const fetchQuery = async (operation, variables) => { try { const response = await fetch( - `http://${await getIP()}:${await getPort()}/query`, + `http://${await getIP()}:${await CoreModule.getPort()}/query`, { method: 'POST', headers: { @@ -106,7 +93,7 @@ const setupSubscription = async (config, variables, cacheConfig, observer) => { try { const query = config.text const subscriptionClient = new SubscriptionClient( - `ws://${await getIP()}:${await getPort()}/query`, + `ws://${await getIP()}:${await CoreModule.getPort()}/query`, { reconnect: true, } diff --git a/client/react-native/common/schema.graphql b/client/react-native/common/schema.graphql index 3d646af53b..73374853ef 100644 --- a/client/react-native/common/schema.graphql +++ b/client/react-native/common/schema.graphql @@ -640,6 +640,9 @@ type Query { AppVersion( T: Bool! ): BertyNodeAppVersionPayload + Panic( + T: Bool! + ): BertyNodeVoidPayload } type Mutation { diff --git a/client/react-native/gomobile/core.go b/client/react-native/gomobile/core.go index 83dd8bcf50..2f5c2f5910 100644 --- a/client/react-native/gomobile/core.go +++ b/client/react-native/gomobile/core.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "net" - "os" "strconv" "strings" "time" @@ -22,7 +21,7 @@ var ( defaultBootstrap = []string{ "/ip4/104.248.78.238/tcp/4004/ipfs/QmPCbsVWDtLTdCtwfp5ftZ96xccUNe4hegKStgbss8YACT", } - currentAccount *account.Account + accountName = "new-berty-user" ) func initLogger(logger Logger) error { @@ -51,24 +50,61 @@ func getRandomPort() (int, error) { } func GetPort() (int, error) { + currentAccount, _ := account.Get(accountName) if currentAccount == nil || currentAccount.GQLBind == "" { - return 0, errors.New("wait for daemon to start") + logger().Debug("waiting for daemon to start") + time.Sleep(time.Second) + return GetPort() } return strconv.Atoi(strings.Split(currentAccount.GQLBind, ":")[1]) } func Start(datastorePath string, loggerNative Logger) error { - if currentAccount != nil { - return errors.New("daemon already started") - } if err := initLogger(loggerNative); err != nil { return err } + a, _ := account.Get(accountName) + if a != nil { + return errors.New("daemon already started") + } + go func() { + for { + err := daemon(datastorePath, loggerNative) + if err != nil { + logger().Error("handle error, try to restart", zap.Error(err)) + } else { + logger().Info("restarting daemon") + } + } + }() + return nil +} - name := os.Getenv("USER") - if name == "" { - name = "new-berty-user" +func Restart(datastorePath string, loggerNative Logger) error { + currentAccount, _ := account.Get(accountName) + if currentAccount != nil { + currentAccount.Close() + account.Remove(currentAccount) + currentAccount = nil + } else { + go func() { + for { + err := daemon(datastorePath, loggerNative) + if err != nil { + logger().Error("handle error, try to restart", zap.Error(err)) + } else { + logger().Info("restarting daemon") + } + } + }() } + return nil +} + +func daemon(datastorePath string, loggerNative Logger) error { + + a := &account.Account{} + defer a.PanicHandler() grpcPort, err := getRandomPort() if err != nil { @@ -79,8 +115,8 @@ func Start(datastorePath string, loggerNative Logger) error { return err } - currentAccount, err = account.New( - account.WithName(name), + a, err = account.New( + account.WithName(accountName), account.WithPassphrase("secure"), account.WithDatabase(&account.DatabaseOptions{ Path: datastorePath, @@ -108,39 +144,12 @@ func Start(datastorePath string, loggerNative Logger) error { return err } - err = currentAccount.Open() + err = a.Open() if err != nil { - currentAccount.Close() - currentAccount = nil + a.Close() + account.Remove(a) + a = nil return err } - - go func() { - err := <-currentAccount.ErrChan() - logger().Error("handle account error, try to restart", zap.Error(err)) - for { - if currentAccount == nil { - err = Start(datastorePath, loggerNative) - } else { - err = Restart(datastorePath, loggerNative) - } - if err != nil { - logger().Error("restart error", zap.Error(err)) - time.Sleep(time.Second) - continue - } - break - } - }() - - return nil -} - -func Restart(datastorePath string, logger Logger) error { - if currentAccount == nil { - return errors.New("daemon not started") - } - currentAccount.Close() - currentAccount = nil - return Start(datastorePath, logger) + return <-a.ErrChan() } diff --git a/core/api/client/jsonclient/berty.node.service.gen.go b/core/api/client/jsonclient/berty.node.service.gen.go index f8a4c6a8a5..78f9e1b577 100644 --- a/core/api/client/jsonclient/berty.node.service.gen.go +++ b/core/api/client/jsonclient/berty.node.service.gen.go @@ -36,6 +36,7 @@ func init() { registerUnary("berty.node.DebugPing", NodeDebugPing) registerUnary("berty.node.DeviceInfos", NodeDeviceInfos) registerUnary("berty.node.AppVersion", NodeAppVersion) + registerUnary("berty.node.Panic", NodePanic) } func NodeEventStream(client *client.Client, ctx context.Context, jsonInput []byte) (GenericServerStreamClient, error) { @@ -417,3 +418,17 @@ func NodeAppVersion(client *client.Client, ctx context.Context, jsonInput []byte } return client.Node().AppVersion(ctx, &typedInput) } + +func NodePanic(client *client.Client, ctx context.Context, jsonInput []byte) (interface{}, error) { + logger().Debug("client call", + zap.String("service", "Service"), + zap.String("method", "Panic"), + zap.String("input", string(jsonInput)), + ) + + var typedInput node.Void + if err := json.Unmarshal(jsonInput, &typedInput); err != nil { + return nil, err + } + return client.Node().Panic(ctx, &typedInput) +} diff --git a/core/api/node/graphql/graph/generated/generated.go b/core/api/node/graphql/graph/generated/generated.go index 18098d0805..16d0d30da7 100644 --- a/core/api/node/graphql/graph/generated/generated.go +++ b/core/api/node/graphql/graph/generated/generated.go @@ -549,6 +549,7 @@ type ComplexityRoot struct { GetConversationMember func(childComplexity int, id string, createdAt *time.Time, updatedAt *time.Time, deletedAt *time.Time, status *int32, contact *entity.Contact, conversationId string, contactId string) int DeviceInfos func(childComplexity int, T bool) int AppVersion func(childComplexity int, T bool) int + Panic func(childComplexity int, T bool) int } Subscription struct { @@ -630,6 +631,7 @@ type QueryResolver interface { GetConversationMember(ctx context.Context, id string, createdAt *time.Time, updatedAt *time.Time, deletedAt *time.Time, status *int32, contact *entity.Contact, conversationId string, contactId string) (*entity.ConversationMember, error) DeviceInfos(ctx context.Context, T bool) (*node.DeviceInfosOutput, error) AppVersion(ctx context.Context, T bool) (*node.AppVersionOutput, error) + Panic(ctx context.Context, T bool) (*node.Void, error) } type SubscriptionResolver interface { EventStream(ctx context.Context, filter *p2p.Event) (<-chan *p2p.Event, error) @@ -2189,6 +2191,21 @@ func field_Query_AppVersion_args(rawArgs map[string]interface{}) (map[string]int } +func field_Query_Panic_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["T"]; ok { + var err error + arg0, err = models.UnmarshalBool(tmp) + if err != nil { + return nil, err + } + } + args["T"] = arg0 + return args, nil + +} + func field_Query___type_args(rawArgs map[string]interface{}) (map[string]interface{}, error) { args := map[string]interface{}{} var arg0 string @@ -4425,6 +4442,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.AppVersion(childComplexity, args["T"].(bool)), true + case "Query.Panic": + if e.complexity.Query.Panic == nil { + break + } + + args, err := field_Query_Panic_args(rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Panic(childComplexity, args["T"].(bool)), true + case "Subscription.EventStream": if e.complexity.Subscription.EventStream == nil { break @@ -15710,6 +15739,12 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr out.Values[i] = ec._Query_AppVersion(ctx, field) wg.Done() }(i, field) + case "Panic": + wg.Add(1) + go func(i int, field graphql.CollectedField) { + out.Values[i] = ec._Query_Panic(ctx, field) + wg.Done() + }(i, field) case "__type": out.Values[i] = ec._Query___type(ctx, field) case "__schema": @@ -16031,6 +16066,37 @@ func (ec *executionContext) _Query_AppVersion(ctx context.Context, field graphql return ec._BertyNodeAppVersionPayload(ctx, field.Selections, res) } +// nolint: vetshadow +func (ec *executionContext) _Query_Panic(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rawArgs := field.ArgumentMap(ec.Variables) + args, err := field_Query_Panic_args(rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + rctx := &graphql.ResolverContext{ + Object: "Query", + Args: args, + Field: field, + } + ctx = graphql.WithResolverContext(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Panic(rctx, args["T"].(bool)) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*node.Void) + rctx.Result = res + + if res == nil { + return graphql.Null + } + + return ec._BertyNodeVoidPayload(ctx, field.Selections, res) +} + // nolint: vetshadow func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { rawArgs := field.ArgumentMap(ec.Variables) @@ -18677,6 +18743,9 @@ type Query { AppVersion( T: Bool! ): BertyNodeAppVersionPayload + Panic( + T: Bool! + ): BertyNodeVoidPayload } type Mutation { diff --git a/core/api/node/graphql/resolver.go b/core/api/node/graphql/resolver.go index 02256d9e25..14e9e0121c 100644 --- a/core/api/node/graphql/resolver.go +++ b/core/api/node/graphql/resolver.go @@ -470,6 +470,9 @@ func (r *queryResolver) DeviceInfos(ctx context.Context, T bool) (*node.DeviceIn func (r *queryResolver) AppVersion(ctx context.Context, T bool) (*node.AppVersionOutput, error) { return r.client.AppVersion(ctx, &node.Void{T: true}) } +func (r *queryResolver) Panic(ctx context.Context, T bool) (*node.Void, error) { + return r.client.Panic(ctx, &node.Void{}) +} type subscriptionResolver struct{ *Resolver } diff --git a/core/api/node/graphql/service.gen.graphql b/core/api/node/graphql/service.gen.graphql index 3d646af53b..73374853ef 100644 --- a/core/api/node/graphql/service.gen.graphql +++ b/core/api/node/graphql/service.gen.graphql @@ -640,6 +640,9 @@ type Query { AppVersion( T: Bool! ): BertyNodeAppVersionPayload + Panic( + T: Bool! + ): BertyNodeVoidPayload } type Mutation { diff --git a/core/api/node/service.pb.go b/core/api/node/service.pb.go index f481b817f9..6686e26980 100644 --- a/core/api/node/service.pb.go +++ b/core/api/node/service.pb.go @@ -46,7 +46,7 @@ func (m *DeviceInfosOutput) Reset() { *m = DeviceInfosOutput{} } func (m *DeviceInfosOutput) String() string { return proto.CompactTextString(m) } func (*DeviceInfosOutput) ProtoMessage() {} func (*DeviceInfosOutput) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{0} + return fileDescriptor_service_15df9137e413a56d, []int{0} } func (m *DeviceInfosOutput) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -94,7 +94,7 @@ func (m *DeviceInfo) Reset() { *m = DeviceInfo{} } func (m *DeviceInfo) String() string { return proto.CompactTextString(m) } func (*DeviceInfo) ProtoMessage() {} func (*DeviceInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{1} + return fileDescriptor_service_15df9137e413a56d, []int{1} } func (m *DeviceInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -148,7 +148,7 @@ func (m *AppVersionOutput) Reset() { *m = AppVersionOutput{} } func (m *AppVersionOutput) String() string { return proto.CompactTextString(m) } func (*AppVersionOutput) ProtoMessage() {} func (*AppVersionOutput) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{2} + return fileDescriptor_service_15df9137e413a56d, []int{2} } func (m *AppVersionOutput) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -195,7 +195,7 @@ func (m *PingDestination) Reset() { *m = PingDestination{} } func (m *PingDestination) String() string { return proto.CompactTextString(m) } func (*PingDestination) ProtoMessage() {} func (*PingDestination) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{3} + return fileDescriptor_service_15df9137e413a56d, []int{3} } func (m *PingDestination) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -243,7 +243,7 @@ func (m *ContactRequestInput) Reset() { *m = ContactRequestInput{} } func (m *ContactRequestInput) String() string { return proto.CompactTextString(m) } func (*ContactRequestInput) ProtoMessage() {} func (*ContactRequestInput) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{4} + return fileDescriptor_service_15df9137e413a56d, []int{4} } func (m *ContactRequestInput) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -298,7 +298,7 @@ func (m *ConversationAddMessageInput) Reset() { *m = ConversationAddMess func (m *ConversationAddMessageInput) String() string { return proto.CompactTextString(m) } func (*ConversationAddMessageInput) ProtoMessage() {} func (*ConversationAddMessageInput) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{5} + return fileDescriptor_service_15df9137e413a56d, []int{5} } func (m *ConversationAddMessageInput) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -352,7 +352,7 @@ func (m *EventStreamInput) Reset() { *m = EventStreamInput{} } func (m *EventStreamInput) String() string { return proto.CompactTextString(m) } func (*EventStreamInput) ProtoMessage() {} func (*EventStreamInput) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{6} + return fileDescriptor_service_15df9137e413a56d, []int{6} } func (m *EventStreamInput) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -403,7 +403,7 @@ func (m *EventListInput) Reset() { *m = EventListInput{} } func (m *EventListInput) String() string { return proto.CompactTextString(m) } func (*EventListInput) ProtoMessage() {} func (*EventListInput) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{7} + return fileDescriptor_service_15df9137e413a56d, []int{7} } func (m *EventListInput) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -458,7 +458,7 @@ func (m *EventEdge) Reset() { *m = EventEdge{} } func (m *EventEdge) String() string { return proto.CompactTextString(m) } func (*EventEdge) ProtoMessage() {} func (*EventEdge) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{8} + return fileDescriptor_service_15df9137e413a56d, []int{8} } func (m *EventEdge) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -513,7 +513,7 @@ func (m *EventListConnection) Reset() { *m = EventListConnection{} } func (m *EventListConnection) String() string { return proto.CompactTextString(m) } func (*EventListConnection) ProtoMessage() {} func (*EventListConnection) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{9} + return fileDescriptor_service_15df9137e413a56d, []int{9} } func (m *EventListConnection) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -571,7 +571,7 @@ func (m *ContactListInput) Reset() { *m = ContactListInput{} } func (m *ContactListInput) String() string { return proto.CompactTextString(m) } func (*ContactListInput) ProtoMessage() {} func (*ContactListInput) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{10} + return fileDescriptor_service_15df9137e413a56d, []int{10} } func (m *ContactListInput) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -626,7 +626,7 @@ func (m *ContactEdge) Reset() { *m = ContactEdge{} } func (m *ContactEdge) String() string { return proto.CompactTextString(m) } func (*ContactEdge) ProtoMessage() {} func (*ContactEdge) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{11} + return fileDescriptor_service_15df9137e413a56d, []int{11} } func (m *ContactEdge) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -681,7 +681,7 @@ func (m *ContactListConnection) Reset() { *m = ContactListConnection{} } func (m *ContactListConnection) String() string { return proto.CompactTextString(m) } func (*ContactListConnection) ProtoMessage() {} func (*ContactListConnection) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{12} + return fileDescriptor_service_15df9137e413a56d, []int{12} } func (m *ContactListConnection) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -739,7 +739,7 @@ func (m *ConversationListInput) Reset() { *m = ConversationListInput{} } func (m *ConversationListInput) String() string { return proto.CompactTextString(m) } func (*ConversationListInput) ProtoMessage() {} func (*ConversationListInput) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{13} + return fileDescriptor_service_15df9137e413a56d, []int{13} } func (m *ConversationListInput) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -794,7 +794,7 @@ func (m *ConversationEdge) Reset() { *m = ConversationEdge{} } func (m *ConversationEdge) String() string { return proto.CompactTextString(m) } func (*ConversationEdge) ProtoMessage() {} func (*ConversationEdge) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{14} + return fileDescriptor_service_15df9137e413a56d, []int{14} } func (m *ConversationEdge) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -849,7 +849,7 @@ func (m *ConversationListConnection) Reset() { *m = ConversationListConn func (m *ConversationListConnection) String() string { return proto.CompactTextString(m) } func (*ConversationListConnection) ProtoMessage() {} func (*ConversationListConnection) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{15} + return fileDescriptor_service_15df9137e413a56d, []int{15} } func (m *ConversationListConnection) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -905,7 +905,7 @@ func (m *ConversationCreateInput) Reset() { *m = ConversationCreateInput func (m *ConversationCreateInput) String() string { return proto.CompactTextString(m) } func (*ConversationCreateInput) ProtoMessage() {} func (*ConversationCreateInput) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{16} + return fileDescriptor_service_15df9137e413a56d, []int{16} } func (m *ConversationCreateInput) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -967,7 +967,7 @@ func (m *ConversationManageMembersInput) Reset() { *m = ConversationMana func (m *ConversationManageMembersInput) String() string { return proto.CompactTextString(m) } func (*ConversationManageMembersInput) ProtoMessage() {} func (*ConversationManageMembersInput) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{17} + return fileDescriptor_service_15df9137e413a56d, []int{17} } func (m *ConversationManageMembersInput) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1021,7 +1021,7 @@ func (m *Void) Reset() { *m = Void{} } func (m *Void) String() string { return proto.CompactTextString(m) } func (*Void) ProtoMessage() {} func (*Void) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{18} + return fileDescriptor_service_15df9137e413a56d, []int{18} } func (m *Void) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1075,7 +1075,7 @@ func (m *Pagination) Reset() { *m = Pagination{} } func (m *Pagination) String() string { return proto.CompactTextString(m) } func (*Pagination) ProtoMessage() {} func (*Pagination) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{19} + return fileDescriptor_service_15df9137e413a56d, []int{19} } func (m *Pagination) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1162,7 +1162,7 @@ func (m *PageInfo) Reset() { *m = PageInfo{} } func (m *PageInfo) String() string { return proto.CompactTextString(m) } func (*PageInfo) ProtoMessage() {} func (*PageInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{20} + return fileDescriptor_service_15df9137e413a56d, []int{20} } func (m *PageInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1237,7 +1237,7 @@ func (m *IntegrationTestInput) Reset() { *m = IntegrationTestInput{} } func (m *IntegrationTestInput) String() string { return proto.CompactTextString(m) } func (*IntegrationTestInput) ProtoMessage() {} func (*IntegrationTestInput) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{21} + return fileDescriptor_service_15df9137e413a56d, []int{21} } func (m *IntegrationTestInput) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1288,7 +1288,7 @@ func (m *IntegrationTestOutput) Reset() { *m = IntegrationTestOutput{} } func (m *IntegrationTestOutput) String() string { return proto.CompactTextString(m) } func (*IntegrationTestOutput) ProtoMessage() {} func (*IntegrationTestOutput) Descriptor() ([]byte, []int) { - return fileDescriptor_service_068ff4384fcb3b34, []int{22} + return fileDescriptor_service_15df9137e413a56d, []int{22} } func (m *IntegrationTestOutput) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1416,6 +1416,7 @@ type ServiceClient interface { DebugPing(ctx context.Context, in *PingDestination, opts ...grpc.CallOption) (*Void, error) DeviceInfos(ctx context.Context, in *Void, opts ...grpc.CallOption) (*DeviceInfosOutput, error) AppVersion(ctx context.Context, in *Void, opts ...grpc.CallOption) (*AppVersionOutput, error) + Panic(ctx context.Context, in *Void, opts ...grpc.CallOption) (*Void, error) } type serviceClient struct { @@ -1716,6 +1717,15 @@ func (c *serviceClient) AppVersion(ctx context.Context, in *Void, opts ...grpc.C return out, nil } +func (c *serviceClient) Panic(ctx context.Context, in *Void, opts ...grpc.CallOption) (*Void, error) { + out := new(Void) + err := c.cc.Invoke(ctx, "/berty.node.Service/Panic", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // ServiceServer is the server API for Service service. type ServiceServer interface { // yield new events in real-time @@ -1744,6 +1754,7 @@ type ServiceServer interface { DebugPing(context.Context, *PingDestination) (*Void, error) DeviceInfos(context.Context, *Void) (*DeviceInfosOutput, error) AppVersion(context.Context, *Void) (*AppVersionOutput, error) + Panic(context.Context, *Void) (*Void, error) } func RegisterServiceServer(s *grpc.Server, srv ServiceServer) { @@ -2158,6 +2169,24 @@ func _Service_AppVersion_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } +func _Service_Panic_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Void) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServiceServer).Panic(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/berty.node.Service/Panic", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServiceServer).Panic(ctx, req.(*Void)) + } + return interceptor(ctx, in, info, handler) +} + var _Service_serviceDesc = grpc.ServiceDesc{ ServiceName: "berty.node.Service", HandlerType: (*ServiceServer)(nil), @@ -2234,6 +2263,10 @@ var _Service_serviceDesc = grpc.ServiceDesc{ MethodName: "AppVersion", Handler: _Service_AppVersion_Handler, }, + { + MethodName: "Panic", + Handler: _Service_Panic_Handler, + }, }, Streams: []grpc.StreamDesc{ { @@ -6452,102 +6485,103 @@ var ( ErrIntOverflowService = fmt.Errorf("proto: integer overflow") ) -func init() { proto.RegisterFile("api/node/service.proto", fileDescriptor_service_068ff4384fcb3b34) } - -var fileDescriptor_service_068ff4384fcb3b34 = []byte{ - // 1497 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x58, 0x4b, 0x73, 0xdb, 0x54, - 0x14, 0xae, 0x5a, 0x3b, 0xb1, 0x8f, 0x93, 0x26, 0xbd, 0x79, 0xd4, 0x71, 0xd3, 0x3c, 0x04, 0x03, - 0x21, 0xb4, 0x76, 0x49, 0x98, 0xe1, 0x31, 0x1d, 0x66, 0xf2, 0x22, 0x64, 0x20, 0x90, 0xaa, 0xa1, - 0x8b, 0x6e, 0x3c, 0xd7, 0xd2, 0xb1, 0x23, 0xea, 0x48, 0xaa, 0x74, 0xe5, 0x49, 0xa6, 0x0b, 0xd8, - 0x30, 0x53, 0x36, 0x0c, 0x4b, 0x16, 0xac, 0xf9, 0x01, 0x2c, 0xf8, 0x0d, 0x5d, 0x32, 0xfd, 0x01, - 0xc0, 0x94, 0x25, 0x9b, 0xb0, 0x65, 0xc5, 0xdc, 0xab, 0xab, 0xa7, 0x65, 0xb7, 0x9d, 0x94, 0x9d, - 0xee, 0xb9, 0xe7, 0xf9, 0x9d, 0xa3, 0x73, 0x8e, 0x04, 0xb3, 0xd4, 0x31, 0x1b, 0x96, 0x6d, 0x60, - 0xc3, 0x43, 0xb7, 0x67, 0xea, 0x58, 0x77, 0x5c, 0x9b, 0xd9, 0x04, 0x5a, 0xe8, 0xb2, 0xd3, 0x3a, - 0xbf, 0xa9, 0xd5, 0x38, 0x8f, 0x20, 0xb7, 0xfc, 0x76, 0xa3, 0xe3, 0x52, 0xe7, 0xe8, 0x61, 0x37, - 0xe0, 0xab, 0x4d, 0x89, 0xbb, 0x35, 0xa7, 0x81, 0x3d, 0xb4, 0x98, 0x24, 0x4e, 0xa3, 0xc5, 0x4c, - 0x76, 0xda, 0xd0, 0x6d, 0x8b, 0x51, 0x3d, 0xa4, 0xce, 0xc5, 0xd4, 0x1e, 0xba, 0x1e, 0x65, 0xa6, - 0x6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 0xc2, 0x64, 0x14, 0x65, 0x41, 0x39, 0xc4, 0x13, - 0xa6, 0x7e, 0xaf, 0xc0, 0xb5, 0xad, 0x44, 0x9a, 0x36, 0x0c, 0x63, 0x3f, 0x48, 0x4d, 0x60, 0xef, - 0x23, 0x18, 0x4b, 0x66, 0x51, 0x1a, 0xad, 0xf5, 0x19, 0x8d, 0x38, 0xb4, 0x14, 0x3f, 0xf7, 0x57, - 0xa6, 0x5a, 0xd8, 0xee, 0xf3, 0x57, 0x1a, 0xd3, 0x42, 0x2e, 0xf5, 0x36, 0x4c, 0xee, 0xf0, 0x02, - 0xbb, 0xcb, 0x5c, 0xa4, 0xc7, 0x81, 0x13, 0x2b, 0x30, 0xd2, 0x36, 0xbb, 0x0c, 0x5d, 0x69, 0x7e, - 0x52, 0xea, 0x70, 0xd6, 0x9c, 0xba, 0x60, 0xd6, 0xe4, 0xbd, 0xca, 0xe0, 0xb2, 0x20, 0x7c, 0x66, - 0x86, 0x80, 0xbd, 0xb0, 0x2c, 0x79, 0x1f, 0x4a, 0x0e, 0xed, 0x70, 0xfc, 0xb1, 0xaa, 0x0b, 0xde, - 0x54, 0xed, 0x1c, 0x04, 0x77, 0xa6, 0x6d, 0x6d, 0x16, 0xce, 0xce, 0xe6, 0x14, 0x2d, 0xe2, 0x56, - 0xf7, 0xa0, 0x2c, 0x54, 0xed, 0x18, 0x1d, 0x24, 0xaf, 0x43, 0x81, 0xf3, 0x0f, 0x34, 0x27, 0x6e, +func init() { proto.RegisterFile("api/node/service.proto", fileDescriptor_service_15df9137e413a56d) } + +var fileDescriptor_service_15df9137e413a56d = []byte{ + // 1508 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x58, 0x4b, 0x73, 0xdb, 0xd4, + 0x17, 0xaf, 0x5a, 0x3b, 0xb1, 0x8f, 0x93, 0x26, 0xbd, 0x79, 0xd4, 0x71, 0xd3, 0x3c,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d, 0x64, 0xf2, 0xf6, 0x15, 0xfd, 0x4f, + 0x94, 0x80, 0x0e, 0xa4, 0x7f, 0x7c, 0x91, 0xff, 0x0d, 0x1a, 0x99, 0x89, 0xf1, 0x56, 0x1b, 0x32, + 0x46, 0x32, 0x08, 0x3d, 0x56, 0xd2, 0xcb, 0x80, 0xc0, 0x69, 0x79, 0x90, 0x8d, 0x18, 0xac, 0x61, + 0x16, 0xd6, 0x93, 0x88, 0xbd, 0x31, 0x4c, 0x57, 0x0a, 0xb6, 0xaf, 0xd3, 0xf1, 0xee, 0x59, 0x3d, + 0x93, 0x21, 0x59, 0x1d, 0x24, 0xdf, 0x3f, 0x53, 0x5f, 0x21, 0xec, 0x07, 0xe2, 0x73, 0x2a, 0x5e, + 0x37, 0x4e, 0xf4, 0xae, 0x6f, 0xfc, 0x57, 0xc6, 0x28, 0xcc, 0xe6, 0x7f, 0x53, 0x91, 0x37, 0x07, + 0xd9, 0xcb, 0x7c, 0x77, 0xe5, 0xf4, 0x8a, 0xb4, 0x89, 0x43, 0x98, 0x08, 0x4a, 0x2e, 0x5e, 0x10, + 0x86, 0xf8, 0x37, 0xd4, 0xf7, 0x44, 0x05, 0xb6, 0x61, 0x26, 0xa3, 0x35, 0x40, 0x80, 0xbc, 0x70, + 0xd7, 0xa8, 0xbd, 0x90, 0x23, 0x69, 0x67, 0x1d, 0x2a, 0x9f, 0x52, 0xcb, 0xe8, 0xe2, 0x8b, 0x5a, + 0xa5, 0xc0, 0x89, 0xaf, 0x2e, 0xea, 0x05, 0xb2, 0x0d, 0x93, 0xbb, 0x68, 0xa1, 0x4b, 0x19, 0x7e, + 0x42, 0x1f, 0xe0, 0x36, 0x65, 0x94, 0xf4, 0xf1, 0xe5, 0x48, 0xa6, 0x81, 0x3b, 0x82, 0x29, 0xcd, + 0xb7, 0x32, 0xc3, 0xd5, 0x8b, 0x02, 0x14, 0x62, 0x79, 0x73, 0xba, 0xb6, 0x3c, 0x84, 0x23, 0x18, + 0xce, 0x19, 0x4b, 0xb7, 0xa1, 0xbc, 0x8d, 0x2d, 0xbf, 0xc3, 0xbf, 0xfd, 0xc9, 0xb5, 0xd4, 0x02, + 0x9b, 0xfe, 0x1b, 0x90, 0x1b, 0xed, 0x1e, 0x54, 0x12, 0xff, 0x36, 0x72, 0x02, 0xbd, 0x9e, 0xff, + 0x63, 0x43, 0xfe, 0x06, 0x49, 0xa2, 0xbd, 0x0b, 0x10, 0xff, 0xad, 0xc8, 0xd1, 0x94, 0xea, 0x92, + 0xd9, 0xff, 0x1a, 0x49, 0x45, 0xef, 0x41, 0xf1, 0x80, 0x5a, 0xa6, 0xfe, 0x52, 0xb0, 0xc7, 0x72, + 0x9b, 0xab, 0x4f, 0x9e, 0x2f, 0x28, 0xbf, 0x3d, 0x5f, 0x50, 0xfe, 0x78, 0xbe, 0xa0, 0xfc, 0xf4, + 0xe7, 0xc2, 0x85, 0xfb, 0xd5, 0x80, 0x9b, 0xa1, 0x7e, 0xd4, 0xd0, 0x6d, 0x17, 0x1b, 0xe1, 0xcf, + 0xa9, 0xd6, 0x88, 0x58, 0x1b, 0xd6, 0xff, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x7d, 0x0f, 0x75, 0xd2, + 0xaf, 0x12, 0x00, 0x00, } diff --git a/core/api/node/service.proto b/core/api/node/service.proto index 434c5c75b1..7999511a0e 100644 --- a/core/api/node/service.proto +++ b/core/api/node/service.proto @@ -114,8 +114,13 @@ service Service { rpc AppVersion(Void) returns (AppVersionOutput) { option (berty.gql.graphql_type) = "Query"; }; + + rpc Panic(Void) returns (Void) { + option (berty.gql.graphql_type) = "Query"; + }; } + message DeviceInfosOutput { repeated DeviceInfo infos = 1; } diff --git a/core/cmd/berty/daemon.go b/core/cmd/berty/daemon.go index c610724799..8c057eb029 100644 --- a/core/cmd/berty/daemon.go +++ b/core/cmd/berty/daemon.go @@ -72,9 +72,12 @@ func newDaemonCommand() *cobra.Command { } func daemon(opts *daemonOptions) error { + var err error a := &account.Account{} + defer a.PanicHandler() + accountOptions := account.Options{ account.WithName(opts.nickname), account.WithPassphrase(opts.password), @@ -85,7 +88,7 @@ func daemon(opts *daemonOptions) error { account.WithBanner(banner), account.WithGrpcServer(&account.GrpcServerOptions{ Bind: opts.grpcBind, - Interceptors: false, + Interceptors: true, JaegerAddr: jaegerAddr, }), account.WithGQL(&account.GQLOptions{ diff --git a/core/manager/account/account.go b/core/manager/account/account.go index 6e15b74fb7..3e40e9ccc1 100644 --- a/core/manager/account/account.go +++ b/core/manager/account/account.go @@ -52,6 +52,8 @@ type Account struct { errChan chan error } +var list []*Account + type NewOption func(*Account) error type Options []NewOption @@ -70,9 +72,37 @@ func New(opts ...NewOption) (*Account, error) { return nil, err } + Add(a) return a, nil } +func Get(name string) (*Account, error) { + for _, account := range list { + if account != nil && account.Name == name { + return account, nil + } + } + return nil, errors.New("account with name " + name + " isn't opened") +} + +func Add(a *Account) { + list = append(list, a) +} + +func Remove(a *Account) { + ForEach(func(i int, current *Account) { + if a == current { + list = append(list[:i], list[i+1:]...) + } + }) +} + +func ForEach(callback func(int, *Account)) { + for index, account := range list { + callback(index, account) + } +} + func (a *Account) Validate() error { if a.Name == "" { return errors.New("missing required field (Name) for account") @@ -97,6 +127,11 @@ func (a *Account) Open() error { if a.initOnly { return nil } + + // start + if err := a.startNetwork(); err != nil { + return err + } if err := a.startGrpcServer(); err != nil { return err } @@ -131,6 +166,7 @@ func (a *Account) Close() { if a.grpcListener != nil { a.grpcListener.Close() } + } // Database @@ -156,6 +192,14 @@ func (a *Account) openDatabase() error { return nil } +func (a *Account) startNetwork() error { + go func() { + defer a.PanicHandler() + a.errChan <- a.network.Start() + }() + return nil +} + func (a *Account) startGrpcServer() error { var err error @@ -170,12 +214,12 @@ func (a *Account) startGrpcServer() error { a.grpcListener, err = reuse.Listen(addr.Network(), fmt.Sprintf("%s:%d", addr.IP.String(), addr.Port)) if err != nil { - defer a.panicHandler() + defer a.PanicHandler() return err } go func() { - defer a.panicHandler() + defer a.PanicHandler() a.errChan <- a.grpcServer.Serve(a.grpcListener) }() @@ -190,7 +234,7 @@ func (a *Account) startGQL() error { } go func() { - defer a.panicHandler() + defer a.PanicHandler() a.errChan <- a.grpcServer.Serve(a.ioGrpc.Listener()) }() @@ -214,7 +258,6 @@ func (a *Account) startGQL() error { // start gql server go func() { - defer a.panicHandler() a.errChan <- http.Serve(a.gqlListener, a.gqlHandler) }() return nil @@ -241,9 +284,10 @@ func (a *Account) initNode() error { } func (a *Account) startNode() error { + // start node go func() { - defer a.panicHandler() + defer a.PanicHandler() a.errChan <- a.node.Start() }() @@ -290,8 +334,9 @@ func (a *Account) ErrChan() chan error { return a.errChan } -func (a *Account) panicHandler() { - if r := recover(); r != nil { +func (a *Account) PanicHandler() { + r := recover() + if r != nil { err := errors.New(fmt.Sprintf("%+v", r)) logger().Error("panic handler: panic received, send error to errChan", zap.Error(err)) a.errChan <- err diff --git a/core/manager/account/options.go b/core/manager/account/options.go index 0505739474..2f61aad98b 100644 --- a/core/manager/account/options.go +++ b/core/manager/account/options.go @@ -107,22 +107,27 @@ func WithGrpcServer(opts *GrpcServerOptions) NewOption { opts = &GrpcServerOptions{} } - interceptors := []grpc.ServerOption{} + serverStreamOpts := []grpc.StreamServerInterceptor{ + grpc_recovery.StreamServerInterceptor(), + } + serverUnaryOpts := []grpc.UnaryServerInterceptor{ + grpc_recovery.UnaryServerInterceptor(), + } if opts.Interceptors { - serverStreamOpts := []grpc.StreamServerInterceptor{ + serverStreamOpts = append(serverStreamOpts, // grpc_auth.StreamServerInterceptor(myAuthFunction), // grpc_prometheus.StreamServerInterceptor, grpc_ctxtags.StreamServerInterceptor(), grpc_zap.StreamServerInterceptor(logger()), grpc_recovery.StreamServerInterceptor(), - } - serverUnaryOpts := []grpc.UnaryServerInterceptor{ + ) + serverUnaryOpts = append(serverUnaryOpts, // grpc_prometheus.UnaryServerInterceptor, // grpc_auth.UnaryServerInterceptor(myAuthFunction), grpc_ctxtags.UnaryServerInterceptor(), grpc_zap.UnaryServerInterceptor(logger()), grpc_recovery.UnaryServerInterceptor(), - } + ) if opts.JaegerAddr != "" { var tracer opentracing.Tracer @@ -136,12 +141,12 @@ func WithGrpcServer(opts *GrpcServerOptions) NewOption { serverUnaryOpts = append(serverUnaryOpts, grpc_ot.UnaryServerInterceptor(tracerOpts)) } - interceptors = []grpc.ServerOption{ - grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(serverStreamOpts...)), - grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(serverUnaryOpts...)), - } - } + interceptors := []grpc.ServerOption{ + grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(serverStreamOpts...)), + grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(serverUnaryOpts...)), + } + a.grpcServer = grpc.NewServer(interceptors...) reflection.Register(a.grpcServer) @@ -239,7 +244,6 @@ func WithGQL(opts *GQLOptions) NewOption { ), ) return next(ctx) - }, ), )) diff --git a/core/network/driver.go b/core/network/driver.go index f68118ab66..ec07f4121b 100644 --- a/core/network/driver.go +++ b/core/network/driver.go @@ -4,9 +4,8 @@ import ( "context" "net" - protocol "github.com/libp2p/go-libp2p-protocol" - "berty.tech/core/api/p2p" + protocol "github.com/libp2p/go-libp2p-protocol" ) type Driver interface { @@ -25,6 +24,9 @@ type Driver interface { // PingOtherNode send a ping message to another node PingOtherNode(ctx context.Context, destination string) error + // Start start service listener + Start() error + // Close cleanups things Close() error } diff --git a/core/network/p2p/p2p.go b/core/network/p2p/p2p.go index c4bebd3448..3d70b57e85 100644 --- a/core/network/p2p/p2p.go +++ b/core/network/p2p/p2p.go @@ -3,6 +3,7 @@ package p2p import ( "context" "fmt" + "io" "net" "sync" "time" @@ -71,6 +72,12 @@ type Driver struct { // services dht *dht.IpfsDHT + + listener net.Listener + gs *grpc.Server + + serverTracerClose io.Closer + dialTracerCloser io.Closer } // New create a new driver @@ -156,7 +163,7 @@ func newDriver(ctx context.Context, cfg driverConfig) (*Driver, error) { grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(clientUnaryOpts...)), } - gs := grpc.NewServer(p2pInterceptorsServer...) + driver.gs = grpc.NewServer(p2pInterceptorsServer...) sgrpc := p2pgrpc.NewP2PGrpcService(host) dialOpts := append([]grpc.DialOption{ @@ -165,20 +172,22 @@ func newDriver(ctx context.Context, cfg driverConfig) (*Driver, error) { }, p2pInterceptorsClient...) driver.ccmanager = p2putil.NewNetManager(dialOpts...) - p2p.RegisterServiceServer(gs, (*DriverService)(driver)) - - l := sgrpc.NewListener(ID) - go func() { - if err := gs.Serve(l); err != nil { - logger().Error("Listen error", zap.Error(err)) - } - }() + p2p.RegisterServiceServer(driver.gs, (*DriverService)(driver)) + driver.listener = sgrpc.NewListener(ID) logger().Debug("Host", zap.String("ID", driver.ID()), zap.Strings("Addrs", driver.Addrs())) return driver, nil } +func (d *Driver) Start() error { + if err := d.gs.Serve(d.listener); err != nil { + logger().Error("Listen error", zap.Error(err)) + return err + } + return nil +} + func NewDriver(ctx context.Context, opts ...Option) (*Driver, error) { var cfg driverConfig if err := cfg.Apply(opts...); err != nil { @@ -213,15 +222,28 @@ func (d *Driver) getPeerInfo(addr string) (*pstore.PeerInfo, error) { func (d *Driver) Close() error { // FIXME: save cache to speedup next connections - + var err error // close dht - err := d.dht.Close() - if err != nil { - return err + if d.dht != nil { + err = d.dht.Close() + if err != nil { + logger().Error("p2p close error", zap.Error(err)) + } } // close host - return d.host.Close() + if d.host != nil { + err = d.host.Close() + if err != nil { + logger().Error("p2p close error", zap.Error(err)) + } + } + + if d.listener != nil { + d.listener.Close() + } + + return nil } func (d *Driver) Peerstore() pstore.Peerstore { diff --git a/core/network/p2p/test/p2p_test.go b/core/network/p2p/test/p2p_test.go index 5929902bf6..f9e595b5dc 100644 --- a/core/network/p2p/test/p2p_test.go +++ b/core/network/p2p/test/p2p_test.go @@ -33,7 +33,7 @@ func getBoostrap(d *p2p.Driver) []string { } func setupDriver(bootstrap ...string) (*p2p.Driver, error) { - return p2p.NewDriver( + driver, err := p2p.NewDriver( context.Background(), p2p.WithRandomIdentity(), p2p.WithDefaultMuxers(), @@ -45,6 +45,15 @@ func setupDriver(bootstrap ...string) (*p2p.Driver, error) { p2p.WithListenAddrStrings("/ip4/127.0.0.1/tcp/0"), p2p.WithBootstrapSync(bootstrap...), ) + if err != nil { + return nil, err + } + go func() { + if err = driver.Start(); err != nil { + logger().Error("driver start error", zap.Error(err)) + } + }() + return driver, err } func setupTestLogging() { diff --git a/core/node/nodeapi_devtools.go b/core/node/nodeapi_devtools.go index 8ee491f21e..cb602edd2f 100644 --- a/core/node/nodeapi_devtools.go +++ b/core/node/nodeapi_devtools.go @@ -175,3 +175,7 @@ func (n *Node) RunIntegrationTests(ctx context.Context, input *node.IntegrationT func (n *Node) AppVersion(_ context.Context, input *node.Void) (*node.AppVersionOutput, error) { return &node.AppVersionOutput{Version: core.Version}, nil } + +func (n *Node) Panic(_ context.Context, input *node.Void) (*node.Void, error) { + panic("panic from client") +} diff --git a/core/test/e2e_test.go b/core/test/e2e_test.go index 5583114a44..bff264f2b8 100644 --- a/core/test/e2e_test.go +++ b/core/test/e2e_test.go @@ -6,17 +6,16 @@ import ( "testing" "time" - "berty.tech/core/testrunner" - - "github.com/libp2p/go-libp2p-kad-dht" - . "github.com/smartystreets/goconvey/convey" - "berty.tech/core/api/node" "berty.tech/core/api/p2p" "berty.tech/core/entity" "berty.tech/core/errorcodes" "berty.tech/core/network/mock" p2pnet "berty.tech/core/network/p2p" + "berty.tech/core/testrunner" + "github.com/libp2p/go-libp2p-kad-dht" + . "github.com/smartystreets/goconvey/convey" + "go.uber.org/zap" ) func init() { @@ -793,6 +792,11 @@ func setupP2PNetwork(bootstrap ...string) (*p2pnet.Driver, error) { if err != nil { return nil, err } + go func() { + if err := driver.Start(); err != nil { + logger().Error("driver start error", zap.Error(err)) + } + }() return driver, nil }