diff --git a/api/client/client.go b/api/client/client.go index 6415752a..ab0e6541 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -9,7 +9,6 @@ import ( ma "github.com/multiformats/go-multiaddr" pb "github.com/textileio/go-threads/api/pb" "github.com/textileio/go-threads/core/thread" - "github.com/textileio/go-threads/crypto/symmetric" "github.com/textileio/go-threads/db" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -95,15 +94,14 @@ func (c *Client) NewDB(ctx context.Context, id thread.ID) error { } // NewDBFromAddr creates a new DB with address and keys. -func (c *Client) NewDBFromAddr(ctx context.Context, addr ma.Multiaddr, followKey, readKey *symmetric.Key, collections ...db.CollectionConfig) error { +func (c *Client) NewDBFromAddr(ctx context.Context, addr ma.Multiaddr, key thread.Key, collections ...db.CollectionConfig) error { pbcollections := make([]*pb.CollectionConfig, len(collections)) for i, c := range collections { pbcollections[i] = collectionConfigToPb(c) } _, err := c.c.NewDBFromAddr(ctx, &pb.NewDBFromAddrRequest{ DbAddr: addr.String(), - FollowKey: followKey.Bytes(), - ReadKey: readKey.Bytes(), + DbKey: key.Bytes(), Collections: pbcollections, }) return err diff --git a/api/client/client_test.go b/api/client/client_test.go index d37725c6..7cbb2e52 100644 --- a/api/client/client_test.go +++ b/api/client/client_test.go @@ -20,7 +20,6 @@ import ( . "github.com/textileio/go-threads/api/client" pb "github.com/textileio/go-threads/api/pb" "github.com/textileio/go-threads/core/thread" - sym "github.com/textileio/go-threads/crypto/symmetric" "github.com/textileio/go-threads/db" "github.com/textileio/go-threads/util" "google.golang.org/grpc" @@ -54,11 +53,8 @@ func TestNewDBFromAddr(t *testing.T) { t.Run("test new db from address", func(t *testing.T) { addr, err := ma.NewMultiaddr(info.Addresses[0]) checkErr(t, err) - fk, err := sym.FromBytes(info.FollowKey) - checkErr(t, err) - rk, err := sym.FromBytes(info.FollowKey) - checkErr(t, err) - if err := client2.NewDBFromAddr(context.Background(), addr, fk, rk); err != nil { + key, err := thread.KeyFromBytes(info.DbKey) + if err := client2.NewDBFromAddr(context.Background(), addr, key); err != nil { t.Fatalf("failed to create new db from address: %v", err) } }) @@ -113,11 +109,8 @@ func TestGetDBInfo(t *testing.T) { if err != nil { t.Fatalf("failed to create collection: %v", err) } - if info.FollowKey == nil { - t.Fatal("got nil follow key") - } - if info.ReadKey == nil { - t.Fatal("got nil read key") + if info.DbKey == nil { + t.Fatal("got nil db key") } if len(info.Addresses) == 0 { t.Fatal("got empty addresses") diff --git a/api/pb/android/threads/src/main/java/io/textile/threads/Client.java b/api/pb/android/threads/src/main/java/io/textile/threads/Client.java index c78035e6..737cc0e6 100644 --- a/api/pb/android/threads/src/main/java/io/textile/threads/Client.java +++ b/api/pb/android/threads/src/main/java/io/textile/threads/Client.java @@ -85,22 +85,20 @@ public void NewDB (String dbID, StreamObserver responseObserver) { asyncStub.newDB(request.build(), responseObserver); } - public void NewDBFromAddrSync (String address, ByteString followKey, ByteString readKey, List collections) { + public void NewDBFromAddrSync (String address, ByteString key, List collections) { NewDBFromAddrRequest.Builder request = NewDBFromAddrRequest.newBuilder(); request.setDbAddr(address); - request.setFollowKey(followKey); - request.setReadKey(readKey); + request.setDbKey(key); for (int i = 0; i < collections.size(); i++) { request.setCollections(i, collections.get(i)); } blockingStub.newDBFromAddr(request.build()); } - public void NewDBFromAddr (String address, ByteString followKey, ByteString readKey, List collections, StreamObserver responseObserver) { + public void NewDBFromAddr (String address, ByteString key, List collections, StreamObserver responseObserver) { NewDBFromAddrRequest.Builder request = NewDBFromAddrRequest.newBuilder(); request.setDbAddr(address); - request.setFollowKey(followKey); - request.setReadKey(readKey); + request.setDbKey(key); for (int i = 0; i < collections.size(); i++) { request.setCollections(i, collections.get(i)); } diff --git a/api/pb/api.pb.go b/api/pb/api.pb.go index 451cdcc5..ad0a6f12 100644 --- a/api/pb/api.pb.go +++ b/api/pb/api.pb.go @@ -226,8 +226,7 @@ func (m *CollectionConfig_IndexConfig) GetUnique() bool { type NewDBFromAddrRequest struct { DbAddr string `protobuf:"bytes,1,opt,name=dbAddr,proto3" json:"dbAddr,omitempty"` - FollowKey []byte `protobuf:"bytes,2,opt,name=followKey,proto3" json:"followKey,omitempty"` - ReadKey []byte `protobuf:"bytes,3,opt,name=readKey,proto3" json:"readKey,omitempty"` + DbKey []byte `protobuf:"bytes,2,opt,name=dbKey,proto3" json:"dbKey,omitempty"` Collections []*CollectionConfig `protobuf:"bytes,4,rep,name=collections,proto3" json:"collections,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -266,16 +265,9 @@ func (m *NewDBFromAddrRequest) GetDbAddr() string { return "" } -func (m *NewDBFromAddrRequest) GetFollowKey() []byte { +func (m *NewDBFromAddrRequest) GetDbKey() []byte { if m != nil { - return m.FollowKey - } - return nil -} - -func (m *NewDBFromAddrRequest) GetReadKey() []byte { - if m != nil { - return m.ReadKey + return m.DbKey } return nil } @@ -359,8 +351,7 @@ func (m *GetDBInfoRequest) GetDbID() string { type GetDBInfoReply struct { Addresses []string `protobuf:"bytes,1,rep,name=addresses,proto3" json:"addresses,omitempty"` - FollowKey []byte `protobuf:"bytes,2,opt,name=followKey,proto3" json:"followKey,omitempty"` - ReadKey []byte `protobuf:"bytes,3,opt,name=readKey,proto3" json:"readKey,omitempty"` + DbKey []byte `protobuf:"bytes,2,opt,name=dbKey,proto3" json:"dbKey,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -398,16 +389,9 @@ func (m *GetDBInfoReply) GetAddresses() []string { return nil } -func (m *GetDBInfoReply) GetFollowKey() []byte { - if m != nil { - return m.FollowKey - } - return nil -} - -func (m *GetDBInfoReply) GetReadKey() []byte { +func (m *GetDBInfoReply) GetDbKey() []byte { if m != nil { - return m.ReadKey + return m.DbKey } return nil } @@ -1787,85 +1771,85 @@ func init() { func init() { proto.RegisterFile("api.proto", fileDescriptor_00212fb1f9d3bf1c) } var fileDescriptor_00212fb1f9d3bf1c = []byte{ - // 1245 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x58, 0xdd, 0x6e, 0xdb, 0x36, - 0x14, 0x96, 0x6c, 0x57, 0xb6, 0x8f, 0xe2, 0xc4, 0x63, 0xd3, 0xc4, 0x10, 0xb2, 0x2e, 0xe0, 0x86, - 0x22, 0x5b, 0x31, 0x23, 0x73, 0x86, 0x76, 0x7f, 0xdd, 0xe0, 0xbf, 0xcc, 0x5e, 0x83, 0xac, 0x50, - 0xd2, 0x6d, 0xc0, 0x06, 0x0c, 0x8a, 0x45, 0x27, 0x1a, 0x14, 0xcb, 0x91, 0x94, 0x36, 0x7e, 0x9b, - 0xa1, 0xaf, 0xb0, 0xab, 0xde, 0xf6, 0x0d, 0xf6, 0x16, 0x03, 0xf6, 0x12, 0x03, 0x29, 0x52, 0xa2, - 0x64, 0xd9, 0xeb, 0xd2, 0xac, 0x77, 0xe6, 0xd1, 0x21, 0x3f, 0x9e, 0x73, 0x3e, 0x7e, 0x87, 0x34, - 0x54, 0xad, 0xa9, 0xd3, 0x9c, 0xfa, 0x5e, 0xe8, 0x21, 0x8d, 0xfd, 0x3c, 0xc1, 0x18, 0x56, 0x0e, - 0xc9, 0xf3, 0x5e, 0xc7, 0x24, 0x17, 0x97, 0x24, 0x08, 0x11, 0x82, 0x92, 0x7d, 0x32, 0xec, 0x35, - 0xd4, 0x6d, 0x75, 0xa7, 0x6a, 0xb2, 0xdf, 0xf8, 0xa5, 0x0a, 0xf5, 0xae, 0xe7, 0xba, 0x64, 0x14, - 0x3a, 0xde, 0xa4, 0xeb, 0x4d, 0xc6, 0xce, 0x29, 0x75, 0x9c, 0x58, 0xe7, 0x44, 0x38, 0xd2, 0xdf, - 0x68, 0x03, 0xb4, 0x60, 0x74, 0x46, 0xce, 0xad, 0x46, 0x81, 0x59, 0xf9, 0x08, 0x7d, 0x0d, 0x65, - 0x67, 0x62, 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0f, 0xaf, 0x03, 0xca, 0xac, 0x4e, 0x73, 0x30, 0x82, - 0x5a, 0xd7, 0x27, 0x56, 0x48, 0x96, 0x81, 0xdd, 0x83, 0xd5, 0x24, 0x8b, 0x87, 0x94, 0x8c, 0x11, - 0xed, 0x32, 0x56, 0x5a, 0xea, 0x67, 0x96, 0x7b, 0xc9, 0xd9, 0x57, 0x35, 0xf9, 0x08, 0xdf, 0x07, - 0x5d, 0x80, 0xf0, 0xec, 0x39, 0x93, 0x20, 0xb4, 0x26, 0xa3, 0x24, 0x7b, 0xb1, 0x01, 0x5b, 0xa0, - 0x1f, 0x59, 0xcf, 0xfe, 0xd7, 0xfd, 0xe8, 0x50, 0x8d, 0x20, 0x68, 0x06, 0xce, 0xa1, 0xd6, 0x23, - 0x2e, 0xb9, 0x99, 0x0c, 0x6c, 0x83, 0x2e, 0x22, 0x19, 0xf6, 0x04, 0xac, 0x6c, 0xc2, 0x35, 0xd0, - 0x05, 0x1c, 0x45, 0xff, 0x0d, 0x60, 0x60, 0x05, 0x6f, 0x07, 0x1a, 0x43, 0x85, 0x61, 0xd1, 0x1a, - 0x6c, 0x80, 0x46, 0xae, 0x9c, 0x20, 0x0c, 0x18, 0x56, 0xc5, 0xe4, 0x23, 0x7c, 0x0a, 0xfa, 0xbe, - 0x33, 0xb1, 0x6f, 0x62, 0x43, 0x5b, 0x50, 0xbd, 0xb8, 0x24, 0xfe, 0xec, 0xbb, 0xa3, 0xef, 0x0f, - 0x39, 0xd5, 0x13, 0x03, 0xfe, 0x10, 0xaa, 0x11, 0x50, 0x2e, 0x23, 0x56, 0x64, 0x46, 0x9c, 0xc3, - 0x1a, 0x75, 0xed, 0xcc, 0x86, 0xbd, 0x9b, 0xd8, 0xd7, 0x5d, 0x80, 0x24, 0x2b, 0x6c, 0x63, 0x55, - 0x53, 0xb2, 0xe0, 0xfb, 0x50, 0x4b, 0xe0, 0xe8, 0xee, 0x0c, 0xa8, 0x88, 0xcf, 0x1c, 0x30, 0x1e,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0xe4, 0x29, 0x0c, 0x56, 0xd0, 0xc7, 0x50, 0x1c, 0x58, 0x01, 0xca, 0x11, 0x71, - 0x63, 0x4e, 0x5d, 0xa2, 0x8d, 0x51, 0x0d, 0x40, 0x79, 0xea, 0x6d, 0xcc, 0xab, 0x0b, 0x56, 0xd0, - 0x57, 0x50, 0x11, 0xaa, 0x81, 0x16, 0xc9, 0xb6, 0x91, 0x2f, 0x30, 0x58, 0x41, 0x4f, 0x61, 0x2d, - 0x73, 0xc9, 0x40, 0x77, 0x85, 0x6f, 0xfe, 0x9d, 0xcd, 0xd8, 0x5a, 0xf8, 0x9d, 0x2d, 0xb9, 0xa3, - 0xee, 0xaa, 0xe8, 0x27, 0xa8, 0x67, 0x1b, 0x01, 0x8a, 0xdb, 0xf9, 0x82, 0x0b, 0x81, 0xf1, 0xee, - 0x62, 0x87, 0x64, 0xe5, 0xcf, 0x40, 0x8b, 0xce, 0x59, 0x52, 0x87, 0x94, 0x82, 0x24, 0x75, 0x90, - 0x8e, 0x23, 0x56, 0x76, 0xd5, 0x4e, 0x13, 0x36, 0x1d, 0xaf, 0x19, 0x92, 0xab, 0xd0, 0x71, 0x49, - 0x33, 0x3c, 0xa3, 0x2f, 0xd5, 0xe0, 0xd7, 0x53, 0x7f, 0x3a, 0xea, 0x94, 0x8f, 0xa3, 0xd1, 0x13, - 0xf5, 0x45, 0xa1, 0x7c, 0x3c, 0x30, 0xfb, 0xed, 0xde, 0xd1, 0x89, 0xc6, 0xfe, 0xf3, 0xd8, 0xfb, - 0x27, 0x00, 0x00, 0xff, 0xff, 0x8b, 0xe3, 0xf7, 0x53, 0x00, 0x11, 0x00, 0x00, + // 1235 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x58, 0xdf, 0x6e, 0xe3, 0xc4, + 0x17, 0xb6, 0x93, 0xd4, 0x89, 0x8f, 0x9b, 0x36, 0xbf, 0xd9, 0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+ 0xac, 0xa0, 0x67, 0xb0, 0x9e, 0xb9, 0x64, 0xa0, 0x7b, 0xc2, 0x37, 0xff, 0xce, 0x66, 0x6e, 0x2f, + 0x7c, 0xce, 0x42, 0xee, 0xaa, 0x7b, 0x2a, 0xfa, 0x0e, 0x6a, 0xd9, 0x41, 0x80, 0xe2, 0x71, 0xbe, + 0xe0, 0x42, 0x60, 0xfe, 0x7f, 0xb1, 0x43, 0x12, 0xf9, 0x23, 0xd0, 0xf8, 0x7b, 0x96, 0x9c, 0x43, + 0x4a, 0x41, 0x92, 0x73, 0x90, 0x5e, 0x47, 0xac, 0xec, 0xa9, 0xed, 0x06, 0x6c, 0xb9, 0x93, 0x46, + 0x48, 0xae, 0x43, 0x77, 0x4c, 0x1a, 0xe1, 0xb9, 0x4f, 0x6c, 0x27, 0xf8, 0xf1, 0xcc, 0x9f, 0x0e, + 0xdb, 0xe5, 0x13, 0xbe, 0x7a, 0xaa, 0xfe, 0x56, 0x28, 0x9f, 0xf4, 0xad, 0x5e, 0xab, 0x7b, 0x7c, + 0xaa, 0xb1, 0xff, 0x2b, 0xf6, 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xea, 0x3f, 0x55, 0xef, 0xbc, + 0x10, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/api/pb/api.proto b/api/pb/api.proto index a255175e..08f0aa25 100644 --- a/api/pb/api.proto +++ b/api/pb/api.proto @@ -23,8 +23,7 @@ message CollectionConfig { message NewDBFromAddrRequest { string dbAddr = 1; - bytes followKey = 2; - bytes readKey = 3; + bytes dbKey = 2; repeated CollectionConfig collections = 4; } @@ -36,8 +35,7 @@ message GetDBInfoRequest { message GetDBInfoReply { repeated string addresses = 1; - bytes followKey = 2; - bytes readKey = 3; + bytes dbKey = 2; } message NewCollectionRequest { diff --git a/api/service.go b/api/service.go index 65403afa..44744af6 100644 --- a/api/service.go +++ b/api/service.go @@ -12,7 +12,6 @@ import ( coredb "github.com/textileio/go-threads/core/db" "github.com/textileio/go-threads/core/net" "github.com/textileio/go-threads/core/thread" - sym "github.com/textileio/go-threads/crypto/symmetric" "github.com/textileio/go-threads/db" "github.com/textileio/go-threads/util" "google.golang.org/grpc/codes" @@ -51,7 +50,7 @@ func NewService(network net.Net, conf Config) (*Service, error) { network, db.WithJsonMode(true), db.WithRepoPath(conf.RepoPath), - db.WithDebug(true)) + db.WithDebug(conf.Debug)) if err != nil { return nil, err } @@ -85,11 +84,7 @@ func (s *Service) NewDBFromAddr(ctx context.Context, req *pb.NewDBFromAddrReques if err != nil { return nil, err } - rk, err := sym.FromBytes(req.ReadKey) - if err != nil { - return nil, err - } - fk, err := sym.FromBytes(req.FollowKey) + key, err := thread.KeyFromBytes(req.DbKey) if err != nil { return nil, err } @@ -98,7 +93,7 @@ func (s *Service) NewDBFromAddr(ctx context.Context, req *pb.NewDBFromAddrReques for i, c := range req.Collections { collections[i] = collectionConfigFromPb(c) } - if _, err = s.manager.NewDBFromAddr(ctx, addr, fk, rk, collections...); err != nil { + if _, err = s.manager.NewDBFromAddr(ctx, addr, key, collections...); err != nil { return nil, err } return &pb.NewDBReply{}, nil @@ -139,8 +134,7 @@ func (s *Service) GetDBInfo(ctx context.Context, req *pb.GetDBInfoRequest) (*pb. } reply := &pb.GetDBInfoReply{ Addresses: res, - FollowKey: tinfo.FollowKey.Bytes(), - ReadKey: tinfo.ReadKey.Bytes(), + DbKey: tinfo.Key.Bytes(), } return reply, nil } diff --git a/cbor/event.go b/cbor/event.go index 9f850181..e75fe040 100644 --- a/cbor/event.go +++ b/cbor/event.go @@ -41,7 +41,7 @@ func CreateEvent(ctx context.Context, dag format.DAGService, body format.Node, r if err != nil { return nil, err } - keyb, err := key.Marshal() + keyb, err := key.MarshalBinary() if err != nil { return nil, err } diff --git a/cbor/record.go b/cbor/record.go index e9575ed1..60ebde76 100644 --- a/cbor/record.go +++ b/cbor/record.go @@ -26,14 +26,7 @@ type record struct { } // CreateRecord returns a new record from the given block and log private key. -func CreateRecord( - ctx context.Context, - dag format.DAGService, - block format.Node, - prev cid.Cid, - sk ic.PrivKey, - key crypto.EncryptionKey, -) (net.Record, error) { +func CreateRecord(ctx context.Context, dag format.DAGService, block format.Node, prev cid.Cid, sk ic.PrivKey, key crypto.EncryptionKey) (net.Record, error) { payload := block.Cid().Bytes() if prev.Defined() { payload = append(payload, prev.Bytes()...) diff --git a/core/logstore/logstore.go b/core/logstore/logstore.go index c3bad650..cd823e8b 100644 --- a/core/logstore/logstore.go +++ b/core/logstore/logstore.go @@ -79,17 +79,17 @@ type KeyBook interface { // AddPrivKey adds a private key under a log. AddPrivKey(thread.ID, peer.ID, ic.PrivKey) error - // ReadKey retrieves the read key of a log. + // ReadKey retrieves the read key of a thread. ReadKey(thread.ID) (*sym.Key, error) - // AddReadKey adds a read key under a log. + // AddReadKey adds a read key under a thread. AddReadKey(thread.ID, *sym.Key) error - // FollowKey retrieves the follow key of a log. - FollowKey(thread.ID) (*sym.Key, error) + // ServiceKey retrieves the service key of a thread. + ServiceKey(thread.ID) (*sym.Key, error) - // AddFollowKey adds a follow key under a log. - AddFollowKey(thread.ID, *sym.Key) error + // AddServiceKey adds a service key under a thread. + AddServiceKey(thread.ID, *sym.Key) error // LogsWithKeys returns a list of log IDs for a service. LogsWithKeys(thread.ID) (peer.IDSlice, error) diff --git a/core/net/service.go b/core/net/net.go similarity index 85% rename from core/net/service.go rename to core/net/net.go index a0667c3c..6d2c0dcf 100644 --- a/core/net/service.go +++ b/core/net/net.go @@ -40,13 +40,16 @@ type API interface { GetThread(ctx context.Context, id thread.ID) (thread.Info, error) // PullThread for new records. + // Logs owned by this host are traversed locally. + // Remotely addressed logs are pulled from the network. + // Is thread-safe. PullThread(ctx context.Context, id thread.ID) error // DeleteThread with id. DeleteThread(ctx context.Context, id thread.ID) error - // AddFollower to a thread. - AddFollower(ctx context.Context, id thread.ID, paddr ma.Multiaddr) (peer.ID, error) + // AddReplicator sends the service key and all logs to another peer. + AddReplicator(ctx context.Context, id thread.ID, paddr ma.Multiaddr) (peer.ID, error) // CreateRecord with body. CreateRecord(ctx context.Context, id thread.ID, body format.Node) (ThreadRecord, error) diff --git a/core/net/options.go b/core/net/options.go index aec57092..cec7ab47 100644 --- a/core/net/options.go +++ b/core/net/options.go @@ -3,30 +3,21 @@ package net import ( "github.com/libp2p/go-libp2p-core/crypto" "github.com/textileio/go-threads/core/thread" - "github.com/textileio/go-threads/crypto/symmetric" ) // KeyOptions defines options for keys when creating / adding a thread. type KeyOptions struct { - FollowKey *symmetric.Key - ReadKey *symmetric.Key + ThreadKey thread.Key LogKey crypto.Key } // KeyOption specifies encryption keys. type KeyOption func(*KeyOptions) -// FollowKey allows thread record traversal. -func FollowKey(key *symmetric.Key) KeyOption { +// ThreadKey handles log encryption. +func ThreadKey(key thread.Key) KeyOption { return func(args *KeyOptions) { - args.FollowKey = key - } -} - -// ReadKey allows for thread record decryption. -func ReadKey(key *symmetric.Key) KeyOption { - return func(args *KeyOptions) { - args.ReadKey = key + args.ThreadKey = key } } diff --git a/core/thread/id.go b/core/thread/id.go index 4c0a1d63..abd222ea 100644 --- a/core/thread/id.go +++ b/core/thread/id.go @@ -10,7 +10,6 @@ import ( "github.com/libp2p/go-libp2p-core/peer" ma "github.com/multiformats/go-multiaddr" mbase "github.com/multiformats/go-multibase" - sym "github.com/textileio/go-threads/crypto/symmetric" ) var ( @@ -304,10 +303,9 @@ func (s IDSlice) Less(i, j int) bool { return s[i].str < s[j].str } // Info holds thread logs and keys. type Info struct { - ID ID - Logs []LogInfo - FollowKey *sym.Key - ReadKey *sym.Key + ID ID + Key Key + Logs []LogInfo } // GetOwnLog returns the first log found with a private key. diff --git a/core/thread/key.go b/core/thread/key.go new file mode 100644 index 00000000..eb96d26e --- /dev/null +++ b/core/thread/key.go @@ -0,0 +1,122 @@ +package thread + +import ( + "fmt" + + mbase "github.com/multiformats/go-multibase" + sym "github.com/textileio/go-threads/crypto/symmetric" +) + +var ( + // ErrInvalidKey indicates an invalid byte slice was given to KeyFromBytes. + ErrInvalidKey = fmt.Errorf("invalid key") +) + +// Key is a thread encryption key with two components. +// Service key is used to encrypt outer log record linkages. +// Read key is used to encrypt inner record events. +type Key struct { + sk *sym.Key + rk *sym.Key +} + +// NewKey wraps service and read keys. +func NewKey(sk, rk *sym.Key) Key { + if sk == nil { + panic("service-key must not be nil") + } + return Key{sk: sk, rk: rk} +} + +// NewServiceKey wraps a service-only key. +func NewServiceKey(sk *sym.Key) Key { + return Key{sk: sk} +} + +// NewRandomKey returns a random key, which includes a service and read key. +func NewRandomKey() Key { + return Key{sk: sym.New(), rk: sym.New()} +} + +// NewRandomServiceKey returns a random service-only key. +func NewRandomServiceKey() Key { + return Key{sk: sym.New()} +} + +// KeyFromBytes returns a key by wrapping k. +func KeyFromBytes(b []byte) (k Key, err error) { + if len(b) != sym.KeyBytes && len(b) != sym.KeyBytes*2 { + return k, ErrInvalidKey + } + sk, err := sym.FromBytes(b[:sym.KeyBytes]) + if err != nil { + return k, err + } + var rk *sym.Key + if len(b) == sym.KeyBytes*2 { + rk, err = sym.FromBytes(b[sym.KeyBytes:]) + if err != nil { + return k, err + } + } + return Key{sk: sk, rk: rk}, nil +} + +// KeyFromString returns a key by decoding a base32-encoded string. +func KeyFromString(s string) (k Key, err error) { + _, b, err := mbase.Decode(s) + if err != nil { + return k, err + } + return KeyFromBytes(b) +} + +// Service returns the service key. +func (k Key) Service() *sym.Key { + return k.sk +} + +// Read returns the read key. +func (k Key) Read() *sym.Key { + return k.rk +} + +// Defined returns whether or not key has any defined components. +// Since it's not possible to have a read key w/o a service key, +// we just need to check service key. +func (k Key) Defined() bool { + return k.sk != nil +} + +// CanRead returns whether or not read key is available. +func (k Key) CanRead() bool { + return k.rk != nil +} + +// MarshalBinary implements BinaryMarshaler. +func (k Key) MarshalBinary() ([]byte, error) { + return k.Bytes(), nil +} + +// Bytes returns raw key bytes. +func (k Key) Bytes() []byte { + if k.rk != nil { + return append(k.sk.Bytes(), k.rk.Bytes()...) + } else if k.sk != nil { + return k.sk.Bytes() + } else { + return nil + } +} + +// String returns the base32-encoded string representation of raw key bytes. +// For example, +// Full: "brv7t5l2h55uklz5qwpntcat26csaasfchzof3emmdy6povabcd3a2to2qdkqdkto2prfhizerqqudqsdvwherbiy4nazqxjejgdr4oy" +// Service: "bp2vvqody5zm6yqycsnazb4kpqvycbdosos352zvpsorxce5koh7q" +func (k Key) String() string { + str, err := mbase.Encode(mbase.Base32, k.Bytes()) + if err != nil { + panic("should not error with hardcoded mbase: " + err.Error()) + } + return str +} diff --git a/core/thread/key_test.go b/core/thread/key_test.go new file mode 100644 index 00000000..3386a650 --- /dev/null +++ b/core/thread/key_test.go @@ -0,0 +1,88 @@ +package thread + +import ( + "bytes" + "testing" +) + +func TestNewRandomKey(t *testing.T) { + k := NewRandomKey() + if k.sk == nil { + t.Fatal("service key should not be nil") + } + if k.rk == nil { + t.Fatal("read key should not be nil") + } +} + +func TestNewRandomServiceKey(t *testing.T) { + k := NewRandomServiceKey() + if k.sk == nil { + t.Fatal("service key should not be nil") + } + if k.rk != nil { + t.Fatal("read key should be nil") + } +} + +func TestKey_FromBytes(t *testing.T) { + t.Run("full", func(t *testing.T) { + k1 := NewRandomKey() + b := k1.Bytes() + k2, err := KeyFromBytes(b) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(k2.sk.Bytes(), k1.sk.Bytes()) { + t.Fatal("service keys are not equal") + } + if !bytes.Equal(k2.rk.Bytes(), k1.rk.Bytes()) { + t.Fatal("read keys are not equal") + } + }) + t.Run("service", func(t *testing.T) { + k1 := NewRandomServiceKey() + b := k1.Bytes() + k2, err := KeyFromBytes(b) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(k2.sk.Bytes(), k1.sk.Bytes()) { + t.Fatal("service keys are not equal") + } + if k2.rk != nil { + t.Fatal("read key should be nil") + } + }) +} + +func TestKey_FromString(t *testing.T) { + t.Run("full", func(t *testing.T) { + k1 := NewRandomKey() + s := k1.String() + k2, err := KeyFromString(s) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(k2.sk.Bytes(), k1.sk.Bytes()) { + t.Fatal("service keys are not equal") + } + if !bytes.Equal(k2.rk.Bytes(), k1.rk.Bytes()) { + t.Fatal("read keys are not equal") + } + }) + t.Run("service", func(t *testing.T) { + k1 := NewRandomServiceKey() + s := k1.String() + k2, err := KeyFromString(s) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(k2.sk.Bytes(), k1.sk.Bytes()) { + t.Fatal("service keys are not equal") + } + if k2.rk != nil { + t.Fatal("read key should be nil") + } + }) +} diff --git a/crypto/asymmetric/asymmetric.go b/crypto/asymmetric/asymmetric.go index c2101220..dbb218c6 100644 --- a/crypto/asymmetric/asymmetric.go +++ b/crypto/asymmetric/asymmetric.go @@ -10,15 +10,15 @@ import ( ) const ( - // Length of nacl nonce + // NonceBytes is the length of nacl nonce. NonceBytes = 24 - // Length of nacl ephemeral public key + // EphemeralPublicKeyBytes is the length of nacl ephemeral public key. EphemeralPublicKeyBytes = 32 ) var ( - // Nacl box decryption failed + // Nacl box decryption failed. BoxDecryptionError = fmt.Errorf("failed to decrypt curve25519") ) @@ -40,8 +40,8 @@ func (k *EncryptionKey) Encrypt(plaintext []byte) ([]byte, error) { return encrypt(plaintext, k.pk) } -// Marshal returns raw key bytes. -func (k *EncryptionKey) Marshal() ([]byte, error) { +// MarshalBinary implements BinaryMarshaler. +func (k *EncryptionKey) MarshalBinary() ([]byte, error) { return ic.MarshalPublicKey(k.pk) } @@ -68,8 +68,8 @@ func (k *DecryptionKey) Decrypt(ciphertext []byte) ([]byte, error) { return decrypt(ciphertext, k.sk) } -// Marshal returns raw key bytes. -func (k *DecryptionKey) Marshal() ([]byte, error) { +// MarshalBinary implements BinaryMarshaler. +func (k *DecryptionKey) MarshalBinary() ([]byte, error) { return ic.MarshalPrivateKey(k.sk) } @@ -89,9 +89,9 @@ func decrypt(ciphertext []byte, sk ic.PrivKey) ([]byte, error) { return nil, fmt.Errorf("could not determine key type") } -func publicToCurve25519(k *ic.Ed25519PublicKey) (*[32]byte, error) { - var cp [32]byte - var pk [32]byte +func publicToCurve25519(k *ic.Ed25519PublicKey) (*[EphemeralPublicKeyBytes]byte, error) { + var cp [EphemeralPublicKeyBytes]byte + var pk [EphemeralPublicKeyBytes]byte r, err := k.Raw() if err != nil { return nil, err @@ -119,13 +119,12 @@ func encryptCurve25519(pubKey *ic.Ed25519PublicKey, bytes []byte) ([]byte, error // encrypt with nacl var ciphertext []byte - var nonce [24]byte - n := make([]byte, 24) - _, err = rand.Read(n) - if err != nil { + var nonce [NonceBytes]byte + n := make([]byte, NonceBytes) + if _, err = rand.Read(n); err != nil { return nil, err } - for i := 0; i < 24; i++ { + for i := 0; i < NonceBytes; i++ { nonce[i] = n[i] } ciphertext = box.Seal(ciphertext, bytes, &nonce, pk, ephemPriv) @@ -150,13 +149,13 @@ func decryptCurve25519(privKey *ic.Ed25519PrivateKey, ciphertext []byte) ([]byte ephemPubkeyBytes := ciphertext[NonceBytes : NonceBytes+EphemeralPublicKeyBytes] ct := ciphertext[NonceBytes+EphemeralPublicKeyBytes:] - var ephemPubkey [32]byte - for i := 0; i < 32; i++ { + var ephemPubkey [EphemeralPublicKeyBytes]byte + for i := 0; i < EphemeralPublicKeyBytes; i++ { ephemPubkey[i] = ephemPubkeyBytes[i] } - var nonce [24]byte - for i := 0; i < 24; i++ { + var nonce [NonceBytes]byte + for i := 0; i < NonceBytes; i++ { nonce[i] = n[i] } @@ -167,8 +166,8 @@ func decryptCurve25519(privKey *ic.Ed25519PrivateKey, ciphertext []byte) ([]byte return plaintext, nil } -func privateToCurve25519(k *ic.Ed25519PrivateKey) (*[32]byte, error) { - var cs [32]byte +func privateToCurve25519(k *ic.Ed25519PrivateKey) (*[EphemeralPublicKeyBytes]byte, error) { + var cs [EphemeralPublicKeyBytes]byte r, err := k.Raw() if err != nil { return nil, err diff --git a/crypto/crypto.go b/crypto/crypto.go index cda5cd26..9c5259f5 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -14,7 +14,7 @@ type EncryptionKey interface { Encrypt([]byte) ([]byte, error) // Marshal to bytes. - Marshal() ([]byte, error) + MarshalBinary() ([]byte, error) } // EncryptionKey represents a key that can be used for decryption. diff --git a/crypto/symmetric/symmetric.go b/crypto/symmetric/symmetric.go index e22ac772..8bf71267 100644 --- a/crypto/symmetric/symmetric.go +++ b/crypto/symmetric/symmetric.go @@ -5,6 +5,16 @@ import ( "crypto/cipher" "crypto/rand" "fmt" + + mbase "github.com/multiformats/go-multibase" +) + +const ( + // NonceBytes is the length of GCM nonce. + NonceBytes = 12 + + // KeyBytes is the length of GCM key. + KeyBytes = 32 ) // Key is a wrapper for a symmetric key. @@ -12,9 +22,9 @@ type Key struct { raw []byte } -// NewRandom returns 44 random bytes, 32 for the key and 12 for a nonce. +// NewRandom returns a random key. func NewRandom() (*Key, error) { - raw := make([]byte, 44) + raw := make([]byte, KeyBytes) if _, err := rand.Read(raw); err != nil { return nil, err } @@ -30,17 +40,45 @@ func New() *Key { return k } -// FromBytes returns a key by wrapping k. +// FromBytes returns a key by decoding bytes. func FromBytes(k []byte) (*Key, error) { - if len(k) != 44 { + if len(k) != KeyBytes { return nil, fmt.Errorf("invalid key") } return &Key{raw: k}, nil } +// FromString returns a key by decoding a base32-encoded string. +func FromString(k string) (*Key, error) { + _, b, err := mbase.Decode(k) + if err != nil { + return nil, err + } + return FromBytes(b) +} + +// Bytes returns raw key bytes. +func (k *Key) Bytes() []byte { + return k.raw +} + +// MarshalBinary implements BinaryMarshaler. +func (k *Key) MarshalBinary() ([]byte, error) { + return k.raw, nil +} + +// String returns the base32-encoded string representation of raw key bytes. +func (k *Key) String() string { + str, err := mbase.Encode(mbase.Base32, k.raw) + if err != nil { + panic("should not error with hardcoded mbase: " + err.Error()) + } + return str +} + // Encrypt performs AES-256 GCM encryption on plaintext. func (k *Key) Encrypt(plaintext []byte) ([]byte, error) { - block, err := aes.NewCipher(k.raw[:32]) + block, err := aes.NewCipher(k.raw[:KeyBytes]) if err != nil { return nil, err } @@ -48,13 +86,18 @@ func (k *Key) Encrypt(plaintext []byte) ([]byte, error) { if err != nil { return nil, err } - ciph := aesgcm.Seal(nil, k.raw[32:], plaintext, nil) - return ciph, nil + nonce := make([]byte, NonceBytes) + if _, err := rand.Read(nonce); err != nil { + return nil, err + } + ciphertext := aesgcm.Seal(nil, nonce, plaintext, nil) + ciphertext = append(nonce[:], ciphertext...) + return ciphertext, nil } -// Decrypt uses key (:32 key, 32:12 nonce) to perform AES-256 GCM decryption on ciphertext. +// Decrypt uses key to perform AES-256 GCM decryption on ciphertext. func (k *Key) Decrypt(ciphertext []byte) ([]byte, error) { - block, err := aes.NewCipher(k.raw[:32]) + block, err := aes.NewCipher(k.raw[:KeyBytes]) if err != nil { return nil, err } @@ -62,20 +105,10 @@ func (k *Key) Decrypt(ciphertext []byte) ([]byte, error) { if err != nil { return nil, err } - plain, err := aesgcm.Open(nil, k.raw[32:], ciphertext, nil) + nonce := ciphertext[:NonceBytes] + plain, err := aesgcm.Open(nil, nonce, ciphertext[NonceBytes:], nil) if err != nil { return nil, err } return plain, nil } - -// Marshal returns raw key bytes. -func (k *Key) Marshal() ([]byte, error) { - return k.raw, nil -} - -// Bytes returns raw key bytes. -// This is cleaner than marshal when your not dealing with an interface type. -func (k *Key) Bytes() []byte { - return k.raw -} diff --git a/db/db.go b/db/db.go index a961b4b4..a18524d3 100644 --- a/db/db.go +++ b/db/db.go @@ -21,7 +21,6 @@ import ( lstore "github.com/textileio/go-threads/core/logstore" "github.com/textileio/go-threads/core/net" "github.com/textileio/go-threads/core/thread" - sym "github.com/textileio/go-threads/crypto/symmetric" "github.com/textileio/go-threads/util" ) @@ -75,7 +74,7 @@ func NewDB(ctx context.Context, network net.Net, id thread.ID, opts ...Option) ( if _, err := network.GetThread(ctx, id); err != nil { if errors.Is(err, lstore.ErrThreadNotFound) { - if _, err = network.CreateThread(ctx, id, net.FollowKey(sym.New()), net.ReadKey(sym.New())); err != nil { + if _, err = network.CreateThread(ctx, id); err != nil { return nil, err } } else { @@ -88,7 +87,7 @@ func NewDB(ctx context.Context, network net.Net, id thread.ID, opts ...Option) ( // NewDBFromAddr creates a new DB from a thread hosted by another peer at address, // which will *own* ds and dispatcher for internal use. // Saying it differently, ds and dispatcher shouldn't be used externally. -func NewDBFromAddr(ctx context.Context, network net.Net, addr ma.Multiaddr, followKey, readKey *sym.Key, opts ...Option) (*DB, error) { +func NewDBFromAddr(ctx context.Context, network net.Net, addr ma.Multiaddr, key thread.Key, opts ...Option) (*DB, error) { config := &Config{} for _, opt := range opts { if err := opt(config); err != nil { @@ -96,7 +95,7 @@ func NewDBFromAddr(ctx context.Context, network net.Net, addr ma.Multiaddr, foll } } - ti, err := network.AddThread(ctx, addr, net.FollowKey(followKey), net.ReadKey(readKey)) + ti, err := network.AddThread(ctx, addr, net.ThreadKey(key)) if err != nil { return nil, err } diff --git a/db/db_test.go b/db/db_test.go index acb959e8..90907b22 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -58,7 +58,7 @@ func TestE2EWithThreads(t *testing.T) { ti, err := n1.GetThread(context.Background(), id1) checkErr(t, err) - d2, err := NewDBFromAddr(context.Background(), n2, addr, ti.FollowKey, ti.ReadKey, WithRepoPath(tmpDir2)) + d2, err := NewDBFromAddr(context.Background(), n2, addr, ti.Key, WithRepoPath(tmpDir2)) checkErr(t, err) defer d2.Close() c2, err := d2.NewCollectionFromInstance("dummy", &dummy{}) diff --git a/db/dbthread.go b/db/dbthread.go index 01f2504a..d1fe54cf 100644 --- a/db/dbthread.go +++ b/db/dbthread.go @@ -119,10 +119,10 @@ func (a *singleThreadAdapter) threadToDB(wg *sync.WaitGroup) { if err != nil { log.Fatalf("error when getting info for thread %s: %v", a.threadID, err) } - if info.ReadKey == nil { + if !info.Key.CanRead() { log.Fatalf("read key not found for thread %s/%s", a.threadID, rec.LogID()) } - node, err := event.GetBody(ctx, a.net, info.ReadKey) + node, err := event.GetBody(ctx, a.net, info.Key.Read()) if err != nil { log.Fatalf("error when getting body of event on thread %s/%s: %v", a.threadID, rec.LogID(), err) } diff --git a/db/manager.go b/db/manager.go index 19db7db6..00a72ccd 100644 --- a/db/manager.go +++ b/db/manager.go @@ -13,7 +13,6 @@ import ( ma "github.com/multiformats/go-multiaddr" "github.com/textileio/go-threads/core/net" "github.com/textileio/go-threads/core/thread" - sym "github.com/textileio/go-threads/crypto/symmetric" "github.com/textileio/go-threads/util" ) @@ -94,7 +93,7 @@ func (m *Manager) NewDB(ctx context.Context, id thread.ID) (*DB, error) { if _, ok := m.dbs[id]; ok { return nil, fmt.Errorf("db %s already exists", id.String()) } - if _, err := m.network.CreateThread(ctx, id, net.FollowKey(sym.New()), net.ReadKey(sym.New())); err != nil { + if _, err := m.network.CreateThread(ctx, id); err != nil { return nil, err } @@ -109,7 +108,7 @@ func (m *Manager) NewDB(ctx context.Context, id thread.ID) (*DB, error) { // NewDBFromAddr creates a new db from address and prefixes its datastore with base key. // Unlike NewDB, this method takes a list of collections added to the original db that // should also be added to this host. -func (m *Manager) NewDBFromAddr(ctx context.Context, addr ma.Multiaddr, followKey, readKey *sym.Key, collections ...CollectionConfig) (*DB, error) { +func (m *Manager) NewDBFromAddr(ctx context.Context, addr ma.Multiaddr, key thread.Key, collections ...CollectionConfig) (*DB, error) { id, err := thread.FromAddr(addr) if err != nil { return nil, err @@ -117,7 +116,7 @@ func (m *Manager) NewDBFromAddr(ctx context.Context, addr ma.Multiaddr, followKe if _, ok := m.dbs[id]; ok { return nil, fmt.Errorf("db %s already exists", id.String()) } - if _, err = m.network.AddThread(ctx, addr, net.FollowKey(followKey), net.ReadKey(readKey)); err != nil { + if _, err = m.network.AddThread(ctx, addr, net.ThreadKey(key)); err != nil { return nil, err } diff --git a/examples/chat/main.go b/examples/chat/main.go index 0101e496..cb2c46d1 100644 --- a/examples/chat/main.go +++ b/examples/chat/main.go @@ -21,13 +21,11 @@ import ( pstore "github.com/libp2p/go-libp2p-core/peerstore" swarm "github.com/libp2p/go-libp2p-swarm" "github.com/libp2p/go-libp2p/p2p/discovery" - "github.com/mr-tron/base58" ma "github.com/multiformats/go-multiaddr" mh "github.com/multiformats/go-multihash" "github.com/textileio/go-threads/cbor" core "github.com/textileio/go-threads/core/net" "github.com/textileio/go-threads/core/thread" - sym "github.com/textileio/go-threads/crypto/symmetric" "github.com/textileio/go-threads/db" util "github.com/textileio/go-threads/util" ) @@ -134,15 +132,15 @@ func main() { logError(err) continue } - if info.ReadKey == nil { - continue // just following, we don't have the read key + if !info.Key.CanRead() { + continue // just servicing, we don't have the read key } event, err := cbor.EventFromRecord(ctx, net, rec.Value()) if err != nil { logError(err) continue } - node, err := event.GetBody(ctx, net, info.ReadKey) + node, err := event.GetBody(ctx, net, info.Key.Read()) if err != nil { continue // Not for us } @@ -151,7 +149,7 @@ func main() { if err != nil { continue // Not one of our messages } - header, err := event.GetHeader(ctx, net, info.ReadKey) + header, err := event.GetHeader(ctx, net, info.Key.Read()) if err != nil { logError(err) continue @@ -253,7 +251,7 @@ func handleLine(line string) (out string, err error) { } args := strings.Split(parts[1], " ") return addCmd(args) - case "add-follower": + case "add-replicator": if !threadID.Defined() { err = fmt.Errorf("enter a thread with `:enter` or specify thread name with :") return @@ -262,7 +260,7 @@ func handleLine(line string) (out string, err error) { err = fmt.Errorf("missing peer address") return } - return addFollowerCmd(threadID, parts[1]) + return addReplicatorCmd(threadID, parts[1]) case "": err = fmt.Errorf("missing command") return @@ -288,16 +286,16 @@ func cmdCmd() (out string, err error) { out += pink(":address ") + grey("Show the host or active thread addresses.\n") out += pink(":threads ") + grey("Show threads.\n") out += pink(":add ") + grey("Add a new thread with name.\n") - out += pink(":add
") + - grey("Add an existing thread with name at address using a base58-encoded follow and read key.\n") + out += pink(":add
") + + grey("Add an existing thread with name at address using a base32-encoded thread key.\n") out += pink(": ") + grey("Send a message to thread with name.\n") out += pink("::address ") + grey("Show thread address.\n") out += pink("::keys ") + grey("Show thread keys.\n") - out += pink("::add-follower
") + grey("Add a follower at address.\n") + out += pink("::add-replicator
") + grey("Add a replicator at address.\n") out += pink(":enter ") + grey("Enter thread with name.\n") out += pink(":exit ") + grey("Exit the active thread.\n") out += pink(":keys ") + grey("Show the active thread's keys.\n") - out += pink(":add-follower
") + grey("Add a follower at address to active thread.\n") + out += pink(":add-replicator
") + grey("Add a replicator at address to active thread.\n") out += pink(" ") + grey("Send a message to the active thread.") return } @@ -369,15 +367,9 @@ func addCmd(args []string) (out string, err error) { } } - var fk, rk *sym.Key + var k thread.Key if len(args) > 2 { - fk, err = util.DecodeKey(args[2]) - if err != nil { - return "", err - } - } - if len(args) > 3 { - rk, err = util.DecodeKey(args[3]) + k, err = thread.KeyFromString(args[2]) if err != nil { return "", err } @@ -397,14 +389,14 @@ func addCmd(args []string) (out string, err error) { if !util.CanDial(addr, net.Host().Network().(*swarm.Swarm)) { return "", fmt.Errorf("address is not dialable") } - info, err := net.AddThread(ctx, addr, core.FollowKey(fk), core.ReadKey(rk)) + info, err := net.AddThread(ctx, addr, core.ThreadKey(k)) if err != nil { return "", err } go net.PullThread(ctx, info.ID) id = info.ID } else { - th, err := net.CreateThread(ctx, thread.NewIDV1(thread.Raw, 32), core.FollowKey(sym.New()), core.ReadKey(sym.New())) + th, err := net.CreateThread(ctx, thread.NewIDV1(thread.Raw, 32)) if err != nil { return "", err } @@ -441,8 +433,8 @@ func threadCmd(cmds []string, input string) (out string, err error) { return threadAddressCmd(id) case "keys": return threadKeysCmd(id) - case "add-follower": - return addFollowerCmd(id, input) + case "add-replicator": + return addReplicatorCmd(id, input) default: err = fmt.Errorf("unknown command: %s", cmds[1]) return @@ -511,18 +503,13 @@ func threadKeysCmd(id thread.ID) (out string, err error) { return } - if info.FollowKey != nil { - out += grey(base58.Encode(info.FollowKey.Bytes())) + cyan(" (follow-key)") - } - if info.ReadKey != nil { - out += "\n" - out += grey(base58.Encode(info.ReadKey.Bytes())) + red(" (read-key)") + if info.Key.Defined() { + out += grey(info.Key.String()) + cyan(" (key)") } - return } -func addFollowerCmd(id thread.ID, addrStr string) (out string, err error) { +func addReplicatorCmd(id thread.ID, addrStr string) (out string, err error) { if addrStr == "" { err = fmt.Errorf("enter a peer address") return @@ -532,11 +519,11 @@ func addFollowerCmd(id thread.ID, addrStr string) (out string, err error) { if err != nil { return } - pid, err := net.AddFollower(ctx, id, addr) + pid, err := net.AddReplicator(ctx, id, addr) if err != nil { return } - return "Added follower " + pid.String(), nil + return "Added replicator " + pid.String(), nil } func sendMessage(id thread.ID, txt string) error { diff --git a/examples/e2e_counter/reader.go b/examples/e2e_counter/reader.go index 108eab64..7ecbc198 100644 --- a/examples/e2e_counter/reader.go +++ b/examples/e2e_counter/reader.go @@ -6,21 +6,20 @@ import ( "io/ioutil" "strings" - "github.com/mr-tron/base58" ma "github.com/multiformats/go-multiaddr" - "github.com/textileio/go-threads/crypto/symmetric" + "github.com/textileio/go-threads/core/thread" "github.com/textileio/go-threads/db" ) func runReaderPeer(repo string) { fmt.Printf("I'm a collection reader.\n") - writerAddr, fkey, rkey := getWriterAddr() + writerAddr, key := getWriterAddr() n, err := db.DefaultNetwork(repo) checkErr(err) defer n.Close() - d, err := db.NewDBFromAddr(context.Background(), n, writerAddr, fkey, rkey, db.WithRepoPath(repo)) + d, err := db.NewDBFromAddr(context.Background(), n, writerAddr, key, db.WithRepoPath(repo)) checkErr(err) defer d.Close() @@ -44,7 +43,7 @@ func runReaderPeer(repo string) { } } -func getWriterAddr() (ma.Multiaddr, *symmetric.Key, *symmetric.Key) { +func getWriterAddr() (ma.Multiaddr, thread.Key) { // Read the multiaddr of the writer which saved it in .full_simple file. mb, err := ioutil.ReadFile(".e2e_counter_writeraddr") checkErr(err) @@ -54,15 +53,8 @@ func getWriterAddr() (ma.Multiaddr, *symmetric.Key, *symmetric.Key) { addr, err := ma.NewMultiaddr(data[0]) checkErr(err) - fkeyBytes, err := base58.Decode(data[1]) - checkErr(err) - rkeyBytes, err := base58.Decode(data[2]) - checkErr(err) - - fkey, err := symmetric.FromBytes(fkeyBytes) - checkErr(err) - rkey, err := symmetric.FromBytes(rkeyBytes) + key, err := thread.KeyFromString(data[1]) checkErr(err) - return addr, fkey, rkey + return addr, key } diff --git a/examples/e2e_counter/writer.go b/examples/e2e_counter/writer.go index a79e7814..0ccbfa8b 100644 --- a/examples/e2e_counter/writer.go +++ b/examples/e2e_counter/writer.go @@ -6,7 +6,6 @@ import ( "io/ioutil" "time" - "github.com/mr-tron/base58" "github.com/multiformats/go-multiaddr" core "github.com/textileio/go-threads/core/db" "github.com/textileio/go-threads/core/net" @@ -70,10 +69,9 @@ func saveThreadMultiaddrForOtherPeer(n net.Net, threadID thread.ID) { threadComp, _ := multiaddr.NewComponent("thread", threadID.String()) listenAddr := n.Host().Addrs()[0].Encapsulate(id).Encapsulate(threadComp).String() - followKey := base58.Encode(tinfo.FollowKey.Bytes()) - readKey := base58.Encode(tinfo.ReadKey.Bytes()) + key := tinfo.Key.String() - data := fmt.Sprintf("%s %s %s", listenAddr, followKey, readKey) + data := fmt.Sprintf("%s %s", listenAddr, key) if err := ioutil.WriteFile(".e2e_counter_writeraddr", []byte(data), 0644); err != nil { panic(err) } diff --git a/logstore/logstore.go b/logstore/logstore.go index ae7a076e..dbc64196 100644 --- a/logstore/logstore.go +++ b/logstore/logstore.go @@ -78,14 +78,14 @@ func (ls *logstore) Threads() (thread.IDSlice, error) { // AddThread adds a thread with keys. func (ls *logstore) AddThread(info thread.Info) error { - if info.FollowKey == nil { - return fmt.Errorf("a follow-key is required to add a thread") + if info.Key.Service() == nil { + return fmt.Errorf("a service-key is required to add a thread") } - if err := ls.AddFollowKey(info.ID, info.FollowKey); err != nil { + if err := ls.AddServiceKey(info.ID, info.Key.Service()); err != nil { return err } - if info.ReadKey != nil { - if err := ls.AddReadKey(info.ID, info.ReadKey); err != nil { + if info.Key.CanRead() { + if err := ls.AddReadKey(info.ID, info.Key.Read()); err != nil { return err } } @@ -94,11 +94,11 @@ func (ls *logstore) AddThread(info thread.Info) error { // GetThread returns thread info of the given id. func (ls *logstore) GetThread(id thread.ID) (info thread.Info, err error) { - fk, err := ls.FollowKey(id) + sk, err := ls.ServiceKey(id) if err != nil { return } - if fk == nil { + if sk == nil { return info, core.ErrThreadNotFound } rk, err := ls.ReadKey(id) @@ -132,10 +132,9 @@ func (ls *logstore) GetThread(id thread.ID) (info thread.Info, err error) { } return thread.Info{ - ID: id, - Logs: logs, - FollowKey: fk, - ReadKey: rk, + ID: id, + Logs: logs, + Key: thread.NewKey(sk, rk), }, nil } diff --git a/logstore/lstoreds/keybook.go b/logstore/lstoreds/keybook.go index 865d0fe1..884177ac 100644 --- a/logstore/lstoreds/keybook.go +++ b/logstore/lstoreds/keybook.go @@ -20,13 +20,13 @@ type dsKeyBook struct { // Public and private keys are stored under the following db key pattern: // /threads/keys///(pub|priv) // Follow and read keys are stored under the following db key pattern: -// /threads/keys//(follow|read) +// /threads/keys//(service|read) var ( - kbBase = ds.NewKey("/thread/keys") - pubSuffix = ds.NewKey("/pub") - privSuffix = ds.NewKey("/priv") - readSuffix = ds.NewKey("/read") - followSuffix = ds.NewKey("/follow") + kbBase = ds.NewKey("/thread/keys") + pubSuffix = ds.NewKey("/pub") + privSuffix = ds.NewKey("/priv") + readSuffix = ds.NewKey("/read") + serviceSuffix = ds.NewKey("/service") ) var _ core.KeyBook = (*dsKeyBook)(nil) @@ -115,7 +115,7 @@ func (kb *dsKeyBook) AddPrivKey(t thread.ID, p peer.ID, sk crypto.PrivKey) error return nil } -// ReadKey returns the read-key associated with thread.ID thread. +// ReadKey returns the read-key associated with thread.ID. // In case it doesn't exist, it will return nil. func (kb *dsKeyBook) ReadKey(t thread.ID) (*sym.Key, error) { key := dsThreadKey(t, kbBase).Child(readSuffix) @@ -129,7 +129,7 @@ func (kb *dsKeyBook) ReadKey(t thread.ID) (*sym.Key, error) { return sym.FromBytes(v) } -// AddReadKey adds a read-key for a peer.ID +// AddReadKey adds a read-key for a peer.ID. func (kb *dsKeyBook) AddReadKey(t thread.ID, rk *sym.Key) error { if rk == nil { return fmt.Errorf("read-key is nil") @@ -141,29 +141,29 @@ func (kb *dsKeyBook) AddReadKey(t thread.ID, rk *sym.Key) error { return nil } -// FollowKey returns the follow-key associated with thread.ID service. +// ServiceKey returns the service-key associated with thread.ID. // In case it doesn't exist, it will return nil. -func (kb *dsKeyBook) FollowKey(t thread.ID) (*sym.Key, error) { - key := dsThreadKey(t, kbBase).Child(followSuffix) +func (kb *dsKeyBook) ServiceKey(t thread.ID) (*sym.Key, error) { + key := dsThreadKey(t, kbBase).Child(serviceSuffix) v, err := kb.ds.Get(key) if err == ds.ErrNotFound { return nil, nil } if err != nil { - return nil, fmt.Errorf("error when getting follow-key from datastore: %v", err) + return nil, fmt.Errorf("error when getting service-key from datastore: %v", err) } return sym.FromBytes(v) } -// AddFollowKey adds a follow-key for a peer.ID -func (kb *dsKeyBook) AddFollowKey(t thread.ID, fk *sym.Key) error { +// AddServiceKey adds a service-key for a peer.ID. +func (kb *dsKeyBook) AddServiceKey(t thread.ID, fk *sym.Key) error { if fk == nil { - return fmt.Errorf("follow-key is nil") + return fmt.Errorf("service-key is nil") } - key := dsThreadKey(t, kbBase).Child(followSuffix) + key := dsThreadKey(t, kbBase).Child(serviceSuffix) if err := kb.ds.Put(key, fk.Bytes()); err != nil { - return fmt.Errorf("error when adding follow-key to datastore: %w", err) + return fmt.Errorf("error when adding service-key to datastore: %w", err) } return nil } diff --git a/logstore/lstoremem/keybook.go b/logstore/lstoremem/keybook.go index 560b9e42..0a724a5a 100644 --- a/logstore/lstoremem/keybook.go +++ b/logstore/lstoremem/keybook.go @@ -156,7 +156,7 @@ func (mkb *memoryKeyBook) AddReadKey(t thread.ID, key *sym.Key) error { return nil } -func (mkb *memoryKeyBook) FollowKey(t thread.ID) (key *sym.Key, err error) { +func (mkb *memoryKeyBook) ServiceKey(t thread.ID) (key *sym.Key, err error) { mkb.RLock() b := mkb.fks[t] if b != nil { @@ -166,9 +166,9 @@ func (mkb *memoryKeyBook) FollowKey(t thread.ID) (key *sym.Key, err error) { return } -func (mkb *memoryKeyBook) AddFollowKey(t thread.ID, key *sym.Key) error { +func (mkb *memoryKeyBook) AddServiceKey(t thread.ID, key *sym.Key) error { if key == nil { - return errors.New("key is nil (FollowKey)") + return errors.New("key is nil (ServiceKey)") } mkb.Lock() diff --git a/net/api/client/client.go b/net/api/client/client.go index ae795d59..0be03010 100644 --- a/net/api/client/client.go +++ b/net/api/client/client.go @@ -123,8 +123,8 @@ func (c *Client) DeleteThread(ctx context.Context, id thread.ID) error { return err } -func (c *Client) AddFollower(ctx context.Context, id thread.ID, paddr ma.Multiaddr) (peer.ID, error) { - resp, err := c.c.AddFollower(ctx, &pb.AddFollowerRequest{ +func (c *Client) AddReplicator(ctx context.Context, id thread.ID, paddr ma.Multiaddr) (peer.ID, error) { + resp, err := c.c.AddReplicator(ctx, &pb.AddReplicatorRequest{ ThreadID: id.Bytes(), Addr: paddr.Bytes(), }) @@ -146,7 +146,7 @@ func (c *Client) CreateRecord(ctx context.Context, id thread.ID, body format.Nod if err != nil { return nil, err } - return threadRecordFromProto(resp, info.FollowKey) + return threadRecordFromProto(resp, info.Key.Service()) } func (c *Client) AddRecord(ctx context.Context, id thread.ID, lid peer.ID, rec core.Record) error { @@ -175,7 +175,7 @@ func (c *Client) GetRecord(ctx context.Context, id thread.ID, rid cid.Cid) (core if err != nil { return nil, err } - return cbor.RecordFromProto(util.RecToServiceRec(resp.Record), info.FollowKey) + return cbor.RecordFromProto(util.RecToServiceRec(resp.Record), info.Key.Service()) } func (c *Client) Subscribe(ctx context.Context, opts ...core.SubOption) (<-chan core.ThreadRecord, error) { @@ -193,7 +193,7 @@ func (c *Client) Subscribe(ctx context.Context, opts ...core.SubOption) (<-chan if err != nil { return nil, err } - threads := make(map[thread.ID]*symmetric.Key) // Follow-key cache + threads := make(map[thread.ID]*symmetric.Key) // Service-key cache channel := make(chan core.ThreadRecord) go func() { defer close(channel) @@ -214,22 +214,22 @@ func (c *Client) Subscribe(ctx context.Context, opts ...core.SubOption) (<-chan log.Errorf("error casting thread ID: %v", err) continue } - var fk *symmetric.Key + var sk *symmetric.Key var ok bool - if fk, ok = threads[threadID]; !ok { + if sk, ok = threads[threadID]; !ok { info, err := c.GetThread(ctx, threadID) if err != nil { log.Errorf("error getting thread: %v", err) continue } - if info.FollowKey == nil { - log.Error("follow-key not found") + if info.Key.Service() == nil { + log.Error("service-key not found") continue } - fk = info.FollowKey - threads[threadID] = fk + sk = info.Key.Service() + threads[threadID] = sk } - rec, err := threadRecordFromProto(resp, fk) + rec, err := threadRecordFromProto(resp, sk) if err != nil { log.Errorf("error unpacking record: %v", err) continue @@ -240,13 +240,9 @@ func (c *Client) Subscribe(ctx context.Context, opts ...core.SubOption) (<-chan return channel, nil } -func getThreadKeys(args *core.KeyOptions) (*pb.ThreadKeys, error) { - keys := &pb.ThreadKeys{} - if args.FollowKey != nil { - keys.FollowKey = args.FollowKey.Bytes() - } - if args.ReadKey != nil { - keys.ReadKey = args.ReadKey.Bytes() +func getThreadKeys(args *core.KeyOptions) (*pb.Keys, error) { + keys := &pb.Keys{ + ThreadKey: args.ThreadKey.Bytes(), } if args.LogKey != nil { var err error @@ -263,14 +259,7 @@ func threadInfoFromProto(reply *pb.ThreadInfoReply) (info thread.Info, err error if err != nil { return } - var rk *symmetric.Key - if reply.ReadKey != nil { - rk, err = symmetric.FromBytes(reply.ReadKey) - if err != nil { - return - } - } - fk, err := symmetric.FromBytes(reply.FollowKey) + k, err := thread.KeyFromBytes(reply.ThreadKey) if err != nil { return } @@ -314,10 +303,9 @@ func threadInfoFromProto(reply *pb.ThreadInfoReply) (info thread.Info, err error } } return thread.Info{ - ID: threadID, - Logs: logs, - FollowKey: fk, - ReadKey: rk, + ID: threadID, + Key: k, + Logs: logs, }, nil } diff --git a/net/api/client/client_test.go b/net/api/client/client_test.go index 80ec02b2..70667946 100644 --- a/net/api/client/client_test.go +++ b/net/api/client/client_test.go @@ -23,7 +23,7 @@ import ( "github.com/textileio/go-threads/cbor" core "github.com/textileio/go-threads/core/net" "github.com/textileio/go-threads/core/thread" - "github.com/textileio/go-threads/crypto/symmetric" + sym "github.com/textileio/go-threads/crypto/symmetric" "github.com/textileio/go-threads/db" "github.com/textileio/go-threads/net/api" . "github.com/textileio/go-threads/net/api/client" @@ -51,26 +51,18 @@ func TestClient_CreateThread(t *testing.T) { t.Run("test create thread", func(t *testing.T) { id := thread.NewIDV1(thread.Raw, 32) - fk, err := symmetric.NewRandom() - if err != nil { - t.Fatal(err) - } - rk, err := symmetric.NewRandom() - if err != nil { - t.Fatal(err) - } - info, err := client.CreateThread(context.Background(), id, core.FollowKey(fk), core.ReadKey(rk)) + info, err := client.CreateThread(context.Background(), id) if err != nil { t.Fatalf("failed to create thread: %v", err) } if !info.ID.Equals(id) { t.Fatal("got bad ID from create thread") } - if info.ReadKey == nil { + if info.Key.Read() == nil { t.Fatal("read key should not be nil") } - if info.FollowKey == nil { - t.Fatal("follow key should not be nil") + if info.Key.Service() == nil { + t.Fatal("service key should not be nil") } }) } @@ -90,11 +82,7 @@ func TestClient_AddThread(t *testing.T) { addr := threadAddr(t, hostAddr1, hostID1, info1) t.Run("test add thread", func(t *testing.T) { - info2, err := client2.AddThread( - context.Background(), - addr, - core.ReadKey(info1.ReadKey), - core.FollowKey(info1.FollowKey)) + info2, err := client2.AddThread(context.Background(), addr, core.ThreadKey(info1.Key)) if err != nil { t.Fatalf("failed to add thread: %v", err) } @@ -151,7 +139,7 @@ func TestClient_DeleteThread(t *testing.T) { }) } -func TestClient_AddFollower(t *testing.T) { +func TestClient_AddReplicator(t *testing.T) { t.Parallel() _, client1, done1 := setup(t) defer done1() @@ -164,14 +152,14 @@ func TestClient_AddFollower(t *testing.T) { t.Fatal(err) } - t.Run("test add follower", func(t *testing.T) { + t.Run("test add replicator", func(t *testing.T) { addr := peerAddr(t, hostAddr2, hostID2) - pid, err := client1.AddFollower(context.Background(), info.ID, addr) + pid, err := client1.AddReplicator(context.Background(), info.ID, addr) if err != nil { - t.Fatalf("failed to add follower: %v", err) + t.Fatalf("failed to add replicator: %v", err) } if pid.String() == "" { - log.Fatal("got bad ID from add follower") + log.Fatal("got bad ID from add replicator") } }) } @@ -211,15 +199,12 @@ func TestClient_AddRecord(t *testing.T) { // Create a thread, keeping read key and log private key on the client id := thread.NewIDV1(thread.Raw, 32) - fk, err := symmetric.NewRandom() - if err != nil { - t.Fatal(err) - } + tk := thread.NewRandomServiceKey() sk, pk, err := crypto.GenerateEd25519Key(crand.Reader) if err != nil { t.Fatal(err) } - info, err := client.CreateThread(context.Background(), id, core.FollowKey(fk), core.LogKey(pk)) + info, err := client.CreateThread(context.Background(), id, core.ThreadKey(tk), core.LogKey(pk)) if err != nil { t.Fatal(err) } @@ -233,15 +218,11 @@ func TestClient_AddRecord(t *testing.T) { } t.Run("test add record", func(t *testing.T) { - rk, err := symmetric.NewRandom() + event, err := cbor.CreateEvent(context.Background(), nil, body, sym.New()) if err != nil { t.Fatal(err) } - event, err := cbor.CreateEvent(context.Background(), nil, body, rk) - if err != nil { - t.Fatal(err) - } - rec, err := cbor.CreateRecord(context.Background(), nil, event, cid.Undef, sk, fk) + rec, err := cbor.CreateRecord(context.Background(), nil, event, cid.Undef, sk, tk.Service()) if err != nil { t.Fatal(err) } @@ -308,7 +289,7 @@ func TestClient_Subscribe(t *testing.T) { t.Fatal(err) } addr := peerAddr(t, hostAddr2, hostID2) - if _, err := client1.AddFollower(context.Background(), info.ID, addr); err != nil { + if _, err := client1.AddReplicator(context.Background(), info.ID, addr); err != nil { t.Fatal(err) } @@ -444,15 +425,7 @@ func makeServer(t *testing.T) (ma.Multiaddr, ma.Multiaddr, func()) { func createThread(t *testing.T, client *Client) thread.Info { id := thread.NewIDV1(thread.Raw, 32) - fk, err := symmetric.NewRandom() - if err != nil { - t.Fatal(err) - } - rk, err := symmetric.NewRandom() - if err != nil { - t.Fatal(err) - } - info, err := client.CreateThread(context.Background(), id, core.FollowKey(fk), core.ReadKey(rk)) + info, err := client.CreateThread(context.Background(), id) if err != nil { t.Fatal(err) } diff --git a/net/api/pb/api.pb.go b/net/api/pb/api.pb.go index 3caa76f1..bdbce06a 100644 --- a/net/api/pb/api.pb.go +++ b/net/api/pb/api.pb.go @@ -94,55 +94,47 @@ func (m *GetHostIDReply) GetPeerID() []byte { return nil } -type ThreadKeys struct { - ReadKey []byte `protobuf:"bytes,1,opt,name=readKey,proto3" json:"readKey,omitempty"` - FollowKey []byte `protobuf:"bytes,2,opt,name=followKey,proto3" json:"followKey,omitempty"` - LogKey []byte `protobuf:"bytes,3,opt,name=logKey,proto3" json:"logKey,omitempty"` +type Keys struct { + ThreadKey []byte `protobuf:"bytes,1,opt,name=threadKey,proto3" json:"threadKey,omitempty"` + LogKey []byte `protobuf:"bytes,2,opt,name=logKey,proto3" json:"logKey,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *ThreadKeys) Reset() { *m = ThreadKeys{} } -func (m *ThreadKeys) String() string { return proto.CompactTextString(m) } -func (*ThreadKeys) ProtoMessage() {} -func (*ThreadKeys) Descriptor() ([]byte, []int) { +func (m *Keys) Reset() { *m = Keys{} } +func (m *Keys) String() string { return proto.CompactTextString(m) } +func (*Keys) ProtoMessage() {} +func (*Keys) Descriptor() ([]byte, []int) { return fileDescriptor_00212fb1f9d3bf1c, []int{2} } -func (m *ThreadKeys) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ThreadKeys.Unmarshal(m, b) +func (m *Keys) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Keys.Unmarshal(m, b) } -func (m *ThreadKeys) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ThreadKeys.Marshal(b, m, deterministic) +func (m *Keys) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Keys.Marshal(b, m, deterministic) } -func (m *ThreadKeys) XXX_Merge(src proto.Message) { - xxx_messageInfo_ThreadKeys.Merge(m, src) +func (m *Keys) XXX_Merge(src proto.Message) { + xxx_messageInfo_Keys.Merge(m, src) } -func (m *ThreadKeys) XXX_Size() int { - return xxx_messageInfo_ThreadKeys.Size(m) +func (m *Keys) XXX_Size() int { + return xxx_messageInfo_Keys.Size(m) } -func (m *ThreadKeys) XXX_DiscardUnknown() { - xxx_messageInfo_ThreadKeys.DiscardUnknown(m) +func (m *Keys) XXX_DiscardUnknown() { + xxx_messageInfo_Keys.DiscardUnknown(m) } -var xxx_messageInfo_ThreadKeys proto.InternalMessageInfo +var xxx_messageInfo_Keys proto.InternalMessageInfo -func (m *ThreadKeys) GetReadKey() []byte { +func (m *Keys) GetThreadKey() []byte { if m != nil { - return m.ReadKey + return m.ThreadKey } return nil } -func (m *ThreadKeys) GetFollowKey() []byte { - if m != nil { - return m.FollowKey - } - return nil -} - -func (m *ThreadKeys) GetLogKey() []byte { +func (m *Keys) GetLogKey() []byte { if m != nil { return m.LogKey } @@ -150,11 +142,11 @@ func (m *ThreadKeys) GetLogKey() []byte { } type CreateThreadRequest struct { - ThreadID []byte `protobuf:"bytes,1,opt,name=threadID,proto3" json:"threadID,omitempty"` - Keys *ThreadKeys `protobuf:"bytes,2,opt,name=keys,proto3" json:"keys,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + ThreadID []byte `protobuf:"bytes,1,opt,name=threadID,proto3" json:"threadID,omitempty"` + Keys *Keys `protobuf:"bytes,2,opt,name=keys,proto3" json:"keys,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *CreateThreadRequest) Reset() { *m = CreateThreadRequest{} } @@ -189,7 +181,7 @@ func (m *CreateThreadRequest) GetThreadID() []byte { return nil } -func (m *CreateThreadRequest) GetKeys() *ThreadKeys { +func (m *CreateThreadRequest) GetKeys() *Keys { if m != nil { return m.Keys } @@ -270,8 +262,7 @@ func (m *LogInfo) GetHeads() [][]byte { type ThreadInfoReply struct { ID []byte `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` Logs []*LogInfo `protobuf:"bytes,2,rep,name=logs,proto3" json:"logs,omitempty"` - ReadKey []byte `protobuf:"bytes,3,opt,name=readKey,proto3" json:"readKey,omitempty"` - FollowKey []byte `protobuf:"bytes,4,opt,name=followKey,proto3" json:"followKey,omitempty"` + ThreadKey []byte `protobuf:"bytes,3,opt,name=threadKey,proto3" json:"threadKey,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -316,26 +307,19 @@ func (m *ThreadInfoReply) GetLogs() []*LogInfo { return nil } -func (m *ThreadInfoReply) GetReadKey() []byte { +func (m *ThreadInfoReply) GetThreadKey() []byte { if m != nil { - return m.ReadKey - } - return nil -} - -func (m *ThreadInfoReply) GetFollowKey() []byte { - if m != nil { - return m.FollowKey + return m.ThreadKey } return nil } type AddThreadRequest struct { - Addr []byte `protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"` - Keys *ThreadKeys `protobuf:"bytes,2,opt,name=keys,proto3" json:"keys,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Addr []byte `protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"` + Keys *Keys `protobuf:"bytes,2,opt,name=keys,proto3" json:"keys,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *AddThreadRequest) Reset() { *m = AddThreadRequest{} } @@ -370,7 +354,7 @@ func (m *AddThreadRequest) GetAddr() []byte { return nil } -func (m *AddThreadRequest) GetKeys() *ThreadKeys { +func (m *AddThreadRequest) GetKeys() *Keys { if m != nil { return m.Keys } @@ -556,7 +540,7 @@ func (m *DeleteThreadReply) XXX_DiscardUnknown() { var xxx_messageInfo_DeleteThreadReply proto.InternalMessageInfo -type AddFollowerRequest struct { +type AddReplicatorRequest struct { ThreadID []byte `protobuf:"bytes,1,opt,name=threadID,proto3" json:"threadID,omitempty"` Addr []byte `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -564,78 +548,78 @@ type AddFollowerRequest struct { XXX_sizecache int32 `json:"-"` } -func (m *AddFollowerRequest) Reset() { *m = AddFollowerRequest{} } -func (m *AddFollowerRequest) String() string { return proto.CompactTextString(m) } -func (*AddFollowerRequest) ProtoMessage() {} -func (*AddFollowerRequest) Descriptor() ([]byte, []int) { +func (m *AddReplicatorRequest) Reset() { *m = AddReplicatorRequest{} } +func (m *AddReplicatorRequest) String() string { return proto.CompactTextString(m) } +func (*AddReplicatorRequest) ProtoMessage() {} +func (*AddReplicatorRequest) Descriptor() ([]byte, []int) { return fileDescriptor_00212fb1f9d3bf1c, []int{12} } -func (m *AddFollowerRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_AddFollowerRequest.Unmarshal(m, b) +func (m *AddReplicatorRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_AddReplicatorRequest.Unmarshal(m, b) } -func (m *AddFollowerRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_AddFollowerRequest.Marshal(b, m, deterministic) +func (m *AddReplicatorRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_AddReplicatorRequest.Marshal(b, m, deterministic) } -func (m *AddFollowerRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_AddFollowerRequest.Merge(m, src) +func (m *AddReplicatorRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_AddReplicatorRequest.Merge(m, src) } -func (m *AddFollowerRequest) XXX_Size() int { - return xxx_messageInfo_AddFollowerRequest.Size(m) +func (m *AddReplicatorRequest) XXX_Size() int { + return xxx_messageInfo_AddReplicatorRequest.Size(m) } -func (m *AddFollowerRequest) XXX_DiscardUnknown() { - xxx_messageInfo_AddFollowerRequest.DiscardUnknown(m) +func (m *AddReplicatorRequest) XXX_DiscardUnknown() { + xxx_messageInfo_AddReplicatorRequest.DiscardUnknown(m) } -var xxx_messageInfo_AddFollowerRequest proto.InternalMessageInfo +var xxx_messageInfo_AddReplicatorRequest proto.InternalMessageInfo -func (m *AddFollowerRequest) GetThreadID() []byte { +func (m *AddReplicatorRequest) GetThreadID() []byte { if m != nil { return m.ThreadID } return nil } -func (m *AddFollowerRequest) GetAddr() []byte { +func (m *AddReplicatorRequest) GetAddr() []byte { if m != nil { return m.Addr } return nil } -type AddFollowerReply struct { +type AddReplicatorReply struct { PeerID []byte `protobuf:"bytes,1,opt,name=peerID,proto3" json:"peerID,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *AddFollowerReply) Reset() { *m = AddFollowerReply{} } -func (m *AddFollowerReply) String() string { return proto.CompactTextString(m) } -func (*AddFollowerReply) ProtoMessage() {} -func (*AddFollowerReply) Descriptor() ([]byte, []int) { +func (m *AddReplicatorReply) Reset() { *m = AddReplicatorReply{} } +func (m *AddReplicatorReply) String() string { return proto.CompactTextString(m) } +func (*AddReplicatorReply) ProtoMessage() {} +func (*AddReplicatorReply) Descriptor() ([]byte, []int) { return fileDescriptor_00212fb1f9d3bf1c, []int{13} } -func (m *AddFollowerReply) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_AddFollowerReply.Unmarshal(m, b) +func (m *AddReplicatorReply) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_AddReplicatorReply.Unmarshal(m, b) } -func (m *AddFollowerReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_AddFollowerReply.Marshal(b, m, deterministic) +func (m *AddReplicatorReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_AddReplicatorReply.Marshal(b, m, deterministic) } -func (m *AddFollowerReply) XXX_Merge(src proto.Message) { - xxx_messageInfo_AddFollowerReply.Merge(m, src) +func (m *AddReplicatorReply) XXX_Merge(src proto.Message) { + xxx_messageInfo_AddReplicatorReply.Merge(m, src) } -func (m *AddFollowerReply) XXX_Size() int { - return xxx_messageInfo_AddFollowerReply.Size(m) +func (m *AddReplicatorReply) XXX_Size() int { + return xxx_messageInfo_AddReplicatorReply.Size(m) } -func (m *AddFollowerReply) XXX_DiscardUnknown() { - xxx_messageInfo_AddFollowerReply.DiscardUnknown(m) +func (m *AddReplicatorReply) XXX_DiscardUnknown() { + xxx_messageInfo_AddReplicatorReply.DiscardUnknown(m) } -var xxx_messageInfo_AddFollowerReply proto.InternalMessageInfo +var xxx_messageInfo_AddReplicatorReply proto.InternalMessageInfo -func (m *AddFollowerReply) GetPeerID() []byte { +func (m *AddReplicatorReply) GetPeerID() []byte { if m != nil { return m.PeerID } @@ -1021,7 +1005,7 @@ func (m *SubscribeRequest) GetThreadIDs() [][]byte { func init() { proto.RegisterType((*GetHostIDRequest)(nil), "net.api.pb.GetHostIDRequest") proto.RegisterType((*GetHostIDReply)(nil), "net.api.pb.GetHostIDReply") - proto.RegisterType((*ThreadKeys)(nil), "net.api.pb.ThreadKeys") + proto.RegisterType((*Keys)(nil), "net.api.pb.Keys") proto.RegisterType((*CreateThreadRequest)(nil), "net.api.pb.CreateThreadRequest") proto.RegisterType((*LogInfo)(nil), "net.api.pb.LogInfo") proto.RegisterType((*ThreadInfoReply)(nil), "net.api.pb.ThreadInfoReply") @@ -1031,8 +1015,8 @@ func init() { proto.RegisterType((*PullThreadReply)(nil), "net.api.pb.PullThreadReply") proto.RegisterType((*DeleteThreadRequest)(nil), "net.api.pb.DeleteThreadRequest") proto.RegisterType((*DeleteThreadReply)(nil), "net.api.pb.DeleteThreadReply") - proto.RegisterType((*AddFollowerRequest)(nil), "net.api.pb.AddFollowerRequest") - proto.RegisterType((*AddFollowerReply)(nil), "net.api.pb.AddFollowerReply") + proto.RegisterType((*AddReplicatorRequest)(nil), "net.api.pb.AddReplicatorRequest") + proto.RegisterType((*AddReplicatorReply)(nil), "net.api.pb.AddReplicatorReply") proto.RegisterType((*CreateRecordRequest)(nil), "net.api.pb.CreateRecordRequest") proto.RegisterType((*Record)(nil), "net.api.pb.Record") proto.RegisterType((*NewRecordReply)(nil), "net.api.pb.NewRecordReply") @@ -1046,55 +1030,54 @@ func init() { func init() { proto.RegisterFile("api.proto", fileDescriptor_00212fb1f9d3bf1c) } var fileDescriptor_00212fb1f9d3bf1c = []byte{ - // 758 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0x4d, 0x6f, 0xda, 0x4a, - 0x14, 0xc5, 0x40, 0x48, 0x7c, 0x41, 0x84, 0x0c, 0x51, 0x84, 0xfc, 0x48, 0x5e, 0x34, 0x9b, 0x87, - 0xb2, 0xf0, 0x4b, 0xe9, 0xb6, 0x9b, 0xa4, 0xa4, 0x89, 0xd3, 0x16, 0x21, 0x37, 0xcb, 0x56, 0x11, - 0xc4, 0x37, 0x04, 0xd5, 0x62, 0x5c, 0xdb, 0x24, 0x65, 0xdb, 0x9f, 0xd2, 0xbf, 0xd3, 0x3f, 0x55, - 0xcd, 0x8c, 0x3f, 0xc6, 0x86, 0x50, 0x47, 0xdd, 0xf9, 0xde, 0x99, 0x39, 0xf7, 0xdc, 0x3b, 0x67, - 0x0e, 0x80, 0x3e, 0xf6, 0x66, 0xa6, 0xe7, 0xb3, 0x90, 0x11, 0x98, 0x63, 0x68, 0x8a, 0x70, 0x42, - 0x09, 0xb4, 0x2e, 0x31, 0xbc, 0x62, 0x41, 0x68, 0x0d, 0x6c, 0xfc, 0xb6, 0xc0, 0x20, 0xa4, 0x3d, - 0x68, 0x2a, 0x39, 0xcf, 0x5d, 0x92, 0x03, 0xa8, 0x79, 0x88, 0xbe, 0x35, 0xe8, 0x68, 0xc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0x34, 0x95, 0x8a, 0x5c, 0x31, - 0xd7, 0x42, 0xed, 0xc5, 0x39, 0x18, 0xb0, 0x23, 0xb1, 0x12, 0x1a, 0x49, 0x4c, 0xdf, 0x08, 0xcb, - 0x55, 0xe7, 0x97, 0x72, 0xd3, 0xfe, 0xc8, 0xed, 0x14, 0x5a, 0x9f, 0x16, 0x93, 0xe0, 0xce, 0x9f, - 0x4d, 0x30, 0x66, 0xd2, 0x05, 0x3d, 0xae, 0x1c, 0x74, 0x34, 0x61, 0x3f, 0x69, 0xa2, 0xff, 0xab, - 0x06, 0x95, 0xb3, 0x91, 0x45, 0x2e, 0x41, 0x4f, 0xac, 0x9e, 0x74, 0xd5, 0x12, 0xf9, 0x5f, 0x05, - 0xc3, 0x78, 0x66, 0x95, 0x8f, 0xa2, 0x44, 0x86, 0xd0, 0x50, 0xbd, 0x9a, 0xfc, 0xab, 0xee, 0x5e, - 0xe3, 0xe2, 0xc6, 0x3f, 0xab, 0x4e, 0x92, 0xb8, 0x21, 0x2d, 0x91, 0x2b, 0xd0, 0x13, 0x7b, 0xca, - 0x12, 0xcb, 0xbb, 0x56, 0x01, 0xa4, 0xc4, 0x94, 0x56, 0x5a, 0x7c, 0x11, 0xd2, 0x35, 0x40, 0xea, - 0x3e, 0xe4, 0x50, 0xdd, 0xbc, 0x62, 0x63, 0x59, 0xac, 0xbc, 0x69, 0x95, 0xc8, 0x08, 0x1a, 0xaa, - 0x07, 0x65, 0xe7, 0xb5, 0xc6, 0xd0, 0x8c, 0xc3, 0xe7, 0x37, 0x48, 0xc4, 0x8f, 0x50, 0x57, 0xac, - 0x87, 0x1c, 0xe5, 0x66, 0x96, 0x73, 0x36, 0xa3, 0xfb, 0xec, 0x7a, 0x0c, 0xd7, 0x50, 0xdd, 0x69, - 0xdd, 0x85, 0x66, 0xa4, 0x9f, 0xd5, 0x47, 0xd6, 0x0c, 0x68, 0x89, 0x0b, 0x2d, 0x79, 0x3e, 0x2b, - 0xf7, 0xb9, 0x01, 0x28, 0xf7, 0xe6, 0x4a, 0x91, 0x62, 0xd7, 0x01, 0xe5, 0x1f, 0xe3, 0x8a, 0x62, - 0xb3, 0x40, 0x16, 0xe8, 0xc9, 0xa3, 0xc9, 0x02, 0xe5, 0xdf, 0xd2, 0xe6, 0xd6, 0x4e, 0xb5, 0xf3, - 0x53, 0x30, 0x66, 0xcc, 0x0c, 0xf1, 0x7b, 0x38, 0x73, 0xd1, 0x94, 0xaf, 0xec, 0x76, 0x8e, 0xe1, - 0xed, 0xd4, 0xf7, 0xee, 0xce, 0x75, 0x79, 0x4f, 0x43, 0x0c, 0x47, 0xda, 0xcf, 0x72, 0xf5, 0x66, - 0x78, 0x71, 0x33, 0xa9, 0x89, 0x7f, 0x62, 0xaf, 0x7f, 0x07, 0x00, 0x00, 0xff, 0xff, 0xec, 0x7b, - 0x40, 0xa4, 0x96, 0x09, 0x00, 0x00, + // 748 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xdd, 0x4e, 0xdb, 0x4c, + 0x10, 0x8d, 0x13, 0x13, 0xc8, 0x90, 0x2f, 0x84, 0x0d, 0xfa, 0x14, 0xb9, 0x40, 0xd1, 0xaa, 0x52, + 0xa3, 0xaa, 0x72, 0x69, 0x7a, 0xcb, 0x0d, 0x34, 0x14, 0x0c, 0x34, 0x8a, 0x02, 0x52, 0x2f, 0x51, + 0x12, 0x4f, 0x93, 0xa8, 0x56, 0xec, 0xda, 0x1b, 0x68, 0x6e, 0xfb, 0x28, 0x7d, 0xa3, 0xbe, 0x51, + 0xb5, 0xbb, 0xfe, 0x59, 0x3b, 0x21, 0x35, 0xea, 0x9d, 0x67, 0x77, 0xe6, 0xcc, 0xcf, 0x9e, 0x39, + 0x32, 0x54, 0x06, 0xde, 0xd4, 0xf4, 0x7c, 0x97, 0xb9, 0x04, 0x66, 0xc8, 0x4c, 0x61, 0x0e, 0x29, + 0x81, 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8, 0x30, 0x2b, 0x9e, 0x35, 0xb5, 0x00, 0x69, 0x96, 0xa4, 0x25, + 0x81, 0x16, 0x38, 0xdd, 0xe2, 0x25, 0x5a, 0x7a, 0xd5, 0x35, 0x40, 0x99, 0xcd, 0x2b, 0x84, 0xbc, + 0x5d, 0x05, 0x94, 0x5d, 0xc9, 0x25, 0xde, 0xa6, 0x81, 0x2c, 0xa8, 0xc4, 0xab, 0x93, 0x06, 0xca, + 0x6e, 0xd4, 0xfa, 0xd6, 0x8e, 0xb5, 0xb3, 0x63, 0x30, 0xa6, 0xae, 0xc9, 0xf0, 0x07, 0x9b, 0x3a, + 0x68, 0xca, 0x5d, 0xbb, 0x9f, 0x21, 0xbb, 0x1f, 0xfb, 0xde, 0xe8, 0xac, 0x22, 0x5f, 0xab, 0x8b, + 0xac, 0xa7, 0xfd, 0x2a, 0xea, 0x77, 0xdd, 0xf3, 0xbb, 0x61, 0x59, 0xfc, 0x4c, 0x7d, 0xf8, 0x13, + 0x00, 0x00, 0xff, 0xff, 0xa0, 0x53, 0x64, 0x5d, 0x59, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1115,7 +1098,7 @@ type APIClient interface { GetThread(ctx context.Context, in *GetThreadRequest, opts ...grpc.CallOption) (*ThreadInfoReply, error) PullThread(ctx context.Context, in *PullThreadRequest, opts ...grpc.CallOption) (*PullThreadReply, error) DeleteThread(ctx context.Context, in *DeleteThreadRequest, opts ...grpc.CallOption) (*DeleteThreadReply, error) - AddFollower(ctx context.Context, in *AddFollowerRequest, opts ...grpc.CallOption) (*AddFollowerReply, error) + AddReplicator(ctx context.Context, in *AddReplicatorRequest, opts ...grpc.CallOption) (*AddReplicatorReply, error) CreateRecord(ctx context.Context, in *CreateRecordRequest, opts ...grpc.CallOption) (*NewRecordReply, error) AddRecord(ctx context.Context, in *AddRecordRequest, opts ...grpc.CallOption) (*AddRecordReply, error) GetRecord(ctx context.Context, in *GetRecordRequest, opts ...grpc.CallOption) (*GetRecordReply, error) @@ -1184,9 +1167,9 @@ func (c *aPIClient) DeleteThread(ctx context.Context, in *DeleteThreadRequest, o return out, nil } -func (c *aPIClient) AddFollower(ctx context.Context, in *AddFollowerRequest, opts ...grpc.CallOption) (*AddFollowerReply, error) { - out := new(AddFollowerReply) - err := c.cc.Invoke(ctx, "/net.api.pb.API/AddFollower", in, out, opts...) +func (c *aPIClient) AddReplicator(ctx context.Context, in *AddReplicatorRequest, opts ...grpc.CallOption) (*AddReplicatorReply, error) { + out := new(AddReplicatorReply) + err := c.cc.Invoke(ctx, "/net.api.pb.API/AddReplicator", in, out, opts...) if err != nil { return nil, err } @@ -1260,7 +1243,7 @@ type APIServer interface { GetThread(context.Context, *GetThreadRequest) (*ThreadInfoReply, error) PullThread(context.Context, *PullThreadRequest) (*PullThreadReply, error) DeleteThread(context.Context, *DeleteThreadRequest) (*DeleteThreadReply, error) - AddFollower(context.Context, *AddFollowerRequest) (*AddFollowerReply, error) + AddReplicator(context.Context, *AddReplicatorRequest) (*AddReplicatorReply, error) CreateRecord(context.Context, *CreateRecordRequest) (*NewRecordReply, error) AddRecord(context.Context, *AddRecordRequest) (*AddRecordReply, error) GetRecord(context.Context, *GetRecordRequest) (*GetRecordReply, error) @@ -1289,8 +1272,8 @@ func (*UnimplementedAPIServer) PullThread(ctx context.Context, req *PullThreadRe func (*UnimplementedAPIServer) DeleteThread(ctx context.Context, req *DeleteThreadRequest) (*DeleteThreadReply, error) { return nil, status.Errorf(codes.Unimplemented, "method DeleteThread not implemented") } -func (*UnimplementedAPIServer) AddFollower(ctx context.Context, req *AddFollowerRequest) (*AddFollowerReply, error) { - return nil, status.Errorf(codes.Unimplemented, "method AddFollower not implemented") +func (*UnimplementedAPIServer) AddReplicator(ctx context.Context, req *AddReplicatorRequest) (*AddReplicatorReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method AddReplicator not implemented") } func (*UnimplementedAPIServer) CreateRecord(ctx context.Context, req *CreateRecordRequest) (*NewRecordReply, error) { return nil, status.Errorf(codes.Unimplemented, "method CreateRecord not implemented") @@ -1417,20 +1400,20 @@ func _API_DeleteThread_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } -func _API_AddFollower_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AddFollowerRequest) +func _API_AddReplicator_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AddReplicatorRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(APIServer).AddFollower(ctx, in) + return srv.(APIServer).AddReplicator(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/net.api.pb.API/AddFollower", + FullMethod: "/net.api.pb.API/AddReplicator", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(APIServer).AddFollower(ctx, req.(*AddFollowerRequest)) + return srv.(APIServer).AddReplicator(ctx, req.(*AddReplicatorRequest)) } return interceptor(ctx, in, info, handler) } @@ -1539,8 +1522,8 @@ var _API_serviceDesc = grpc.ServiceDesc{ Handler: _API_DeleteThread_Handler, }, { - MethodName: "AddFollower", - Handler: _API_AddFollower_Handler, + MethodName: "AddReplicator", + Handler: _API_AddReplicator_Handler, }, { MethodName: "CreateRecord", diff --git a/net/api/pb/api.proto b/net/api/pb/api.proto index 82b0f33d..c4af2b86 100644 --- a/net/api/pb/api.proto +++ b/net/api/pb/api.proto @@ -2,9 +2,9 @@ syntax = "proto3"; package net.api.pb; option java_multiple_files = true; -option java_package = "io.textile.thread_net_grpc"; -option java_outer_classname = "ThreadNet"; -option objc_class_prefix = "TNET"; +option java_package = "io.textile.threads_net_grpc"; +option java_outer_classname = "ThreadsNet"; +option objc_class_prefix = "THREADSNET"; message GetHostIDRequest {} @@ -12,15 +12,14 @@ message GetHostIDReply { bytes peerID = 1; } -message ThreadKeys { - bytes readKey = 1; - bytes followKey = 2; - bytes logKey = 3; +message Keys { + bytes threadKey = 1; + bytes logKey = 2; } message CreateThreadRequest { bytes threadID = 1; - ThreadKeys keys = 2; + Keys keys = 2; } message LogInfo { @@ -34,13 +33,12 @@ message LogInfo { message ThreadInfoReply { bytes ID = 1; repeated LogInfo logs = 2; - bytes readKey = 3; - bytes followKey = 4; + bytes threadKey = 3; } message AddThreadRequest { bytes addr = 1; - ThreadKeys keys = 2; + Keys keys = 2; } message GetThreadRequest { @@ -59,12 +57,12 @@ message DeleteThreadRequest { message DeleteThreadReply {} -message AddFollowerRequest { +message AddReplicatorRequest { bytes threadID = 1; bytes addr = 2; } -message AddFollowerReply { +message AddReplicatorReply { bytes peerID = 1; } @@ -114,7 +112,7 @@ service API { rpc GetThread(GetThreadRequest) returns (ThreadInfoReply) {} rpc PullThread(PullThreadRequest) returns (PullThreadReply) {} rpc DeleteThread(DeleteThreadRequest) returns (DeleteThreadReply) {} - rpc AddFollower(AddFollowerRequest) returns (AddFollowerReply) {} + rpc AddReplicator(AddReplicatorRequest) returns (AddReplicatorReply) {} rpc CreateRecord(CreateRecordRequest) returns (NewRecordReply) {} rpc AddRecord(AddRecordRequest) returns (AddRecordReply) {} rpc GetRecord(GetRecordRequest) returns (GetRecordReply) {} diff --git a/net/api/pb/javascript/package-lock.json b/net/api/pb/javascript/package-lock.json index 4f6f80d5..2ef4c9d6 100644 --- a/net/api/pb/javascript/package-lock.json +++ b/net/api/pb/javascript/package-lock.json @@ -1,5 +1,5 @@ { - "name": "@textile/thread-net-grpc", + "name": "@textile/threads-net-grpc", "version": "0.0.0", "lockfileVersion": 1, "requires": true, diff --git a/net/api/pb/javascript/package.json b/net/api/pb/javascript/package.json index bf07ac03..cb610367 100644 --- a/net/api/pb/javascript/package.json +++ b/net/api/pb/javascript/package.json @@ -1,7 +1,7 @@ { - "name": "@textile/thread-net-grpc", + "name": "@textile/threads-net-grpc", "version": "0.0.0", - "description": "A gRPC client for interacting with a remote Thread network.", + "description": "A gRPC client for interacting with a remote Threads network.", "repository": { "type": "git", "url": "git+https://github.com/textileio/go-threads.git" diff --git a/net/api/service.go b/net/api/service.go index 10d44de1..e4cb578b 100644 --- a/net/api/service.go +++ b/net/api/service.go @@ -14,7 +14,6 @@ import ( "github.com/textileio/go-threads/cbor" "github.com/textileio/go-threads/core/net" "github.com/textileio/go-threads/core/thread" - sym "github.com/textileio/go-threads/crypto/symmetric" pb "github.com/textileio/go-threads/net/api/pb" "github.com/textileio/go-threads/net/util" tutil "github.com/textileio/go-threads/util" @@ -141,8 +140,8 @@ func (s *Service) DeleteThread(ctx context.Context, req *pb.DeleteThreadRequest) return &pb.DeleteThreadReply{}, nil } -func (s *Service) AddFollower(ctx context.Context, req *pb.AddFollowerRequest) (*pb.AddFollowerReply, error) { - log.Debugf("received add follower request") +func (s *Service) AddReplicator(ctx context.Context, req *pb.AddReplicatorRequest) (*pb.AddReplicatorReply, error) { + log.Debugf("received add replicator request") threadID, err := thread.Cast(req.ThreadID) if err != nil { @@ -152,11 +151,11 @@ func (s *Service) AddFollower(ctx context.Context, req *pb.AddFollowerRequest) ( if err != nil { return nil, err } - pid, err := s.net.AddFollower(ctx, threadID, addr) + pid, err := s.net.AddReplicator(ctx, threadID, addr) if err != nil { return nil, err } - return &pb.AddFollowerReply{ + return &pb.AddReplicatorReply{ PeerID: marshalPeerID(pid), }, nil } @@ -202,7 +201,7 @@ func (s *Service) AddRecord(ctx context.Context, req *pb.AddRecordRequest) (*pb. if err != nil { return nil, err } - rec, err := cbor.RecordFromProto(util.RecToServiceRec(req.Record), info.FollowKey) + rec, err := cbor.RecordFromProto(util.RecToServiceRec(req.Record), info.Key.Service()) if err != nil { return nil, err } @@ -273,23 +272,16 @@ func marshalPeerID(id peer.ID) []byte { return b } -func getKeyOptions(keys *pb.ThreadKeys) (opts []net.KeyOption, err error) { +func getKeyOptions(keys *pb.Keys) (opts []net.KeyOption, err error) { if keys == nil { return } - if keys.FollowKey != nil { - fk, err := sym.FromBytes(keys.FollowKey) + if keys.ThreadKey != nil { + k, err := thread.KeyFromBytes(keys.ThreadKey) if err != nil { - return nil, fmt.Errorf("invalid follow-key: %v", err) + return nil, fmt.Errorf("invalid thread-key: %v", err) } - opts = append(opts, net.FollowKey(fk)) - } - if keys.ReadKey != nil { - rk, err := sym.FromBytes(keys.ReadKey) - if err != nil { - return nil, fmt.Errorf("invalid read-key: %v", err) - } - opts = append(opts, net.ReadKey(rk)) + opts = append(opts, net.ThreadKey(k)) } var lk crypto.Key if keys.LogKey != nil { @@ -335,14 +327,9 @@ func threadInfoToProto(info thread.Info) (*pb.ThreadInfoReply, error) { Heads: heads, } } - var rk []byte - if info.ReadKey != nil { - rk = info.ReadKey.Bytes() - } return &pb.ThreadInfoReply{ ID: info.ID.Bytes(), + ThreadKey: info.Key.Bytes(), Logs: logs, - ReadKey: rk, - FollowKey: info.FollowKey.Bytes(), }, nil } diff --git a/net/client.go b/net/client.go index aae5e599..d108e256 100644 --- a/net/client.go +++ b/net/client.go @@ -28,20 +28,20 @@ const ( // getLogs in a thread. func (s *server) getLogs(ctx context.Context, id thread.ID, pid peer.ID) ([]thread.LogInfo, error) { - fk, err := s.net.store.FollowKey(id) + sk, err := s.net.store.ServiceKey(id) if err != nil { return nil, err } - if fk == nil { - return nil, fmt.Errorf("a follow-key is required to request logs") + if sk == nil { + return nil, fmt.Errorf("a service-key is required to request logs") } req := &pb.GetLogsRequest{ Header: &pb.GetLogsRequest_Header{ From: &pb.ProtoPeerID{ID: s.net.host.ID()}, }, - ThreadID: &pb.ProtoThreadID{ID: id}, - FollowKey: &pb.ProtoKey{Key: fk}, + ThreadID: &pb.ProtoThreadID{ID: id}, + ServiceKey: &pb.ProtoKey{Key: sk}, } log.Debugf("getting %s logs from %s...", id.String(), pid.String()) @@ -71,7 +71,7 @@ func (s *server) getLogs(ctx context.Context, id thread.ID, pid peer.ID) ([]thre } // pushLog to a peer. -func (s *server) pushLog(ctx context.Context, id thread.ID, lg thread.LogInfo, pid peer.ID, fk *sym.Key, rk *sym.Key) error { +func (s *server) pushLog(ctx context.Context, id thread.ID, lg thread.LogInfo, pid peer.ID, sk *sym.Key, rk *sym.Key) error { lreq := &pb.PushLogRequest{ Header: &pb.PushLogRequest_Header{ From: &pb.ProtoPeerID{ID: s.net.host.ID()}, @@ -79,8 +79,8 @@ func (s *server) pushLog(ctx context.Context, id thread.ID, lg thread.LogInfo, p ThreadID: &pb.ProtoThreadID{ID: id}, Log: logToProto(lg), } - if fk != nil { - lreq.FollowKey = &pb.ProtoKey{Key: fk} + if sk != nil { + lreq.ServiceKey = &pb.ProtoKey{Key: sk} } if rk != nil { lreq.ReadKey = &pb.ProtoKey{Key: rk} @@ -147,12 +147,12 @@ func (r *records) Store(p peer.ID, key cid.Cid, value core.Record) { // getRecords from log addresses. func (s *server) getRecords(ctx context.Context, id thread.ID, lid peer.ID, offsets map[peer.ID]cid.Cid, limit int) (map[peer.ID][]core.Record, error) { - fk, err := s.net.store.FollowKey(id) + sk, err := s.net.store.ServiceKey(id) if err != nil { return nil, err } - if fk == nil { - return nil, fmt.Errorf("a follow-key is required to request records") + if sk == nil { + return nil, fmt.Errorf("a service-key is required to request records") } pblgs := make([]*pb.GetRecordsRequest_LogEntry, 0, len(offsets)) @@ -168,9 +168,9 @@ func (s *server) getRecords(ctx context.Context, id thread.ID, lid peer.ID, offs Header: &pb.GetRecordsRequest_Header{ From: &pb.ProtoPeerID{ID: s.net.host.ID()}, }, - ThreadID: &pb.ProtoThreadID{ID: id}, - FollowKey: &pb.ProtoKey{Key: fk}, - Logs: pblgs, + ThreadID: &pb.ProtoThreadID{ID: id}, + ServiceKey: &pb.ProtoKey{Key: sk}, + Logs: pblgs, } lg, err := s.net.store.GetLog(id, lid) @@ -239,7 +239,7 @@ func (s *server) getRecords(ctx context.Context, id thread.ID, lid peer.ID, offs } for _, r := range l.Records { - rec, err := cbor.RecordFromProto(r, fk) + rec, err := cbor.RecordFromProto(r, sk) if err != nil { log.Error(err) return diff --git a/net/net.go b/net/net.go index 46698370..0bad6658 100644 --- a/net/net.go +++ b/net/net.go @@ -25,7 +25,6 @@ import ( lstore "github.com/textileio/go-threads/core/logstore" core "github.com/textileio/go-threads/core/net" "github.com/textileio/go-threads/core/thread" - sym "github.com/textileio/go-threads/crypto/symmetric" pb "github.com/textileio/go-threads/net/pb" "github.com/textileio/go-threads/util" "google.golang.org/grpc" @@ -116,7 +115,6 @@ func NewNetwork(ctx context.Context, h host.Host, bstore bs.Blockstore, ds forma return t, nil } -// Close the net instance. func (t *net) Close() (err error) { t.rpc.GracefulStop() @@ -150,22 +148,18 @@ func (t *net) Close() (err error) { return nil } -// Host returns the underlying libp2p host. func (t *net) Host() host.Host { return t.host } -// Store returns the threadstore. func (t *net) Store() lstore.Logstore { return t.store } -// GetHostID returns the host's peer id. func (t *net) GetHostID(context.Context) (peer.ID, error) { return t.host.ID(), nil } -// CreateThread with id. func (t *net) CreateThread(_ context.Context, id thread.ID, opts ...core.KeyOption) (info thread.Info, err error) { if err = t.ensureUnique(id); err != nil { return @@ -177,15 +171,11 @@ func (t *net) CreateThread(_ context.Context, id thread.ID, opts ...core.KeyOpti } info = thread.Info{ - ID: id, - FollowKey: args.FollowKey, - ReadKey: args.ReadKey, + ID: id, + Key: args.ThreadKey, } - if info.FollowKey == nil { - info.FollowKey, err = sym.NewRandom() - if err != nil { - return - } + if !info.Key.Defined() { + info.Key = thread.NewRandomKey() } if err = t.store.AddThread(info); err != nil { return @@ -211,7 +201,6 @@ func (t *net) ensureUnique(id thread.ID) error { return nil } -// AddThread from a multiaddress. func (t *net) AddThread(ctx context.Context, addr ma.Multiaddr, opts ...core.KeyOption) (info thread.Info, err error) { id, err := thread.FromAddr(addr) if err != nil { @@ -227,13 +216,12 @@ func (t *net) AddThread(ctx context.Context, addr ma.Multiaddr, opts ...core.Key } if err = t.store.AddThread(thread.Info{ - ID: id, - FollowKey: args.FollowKey, - ReadKey: args.ReadKey, + ID: id, + Key: args.ThreadKey, }); err != nil { return } - if args.ReadKey != nil { + if args.ThreadKey.CanRead() { var linfo thread.LogInfo linfo, err = createLog(t.host.ID(), args.LogKey) if err != nil { @@ -270,7 +258,6 @@ func (t *net) AddThread(ctx context.Context, addr ma.Multiaddr, opts ...core.Key return t.store.GetThread(id) } -// GetThread with id. func (t *net) GetThread(_ context.Context, id thread.ID) (thread.Info, error) { return t.store.GetThread(id) } @@ -287,10 +274,6 @@ func (t *net) getThreadSemaphore(id thread.ID) chan struct{} { return ptl } -// PullThread for new records. -// Logs owned by this host are traversed locally. -// Remotely addressed logs are pulled from the network. -// Is thread-safe. func (t *net) PullThread(ctx context.Context, id thread.ID) error { log.Debugf("pulling thread %s...", id.String()) ptl := t.getThreadSemaphore(id) @@ -365,13 +348,12 @@ func (t *net) pullThread(ctx context.Context, id thread.ID) error { return nil } -// Delete a thread (@todo). +// @todo func (t *net) DeleteThread(context.Context, thread.ID) error { panic("implement me") } -// AddFollower to a thread. -func (t *net) AddFollower(ctx context.Context, id thread.ID, paddr ma.Multiaddr) (pid peer.ID, err error) { +func (t *net) AddReplicator(ctx context.Context, id thread.ID, paddr ma.Multiaddr) (pid peer.ID, err error) { info, err := t.store.GetThread(id) if err != nil { return @@ -412,9 +394,9 @@ func (t *net) AddFollower(ctx context.Context, id thread.ID, paddr ma.Multiaddr) log.Warnf("peer %s address requires a DHT lookup", pid.String()) } - // Send all logs to the new follower + // Send all logs to the new replicator for _, l := range info.Logs { - if err = t.server.pushLog(ctx, id, l, pid, info.FollowKey, nil); err != nil { + if err = t.server.pushLog(ctx, id, l, pid, info.Key.Service(), nil); err != nil { if err := t.store.SetAddrs(id, ownlg.ID, ownlg.Addrs, pstore.PermanentAddrTTL); err != nil { log.Errorf("error rolling back log address change: %s", err) } @@ -462,7 +444,6 @@ func getDialable(addr ma.Multiaddr) (ma.Multiaddr, error) { return ma.NewMultiaddr(parts[0]) } -// CreateRecord with body. func (t *net) CreateRecord(ctx context.Context, id thread.ID, body format.Node) (r core.ThreadRecord, err error) { // Get or create a log for the new node lg, err := t.getOrCreateOwnLog(id) @@ -497,7 +478,6 @@ func (t *net) CreateRecord(ctx context.Context, id thread.ID, body format.Node) return r, nil } -// AddRecord with record. func (t *net) AddRecord(ctx context.Context, id thread.ID, lid peer.ID, rec core.Record) error { logpk, err := t.store.PubKey(id, lid) if err != nil { @@ -523,16 +503,15 @@ func (t *net) AddRecord(ctx context.Context, id thread.ID, lid peer.ID, rec core return t.PutRecord(ctx, id, lid, rec) } -// GetRecord returns the record at cid. func (t *net) GetRecord(ctx context.Context, id thread.ID, rid cid.Cid) (core.Record, error) { - fk, err := t.store.FollowKey(id) + sk, err := t.store.ServiceKey(id) if err != nil { return nil, err } - if fk == nil { - return nil, fmt.Errorf("a follow-key is required to get records") + if sk == nil { + return nil, fmt.Errorf("a service-key is required to get records") } - return cbor.GetRecord(ctx, t, rid, fk) + return cbor.GetRecord(ctx, t, rid, sk) } // Record wraps a core.Record within a thread and log context. @@ -562,7 +541,6 @@ func (r *Record) LogID() peer.ID { return r.logID } -// Subscribe returns a read-only channel of records. func (t *net) Subscribe(ctx context.Context, opts ...core.SubOption) (<-chan core.ThreadRecord, error) { args := &core.SubOptions{} for _, opt := range opts { @@ -697,12 +675,12 @@ func (t *net) createRecord(ctx context.Context, id thread.ID, lg thread.LogInfo, if lg.PrivKey == nil { return nil, fmt.Errorf("a private-key is required to create records") } - fk, err := t.store.FollowKey(id) + sk, err := t.store.ServiceKey(id) if err != nil { return nil, err } - if fk == nil { - return nil, fmt.Errorf("a follow-key is required to create records") + if sk == nil { + return nil, fmt.Errorf("a service-key is required to create records") } rk, err := t.store.ReadKey(id) if err != nil { @@ -720,7 +698,7 @@ func (t *net) createRecord(ctx context.Context, id thread.ID, lg thread.LogInfo, if len(lg.Heads) != 0 { prev = lg.Heads[0] } - return cbor.CreateRecord(ctx, t, event, prev, lg.PrivKey, fk) + return cbor.CreateRecord(ctx, t, event, prev, lg.PrivKey, sk) } // getLocalRecords returns local records from the given thread that are ahead of @@ -735,12 +713,12 @@ func (t *net) getLocalRecords(ctx context.Context, id thread.ID, lid peer.ID, of if lg.PubKey == nil { return nil, fmt.Errorf("log not found") } - fk, err := t.store.FollowKey(id) + sk, err := t.store.ServiceKey(id) if err != nil { return nil, err } - if fk == nil { - return nil, fmt.Errorf("a follow-key is required to get records") + if sk == nil { + return nil, fmt.Errorf("a service-key is required to get records") } var recs []core.Record @@ -760,7 +738,7 @@ func (t *net) getLocalRecords(ctx context.Context, id thread.ID, lid peer.ID, of if !cursor.Defined() || cursor.String() == offset.String() { break } - r, err := cbor.GetRecord(ctx, t, cursor, fk) // Important invariant: heads are always in blockstore + r, err := cbor.GetRecord(ctx, t, cursor, sk) // Important invariant: heads are always in blockstore if err != nil { return nil, err } diff --git a/net/net_test.go b/net/net_test.go index 106db214..4f748167 100644 --- a/net/net_test.go +++ b/net/net_test.go @@ -19,7 +19,6 @@ import ( "github.com/textileio/go-threads/cbor" core "github.com/textileio/go-threads/core/net" "github.com/textileio/go-threads/core/thread" - sym "github.com/textileio/go-threads/crypto/symmetric" tstore "github.com/textileio/go-threads/logstore/lstoremem" "github.com/textileio/go-threads/util" ) @@ -71,7 +70,7 @@ func TestService_CreateRecord(t *testing.T) { t.Fatal(err) } - back, err := event.GetBody(ctx, n, info.ReadKey) + back, err := event.GetBody(ctx, n, info.Key.Read()) if err != nil { t.Fatal(err) } @@ -111,7 +110,7 @@ func TestService_AddThread(t *testing.T) { t.Fatal(err) } - info2, err := n2.AddThread(ctx, addr, core.FollowKey(info.FollowKey), core.ReadKey(info.ReadKey)) + info2, err := n2.AddThread(ctx, addr, core.ThreadKey(info.Key)) if err != nil { t.Fatal(err) } @@ -142,7 +141,7 @@ func TestService_AddThread(t *testing.T) { }) } -func TestService_AddFollower(t *testing.T) { +func TestService_AddReplicator(t *testing.T) { t.Parallel() n1 := makeNetwork(t) defer n1.Close() @@ -152,7 +151,7 @@ func TestService_AddFollower(t *testing.T) { n1.Host().Peerstore().AddAddrs(n2.Host().ID(), n2.Host().Addrs(), peerstore.PermanentAddrTTL) n2.Host().Peerstore().AddAddrs(n1.Host().ID(), n1.Host().Addrs(), peerstore.PermanentAddrTTL) - t.Run("test add follower", func(t *testing.T) { + t.Run("test add replicator", func(t *testing.T) { ctx := context.Background() info := createThread(t, ctx, n1) @@ -170,7 +169,7 @@ func TestService_AddFollower(t *testing.T) { if err != nil { t.Fatal(err) } - if _, err = n1.AddFollower(ctx, info.ID, addr); err != nil { + if _, err = n1.AddReplicator(ctx, info.ID, addr); err != nil { t.Fatal(err) } @@ -244,7 +243,7 @@ func makeNetwork(t *testing.T) core.Net { func createThread(t *testing.T, ctx context.Context, api core.API) thread.Info { id := thread.NewIDV1(thread.Raw, 32) - info, err := api.CreateThread(ctx, id, core.FollowKey(sym.New()), core.ReadKey(sym.New())) + info, err := api.CreateThread(ctx, id) if err != nil { t.Fatal(err) } diff --git a/net/pb/custom.go b/net/pb/custom.go index b15826e2..1583fbbf 100644 --- a/net/pb/custom.go +++ b/net/pb/custom.go @@ -12,7 +12,7 @@ import ( mh "github.com/multiformats/go-multihash" varint "github.com/multiformats/go-varint" "github.com/textileio/go-threads/core/thread" - "github.com/textileio/go-threads/crypto/symmetric" + sym "github.com/textileio/go-threads/crypto/symmetric" ) // customGogoType aggregates the interfaces that custom Gogo types need to implement. @@ -184,17 +184,17 @@ func (id ProtoThreadID) Size() int { // ProtoKey is a custom type used by gogo to serde raw keys into the symmetric.Key type, and back. type ProtoKey struct { - *symmetric.Key + *sym.Key } var _ customGogoType = (*ProtoKey)(nil) func (k ProtoKey) Marshal() ([]byte, error) { - return k.Key.Marshal() + return k.Key.MarshalBinary() } func (k ProtoKey) MarshalTo(data []byte) (n int, err error) { - b, err := k.Key.Marshal() + b, err := k.Key.MarshalBinary() return copy(data, b), err } @@ -204,7 +204,7 @@ func (k ProtoKey) MarshalJSON() ([]byte, error) { } func (k *ProtoKey) Unmarshal(data []byte) (err error) { - k.Key, err = symmetric.FromBytes(data) + k.Key, err = sym.FromBytes(data) return err } @@ -334,7 +334,7 @@ func NewPopulatedProtoThreadID(_ randyNet) *ProtoThreadID { // NewPopulatedProtoKey generates a populated instance of the custom gogo type ProtoKey. // It is required by gogo-generated tests. func NewPopulatedProtoKey(_ randyNet) *ProtoKey { - k, _ := symmetric.NewRandom() + k, _ := sym.NewRandom() return &ProtoKey{Key: k} } diff --git a/net/pb/net.pb.go b/net/pb/net.pb.go index 0b038091..f1d3093f 100644 --- a/net/pb/net.pb.go +++ b/net/pb/net.pb.go @@ -148,8 +148,8 @@ type GetLogsRequest struct { Header *GetLogsRequest_Header `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // threadID is the target thread's ID. ThreadID *ProtoThreadID `protobuf:"bytes,2,opt,name=threadID,proto3,customtype=ProtoThreadID" json:"threadID,omitempty"` - // followKey for the thread. - FollowKey *ProtoKey `protobuf:"bytes,3,opt,name=followKey,proto3,customtype=ProtoKey" json:"followKey,omitempty"` + // serviceKey for the thread. + ServiceKey *ProtoKey `protobuf:"bytes,3,opt,name=serviceKey,proto3,customtype=ProtoKey" json:"serviceKey,omitempty"` } func (m *GetLogsRequest) Reset() { *m = GetLogsRequest{} } @@ -282,8 +282,8 @@ type PushLogRequest struct { Header *PushLogRequest_Header `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // threadID is the target thread's ID. ThreadID *ProtoThreadID `protobuf:"bytes,2,opt,name=threadID,proto3,customtype=ProtoThreadID" json:"threadID,omitempty"` - // followKey for the thread. - FollowKey *ProtoKey `protobuf:"bytes,3,opt,name=followKey,proto3,customtype=ProtoKey" json:"followKey,omitempty"` + // serviceKey for the thread. + ServiceKey *ProtoKey `protobuf:"bytes,3,opt,name=serviceKey,proto3,customtype=ProtoKey" json:"serviceKey,omitempty"` // readKey for the thread. ReadKey *ProtoKey `protobuf:"bytes,4,opt,name=readKey,proto3,customtype=ProtoKey" json:"readKey,omitempty"` // log is the actual log payload. @@ -418,8 +418,8 @@ type GetRecordsRequest struct { Header *GetRecordsRequest_Header `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // threadID is the target thread's ID. ThreadID *ProtoThreadID `protobuf:"bytes,2,opt,name=threadID,proto3,customtype=ProtoThreadID" json:"threadID,omitempty"` - // followKey for the thread. - FollowKey *ProtoKey `protobuf:"bytes,3,opt,name=followKey,proto3,customtype=ProtoKey" json:"followKey,omitempty"` + // serviceKey for the thread. + ServiceKey *ProtoKey `protobuf:"bytes,3,opt,name=serviceKey,proto3,customtype=ProtoKey" json:"serviceKey,omitempty"` // List of requested logs. Logs []*GetRecordsRequest_LogEntry `protobuf:"bytes,4,rep,name=logs,proto3" json:"logs,omitempty"` } @@ -830,55 +830,55 @@ func init() { func init() { proto.RegisterFile("net.proto", fileDescriptor_a5b10ce944527a32) } var fileDescriptor_a5b10ce944527a32 = []byte{ - // 753 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0x4d, 0x6f, 0xd3, 0x40, - 0x10, 0x8d, 0xed, 0xc4, 0x4d, 0x26, 0x69, 0xab, 0xac, 0x2a, 0x30, 0x16, 0x75, 0x82, 0xcb, 0x47, - 0x55, 0xd1, 0x54, 0x2a, 0x1f, 0x82, 0x23, 0x21, 0xa8, 0x44, 0x44, 0xa8, 0x32, 0xfc, 0x81, 0xa4, - 0xde, 0x38, 0x11, 0x4e, 0x36, 0xd8, 0x4e, 0x91, 0x2f, 0x1c, 0xb8, 0x70, 0xe5, 0xc8, 0x85, 0xdf, - 0x02, 0x37, 0x38, 0x96, 0x1b, 0xca, 0x21, 0x82, 0xe4, 0x4f, 0x70, 0x42, 0x68, 0x77, 0x1d, 0x3b, - 0xce, 0x07, 0x55, 0x84, 0xd4, 0x9b, 0x77, 0xde, 0x9b, 0xdd, 0x99, 0xb7, 0x6f, 0x27, 0x81, 0x4c, - 0x17, 0x7b, 0xa5, 0x9e, 0x43, 0x3c, 0x82, 0x64, 0xf6, 0xd9, 0x50, 0xf7, 0xad, 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87, 0xee, 0x81, 0xcc, 0x93, 0x59, 0x21, 0xd9, 0xc3, 0xed, 0x12, 0x97, - 0xbe, 0x14, 0xe7, 0x95, 0x9e, 0x32, 0x92, 0x11, 0x90, 0xd1, 0x3e, 0xa4, 0xbd, 0x96, 0x83, 0xeb, - 0x66, 0xb5, 0x12, 0x48, 0x98, 0x1f, 0x0c, 0x0b, 0xeb, 0xac, 0xeb, 0x97, 0x01, 0x60, 0x84, 0x14, - 0xb4, 0x07, 0x99, 0x26, 0xb1, 0x6d, 0xf2, 0x86, 0x4a, 0xce, 0x6a, 0x9e, 0x52, 0x89, 0xea, 0x1d, - 0xc1, 0xea, 0x3e, 0xc8, 0xfc, 0x30, 0xb4, 0x03, 0xc9, 0xa6, 0x43, 0x3a, 0xcb, 0x2e, 0x92, 0x81, - 0xfa, 0x01, 0xe4, 0xc2, 0x52, 0x7b, 0xb6, 0x8f, 0x0a, 0x90, 0xb4, 0x89, 0xe5, 0x2a, 0x42, 0x51, - 0xda, 0xcd, 0x1e, 0x66, 0x27, 0xed, 0xd4, 0x88, 0x65, 0x30, 0x40, 0xff, 0x28, 0xc2, 0xc6, 0x71, - 0xdf, 0x6d, 0xd1, 0xc8, 0x79, 0x22, 0xc4, 0x79, 0x17, 0x27, 0x02, 0xba, 0x09, 0x6b, 0x34, 0x8b, - 0x32, 0x93, 0x0b, 0x98, 0x13, 0x10, 0x6d, 0x83, 0x64, 0x13, 0x4b, 0x49, 0xb1, 0xb2, 0x63, 0xcd, - 0xd2, 0xf8, 0xaa, 0x5a, 0x6e, 0x40, 0x2e, 0xec, 0xb8, 0x67, 0xfb, 0xfa, 0x1f, 0x11, 0xf2, 0x47, - 0xd8, 0xe3, 0xbe, 0x0d, 0x2d, 0xf3, 0x60, 0x46, 0xad, 0xe2, 0x94, 0x65, 0xe2, 0xd4, 0x0b, 0x14, - 0xec, 0x7e, 0x70, 0xed, 0x49, 0x76, 0xed, 0xfa, 0xf2, 0x92, 0x6a, 0xc4, 0x7a, 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, 0x8f, 0x3c, 0x41, 0x53, 0x83, 0x67, 0x1f, 0xa5, 0xc6, 0x27, 0x5f, 0x94, - 0x1a, 0x9b, 0x0f, 0x09, 0x54, 0x06, 0x88, 0x8c, 0x87, 0xae, 0x2c, 0x7d, 0x76, 0xea, 0xe5, 0x25, - 0x3e, 0xe5, 0x7b, 0x44, 0x8d, 0x45, 0x7b, 0xcc, 0x59, 0x20, 0xda, 0x63, 0x46, 0x07, 0x3d, 0x51, - 0x2e, 0xfe, 0xfe, 0xa5, 0x09, 0x5f, 0x46, 0x9a, 0xf0, 0x6d, 0xa4, 0x09, 0x67, 0x23, 0x4d, 0xf8, - 0x39, 0xd2, 0x84, 0x0f, 0x63, 0x2d, 0x71, 0x36, 0xd6, 0x12, 0x3f, 0xc6, 0x5a, 0xa2, 0x21, 0xb3, - 0xbf, 0x08, 0x77, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0x12, 0xec, 0x17, 0x31, 0x66, 0x08, 0x00, - 0x00, + // 754 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0x4d, 0x6f, 0xd3, 0x4a, + 0x14, 0x8d, 0xed, 0xc4, 0x4d, 0x6f, 0xd2, 0x56, 0x19, 0x55, 0xef, 0xe5, 0x59, 0xaf, 0x4e, 0x9e, + 0xfb, 0x80, 0x0a, 0xb5, 0xa9, 0x54, 0x3e, 0x04, 0x4b, 0x42, 0x50, 0x89, 0x88, 0x50, 0x65, 0xf8, + 0x03, 0x49, 0x3d, 0x71, 0x22, 0x9c, 0x4c, 0xb0, 0x9d, 0x4a, 0xd9, 0x20, 0xc4, 0x86, 0x2d, 0x6b, + 0x24, 0x7e, 0x0b, 0xec, 0x60, 0x59, 0x89, 0x0d, 0xca, 0x22, 0x82, 0xf4, 0x4f, 0xb0, 0x44, 0x73, + 0xc7, 0xb1, 0xe3, 0x7c, 0x50, 0x45, 0x48, 0x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, 0x88, 0x06, 0xe9, + 0x06, 0xb3, 0x06, 0x88, 0x26, 0x11, 0x0d, 0xd7, 0xc6, 0x57, 0x09, 0x36, 0x8f, 0xa9, 0x5f, 0x63, + 0xb6, 0x67, 0xd2, 0x97, 0x7d, 0xea, 0xf9, 0xe4, 0x0e, 0xa8, 0x22, 0x19, 0x0b, 0xc9, 0x1c, 0xed, + 0x94, 0x84, 0xf4, 0xa5, 0x38, 0xaf, 0xf4, 0x18, 0x49, 0x66, 0x40, 0x26, 0x07, 0x90, 0xf6, 0x5b, + 0x2e, 0xad, 0x5b, 0xd5, 0x4a, 0x20, 0x61, 0x6e, 0x38, 0x2a, 0x6c, 0x60, 0xd7, 0xcf, 0x03, 0xc0, + 0x0c, 0x29, 0x64, 0x1f, 0xc0, 0xa3, 0xee, 0x59, 0xfb, 0x94, 0x72, 0xcd, 0xb1, 0xe8, 0x29, 0x99, + 0xb8, 0xe0, 0x53, 0xb8, 0x76, 0x00, 0xaa, 0x38, 0x8e, 0xec, 0x42, 0xb2, 0xe9, 0xb2, 0xce, 0xb2, + 0xab, 0x44, 0xd0, 0x38, 0x84, 0x6c, 0x58, 0x6c, 0xcf, 0x19, 0x90, 0x02, 0x24, 0x1d, 0x66, 0x7b, + 0x79, 0xa9, 0xa8, 0xec, 0x65, 0x8e, 0x32, 0x93, 0x86, 0x6a, 0xcc, 0x36, 0x11, 0x30, 0xde, 0xcb, + 0xb0, 0x79, 0xd2, 0xf7, 0x5a, 0x3c, 0x72, 0x99, 0x0c, 0x71, 0xde, 0x55, 0xca, 0x40, 0xae, 0xc3, + 0x1a, 0xcf, 0xe3, 0xd4, 0xe4, 0x02, 0xea, 0x04, 0x24, 0x3b, 0xa0, 0x38, 0xcc, 0xce, 0xa7, 0xb0, + 0xf0, 0x58, 0xbb, 0x3c, 0xbe, 0xaa, 0x9a, 0x9b, 0x90, 0x0d, 0x7b, 0xee, 0x39, 0x03, 0xe3, 0xb5, + 0x02, 0xb9, 0x63, 0xea, 0x0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4a, 0xcf, 0x19, 0x1c, 0xbd, + 0x95, 0x61, 0xed, 0x99, 0x78, 0x03, 0xe4, 0x3e, 0xac, 0x05, 0xb3, 0x90, 0xfc, 0xb5, 0x78, 0x92, + 0x6b, 0xdb, 0x73, 0x71, 0xfe, 0xcc, 0x13, 0x3c, 0x35, 0x78, 0xf8, 0x51, 0x6a, 0x7c, 0xfa, 0x45, + 0xa9, 0xb1, 0x09, 0x91, 0x20, 0x65, 0x80, 0xc8, 0x78, 0xe4, 0x9f, 0xa5, 0xcf, 0x4e, 0xfb, 0x7b, + 0x89, 0x4f, 0xc5, 0x1e, 0x51, 0x63, 0xd1, 0x1e, 0x73, 0x16, 0x88, 0xf6, 0x98, 0xd1, 0xc1, 0x48, + 0x94, 0x8b, 0x3f, 0x7f, 0xe8, 0xd2, 0xa7, 0xb1, 0x2e, 0x7d, 0x19, 0xeb, 0xd2, 0xf9, 0x58, 0x97, + 0xbe, 0x8f, 0x75, 0xe9, 0xdd, 0x85, 0x9e, 0x38, 0xbf, 0xd0, 0x13, 0xdf, 0x2e, 0xf4, 0x44, 0x43, + 0xc5, 0x3f, 0x0a, 0xb7, 0x7e, 0x05, 0x00, 0x00, 0xff, 0xff, 0x08, 0xee, 0x76, 0xf8, 0x6c, 0x08, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1199,11 +1199,11 @@ func (m *GetLogsRequest) MarshalTo(dAtA []byte) (int, error) { } i += n4 } - if m.FollowKey != nil { + if m.ServiceKey != nil { dAtA[i] = 0x1a i++ - i = encodeVarintNet(dAtA, i, uint64(m.FollowKey.Size())) - n5, err := m.FollowKey.MarshalTo(dAtA[i:]) + i = encodeVarintNet(dAtA, i, uint64(m.ServiceKey.Size())) + n5, err := m.ServiceKey.MarshalTo(dAtA[i:]) if err != nil { return 0, err } @@ -1305,11 +1305,11 @@ func (m *PushLogRequest) MarshalTo(dAtA []byte) (int, error) { } i += n8 } - if m.FollowKey != nil { + if m.ServiceKey != nil { dAtA[i] = 0x1a i++ - i = encodeVarintNet(dAtA, i, uint64(m.FollowKey.Size())) - n9, err := m.FollowKey.MarshalTo(dAtA[i:]) + i = encodeVarintNet(dAtA, i, uint64(m.ServiceKey.Size())) + n9, err := m.ServiceKey.MarshalTo(dAtA[i:]) if err != nil { return 0, err } @@ -1419,11 +1419,11 @@ func (m *GetRecordsRequest) MarshalTo(dAtA []byte) (int, error) { } i += n14 } - if m.FollowKey != nil { + if m.ServiceKey != nil { dAtA[i] = 0x1a i++ - i = encodeVarintNet(dAtA, i, uint64(m.FollowKey.Size())) - n15, err := m.FollowKey.MarshalTo(dAtA[i:]) + i = encodeVarintNet(dAtA, i, uint64(m.ServiceKey.Size())) + n15, err := m.ServiceKey.MarshalTo(dAtA[i:]) if err != nil { return 0, err } @@ -1778,7 +1778,7 @@ func NewPopulatedGetLogsRequest(r randyNet, easy bool) *GetLogsRequest { this.Header = NewPopulatedGetLogsRequest_Header(r, easy) } this.ThreadID = NewPopulatedProtoThreadID(r) - this.FollowKey = NewPopulatedProtoKey(r) + this.ServiceKey = NewPopulatedProtoKey(r) if !easy && r.Intn(10) != 0 { } return this @@ -1812,7 +1812,7 @@ func NewPopulatedPushLogRequest(r randyNet, easy bool) *PushLogRequest { this.Header = NewPopulatedPushLogRequest_Header(r, easy) } this.ThreadID = NewPopulatedProtoThreadID(r) - this.FollowKey = NewPopulatedProtoKey(r) + this.ServiceKey = NewPopulatedProtoKey(r) this.ReadKey = NewPopulatedProtoKey(r) if r.Intn(10) != 0 { this.Log = NewPopulatedLog(r, easy) @@ -1843,7 +1843,7 @@ func NewPopulatedGetRecordsRequest(r randyNet, easy bool) *GetRecordsRequest { this.Header = NewPopulatedGetRecordsRequest_Header(r, easy) } this.ThreadID = NewPopulatedProtoThreadID(r) - this.FollowKey = NewPopulatedProtoKey(r) + this.ServiceKey = NewPopulatedProtoKey(r) if r.Intn(10) != 0 { v10 := r.Intn(5) this.Logs = make([]*GetRecordsRequest_LogEntry, v10) @@ -2085,8 +2085,8 @@ func (m *GetLogsRequest) Size() (n int) { l = m.ThreadID.Size() n += 1 + l + sovNet(uint64(l)) } - if m.FollowKey != nil { - l = m.FollowKey.Size() + if m.ServiceKey != nil { + l = m.ServiceKey.Size() n += 1 + l + sovNet(uint64(l)) } return n @@ -2134,8 +2134,8 @@ func (m *PushLogRequest) Size() (n int) { l = m.ThreadID.Size() n += 1 + l + sovNet(uint64(l)) } - if m.FollowKey != nil { - l = m.FollowKey.Size() + if m.ServiceKey != nil { + l = m.ServiceKey.Size() n += 1 + l + sovNet(uint64(l)) } if m.ReadKey != nil { @@ -2185,8 +2185,8 @@ func (m *GetRecordsRequest) Size() (n int) { l = m.ThreadID.Size() n += 1 + l + sovNet(uint64(l)) } - if m.FollowKey != nil { - l = m.FollowKey.Size() + if m.ServiceKey != nil { + l = m.ServiceKey.Size() n += 1 + l + sovNet(uint64(l)) } if len(m.Logs) > 0 { @@ -2821,7 +2821,7 @@ func (m *GetLogsRequest) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FollowKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ServiceKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -2849,8 +2849,8 @@ func (m *GetLogsRequest) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } var v ProtoKey - m.FollowKey = &v - if err := m.FollowKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ServiceKey = &v + if err := m.ServiceKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -3155,7 +3155,7 @@ func (m *PushLogRequest) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FollowKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ServiceKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -3183,8 +3183,8 @@ func (m *PushLogRequest) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } var v ProtoKey - m.FollowKey = &v - if err := m.FollowKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ServiceKey = &v + if err := m.ServiceKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -3526,7 +3526,7 @@ func (m *GetRecordsRequest) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FollowKey", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ServiceKey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -3554,8 +3554,8 @@ func (m *GetRecordsRequest) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } var v ProtoKey - m.FollowKey = &v - if err := m.FollowKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ServiceKey = &v + if err := m.ServiceKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/net/pb/net.proto b/net/pb/net.proto index 878a41d4..1ff4e0f0 100644 --- a/net/pb/net.proto +++ b/net/pb/net.proto @@ -44,8 +44,8 @@ message GetLogsRequest { // threadID is the target thread's ID. bytes threadID = 2 [(gogoproto.customtype) = "ProtoThreadID"]; - // followKey for the thread. - bytes followKey = 3 [(gogoproto.customtype) = "ProtoKey"]; + // serviceKey for the thread. + bytes serviceKey = 3 [(gogoproto.customtype) = "ProtoKey"]; // Header holds sender information. message Header { @@ -67,8 +67,8 @@ message PushLogRequest { // threadID is the target thread's ID. bytes threadID = 2 [(gogoproto.customtype) = "ProtoThreadID"]; - // followKey for the thread. - bytes followKey = 3 [(gogoproto.customtype) = "ProtoKey"]; + // serviceKey for the thread. + bytes serviceKey = 3 [(gogoproto.customtype) = "ProtoKey"]; // readKey for the thread. bytes readKey = 4 [(gogoproto.customtype) = "ProtoKey"]; @@ -93,8 +93,8 @@ message GetRecordsRequest { // threadID is the target thread's ID. bytes threadID = 2 [(gogoproto.customtype) = "ProtoThreadID"]; - // followKey for the thread. - bytes followKey = 3 [(gogoproto.customtype) = "ProtoKey"]; + // serviceKey for the thread. + bytes serviceKey = 3 [(gogoproto.customtype) = "ProtoKey"]; // List of requested logs. repeated LogEntry logs = 4; diff --git a/net/server.go b/net/server.go index a958fe8f..92cfed5b 100644 --- a/net/server.go +++ b/net/server.go @@ -66,7 +66,7 @@ func (s *server) GetLogs(_ context.Context, req *pb.GetLogsRequest) (*pb.GetLogs pblgs := &pb.GetLogsReply{} - if err := s.checkFollowKey(req.ThreadID.ID, req.FollowKey); err != nil { + if err := s.checkServiceKey(req.ThreadID.ID, req.ServiceKey); err != nil { return pblgs, err } @@ -99,16 +99,15 @@ func (s *server) PushLog(_ context.Context, req *pb.PushLogRequest) (*pb.PushLog if err != nil && !errors.Is(err, lstore.ErrThreadNotFound) { return nil, status.Error(codes.Internal, err.Error()) } - if info.FollowKey == nil { - if req.FollowKey != nil && req.FollowKey.Key != nil { - if err = s.net.store.AddFollowKey(req.ThreadID.ID, req.FollowKey.Key); err != nil { + if !info.Key.Defined() { + if req.ServiceKey != nil && req.ServiceKey.Key != nil { + if err = s.net.store.AddServiceKey(req.ThreadID.ID, req.ServiceKey.Key); err != nil { return nil, status.Error(codes.Internal, err.Error()) } } else { return nil, status.Error(codes.NotFound, lstore.ErrThreadNotFound.Error()) } - } - if info.ReadKey == nil { + } else if !info.Key.CanRead() { if req.ReadKey != nil && req.ReadKey.Key != nil { if err = s.net.store.AddReadKey(req.ThreadID.ID, req.ReadKey.Key); err != nil { return nil, status.Error(codes.Internal, err.Error()) @@ -137,7 +136,7 @@ func (s *server) GetRecords(ctx context.Context, req *pb.GetRecordsRequest) (*pb pbrecs := &pb.GetRecordsReply{} - if err := s.checkFollowKey(req.ThreadID.ID, req.FollowKey); err != nil { + if err := s.checkServiceKey(req.ThreadID.ID, req.ServiceKey); err != nil { return pbrecs, err } @@ -218,7 +217,7 @@ func (s *server) PushRecord(ctx context.Context, req *pb.PushRecordRequest) (*pb return nil, status.Error(codes.NotFound, "log not found") } - key, err := s.net.store.FollowKey(req.ThreadID.ID) + key, err := s.net.store.ServiceKey(req.ThreadID.ID) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } @@ -286,20 +285,20 @@ func (s *server) subscribe(id thread.ID) { } } -// checkFollowKey compares a key with the one stored under thread. -func (s *server) checkFollowKey(id thread.ID, pfk *pb.ProtoKey) error { - if pfk == nil || pfk.Key == nil { - return status.Error(codes.Unauthenticated, "a follow-key is required to get logs") +// checkServiceKey compares a key with the one stored under thread. +func (s *server) checkServiceKey(id thread.ID, k *pb.ProtoKey) error { + if k == nil || k.Key == nil { + return status.Error(codes.Unauthenticated, "a service-key is required to get logs") } - fk, err := s.net.store.FollowKey(id) + sk, err := s.net.store.ServiceKey(id) if err != nil { return status.Error(codes.Internal, err.Error()) } - if fk == nil { + if sk == nil { return status.Error(codes.NotFound, lstore.ErrThreadNotFound.Error()) } - if !bytes.Equal(pfk.Key.Bytes(), fk.Bytes()) { - return status.Error(codes.PermissionDenied, "invalid follow-key") + if !bytes.Equal(k.Key.Bytes(), sk.Bytes()) { + return status.Error(codes.PermissionDenied, "invalid service-key") } return nil } diff --git a/test/keybook_suite.go b/test/keybook_suite.go index 4aa4ddbd..1d79cd17 100644 --- a/test/keybook_suite.go +++ b/test/keybook_suite.go @@ -153,12 +153,12 @@ func testKeyBookFollowKey(kb core.KeyBook) func(t *testing.T) { t.Error(err) } - err = kb.AddFollowKey(tid, key) + err = kb.AddServiceKey(tid, key) if err != nil { t.Error(err) } - if res, err := kb.FollowKey(tid); err != nil || !bytes.Equal(res.Bytes(), key.Bytes()) { + if res, err := kb.ServiceKey(tid); err != nil || !bytes.Equal(res.Bytes(), key.Bytes()) { t.Error("retrieved read key did not match stored read key without errors") } } diff --git a/test/logstore_suite.go b/test/logstore_suite.go index 456353b6..1e28da5d 100644 --- a/test/logstore_suite.go +++ b/test/logstore_suite.go @@ -236,7 +236,7 @@ func testBasicLogstore(ls core.Logstore) func(t *testing.T) { for _, a := range addrs { tid := thread.NewIDV1(thread.Raw, 24) tids = append(tids, tid) - err := ls.AddFollowKey(tid, sym.New()) + err := ls.AddServiceKey(tid, sym.New()) check(t, err) err = ls.AddReadKey(tid, sym.New()) check(t, err) diff --git a/util/util.go b/util/util.go index 22354939..c3369276 100644 --- a/util/util.go +++ b/util/util.go @@ -11,9 +11,7 @@ import ( "github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/peer" swarm "github.com/libp2p/go-libp2p-swarm" - "github.com/mr-tron/base58" ma "github.com/multiformats/go-multiaddr" - sym "github.com/textileio/go-threads/crypto/symmetric" "go.uber.org/zap/zapcore" ) @@ -33,15 +31,6 @@ func CanDial(addr ma.Multiaddr, s *swarm.Swarm) bool { return tr != nil && tr.CanDial(addr) } -// DecodeKey from a string into a symmetric key. -func DecodeKey(k string) (*sym.Key, error) { - b, err := base58.Decode(k) - if err != nil { - return nil, err - } - return sym.FromBytes(b) -} - // SetupDefaultLoggingConfig sets up a standard logging configuration. func SetupDefaultLoggingConfig(repoPath string) { _ = os.Setenv("GOLOG_LOG_FMT", "color")