Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/sharing: some more bugs with sharing and mirror file creation #161

Merged
merged 5 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/space-daemon",
"env": {},
"envFile": "${workspaceFolder}/.env",
"args": ["-dev=true"]
}
]
Expand Down
5 changes: 5 additions & 0 deletions config/map_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func NewMap(envVal env.SpaceEnv, flags *Flags) Config {
configBool[Ipfsnode] = flags.Ipfsnode
}

// Temp fix until we move to viper
if configStr[Ipfsaddr] == "" {
configStr[Ipfsaddr] = "/ip4/127.0.0.1/tcp/5001"
}

c := mapConfig{
configStr: configStr,
configInt: configInt,
Expand Down
5 changes: 3 additions & 2 deletions core/env/file_env.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package env

import (
"github.com/joho/godotenv"
syslog "log"
"os"
"strings"

"github.com/joho/godotenv"
)

type spaceEnv struct {
Expand Down Expand Up @@ -55,4 +56,4 @@ func (s spaceEnv) LogLevel() string {
}

return ll
}
}
36 changes: 24 additions & 12 deletions core/space/services/services_sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,22 @@ func (s *Space) OpenSharedFile(ctx context.Context, hash, password, filename str
}, nil
}

func (s *Space) ShareFilesViaPublicKey(ctx context.Context, paths *[]domain.FullPath, pubkeys []crypto.PubKey) error {
func (s *Space) ShareFilesViaPublicKey(ctx context.Context, paths []domain.FullPath, pubkeys []crypto.PubKey) error {
m := s.tc.GetModel()

enckeys := make([][]byte, len(*paths))
for i, path := range *paths {
enhancedPaths := make([]domain.FullPath, len(paths))
enckeys := make([][]byte, len(paths))
for i, path := range paths {
ep := domain.FullPath{
DbId: path.DbId,
Bucket: path.Bucket,
Path: path.Path,
BucketKey: path.BucketKey,
}

// this handles personal bucket since for shared-with-me files
// the dbid will be preset
if path.DbId == "" {
if ep.DbId == "" {
b, err := s.tc.GetDefaultBucket(ctx)
if err != nil {
return err
Expand All @@ -244,10 +251,13 @@ func (s *Space) ShareFilesViaPublicKey(ctx context.Context, paths *[]domain.Full
if err != nil {
return err
}
(*paths)[i].DbId = bs.RemoteDbID

log.Info("incoming dbid nil, updating")
log.Info("using new remote db id: " + bs.RemoteDbID)
dmerrill6 marked this conversation as resolved.
Show resolved Hide resolved
ep.DbId = bs.RemoteDbID
}

if path.Bucket == "" || path.Bucket == t.GetDefaultBucketSlug() {
if ep.Bucket == "" || ep.Bucket == t.GetDefaultBucketSlug() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do shared with me files have ep.Bucket == ""? Because if that's the case it might unintendedly fall into this block for shared-with-me files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So shared with me files will always have a bucket name. But the weird part is that the mirror bucket name is also called personal so it would erroneous fall into the second clause. I made both clauses so that it would default to the personal bucket if it was empty or if personal was supplied explicitly. For now I'm thinking to keep it clean we can change the name of the mirrored buckets to something like shared so it doesn't fall into this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maurycy do you see any issues with this idea? Like if I used personal_mirror for the mirror bucket names. As long as we are not referring the mirror bucket name hardcoded as personal elsewhere that should be fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsonsivar

Not sure if I understand. Do you mean adding a prefix, eg: shared_, personal_?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1742bb0. Mirror buckets now use a different name so it wouldn't fall into this slot unless it was actually a personal bucket (or empty in which case it is personal).

b, err := s.tc.GetDefaultBucket(ctx)
if err != nil {
return err
Expand All @@ -256,29 +266,31 @@ func (s *Space) ShareFilesViaPublicKey(ctx context.Context, paths *[]domain.Full
if err != nil {
return err
}
(*paths)[i].Bucket = b.Slug()
(*paths)[i].BucketKey = bs.RemoteBucketKey
ep.Bucket = b.Slug()
ep.BucketKey = bs.RemoteBucketKey
enckeys = append(enckeys, bs.EncryptionKey)
} else {
r, err := m.FindReceivedFile(ctx, path)
if err != nil {
return err
}
(*paths)[i].Bucket = r.Bucket
(*paths)[i].BucketKey = r.BucketKey
ep.Bucket = r.Bucket
ep.BucketKey = r.BucketKey
enckeys = append(enckeys, r.EncryptionKey)
}

enhancedPaths[i] = ep
}

err := s.tc.ShareFilesViaPublicKey(ctx, *paths, pubkeys, enckeys)
err := s.tc.ShareFilesViaPublicKey(ctx, enhancedPaths, pubkeys, enckeys)
if err != nil {
return err
}

for _, pk := range pubkeys {

d := &domain.Invitation{
ItemPaths: *paths,
ItemPaths: enhancedPaths,
Keys: enckeys,
}

Expand Down
2 changes: 1 addition & 1 deletion core/space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Service interface {
RecoverKeysByLocalBackup(ctx context.Context, pathToKeyBackup string) error
GetNotifications(ctx context.Context, seek string, limit int) ([]*domain.Notification, error)
ToggleBucketBackup(ctx context.Context, bucketName string, bucketBackup bool) error
ShareFilesViaPublicKey(ctx context.Context, paths *[]domain.FullPath, pubkeys []crypto.PubKey) error
ShareFilesViaPublicKey(ctx context.Context, paths []domain.FullPath, pubkeys []crypto.PubKey) error
HandleSharedFilesInvitation(ctx context.Context, invitationId string, accept bool) error
GetAPISessionTokens(ctx context.Context) (*domain.APISessionTokens, error)
AddRecentlySharedPublicKeys(ctx context.Context, pubkeys []crypto.PubKey) error
Expand Down
1 change: 1 addition & 0 deletions core/textile/buckd.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (tb *TextileBuckd) Start(ctx context.Context) error {
addrAPIProxy := cmd.AddrFromStr("/ip4/127.0.0.1/tcp/3007")
addrThreadsHost := cmd.AddrFromStr("/ip4/0.0.0.0/tcp/4006")
// TODO: replace with local blockstore

addrIpfsAPI := cmd.AddrFromStr(IpfsAddr)

addrGatewayHost := cmd.AddrFromStr("/ip4/127.0.0.1/tcp/8006")
Expand Down
8 changes: 3 additions & 5 deletions core/textile/sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/FleekHQ/space-daemon/core/space/domain"
"github.com/FleekHQ/space-daemon/log"
crypto "github.com/libp2p/go-libp2p-crypto"
"github.com/textileio/go-threads/core/thread"
"github.com/textileio/textile/buckets"
)

Expand All @@ -27,11 +28,8 @@ func (tc *textileClient) ShareFilesViaPublicKey(ctx context.Context, paths []dom
log.Info("Adding roles for pth: " + pth.Path)
roles := make(map[string]buckets.Role)
for _, pk := range pubkeys {
pkb, err := pk.Bytes()
if err != nil {
return err
}
roles[string(pkb)] = buckets.Writer
tpk := thread.NewLibp2pPubKey(pk)
roles[tpk.String()] = buckets.Writer
}

err := tc.hb.PushPathAccessRoles(ctx, pth.BucketKey, pth.Path, roles)
Expand Down
2 changes: 1 addition & 1 deletion grpc/handlers_sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (srv *grpcServer) ShareFilesViaPublicKey(ctx context.Context, request *pb.S
return nil, err
}

err = srv.sv.ShareFilesViaPublicKey(ctx, &cleanedPaths, pks)
err = srv.sv.ShareFilesViaPublicKey(ctx, cleanedPaths, pks)
if err != nil {
return nil, err
}
Expand Down