Skip to content
Snippets Groups Projects
Commit b964e54b authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'release' into 'XX-2876/Re-reg'

# Conflicts:
#   globals/version_vars.go
#   go.mod
#   go.sum
parents c49e3c05 6e947df2
Branches
Tags
No related merge requests found
......@@ -206,7 +206,7 @@ var rootCmd = &cobra.Command{
}
}
fmt.Printf("Received %d\n", receiveCnt)
client.StopNetworkFollower(1 * time.Second)
// client.StopNetworkFollower(1 * time.Second)
/*if err!=nil{
fmt.Printf("Failed to cleanly close threads: %+v\n", err)
}*/
......
......
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2020-12-29 12:46:48.788148 -0600 CST m=+0.044052513
// 2020-12-30 13:10:27.265664 -0600 CST m=+0.032380471
package globals
const GITVERSION = `1e31ca2 run update`
const GITVERSION = `8185927 Merge branch 'XX-2971/contactCompression' into 'release'`
const SEMVER = "1.4.0"
const DEPENDENCIES = `module gitlab.com/elixxir/client
......@@ -25,13 +25,13 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.1
gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228
gitlab.com/elixxir/comms v0.0.4-0.20201229184530-2144db6af810
gitlab.com/elixxir/comms v0.0.4-0.20201229200853-c403d72e877c
gitlab.com/elixxir/crypto v0.0.7-0.20201222203132-9b4cc1ae3da6
gitlab.com/elixxir/ekv v0.1.4-0.20201217220111-9c7e8be21577
gitlab.com/elixxir/primitives v0.0.3-0.20201222171449-bdfe30389bb5
gitlab.com/elixxir/primitives v0.0.3-0.20201229212305-2ab1e938b1cb
gitlab.com/xx_network/comms v0.0.4-0.20201222193955-56206d700360
gitlab.com/xx_network/crypto v0.0.5-0.20201215233953-36cca1af8b2f
gitlab.com/xx_network/primitives v0.0.3
gitlab.com/xx_network/primitives v0.0.4-0.20201229212313-fe33d9809f27
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b // indirect
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e // indirect
......
......
......@@ -18,13 +18,13 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.1
gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228
gitlab.com/elixxir/comms v0.0.4-0.20201229184530-2144db6af810
gitlab.com/elixxir/comms v0.0.4-0.20201229200853-c403d72e877c
gitlab.com/elixxir/crypto v0.0.7-0.20201222203132-9b4cc1ae3da6
gitlab.com/elixxir/ekv v0.1.4-0.20201217220111-9c7e8be21577
gitlab.com/elixxir/primitives v0.0.3-0.20201222171449-bdfe30389bb5
gitlab.com/elixxir/primitives v0.0.3-0.20201229212305-2ab1e938b1cb
gitlab.com/xx_network/comms v0.0.4-0.20201222193955-56206d700360
gitlab.com/xx_network/crypto v0.0.5-0.20201215233953-36cca1af8b2f
gitlab.com/xx_network/primitives v0.0.3
gitlab.com/xx_network/primitives v0.0.4-0.20201229212313-fe33d9809f27
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b // indirect
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e // indirect
......
......
......@@ -258,8 +258,8 @@ github.com/zeebo/pcg v1.0.0 h1:dt+dx+HvX8g7Un32rY9XWoYnd0NmKmrIzpHF7qiTDj0=
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/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k=
gitlab.com/elixxir/comms v0.0.4-0.20201229184530-2144db6af810 h1:AFWRGkbgrH2dmni35QG1IN96728C45zR82G0ANbp8Ak=
gitlab.com/elixxir/comms v0.0.4-0.20201229184530-2144db6af810/go.mod h1:ezjHgNNuvDBeiFn+N2IcafKKV4ewhzzSpwSjxxaMCcA=
gitlab.com/elixxir/comms v0.0.4-0.20201229200853-c403d72e877c h1:YjTlUbZiNiJdL7Fy4TIUoWlHNK4dFOtuJ40YgsG7fac=
gitlab.com/elixxir/comms v0.0.4-0.20201229200853-c403d72e877c/go.mod h1:ezjHgNNuvDBeiFn+N2IcafKKV4ewhzzSpwSjxxaMCcA=
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.3 h1:znCt/x2bL4y8czTPaaFkwzdgSgW3BJc/1+dxyf1jqVw=
......@@ -275,6 +275,8 @@ gitlab.com/elixxir/primitives v0.0.1 h1:q61anawANlNAExfkeQEE1NCsNih6vNV1FFLoUQX6
gitlab.com/elixxir/primitives v0.0.1/go.mod h1:kNp47yPqja2lHSiS4DddTvFpB/4D9dB2YKnw5c+LJCE=
gitlab.com/elixxir/primitives v0.0.3-0.20201222171449-bdfe30389bb5 h1:BUV1ouY+9NA5+ZF+QfTpIBL1vO5zk31I68N7DX9bKj8=
gitlab.com/elixxir/primitives v0.0.3-0.20201222171449-bdfe30389bb5/go.mod h1:5Z8fce94mks0aFhMvzftx2jJpDx4/pzDU20G2oTiU9w=
gitlab.com/elixxir/primitives v0.0.3-0.20201229212305-2ab1e938b1cb h1:7LMaemxU2c3qlsK/4m4/sXVj5OWdn+9rhXC2u6b03aQ=
gitlab.com/elixxir/primitives v0.0.3-0.20201229212305-2ab1e938b1cb/go.mod h1:5Z8fce94mks0aFhMvzftx2jJpDx4/pzDU20G2oTiU9w=
gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw=
gitlab.com/xx_network/comms v0.0.4-0.20201130190834-365ddae56e7b/go.mod h1:YViGbRj7FjJYoaO4NpALGEd9dK/l8uUT000FEBbUTL8=
gitlab.com/xx_network/comms v0.0.4-0.20201222193955-56206d700360 h1:IlPemXfxV/yyUl5bAV5yATQKtmrsL7SMzho5FqAUv0s=
......@@ -292,6 +294,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.3 h1:RBJGPtphUyDvN8iG8+VTF8tr5iT9f5WHo0NCbenspYE=
gitlab.com/xx_network/primitives v0.0.3/go.mod h1:cs0QlFpdMDI6lAo61lDRH2JZz+3aVkHy+QogOB6F/qc=
gitlab.com/xx_network/primitives v0.0.4-0.20201229212313-fe33d9809f27 h1:JGpYRKkhPw58dlhii/wH8N9uWZ1AOTyVw3b6ZYdndA8=
gitlab.com/xx_network/primitives v0.0.4-0.20201229212313-fe33d9809f27/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.2/go.mod h1:aLzpP2TiZTQut/PVHR40EJAomzugDdHXetbieRClXIM=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
......
......
......@@ -8,15 +8,15 @@
package contact
import (
"encoding/json"
"bytes"
"encoding/binary"
"github.com/pkg/errors"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/primitives/id"
)
const factDelimiter = ","
const factBreak = ";"
const sizeByteLength = 2
// Contact implements the Contact interface defined in interface/contact.go,
// in go, the structure is meant to be edited directly, the functions are for
......@@ -28,21 +28,103 @@ type Contact struct {
Facts fact.FactList
}
// Marshal saves the Contact in a compact byte slice. The byte slice has
// the following structure (not to scale).
//
// +----------+----------------+---------+----------+----------+----------------+----------+
// | DhPubKey | OwnershipProof | Facts | ID | | | |
// | size | size | size | | DhPubKey | OwnershipProof | FactList |
// | 2 bytes | 2 bytes | 2 bytes | 33 bytes | | | |
// +----------+----------------+---------+----------+----------+----------------+----------+
func (c Contact) Marshal() ([]byte, error) {
return json.Marshal(&c)
var buff bytes.Buffer
b := make([]byte, sizeByteLength)
// Write size of DhPubKey
var dhPubKey []byte
var err error
if c.DhPubKey != nil {
dhPubKey, err = c.DhPubKey.GobEncode()
if err != nil {
return nil, errors.Errorf("Failed to gob encode DhPubKey: %+v", err)
}
}
binary.PutVarint(b, int64(len(dhPubKey)))
buff.Write(b)
// Write size of OwnershipProof
binary.PutVarint(b, int64(len(c.OwnershipProof)))
buff.Write(b)
// Write length of Facts
factList := c.Facts.Stringify()
binary.PutVarint(b, int64(len(factList)))
buff.Write(b)
// Write ID
if c.ID != nil {
buff.Write(c.ID.Marshal())
} else {
emptyID := make([]byte, id.ArrIDLen)
buff.Write(emptyID)
}
// Write DhPubKey
buff.Write(dhPubKey)
// Write OwnershipProof
buff.Write(c.OwnershipProof)
// Write fact list
buff.Write([]byte(factList))
return buff.Bytes(), nil
}
// Unmarshal decodes the byte slice produced by Contact.Marshal into a Contact.
func Unmarshal(b []byte) (Contact, error) {
c := Contact{}
err := json.Unmarshal(b, &c)
c := Contact{DhPubKey: &cyclic.Int{}}
var err error
buf := bytes.NewBuffer(b)
// Get size (in bytes) of each field
dhPubKeySize, _ := binary.Varint(buf.Next(sizeByteLength))
ownershipProofSize, _ := binary.Varint(buf.Next(sizeByteLength))
factsSize, _ := binary.Varint(buf.Next(sizeByteLength))
// Get and unmarshal ID
c.ID, err = id.Unmarshal(buf.Next(id.ArrIDLen))
if err != nil {
return c, errors.Errorf("Failed to unmarshal Contact ID: %+v", err)
}
// Handle nil ID
if bytes.Equal(c.ID.Marshal(), make([]byte, id.ArrIDLen)) {
c.ID = nil
}
// Get and decode DhPubKey
if dhPubKeySize == 0 {
// Handle nil key
c.DhPubKey = nil
} else {
err = c.DhPubKey.GobDecode(buf.Next(int(dhPubKeySize)))
if err != nil {
return c, err
return c, errors.Errorf("Failed to gob decode Contact DhPubKey: %+v", err)
}
}
for i, fact := range c.Facts {
if !fact.T.IsValid() {
return Contact{}, errors.Errorf("Fact %v/%v has invalid "+
"type: %s", i, len(c.Facts), fact.T)
// Get OwnershipProof
c.OwnershipProof = buf.Next(int(ownershipProofSize))
if len(c.OwnershipProof) == 0 {
c.OwnershipProof = nil
}
// Get and unstringify fact list
c.Facts, _, err = fact.UnstringifyFactList(string(buf.Next(int(factsSize))))
if err != nil {
return c, errors.Errorf("Failed to unstringify Fact List: %+v", err)
}
return c, nil
}
package contact
import (
"encoding/json"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/crypto/csprng"
"gitlab.com/xx_network/crypto/large"
"gitlab.com/xx_network/primitives/id"
"math"
"math/rand"
"reflect"
"testing"
)
// Tests marshaling and unmarshalling of a common contact.
func TestContact_Marshal_Unmarshal(t *testing.T) {
expectedContact := Contact{
ID: id.NewIdFromUInt(rand.Uint64(), id.User, t),
DhPubKey: getCycInt(256),
Facts: fact.FactList{
{Fact: "myUsername", T: fact.Username},
{Fact: "devinputvalidation@elixxir.io", T: fact.Email},
{Fact: "6502530000US", T: fact.Phone},
{Fact: "6502530001US", T: fact.Phone},
},
}
buff, err := expectedContact.Marshal()
if err != nil {
t.Errorf("Marshal() produced an error: %+v", err)
}
testContact, err := Unmarshal(buff)
if err != nil {
t.Errorf("Unmarshal() produced an error: %+v", err)
}
if !reflect.DeepEqual(expectedContact, testContact) {
t.Errorf("Unmarshaled Contact does not match expected."+
"\nexpected: %#v\nreceived: %#v", expectedContact, testContact)
t.Errorf("DhPubKey."+
"\nexpected: %+v\nreceived: %+v", expectedContact.DhPubKey.TextVerbose(10, math.MaxInt64), testContact.DhPubKey.TextVerbose(10, math.MaxInt64))
}
}
// Tests the size of marshaling and JSON marshaling of a Contact with a large
// amount of data.
func TestContact_Marshal_Size(t *testing.T) {
expectedContact := Contact{
ID: id.NewIdFromUInt(rand.Uint64(), id.User, t),
DhPubKey: getCycInt(512),
OwnershipProof: make([]byte, 1024),
Facts: fact.FactList{
{Fact: "myVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongUsername", T: fact.Username},
{Fact: "myVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongEmail@elixxir.io", T: fact.Email},
{Fact: "6502530000US", T: fact.Phone},
},
}
rand.Read(expectedContact.OwnershipProof)
buff, err := expectedContact.Marshal()
if err != nil {
t.Errorf("Marshal() produced an error: %+v", err)
}
marshalBuff, err := json.Marshal(expectedContact)
if err != nil {
t.Errorf("Marshal() produced an error: %+v", err)
}
t.Logf("size of buff: %d", len(buff))
t.Logf("size of marshalBuff: %d", len(marshalBuff))
t.Logf("ratio: %.2f%%", float32(len(buff))/float32(len(marshalBuff))*100)
t.Logf("%s", marshalBuff)
if len(marshalBuff) < len(buff) {
t.Errorf("JSON Contact smaller than marshaled contact."+
"\nJSON: %d\nmarshal: %d", len(marshalBuff), len(buff))
}
}
func getCycInt(size int) *cyclic.Int {
var primeString = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" +
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD" +
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" +
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" +
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" +
"C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" +
"83655D23DCA3AD961C62F356208552BB9ED529077096966D" +
"670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" +
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" +
"DE2BCBF6955817183995497CEA956AE515D2261898FA0510" +
"15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" +
"ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" +
"ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" +
"F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" +
"BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" +
"43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" +
"88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" +
"2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" +
"287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" +
"1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" +
"93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199" +
"FFFFFFFFFFFFFFFF"
buff, err := csprng.GenerateInGroup([]byte(primeString), size, csprng.NewSystemRNG())
if err != nil {
panic(err)
}
grp := cyclic.NewGroup(large.NewIntFromString(primeString, 16), large.NewInt(2)).NewIntFromBytes(buff)
return grp
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment