Skip to content
Snippets Groups Projects
Commit 93882e4d authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

more in progress work on UD

parent d424f24d
Branches
Tags
No related merge requests found
......@@ -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)
......
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
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
......@@ -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,
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment