From 183534123f975fda281606247ad65f3bc79cd5e2 Mon Sep 17 00:00:00 2001 From: Daniel Merrill Date: Mon, 19 Oct 2020 17:19:07 -0300 Subject: [PATCH] Fix daemon initialization after deleting keys (#212) --- core/space/services/services_keypair.go | 6 +++--- core/textile/client.go | 13 ++++++++++++- core/textile/model/model.go | 4 +++- core/textile/textile.go | 2 +- mocks/Client.go | 12 ++++++------ 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/core/space/services/services_keypair.go b/core/space/services/services_keypair.go index 02d8be35..5a304211 100644 --- a/core/space/services/services_keypair.go +++ b/core/space/services/services_keypair.go @@ -77,12 +77,12 @@ func (s *Space) DeleteKeypair(ctx context.Context) error { return err } - if err := s.keychain.DeleteKeypair(); err != nil { + // Tell the textile client to stop operations + if err := s.tc.RemoveKeys(ctx); err != nil { return err } - // Tell the textile client to stop operations - if err := s.tc.RemoveKeys(); err != nil { + if err := s.keychain.DeleteKeypair(); err != nil { return err } diff --git a/core/textile/client.go b/core/textile/client.go index 1f36a058..135e2bdf 100644 --- a/core/textile/client.go +++ b/core/textile/client.go @@ -18,6 +18,7 @@ import ( "github.com/FleekHQ/space-daemon/core/textile/model" "github.com/FleekHQ/space-daemon/core/textile/notifier" synchronizer "github.com/FleekHQ/space-daemon/core/textile/sync" + "github.com/FleekHQ/space-daemon/core/textile/utils" "github.com/FleekHQ/space-daemon/core/util/address" "github.com/FleekHQ/space-daemon/log" threadsClient "github.com/textileio/go-threads/api/client" @@ -471,7 +472,7 @@ func (tc *textileClient) healthcheck(ctx context.Context) { } } -func (tc *textileClient) RemoveKeys() error { +func (tc *textileClient) RemoveKeys(ctx context.Context) error { if err := tc.hubAuth.ClearCache(); err != nil { return err } @@ -484,6 +485,16 @@ func (tc *textileClient) RemoveKeys() error { tc.isConnectedToHub = false tc.keypairDeleted <- true + metathreadID, err := utils.NewDeterministicThreadID(tc.kc, utils.MetathreadThreadVariant) + if err != nil { + return err + } + + err = tc.threads.DeleteDB(ctx, metathreadID) + if err != nil { + return err + } + return nil } diff --git a/core/textile/model/model.go b/core/textile/model/model.go index 0d1afd13..1c7c87a0 100644 --- a/core/textile/model/model.go +++ b/core/textile/model/model.go @@ -112,7 +112,9 @@ func (m *model) findOrCreateMetaThreadID(ctx context.Context) (*thread.ID, error return nil, err } - if err := m.threads.NewDB(ctx, dbID, db.WithNewManagedThreadKey(managedKey)); err != nil { + err = m.threads.NewDB(ctx, dbID, db.WithNewManagedThreadKey(managedKey)) + st := err.Error() + if err != nil && st != "rpc error: code = Unknown desc = db already exists" { return nil, err } diff --git a/core/textile/textile.go b/core/textile/textile.go index c55f5c52..cf00dade 100644 --- a/core/textile/textile.go +++ b/core/textile/textile.go @@ -57,7 +57,7 @@ type Client interface { ShareFilesViaPublicKey(ctx context.Context, paths []domain.FullPath, pubkeys []crypto.PubKey, keys [][]byte) error AcceptSharedFilesInvitation(ctx context.Context, invitation domain.Invitation) (domain.Invitation, error) RejectSharedFilesInvitation(ctx context.Context, invitation domain.Invitation) (domain.Invitation, error) - RemoveKeys() error + RemoveKeys(ctx context.Context) error AttachMailboxNotifier(notif GrpcMailboxNotifier) AttachSynchronizerNotifier(notif sync.EventNotifier) GetReceivedFiles(ctx context.Context, accepted bool, seek string, limit int) ([]*domain.SharedDirEntry, string, error) diff --git a/mocks/Client.go b/mocks/Client.go index 5406109b..78007210 100644 --- a/mocks/Client.go +++ b/mocks/Client.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.3.0. DO NOT EDIT. +// Code generated by mockery v2.0.0. DO NOT EDIT. package mocks @@ -415,13 +415,13 @@ func (_m *Client) RejectSharedFilesInvitation(ctx context.Context, invitation do return r0, r1 } -// RemoveKeys provides a mock function with given fields: -func (_m *Client) RemoveKeys() error { - ret := _m.Called() +// RemoveKeys provides a mock function with given fields: ctx +func (_m *Client) RemoveKeys(ctx context.Context) error { + ret := _m.Called(ctx) var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(ctx) } else { r0 = ret.Error(0) }