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

Merge branch 'XX-2791/FactAdd' into 'Ursula/UD'

Add the Add Fact comms handler

See merge request !465
parents ad7bb9a0 9c8bc61c
No related branches found
No related tags found
No related merge requests found
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at // This file was generated by robots at
// 2020-11-19 13:39:33.271593 -0800 PST m=+0.018178459 // 2020-11-20 09:50:07.543626 -0800 PST m=+0.016833164
package globals package globals
const GITVERSION = `df5c21e Fix tests for removeFact` const GITVERSION = `788439a Do the hashing of adding a fact properly`
const SEMVER = "1.4.0" const SEMVER = "1.4.0"
const DEPENDENCIES = `module gitlab.com/elixxir/client const DEPENDENCIES = `module gitlab.com/elixxir/client
...@@ -25,11 +25,11 @@ require ( ...@@ -25,11 +25,11 @@ require (
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/bloomfilter v0.0.0-20200930191214-10e9ac31b228 gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228
gitlab.com/elixxir/comms v0.0.4-0.20201116233755-b476dea10095 gitlab.com/elixxir/comms v0.0.4-0.20201120005227-ec9177071abb
gitlab.com/elixxir/crypto v0.0.5-0.20201118204646-9b23991834c6 gitlab.com/elixxir/crypto v0.0.5-0.20201118204646-9b23991834c6
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
gitlab.com/xx_network/comms v0.0.4-0.20201118225304-345dad24bb1e gitlab.com/xx_network/comms v0.0.4-0.20201119231004-a67d08045535
gitlab.com/xx_network/crypto v0.0.4 gitlab.com/xx_network/crypto v0.0.4
gitlab.com/xx_network/primitives v0.0.3-0.20201116234927-44e42fc91e7c gitlab.com/xx_network/primitives v0.0.3-0.20201116234927-44e42fc91e7c
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
......
...@@ -18,11 +18,11 @@ require ( ...@@ -18,11 +18,11 @@ require (
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/bloomfilter v0.0.0-20200930191214-10e9ac31b228 gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228
gitlab.com/elixxir/comms v0.0.4-0.20201116233755-b476dea10095 gitlab.com/elixxir/comms v0.0.4-0.20201120005227-ec9177071abb
gitlab.com/elixxir/crypto v0.0.5-0.20201118204646-9b23991834c6 gitlab.com/elixxir/crypto v0.0.5-0.20201118204646-9b23991834c6
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
gitlab.com/xx_network/comms v0.0.4-0.20201118225304-345dad24bb1e gitlab.com/xx_network/comms v0.0.4-0.20201119231004-a67d08045535
gitlab.com/xx_network/crypto v0.0.4 gitlab.com/xx_network/crypto v0.0.4
gitlab.com/xx_network/primitives v0.0.3-0.20201116234927-44e42fc91e7c gitlab.com/xx_network/primitives v0.0.3-0.20201116234927-44e42fc91e7c
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
......
...@@ -252,12 +252,13 @@ github.com/zeebo/pcg v1.0.0 h1:dt+dx+HvX8g7Un32rY9XWoYnd0NmKmrIzpHF7qiTDj0= ...@@ -252,12 +252,13 @@ github.com/zeebo/pcg v1.0.0 h1:dt+dx+HvX8g7Un32rY9XWoYnd0NmKmrIzpHF7qiTDj0=
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/bloomfilter v0.0.0-20200930191214-10e9ac31b228 h1:Gi6rj4mAlK0BJIk1HIzBVMjWNjIUfstrsXC2VqLYPcA= gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 h1:Gi6rj4mAlK0BJIk1HIzBVMjWNjIUfstrsXC2VqLYPcA=
gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k= gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k=
gitlab.com/elixxir/comms v0.0.4-0.20201116233755-b476dea10095 h1:YptJAYLxqy5CAJIcM9kOwfxmJ2D2A8uXWTT8rgXYG+E= gitlab.com/elixxir/comms v0.0.4-0.20201120005227-ec9177071abb h1:nqceIUadPdJGLQZHGHOEA4lbb4qADYLm/f0nfeQPZ/o=
gitlab.com/elixxir/comms v0.0.4-0.20201116233755-b476dea10095/go.mod h1:spFKl7jsMy8M6NDvhJ27IJ+CnZ/07JHJCYpYsG8JQ4o= gitlab.com/elixxir/comms v0.0.4-0.20201120005227-ec9177071abb/go.mod h1:Xdo7hhfg+wGShftpN4S/2tgO+6A8K+5OijlVO+wrl7s=
gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4 h1:28ftZDeYEko7xptCZzeFWS1Iam95dj46TWFVVlKmw6A= 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 h1:znCt/x2bL4y8czTPaaFkwzdgSgW3BJc/1+dxyf1jqVw= gitlab.com/elixxir/crypto v0.0.3 h1:znCt/x2bL4y8czTPaaFkwzdgSgW3BJc/1+dxyf1jqVw=
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.5-0.20201110193609-6b5e881867b4 h1:1a1zZDuqZ56qU1EPgpc+Sqny1YFl0kAKJgQbsVc0WJQ=
gitlab.com/elixxir/crypto v0.0.5-0.20201110193609-6b5e881867b4/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= gitlab.com/elixxir/crypto v0.0.5-0.20201110193609-6b5e881867b4/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA=
gitlab.com/elixxir/crypto v0.0.5-0.20201118204646-9b23991834c6 h1:HEJHC6gyVMdCZ1PSJkFDScHnsrWAMF+PFxyL2zpNrgU= gitlab.com/elixxir/crypto v0.0.5-0.20201118204646-9b23991834c6 h1:HEJHC6gyVMdCZ1PSJkFDScHnsrWAMF+PFxyL2zpNrgU=
gitlab.com/elixxir/crypto v0.0.5-0.20201118204646-9b23991834c6/go.mod h1:BqvmtLM4eW+3NNOVK7U3COnnxqhJZxdCv4yziCuYhlA= gitlab.com/elixxir/crypto v0.0.5-0.20201118204646-9b23991834c6/go.mod h1:BqvmtLM4eW+3NNOVK7U3COnnxqhJZxdCv4yziCuYhlA=
...@@ -272,8 +273,8 @@ gitlab.com/elixxir/primitives v0.0.3-0.20201116174806-97f190989704 h1:JkFREumz8s ...@@ -272,8 +273,8 @@ gitlab.com/elixxir/primitives v0.0.3-0.20201116174806-97f190989704 h1:JkFREumz8s
gitlab.com/elixxir/primitives v0.0.3-0.20201116174806-97f190989704/go.mod h1:3fxFHSlQhkV4vs+S0dZEz3Om3m+40WX8L806yvSnNFc= gitlab.com/elixxir/primitives v0.0.3-0.20201116174806-97f190989704/go.mod h1:3fxFHSlQhkV4vs+S0dZEz3Om3m+40WX8L806yvSnNFc=
gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw= gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw=
gitlab.com/xx_network/comms v0.0.4-0.20201110022115-4a6171cad07d/go.mod h1:YViGbRj7FjJYoaO4NpALGEd9dK/l8uUT000FEBbUTL8= gitlab.com/xx_network/comms v0.0.4-0.20201110022115-4a6171cad07d/go.mod h1:YViGbRj7FjJYoaO4NpALGEd9dK/l8uUT000FEBbUTL8=
gitlab.com/xx_network/comms v0.0.4-0.20201118225304-345dad24bb1e h1:sJjDnRQmAmojq64OS3ZIvhDgaY1nTRYAo/3GeR+yyCI= gitlab.com/xx_network/comms v0.0.4-0.20201119231004-a67d08045535 h1:3KoNUndePTAUMlX1xc+zk0wuOZMb/xJMUVuhS+HisdA=
gitlab.com/xx_network/comms v0.0.4-0.20201118225304-345dad24bb1e/go.mod h1:YViGbRj7FjJYoaO4NpALGEd9dK/l8uUT000FEBbUTL8= gitlab.com/xx_network/comms v0.0.4-0.20201119231004-a67d08045535/go.mod h1:YViGbRj7FjJYoaO4NpALGEd9dK/l8uUT000FEBbUTL8=
gitlab.com/xx_network/crypto v0.0.3/go.mod h1:DF2HYvvCw9wkBybXcXAgQMzX+MiGbFPjwt3t17VRqRE= gitlab.com/xx_network/crypto v0.0.3/go.mod h1:DF2HYvvCw9wkBybXcXAgQMzX+MiGbFPjwt3t17VRqRE=
gitlab.com/xx_network/crypto v0.0.4 h1:lpKOL5mTJ2awWMfgBy30oD/UvJVrWZzUimSHlOdZZxo= gitlab.com/xx_network/crypto v0.0.4 h1:lpKOL5mTJ2awWMfgBy30oD/UvJVrWZzUimSHlOdZZxo=
gitlab.com/xx_network/crypto v0.0.4/go.mod h1:+lcQEy+Th4eswFgQDwT0EXKp4AXrlubxalwQFH5O0Mk= gitlab.com/xx_network/crypto v0.0.4/go.mod h1:+lcQEy+Th4eswFgQDwT0EXKp4AXrlubxalwQFH5O0Mk=
...@@ -284,8 +285,8 @@ gitlab.com/xx_network/primitives v0.0.2 h1:r45yKenJ9e7PylI1ZXJ1Es09oYNaYXjxVy9+u ...@@ -284,8 +285,8 @@ gitlab.com/xx_network/primitives v0.0.2 h1:r45yKenJ9e7PylI1ZXJ1Es09oYNaYXjxVy9+u
gitlab.com/xx_network/primitives v0.0.2/go.mod h1:cs0QlFpdMDI6lAo61lDRH2JZz+3aVkHy+QogOB6F/qc= gitlab.com/xx_network/primitives v0.0.2/go.mod h1:cs0QlFpdMDI6lAo61lDRH2JZz+3aVkHy+QogOB6F/qc=
gitlab.com/xx_network/primitives v0.0.3-0.20201116234927-44e42fc91e7c h1:mYId667WIN97E6KhPw4HDYyCjWzsG7gCM/HLTNTCXZQ= gitlab.com/xx_network/primitives v0.0.3-0.20201116234927-44e42fc91e7c h1:mYId667WIN97E6KhPw4HDYyCjWzsG7gCM/HLTNTCXZQ=
gitlab.com/xx_network/primitives v0.0.3-0.20201116234927-44e42fc91e7c/go.mod h1:cs0QlFpdMDI6lAo61lDRH2JZz+3aVkHy+QogOB6F/qc= gitlab.com/xx_network/primitives v0.0.3-0.20201116234927-44e42fc91e7c/go.mod h1:cs0QlFpdMDI6lAo61lDRH2JZz+3aVkHy+QogOB6F/qc=
gitlab.com/xx_network/ring v0.0.2 h1:TlPjlbFdhtJrwvRgIg4ScdngMTaynx/ByHBRZiXCoL0= gitlab.com/xx_network/ring v0.0.3-0.20201120004140-b0e268db06d1 h1:yqXC/naXN6Hw1fmfI6qOOMmBbmZGsYXsESVSwf6IEdM=
gitlab.com/xx_network/ring v0.0.2/go.mod h1:aLzpP2TiZTQut/PVHR40EJAomzugDdHXetbieRClXIM= gitlab.com/xx_network/ring v0.0.3-0.20201120004140-b0e268db06d1/go.mod h1:aLzpP2TiZTQut/PVHR40EJAomzugDdHXetbieRClXIM=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
......
package ud
import (
"crypto/rand"
pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/crypto/factID"
"gitlab.com/elixxir/crypto/hash"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/crypto/signature/rsa"
)
type addFactComms interface {
SendRegisterFact(host *connect.Host, message *pb.FactRegisterRequest) (*pb.FactRegisterResponse, error)
}
func (m *Manager) SendRegisterFact(fact fact.Fact) (*pb.FactRegisterResponse, error) {
return m.addFact(fact, m.comms)
}
func (m *Manager) addFact(inFact fact.Fact, aFC addFactComms) (*pb.FactRegisterResponse, error) {
// Create a primitives Fact so we can hash it
f, err := fact.NewFact(inFact.T, inFact.Fact)
if err != nil {
return &pb.FactRegisterResponse{}, err
}
// Create a hash of our fact
fhash := factID.Fingerprint(f)
// Sign our inFact for putting into the request
fsig, err := rsa.Sign(rand.Reader, m.privKey, hash.CMixHash, fhash, nil)
if err != nil {
return &pb.FactRegisterResponse{}, err
}
// Create our Fact Removal Request message data
remFactMsg := pb.FactRegisterRequest{
UID: m.host.GetId().Marshal(),
Fact: &pb.Fact{
Fact: inFact.Fact,
FactType: uint32(inFact.T),
},
FactSig: fsig,
}
// Send the message
response, err := aFC.SendRegisterFact(m.host, &remFactMsg)
// Return the error
return response, err
}
package ud
import (
pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
"testing"
)
type testAFC struct{}
// Dummy implementation of SendRegisterFact so we don't need
// to run our own UDB server
func (rFC *testAFC) SendRegisterFact(host *connect.Host, message *pb.FactRegisterRequest) (*pb.FactRegisterResponse, error) {
return &pb.FactRegisterResponse{}, nil
}
// Test that the addFact function completes successfully
func TestAddFact(t *testing.T) {
// Add our host, addFact uses it to get the ID of the user
h, err := connect.NewHost(&id.DummyUser, "address", nil, connect.GetDefaultHostParams())
if err != nil {
t.Fatal(err)
}
// Create a new Private Key to use for signing the Fact
rng := csprng.NewSystemRNG()
cpk, err := rsa.GenerateKey(rng, 2048)
if err != nil {
t.Fatal(err)
}
// Create our Manager object
m := Manager{
comms: nil,
host: h,
privKey: cpk,
}
// Create our test fact
f := fact.Fact{
Fact: "testing",
T: 2,
}
// Setup a dummy comms that implements SendRegisterFact
// This way we don't need to run UDB just to check that this
// function works.
tafc := testAFC{}
// Run addFact and see if it returns without an error!
_, err = m.addFact(f, &tafc)
if err != nil {
t.Fatal(err)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment