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

fixed the process for checking if messages are properly submitted to cmix

parent d1635b97
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ import (
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
)
type addFactComms interface {
......@@ -16,10 +17,11 @@ type addFactComms interface {
}
func (m *Manager) SendRegisterFact(fact fact.Fact) (*pb.FactRegisterResponse, error) {
return m.addFact(fact, m.comms)
uid := m.storage.User().GetCryptographicIdentity().GetUserID()
return m.addFact(fact, uid, m.comms)
}
func (m *Manager) addFact(inFact fact.Fact, aFC addFactComms) (*pb.FactRegisterResponse, error) {
func (m *Manager) addFact(inFact fact.Fact, uid *id.ID, aFC addFactComms) (*pb.FactRegisterResponse, error) {
if !m.IsRegistered() {
return nil, errors.New("Failed to add fact: " +
"client is not registered")
......@@ -40,8 +42,6 @@ func (m *Manager) addFact(inFact fact.Fact, aFC addFactComms) (*pb.FactRegisterR
return &pb.FactRegisterResponse{}, err
}
uid := m.storage.User().GetCryptographicIdentity().GetUserID()
// Create our Fact Removal Request message data
remFactMsg := pb.FactRegisterRequest{
UID: uid.Marshal(),
......
......@@ -53,9 +53,9 @@ func TestAddFact(t *testing.T) {
// This way we don't need to run UDB just to check that this
// function works.
tafc := testAFC{}
uid := &id.ID{}
// Run addFact and see if it returns without an error!
_, err = m.addFact(f, &tafc)
_, err = m.addFact(f, uid, &tafc)
if err != nil {
t.Fatal(err)
}
......
package ud
import (
"fmt"
"github.com/golang/protobuf/proto"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
......@@ -22,7 +23,6 @@ func (m *Manager) lookupProcess(c chan message.Receive, quitCh <-chan struct{})
return
case response := <-c:
// Unmarshal the message
lookupResponse := &LookupResponse{}
if err := proto.Unmarshal(response.Payload, lookupResponse); err != nil {
......@@ -101,7 +101,8 @@ func (m *Manager) Lookup(uid *id.ID, callback lookupCallback, timeout time.Durat
// 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)
roundFailChan, timeout-1*time.Millisecond, states.FAILED,
states.COMPLETED)
}
// Start the go routine which will trigger the callback
......@@ -111,30 +112,44 @@ func (m *Manager) Lookup(uid *id.ID, callback lookupCallback, timeout time.Durat
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: uid,
DhPubKey: pubkey,
OwnershipProof: nil,
Facts: nil,
done := false
for !done {
select {
// Return an error if the round fails
case fail := <-roundFailChan:
if states.Round(fail.RoundInfo.State)==states.FAILED{
fType := ""
if fail.TimedOut{
fType = "timeout"
}else{
fType = fmt.Sprintf("round failure: %v", fail.RoundInfo.ID)
}
err = errors.Errorf("One or more rounds (%v) failed to " +
"resolve due to: %s; search not delivered", rounds, fType)
done = true
}
// Return an error if the timeout is reached
case <-timer.C:
err = errors.New("Response from User Discovery did not come " +
"before timeout")
done = true
// 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: uid,
DhPubKey: pubkey,
OwnershipProof: nil,
Facts: nil,
}
}
done = true
}
}
......
......@@ -104,7 +104,8 @@ func (m *Manager) Search(list fact.FactList, callback searchCallback, timeout ti
// 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)
roundFailChan, timeout-1*time.Millisecond, states.FAILED,
states.COMPLETED)
}
// Start the go routine which will trigger the callback
......@@ -114,33 +115,42 @@ func (m *Manager) Search(list fact.FactList, callback searchCallback, timeout ti
var err error
var c []contact.Contact
select {
// Return an error if the round fails
case fail := <-roundFailChan:
fType := ""
if fail.TimedOut{
fType = "timeout"
}else{
fType = fmt.Sprintf("round failure: %v", fail.RoundInfo.ID)
}
err = errors.Errorf("One or more rounds (%v) failed to " +
"resolve due to: %s; search not delivered", rounds, fType)
// 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 contacts if one is returned
case response := <-responseChan:
if response.Error != "" {
err = errors.Errorf("User Discovery returned an error on "+
"search: %s", response.Error)
} else {
c, err = m.parseContacts(response.Contacts, factMap)
done := false
for !done{
select {
// Return an error if the round fails
case fail := <-roundFailChan:
if states.Round(fail.RoundInfo.State)==states.FAILED{
fType := ""
if fail.TimedOut{
fType = "timeout"
}else{
fType = fmt.Sprintf("round failure: %v", fail.RoundInfo.ID)
}
err = errors.Errorf("One or more rounds (%v) failed to " +
"resolve due to: %s; search not delivered", rounds, fType)
done = true
}
// Return an error if the timeout is reached
case <-timer.C:
err = errors.New("Response from User Discovery did not come " +
"before timeout")
done = true
// Return the contacts if one is returned
case response := <-responseChan:
if response.Error != "" {
err = errors.Errorf("User Discovery returned an error on "+
"search: %s", response.Error)
} else {
c, err = m.parseContacts(response.Contacts, factMap)
}
done = true
}
}
// Delete the response channel from the map
m.inProgressSearchMux.Lock()
delete(m.inProgressSearch, commID)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment