Skip to content
Snippets Groups Projects
Commit 47ac0b35 authored by Sydney Anne Erickson's avatar Sydney Anne Erickson :chipmunk:
Browse files

Merge branch 'Ursula/UD' into 'Anne/FactCommsHotfix'

# Conflicts:
#   Makefile
#   go.mod
#   go.sum
parents 2eca2ee4 6039dc23
No related branches found
No related tags found
No related merge requests found
...@@ -20,20 +20,20 @@ build: ...@@ -20,20 +20,20 @@ build:
go mod tidy go mod tidy
update_release: update_release:
GOFLAGS="" go get -u gitlab.com/elixxir/primitives@release GOFLAGS="" go get gitlab.com/elixxir/primitives@release
GOFLAGS="" go get -u gitlab.com/elixxir/crypto@release GOFLAGS="" go get gitlab.com/elixxir/crypto@release
GOFLAGS="" go get -u gitlab.com/xx_network/crypto@release GOFLAGS="" go get gitlab.com/xx_network/crypto@release
GOFLAGS="" go get -u gitlab.com/elixxir/comms@"Anne/FactCommsHotfix" GOFLAGS="" go get gitlab.com/elixxir/comms@release
GOFLAGS="" go get -u gitlab.com/xx_network/comms@release GOFLAGS="" go get gitlab.com/xx_network/comms@release
GOFLAGS="" go get -u gitlab.com/xx_network/primitives@release GOFLAGS="" go get gitlab.com/xx_network/primitives@release
update_master: update_master:
GOFLAGS="" go get -u gitlab.com/elixxir/primitives@master GOFLAGS="" go get gitlab.com/elixxir/primitives@master
GOFLAGS="" go get -u gitlab.com/elixxir/crypto@master GOFLAGS="" go get gitlab.com/elixxir/crypto@master
GOFLAGS="" go get -u gitlab.com/xx_network/crypto@master GOFLAGS="" go get gitlab.com/xx_network/crypto@master
GOFLAGS="" go get -u gitlab.com/elixxir/comms@master GOFLAGS="" go get gitlab.com/elixxir/comms@master
GOFLAGS="" go get -u gitlab.com/xx_network/comms@master GOFLAGS="" go get gitlab.com/xx_network/comms@master
GOFLAGS="" go get -u gitlab.com/xx_network/primitives@master GOFLAGS="" go get gitlab.com/xx_network/primitives@master
master: clean update_master build version master: clean update_master build version
......
...@@ -17,7 +17,7 @@ require ( ...@@ -17,7 +17,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.1 github.com/spf13/viper v1.7.1
gitlab.com/elixxir/comms v0.0.4-0.20201116215317-0febe6765554 gitlab.com/elixxir/comms v0.0.4-0.20201111205457-b073b28c367a
gitlab.com/elixxir/crypto v0.0.5-0.20201110193609-6b5e881867b4 gitlab.com/elixxir/crypto v0.0.5-0.20201110193609-6b5e881867b4
gitlab.com/elixxir/ekv v0.1.3 gitlab.com/elixxir/ekv v0.1.3
gitlab.com/elixxir/primitives v0.0.3-0.20201116174806-97f190989704 gitlab.com/elixxir/primitives v0.0.3-0.20201116174806-97f190989704
......
...@@ -226,10 +226,11 @@ github.com/zeebo/pcg v0.0.0-20181207190024-3cdc6b625a05/go.mod h1:Gr+78ptB0MwXxm ...@@ -226,10 +226,11 @@ github.com/zeebo/pcg v0.0.0-20181207190024-3cdc6b625a05/go.mod h1:Gr+78ptB0MwXxm
github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
gitlab.com/elixxir/comms v0.0.4-0.20201103220934-c476c9282f30 h1:9q+xVbu5m7XDvT1CVz8s1S/SOVpasWJOx7V/3rAY/pE= gitlab.com/elixxir/comms v0.0.4-0.20201103220934-c476c9282f30 h1:9q+xVbu5m7XDvT1CVz8s1S/SOVpasWJOx7V/3rAY/pE=
gitlab.com/elixxir/comms v0.0.4-0.20201103220934-c476c9282f30/go.mod h1:5p7oz4yFrK037rPap6ooaWrloJrzuVZ4jnzOdvgyqnU= gitlab.com/elixxir/comms v0.0.4-0.20201103220934-c476c9282f30/go.mod h1:5p7oz4yFrK037rPap6ooaWrloJrzuVZ4jnzOdvgyqnU=
gitlab.com/elixxir/comms v0.0.4-0.20201116214359-6714b02d2fad h1:jr/vHpuK9dbSMCydxWJ5fH6KshUTpH8L7LqotxPvQrs= gitlab.com/elixxir/comms v0.0.4-0.20201111205457-b073b28c367a h1:GnZLdgn5ZSDtPFsiCUPgqQk2D+e7LmzVOZ9Rq/B8hCY=
gitlab.com/elixxir/comms v0.0.4-0.20201116214359-6714b02d2fad/go.mod h1:spFKl7jsMy8M6NDvhJ27IJ+CnZ/07JHJCYpYsG8JQ4o= gitlab.com/elixxir/comms v0.0.4-0.20201111205457-b073b28c367a/go.mod h1:5p7oz4yFrK037rPap6ooaWrloJrzuVZ4jnzOdvgyqnU=
gitlab.com/elixxir/comms v0.0.4-0.20201116215317-0febe6765554 h1:PGFYXmpv8vT7vYBvcynN9uDqMQArzgo88rlZ51NyaV4= gitlab.com/elixxir/comms v0.0.4-0.20201112000135-4147e270e129 h1:d4s9JGimUVmqdKlK4NhICayzWBUSM2XmKta821ZJTF0=
gitlab.com/elixxir/comms v0.0.4-0.20201116215317-0febe6765554/go.mod h1:spFKl7jsMy8M6NDvhJ27IJ+CnZ/07JHJCYpYsG8JQ4o= gitlab.com/elixxir/comms v0.0.4-0.20201112000135-4147e270e129/go.mod h1:5p7oz4yFrK037rPap6ooaWrloJrzuVZ4jnzOdvgyqnU=
gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4 h1:28ftZDeYEko7xptCZzeFWS1Iam95dj46TWFVVlKmw6A=
gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c=
gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA=
gitlab.com/elixxir/crypto v0.0.4/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= gitlab.com/elixxir/crypto v0.0.4/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA=
......
...@@ -7,23 +7,71 @@ import ( ...@@ -7,23 +7,71 @@ import (
"gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/interfaces/params"
"gitlab.com/elixxir/client/interfaces/utility" "gitlab.com/elixxir/client/interfaces/utility"
"gitlab.com/elixxir/comms/network/dataStructures"
"gitlab.com/elixxir/primitives/states"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"google.golang.org/protobuf/runtime/protoimpl" "google.golang.org/protobuf/runtime/protoimpl"
"time" "time"
jww "github.com/spf13/jwalterweatherman"
) )
type lookupCallback func([]contact.Contact, error) type lookupCallback func(contact.Contact, error)
func (m *Manager)lookupProcess(c chan message.Receive, quitCh <-chan struct{}){
for true {
select {
case <-quitCh:
return
case response := <-c:
// edge check the encryption
if response.Encryption!=message.E2E{
jww.WARN.Printf("Dropped a lookup response from user " +
"discovery due to incorrect encryption")
}
// unmarshal the message
lookupResponse := &LookupResponse{}
if err :=proto.Unmarshal(response.Payload, lookupResponse); err!=nil{
jww.WARN.Printf("Dropped a lookup response from user " +
"discovery due to failed unmarshal: %s", err)
}
// get the appropriate channel from the lookup
m.inProgressMux.RLock()
ch, ok := m.inProgressLookup[lookupResponse.CommID]
m.inProgressMux.RUnlock()
if !ok{
jww.WARN.Printf("Dropped a lookup response from user " +
"discovery due to unknown comm ID: %d",
lookupResponse.CommID)
}
// send the response on the correct channel
// drop if the send cannot be completed
select{
case ch<-lookupResponse:
default:
jww.WARN.Printf("Dropped a lookup response from user " +
"discovery due failure to transmit to handling thread: " +
"commID: %d", lookupResponse.CommID)
}
}
}
}
// returns the public key of the passed id as known by the user discovery system // returns the public key of the passed id as known by the user discovery system
// or returns by the timeout // or returns by the timeout
func (m *Manager)Lookup(id *id.ID, callback lookupCallback, timeout time.Duration)error{ func (m *Manager)Lookup(id *id.ID, callback lookupCallback, timeout time.Duration)error{
//get the id of this comm so it can be connected to its responce
commID, err := m.getCommID() commID, err := m.getCommID()
if err!=nil{ if err!=nil{
return errors.WithMessage(err, "Random generation failed") return errors.WithMessage(err, "Random generation failed")
} }
//build the request
request := &LookupSend{ request := &LookupSend{
UserID: id.Marshal(), UserID: id.Marshal(),
CommID: commID, CommID: commID,
...@@ -40,20 +88,68 @@ func (m *Manager)Lookup(id *id.ID, callback lookupCallback, timeout time.Duratio ...@@ -40,20 +88,68 @@ func (m *Manager)Lookup(id *id.ID, callback lookupCallback, timeout time.Duratio
MessageType: message.UdLookup, MessageType: message.UdLookup,
} }
rounds, mid, err := m.net.SendE2E(msg, params.GetDefaultE2E()) //register the request in the responce map so it can be procesed on return
responseChan := make(chan *LookupResponse, 1)
m.inProgressMux.Lock()
m.inProgressLookup[commID] = responseChan
m.inProgressMux.Unlock()
//send the request
rounds, _, err := m.net.SendE2E(msg, params.GetDefaultE2E())
if err!=nil{ if err!=nil{
return errors.WithMessage(err, "Failed to send the lookup " + return errors.WithMessage(err, "Failed to send the lookup " +
"request") "request")
} }
//register the round event to capture if the round fails
roundFailChan := make(chan dataStructures.EventReturn, len(rounds))
for _, round := range rounds{
//subtract a millisecond to ensure this timeout will trigger before
// the one below
m.net.GetInstance().GetRoundEvents().AddRoundEventChan(round,
roundFailChan, timeout-1*time.Millisecond, states.FAILED)
}
//start the go routine which will trigger the callback
go func(){ go func(){
results := timer := time.NewTimer(timeout)
utility.TrackResults()
var err error
var c contact.Contact
select{
//return an error if the round fails
case <-roundFailChan:
err= errors.New("One or more rounds failed to " +
"resolve, lookup not delivered")
//return an error if the timeout is reached
case <-timer.C:
err= errors.New("Response from User Discovery" +
" did not come before timeout")
//return the contact if one is returned
case response := <-responseChan:
if response.Error!=""{
err = errors.Errorf("User Discovery returned an " +
"error on Lookup: %s", response.Error)
}else{
pubkey := m.grp.NewIntFromBytes(response.PubKey)
c = contact.Contact{
ID: id,
DhPubKey: pubkey,
OwnershipProof: nil,
Facts: nil,
} }
}
}
//delete the response channel from the map
m.inProgressMux.Lock()
delete(m.inProgressLookup, commID)
m.inProgressMux.Unlock()
//call the callback last in case it is blocking
callback(c, err)
}()
return nil
} }
\ No newline at end of file
...@@ -3,7 +3,10 @@ package ud ...@@ -3,7 +3,10 @@ package ud
import ( import (
"encoding/binary" "encoding/binary"
"gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/interfaces/message"
"gitlab.com/elixxir/client/stoppable"
"gitlab.com/elixxir/comms/client" "gitlab.com/elixxir/comms/client"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/crypto/fastRNG"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/crypto/signature/rsa"
...@@ -16,17 +19,20 @@ type Manager struct { ...@@ -16,17 +19,20 @@ type Manager struct {
host *connect.Host host *connect.Host
privKey *rsa.PrivateKey privKey *rsa.PrivateKey
rng *fastRNG.StreamGenerator rng *fastRNG.StreamGenerator
grp *cyclic.Group
sw interfaces.Switchboard
udID *id.ID udID *id.ID
inProgressLookup map[int64]chan *LookupResponse inProgressLookup map[uint64]chan *LookupResponse
inProgressMux sync.RWMutex inProgressMux sync.RWMutex
net interfaces.NetworkManager net interfaces.NetworkManager
} }
func (m *Manager)getCommID()(uint64, error){ func (m *Manager)getCommID()(uint64, error){
//fixme: this should use incremenetation
stream := m.rng.GetStream() stream := m.rng.GetStream()
idBytes := make([]byte, 8) idBytes := make([]byte, 8)
...@@ -36,3 +42,16 @@ func (m *Manager)getCommID()(uint64, error){ ...@@ -36,3 +42,16 @@ func (m *Manager)getCommID()(uint64, error){
return binary.BigEndian.Uint64(idBytes), nil return binary.BigEndian.Uint64(idBytes), nil
} }
func (m *Manager)StartProcessies()stoppable.Stoppable{
lookupStop := stoppable.NewSingle("UDLookup")
lookupChan := make(chan message.Receive, 100)
m.sw.RegisterChannel("UDLookupResponse", m.udID, message.UdLookupResponse, lookupChan)
go m.lookupProcess(lookupChan, lookupStop.Quit())
udMulti := stoppable.NewMulti("UD")
udMulti.Add(lookupStop)
return lookupStop
}
\ No newline at end of file
package ud
import (
"gitlab.com/xx_network/comms/messages"
"gitlab.com/xx_network/primitives/id"
)
func (m *Manager)Register(myID *id.ID, username string)error{
msg := &messages.AuthenticatedMessage{
ID: myID.Bytes(),
Signature: nil,
Token: nil,
Client: nil,
Message: nil,
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: nil,
XXX_sizecache: 0,
}
m.comms.SendRegisterUser(m.host)
}
\ 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