diff --git a/interfaces/contact/factList.go b/interfaces/contact/factList.go index f875af67216028f656f68c02e6b1a5892e812dd6..ad2b7c09627d530a9de0cb29f9b217bdf319d062 100644 --- a/interfaces/contact/factList.go +++ b/interfaces/contact/factList.go @@ -21,7 +21,9 @@ func (fl FactList) Stringify() string { // atttached at the end func UnstringifyFactList(s string) ([]Fact, string, error) { parts := strings.SplitN(s, factBreak, 1) - if len(parts) != 2 { + if len(parts) == 1{ + return nil, parts[0], nil + }else if len(parts) != 2 { return nil, "", errors.New("Invalid fact string passed") } factStrings := strings.Split(parts[0], factDelimiter) diff --git a/ud/lookup.go b/ud/lookup.go new file mode 100644 index 0000000000000000000000000000000000000000..a2df280190e3ca48c4a03af31d1731113d15e368 --- /dev/null +++ b/ud/lookup.go @@ -0,0 +1,59 @@ +package ud + +import ( + "github.com/golang/protobuf/proto" + "github.com/pkg/errors" + "gitlab.com/elixxir/client/interfaces/contact" + "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/interfaces/params" + "gitlab.com/elixxir/client/interfaces/utility" + "gitlab.com/xx_network/primitives/id" + "google.golang.org/protobuf/runtime/protoimpl" + "time" +) + +type lookupCallback func([]contact.Contact, error) + +// returns the public key of the passed id as known by the user discovery system +// or returns by the timeout +func (m *Manager)Lookup(id *id.ID, callback lookupCallback, timeout time.Duration)error{ + + commID, err := m.getCommID() + if err!=nil{ + return errors.WithMessage(err, "Random generation failed") + } + + + request := &LookupSend{ + UserID: id.Marshal(), + CommID: commID, + } + + requestMarshaled, err := proto.Marshal(request) + if err!=nil{ + return errors.WithMessage(err, "Failed to form outgoing request") + } + + msg := message.Send{ + Recipient: m.udID, + Payload: requestMarshaled, + MessageType: message.UdLookup, + } + + rounds, mid, err := m.net.SendE2E(msg, params.GetDefaultE2E()) + + if err!=nil{ + return errors.WithMessage(err, "Failed to send the lookup " + + "request") + } + + + + go func(){ + results := + utility.TrackResults() + } + + + +} \ No newline at end of file diff --git a/ud/manager.go b/ud/manager.go index 697d229dd965aa9662afbc70ee7ac9747852f8d3..f2f4f3cfb4009e505806b8cb5ec3a0afd8faeb53 100644 --- a/ud/manager.go +++ b/ud/manager.go @@ -1,14 +1,38 @@ package ud import ( + "encoding/binary" + "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/comms/client" + "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/crypto/signature/rsa" + "gitlab.com/xx_network/primitives/id" + "sync" ) type Manager struct { comms *client.Comms host *connect.Host privKey *rsa.PrivateKey + rng *fastRNG.StreamGenerator + + udID *id.ID + + + inProgressLookup map[int64]chan *LookupResponse + inProgressMux sync.RWMutex + + net interfaces.NetworkManager } +func (m *Manager)getCommID()(uint64, error){ + stream := m.rng.GetStream() + + idBytes := make([]byte, 8) + if _, err := stream.Read(idBytes); err!=nil{ + return 0, err + } + + return binary.BigEndian.Uint64(idBytes), nil +} \ No newline at end of file diff --git a/ud/udMessages.pb.go b/ud/udMessages.pb.go index 3f1dcba8f10f6edcbfa00a635428975fe42b3a1c..c556a703c57632b1690198e8597da8b8df0b13d0 100644 --- a/ud/udMessages.pb.go +++ b/ud/udMessages.pb.go @@ -163,7 +163,7 @@ type SearchSend struct { // PublicKey used in the registration Fact []*HashFact `protobuf:"bytes,1,rep,name=fact,proto3" json:"fact,omitempty"` // ID of the session used to create this session - CommID int64 `protobuf:"varint,2,opt,name=commID,proto3" json:"commID,omitempty"` + CommID uint64 `protobuf:"varint,2,opt,name=commID,proto3" json:"commID,omitempty"` } func (x *SearchSend) Reset() { @@ -205,7 +205,7 @@ func (x *SearchSend) GetFact() []*HashFact { return nil } -func (x *SearchSend) GetCommID() int64 { +func (x *SearchSend) GetCommID() uint64 { if x != nil { return x.CommID } @@ -220,7 +220,7 @@ type SearchResponse struct { // ID of the session created Contacts []*Contact `protobuf:"bytes,1,rep,name=contacts,proto3" json:"contacts,omitempty"` - CommID int64 `protobuf:"varint,2,opt,name=commID,proto3" json:"commID,omitempty"` + CommID uint64 `protobuf:"varint,2,opt,name=commID,proto3" json:"commID,omitempty"` Error string `protobuf:"bytes,3,opt,name=error,proto3" json:"error,omitempty"` } @@ -263,7 +263,7 @@ func (x *SearchResponse) GetContacts() []*Contact { return nil } -func (x *SearchResponse) GetCommID() int64 { +func (x *SearchResponse) GetCommID() uint64 { if x != nil { return x.CommID } @@ -284,7 +284,7 @@ type LookupSend struct { unknownFields protoimpl.UnknownFields UserID []byte `protobuf:"bytes,1,opt,name=userID,proto3" json:"userID,omitempty"` - CommID int64 `protobuf:"varint,2,opt,name=commID,proto3" json:"commID,omitempty"` + CommID uint64 `protobuf:"varint,2,opt,name=commID,proto3" json:"commID,omitempty"` } func (x *LookupSend) Reset() { @@ -326,7 +326,7 @@ func (x *LookupSend) GetUserID() []byte { return nil } -func (x *LookupSend) GetCommID() int64 { +func (x *LookupSend) GetCommID() uint64 { if x != nil { return x.CommID } @@ -340,7 +340,7 @@ type LookupResponse struct { unknownFields protoimpl.UnknownFields PubKey []byte `protobuf:"bytes,1,opt,name=pubKey,proto3" json:"pubKey,omitempty"` - CommID int64 `protobuf:"varint,2,opt,name=commID,proto3" json:"commID,omitempty"` + CommID uint64 `protobuf:"varint,2,opt,name=commID,proto3" json:"commID,omitempty"` Error string `protobuf:"bytes,3,opt,name=error,proto3" json:"error,omitempty"` } @@ -383,7 +383,7 @@ func (x *LookupResponse) GetPubKey() []byte { return nil } -func (x *LookupResponse) GetCommID() int64 { +func (x *LookupResponse) GetCommID() uint64 { if x != nil { return x.CommID } @@ -415,22 +415,22 @@ var file_udMessages_proto_rawDesc = []byte{ 0x68, 0x53, 0x65, 0x6e, 0x64, 0x12, 0x23, 0x0a, 0x04, 0x66, 0x61, 0x63, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x70, 0x61, 0x72, 0x73, 0x65, 0x2e, 0x48, 0x61, 0x73, 0x68, 0x46, 0x61, 0x63, 0x74, 0x52, 0x04, 0x66, 0x61, 0x63, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6f, - 0x6d, 0x6d, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x63, 0x6f, 0x6d, 0x6d, + 0x6d, 0x6d, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x49, 0x44, 0x22, 0x6a, 0x0a, 0x0e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2a, 0x0a, 0x08, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x63, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x70, 0x61, 0x72, 0x73, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x63, 0x74, 0x52, 0x08, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x63, 0x74, 0x73, - 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, + 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x49, 0x44, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x3c, 0x0a, 0x0a, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x65, 0x6e, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x49, 0x44, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x49, 0x44, 0x22, 0x56, 0x0a, 0x0e, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x49, 0x44, 0x22, 0x56, 0x0a, 0x0e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x75, 0x62, 0x4b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x70, 0x75, 0x62, 0x4b, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x49, 0x44, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x49, 0x44, 0x12, 0x14, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x49, 0x44, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x42, 0x04, 0x5a, 0x02, 0x75, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, diff --git a/ud/udMessages.proto b/ud/udMessages.proto index 36fb59a02860a17a7e3d6fc71b19be2e4a045fab..2e3d47c904535deed50a82b2bcd7d3cca0660e49 100644 --- a/ud/udMessages.proto +++ b/ud/udMessages.proto @@ -30,26 +30,26 @@ message SearchSend { // PublicKey used in the registration repeated HashFact fact = 1; // ID of the session used to create this session - int64 commID = 2; + uint64 commID = 2; } // Message sent from UDB to client in response to a search message SearchResponse { // ID of the session created repeated Contact contacts = 1; - int64 commID = 2; + uint64 commID = 2; string error = 3; } // Message sent to UDB for looking up a user message LookupSend { bytes userID = 1; - int64 commID = 2; + uint64 commID = 2; } // Message sent from UDB for looking up a user message LookupResponse { bytes pubKey = 1; - int64 commID = 2; + uint64 commID = 2; string error = 3; } \ No newline at end of file