Skip to content

Commit

Permalink
Fix daemon initialization after deleting keys (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmerrill6 authored Oct 19, 2020
1 parent e2349fe commit 1835341
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
6 changes: 3 additions & 3 deletions core/space/services/services_keypair.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
13 changes: 12 additions & 1 deletion core/textile/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down
4 changes: 3 additions & 1 deletion core/textile/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion core/textile/textile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions mocks/Client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1835341

Please sign in to comment.