diff --git a/Makefile b/Makefile index 31e9c90..fa19dbb 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ test_lint: } test_local: - go test -v -race -short -p=1 ./... + go test -v -short -race -p=1 ./... test_codecov: ./coveralls.sh diff --git a/cmd/unlynx/client.go b/cmd/unlynx/client.go index 10b0f4f..7709fff 100644 --- a/cmd/unlynx/client.go +++ b/cmd/unlynx/client.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "os" "regexp" "strconv" @@ -32,7 +32,7 @@ func startQuery(el *onet.Roster, proofs bool, sum []string, count bool, whereQue grp, aggr, err := client.SendSurveyResultsQuery(*surveyID) if err != nil { - return errors.New("service could not output the results: " + err.Error()) + return fmt.Errorf("service could not output the results: %v", err) } // Print Output @@ -77,7 +77,7 @@ func openGroupToml(tomlFileName string) (*onet.Roster, error) { } if len(el.Roster.List) <= 0 { - return nil, errors.New("empty or invalid unlynx group file:" + tomlFileName) + return nil, fmt.Errorf("empty or invalid unlynx group file: %v", tomlFileName) } return el.Roster, nil @@ -91,7 +91,7 @@ func checkRegex(input, expression string) bool { func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, groupBy string) ([]string, bool, []libunlynx.WhereQueryAttribute, string, []string, error) { if sum == "" || (where != "" && predicate == "") || (where == "" && predicate != "") { - return nil, false, nil, "", nil, errors.New("wrong query! please check the sum, where and the predicate parameters") + return nil, false, nil, "", nil, fmt.Errorf("wrong query! please check the sum, where and the predicate parameters") } sumRegex := "{s[0-9]+(,\\s*s[0-9]+)*}" @@ -99,7 +99,7 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group groupByRegex := "{g[0-9]+(,\\s*g[0-9]+)*}" if !checkRegex(sum, sumRegex) { - return nil, false, nil, "", nil, errors.New("error parsing the sum parameter(s)") + return nil, false, nil, "", nil, fmt.Errorf("error parsing the sum parameter(s)") } sum = strings.Replace(sum, " ", "", -1) sum = strings.Replace(sum, "{", "", -1) @@ -115,27 +115,27 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group } if !check { - return nil, false, nil, "", nil, errors.New("no 'count' attribute in the sum variables") + return nil, false, nil, "", nil, fmt.Errorf("no 'count' attribute in the sum variables") } } if !checkRegex(where, whereRegex) { - return nil, false, nil, "", nil, errors.New("error parsing the where parameter(s)") + return nil, false, nil, "", nil, fmt.Errorf("error parsing the where parameter(s)") } where = strings.Replace(where, " ", "", -1) where = strings.Replace(where, "{", "", -1) where = strings.Replace(where, "}", "", -1) - tmp := strings.Split(where, ",") + whereTokens := strings.Split(where, ",") whereFinal := make([]libunlynx.WhereQueryAttribute, 0) var variable string - for i := range tmp { + for i := range whereTokens { // if is a variable (w1, w2...) if i%2 == 0 { - variable = tmp[i] + variable = whereTokens[i] } else { // if it is a value - value, err := strconv.Atoi(tmp[i]) + value, err := strconv.Atoi(whereTokens[i]) if err != nil { return nil, false, nil, "", nil, err } @@ -145,7 +145,7 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group } if !checkRegex(groupBy, groupByRegex) { - return nil, false, nil, "", nil, errors.New("error parsing the groupBy parameter(s)") + return nil, false, nil, "", nil, fmt.Errorf("error parsing the groupBy parameter(s)") } groupBy = strings.Replace(groupBy, " ", "", -1) groupBy = strings.Replace(groupBy, "{", "", -1) diff --git a/cmd/unlynx/main.go b/cmd/unlynx/main.go index 2b36d36..85f1271 100644 --- a/cmd/unlynx/main.go +++ b/cmd/unlynx/main.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "os" "github.com/ldsec/unlynx/lib" @@ -123,7 +123,7 @@ func main() { Usage: "Start unlynx server", Action: func(c *cli.Context) error { if err := runServer(c); err != nil { - return errors.New("error during runServer(): " + err.Error()) + return fmt.Errorf("error during runServer(): %v", err) } return nil }, @@ -135,10 +135,10 @@ func main() { Usage: "Setup server configuration (interactive)", Action: func(c *cli.Context) error { if c.String(optionConfig) != "" { - return errors.New("[-] Configuration file option cannot be used for the 'setup' command") + return fmt.Errorf("[-] configuration file option cannot be used for the 'setup' command") } if c.GlobalIsSet("debug") { - return errors.New("[-] Debug option cannot be used for the 'setup' command") + return fmt.Errorf("[-] debug option cannot be used for the 'setup' command") } app.InteractiveConfig(libunlynx.SuiTe, BinaryName) return nil diff --git a/data/handle_data.go b/data/handle_data.go index ee7d852..913b07f 100644 --- a/data/handle_data.go +++ b/data/handle_data.go @@ -2,7 +2,6 @@ package dataunlynx import ( "bufio" - "errors" "fmt" "math" "math/rand" @@ -78,7 +77,7 @@ func GenerateData(numDPs, numEntries, numEntriesFiltered, numGroupsClear, numGro numWhereClear, numWhereEnc, numAggrClear, numAggrEnc int64, numType []int64, randomGroups bool) (map[string][]libunlynx.DpClearResponse, error) { if int64(len(numType)) != (numGroupsClear + numGroupsEnc) { - return nil, errors.New("specify the correct number of group types for each grouping attribute") + return nil, fmt.Errorf("specify the correct number of group types for each grouping attribute") } testData := make(map[string][]libunlynx.DpClearResponse) @@ -94,7 +93,7 @@ func GenerateData(numDPs, numEntries, numEntriesFiltered, numGroupsClear, numGro group := make([]int64, 0) AllPossibleGroups(numType[:], group, 0, &groups) } else { - return nil, errors.New("the number of groups is different from the number of entries") + return nil, fmt.Errorf("the number of groups is different from the number of entries") } } diff --git a/go.mod b/go.mod index eae1b42..619136d 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,23 @@ module github.com/ldsec/unlynx +go 1.14 + require ( github.com/BurntSushi/toml v0.3.1 github.com/Knetic/govaluate v3.0.0+incompatible + github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/fanliao/go-concurrentMap v0.0.0-20141114143905-7d2d7a5ea67b + github.com/gorilla/websocket v1.4.1 // indirect + github.com/montanaflynn/stats v0.6.3 // indirect github.com/r0fls/gostats v0.0.0-20180711082619-e793b1fda35c github.com/satori/go.uuid v1.2.0 - github.com/stretchr/testify v1.3.0 - github.com/urfave/cli v1.22.1 - go.dedis.ch/kyber/v3 v3.0.5 - go.dedis.ch/onet/v3 v3.0.24 + github.com/stretchr/testify v1.4.0 + github.com/urfave/cli v1.22.3 + go.dedis.ch/kyber/v3 v3.0.12 + go.dedis.ch/onet/v3 v3.1.1 + golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 // indirect + golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect + golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 ) //replace go.dedis.ch/onet/v3 => ../../../go.dedis.ch/onet diff --git a/go.sum b/go.sum index fe57fc0..4879da9 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8L github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -18,11 +20,15 @@ github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkY github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= +github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/montanaflynn/stats v0.5.0 h1:2EkzeTSqBB4V4bJwWrt5gIIrZmpJBcoIRGS2kWLgzmk= github.com/montanaflynn/stats v0.5.0/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/montanaflynn/stats v0.6.3 h1:F8446DrvIF5V5smZfZ8K9nrmmix0AFgevPdLruGOmzk= +github.com/montanaflynn/stats v0.6.3/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -39,8 +45,13 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v0.0.0-20190311161405-34c6fa2dc709/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli v1.22.3 h1:FpNT6zq26xNpHZy08emi755QwzLPs6Pukqjlc7RfOMU= +github.com/urfave/cli v1.22.3/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs= go.dedis.ch/fixbuf v1.0.3/go.mod h1:yzJMt34Wa5xD37V5RTdmp38cz3QhMagdGoem9anUalw= go.dedis.ch/kyber/v3 v3.0.0-pre2/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ= @@ -51,11 +62,18 @@ go.dedis.ch/kyber/v3 v3.0.2/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhs go.dedis.ch/kyber/v3 v3.0.4/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ= go.dedis.ch/kyber/v3 v3.0.5 h1:BpjX6vY1R3b7TnJ0mUnCFRVXEJThSAj1zQzmNh4v+70= go.dedis.ch/kyber/v3 v3.0.5/go.mod h1:V1z0JihG9+dUEUCKLI9j9tjnlIflBw3wx8UOg0g3Pnk= +go.dedis.ch/kyber/v3 v3.0.9/go.mod h1:rhNjUUg6ahf8HEg5HUvVBYoWY4boAafX8tYxX+PS+qg= +go.dedis.ch/kyber/v3 v3.0.12 h1:15d61EyBcBoFIS97kS2c/Vz4o3FR8ALnZ2ck9J/ebYM= +go.dedis.ch/kyber/v3 v3.0.12/go.mod h1:kXy7p3STAurkADD+/aZcsznZGKVHEqbtmdIzvPfrs1U= go.dedis.ch/onet/v3 v3.0.0 h1:haBqkwkNNu/jHz7+PoZJS+xbtA5JheQvt0SSIjGyk5I= go.dedis.ch/onet/v3 v3.0.0/go.mod h1:xqmP2+NvxeNzgmNj/4hf56EZm3KT0Qksz98miZw5G3A= go.dedis.ch/onet/v3 v3.0.4 h1:sIHdiuhg5LMVVDAKQbSiBZsQnJGP2EDxImcp12OnWKo= go.dedis.ch/onet/v3 v3.0.24 h1:DjPcMDgQgQdxi6Z6vHt3BSuKtZioDUHpIUEC9wQ9NmI= go.dedis.ch/onet/v3 v3.0.24/go.mod h1:JhOZn9nJgpvxQWiY7Uebjj1AdXTW0ksQyq8RocRhwPk= +go.dedis.ch/onet/v3 v3.1.0 h1:KwofJGuw9T+051ejuWWxA6K1N6blNvhuwz5neasWg8Y= +go.dedis.ch/onet/v3 v3.1.0/go.mod h1:dDV7bRKbT3LJ7enHBcys2O0jXEY2jTUB4dq8HtekGbA= +go.dedis.ch/onet/v3 v3.1.1 h1:DN0t3Qj611kUrdmNn5quhWDdite1bxhoqoPna8IAWS0= +go.dedis.ch/onet/v3 v3.1.1/go.mod h1:dDV7bRKbT3LJ7enHBcys2O0jXEY2jTUB4dq8HtekGbA= go.dedis.ch/protobuf v1.0.5/go.mod h1:eIV4wicvi6JK0q/QnfIEGeSFNG0ZeB24kzut5+HaRLo= go.dedis.ch/protobuf v1.0.6 h1:E61p2XjYbYrTf3WeXE8M8Ui5WA3hX/NgbHHi5D0FLxI= go.dedis.ch/protobuf v1.0.6/go.mod h1:YHYXW6dQ9p2iJ3f+2fxKnOpjGx0MvL4cwpg1RVNXaV8= @@ -63,6 +81,8 @@ go.dedis.ch/protobuf v1.0.7 h1:wRUEiq3u0/vBhLjcw9CmAVrol+BnDyq2M0XLukdphyI= go.dedis.ch/protobuf v1.0.7/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI4= go.dedis.ch/protobuf v1.0.8 h1:lmyHigYqVxoTN1V0adoGPvqSdjycAMK0XmTFjP893mA= go.dedis.ch/protobuf v1.0.8/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI4= +go.dedis.ch/protobuf v1.0.11 h1:FTYVIEzY/bfl37lu3pR4lIj+F9Vp1jE8oh91VmxKgLo= +go.dedis.ch/protobuf v1.0.11/go.mod h1:97QR256dnkimeNdfmURz0wAMNVbd1VmLXhG1CrTYrJ4= go.etcd.io/bbolt v1.3.0 h1:oY10fI923Q5pVCVt1GBTZMn8LHo5M+RCInFpeMnV4QI= go.etcd.io/bbolt v1.3.0/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= @@ -71,7 +91,10 @@ golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b h1:Elez2XeF2p9uyVj0yEUDqQ golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f h1:hX65Cu3JDlGH3uEdK7I99Ii+9kjD6mvnnpfLdEAH0x4= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -79,17 +102,25 @@ golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20191021144547-ec77196f6094/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sys v0.0.0-20190124100055-b90733256f2e h1:3GIlrlVLfkoipSReOMNAgApI0ajnalyLa/EZHHca/XI= golang.org/x/sys v0.0.0-20190124100055-b90733256f2e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190311215038-5c2858a9cfe5 h1:ZcPpqKMdoZeNQ/4GHlyY4COf8n8SmpPv6mcqF1+VPSM= golang.org/x/tools v0.0.0-20190311215038-5c2858a9cfe5/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/satori/go.uuid.v1 v1.2.0 h1:AH9uksa7bGe9rluapecRKBCpZvxaBEyu0RepitcD0Hw= @@ -99,6 +130,7 @@ gopkg.in/tylerb/graceful.v1 v1.2.15/go.mod h1:yBhekWvR20ACXVObSSdD3u6S9DeSylanL2 gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0= gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= rsc.io/goversion v1.2.0 h1:SPn+NLTiAG7w30IRK/DKp1BjvpWabYgxlLp/+kx5J8w= rsc.io/goversion v1.2.0/go.mod h1:Eih9y/uIBS3ulggl7KNJ09xGSLcuNaLgmvvqa07sgfo= diff --git a/lib/add_rm/add_rm_proofs.go b/lib/add_rm/add_rm_proofs.go index 1b0c4c5..817cafd 100644 --- a/lib/add_rm/add_rm_proofs.go +++ b/lib/add_rm/add_rm_proofs.go @@ -1,7 +1,7 @@ package libunlynxaddrm import ( - "errors" + "fmt" "math" "sync" @@ -65,7 +65,7 @@ func AddRmProofCreation(cBef, cAft libunlynx.CipherText, K kyber.Point, k kyber. proofTmp, err := proof.HashProve(libunlynx.SuiTe, "proofTest", prover) if err != nil { - return PublishedAddRmProof{}, errors.New("---------Prover:" + err.Error()) + return PublishedAddRmProof{}, fmt.Errorf("---------prover: %v", err) } return PublishedAddRmProof{Proof: proofTmp, CtBef: cBef, CtAft: cAft, RB: rB}, nil diff --git a/lib/aggregation/aggregation_proofs.go b/lib/aggregation/aggregation_proofs.go index a74b7a5..3658644 100644 --- a/lib/aggregation/aggregation_proofs.go +++ b/lib/aggregation/aggregation_proofs.go @@ -164,15 +164,15 @@ func (palp *PublishedAggregationListProof) FromBytes(palpb PublishedAggregationL for i, papb := range palpb.List { go func(index int, papb PublishedAggregationProofBytes) { defer wg.Done() - tmp := PublishedAggregationProof{} - tmpErr := tmp.FromBytes(papb) + pap := PublishedAggregationProof{} + tmpErr := pap.FromBytes(papb) if tmpErr != nil { mutex.Lock() err = tmpErr mutex.Unlock() return } - palp.List[index] = tmp + palp.List[index] = pap }(i, papb) } libunlynx.EndParallelize(wg) diff --git a/lib/constants.go b/lib/constants.go index a7719c3..824ce33 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -1,16 +1,28 @@ package libunlynx import ( + "go.dedis.ch/onet/v3/log" + "os" "sync" + "time" "go.dedis.ch/onet/v3/simul/monitor" ) +func init() { + timeout, err := time.ParseDuration(os.Getenv("MEDCO_TIMEOUT")) + if err == nil { + TIMEOUT = timeout + } else { + log.Warn("Couldn't parse MEDCO_TIMEOUT, using default value: ", TIMEOUT.String()) + } +} + // Global Variables //______________________________________________________________________________________________________________________ // TIME is true if we use protocols with time measurements of computations. -const TIME = false +var TIME = false // VPARALLELIZE allows to choose the level of parallelization in the vector computations const VPARALLELIZE = 100 @@ -18,13 +30,15 @@ const VPARALLELIZE = 100 // DIFFPRI enables the DRO protocol (Distributed Results Obfuscation) const DIFFPRI = false +// TIMEOUT ddefines the default channel timeout +var TIMEOUT = 10 * time.Minute + // StartTimer starts measurement of time func StartTimer(name string) *monitor.TimeMeasure { - var timer *monitor.TimeMeasure if TIME { - timer = monitor.NewTimeMeasure(name) + return monitor.NewTimeMeasure(name) } - return timer + return nil } // EndTimer finishes measurement of time diff --git a/lib/crypto.go b/lib/crypto.go index 69306aa..9b85049 100644 --- a/lib/crypto.go +++ b/lib/crypto.go @@ -3,7 +3,6 @@ package libunlynx import ( "encoding" "encoding/base64" - "errors" "fmt" "math/big" "strings" @@ -635,7 +634,7 @@ func (c *CipherText) Serialize() (string, error) { func (c *CipherText) Deserialize(b64Encoded string) error { decoded, err := base64.URLEncoding.DecodeString(b64Encoded) if err != nil { - return errors.New("Invalid CipherText (decoding failed): " + err.Error()) + return fmt.Errorf("invalid ciphertext (decoding failed): %v", err) } err = (*c).FromBytes(decoded) if err != nil { @@ -648,7 +647,7 @@ func (c *CipherText) Deserialize(b64Encoded string) error { func SerializeElement(el encoding.BinaryMarshaler) (string, error) { bytes, err := el.MarshalBinary() if err != nil { - return "", errors.New("Error marshalling element: " + err.Error()) + return "", fmt.Errorf("error marshalling element: %v", err) } return base64.URLEncoding.EncodeToString(bytes), nil } @@ -665,15 +664,15 @@ func SerializeScalar(scalar encoding.BinaryMarshaler) (string, error) { // DeserializePoint deserializes a point using base64 encoding func DeserializePoint(encodedPoint string) (kyber.Point, error) { - decoded, errD := base64.URLEncoding.DecodeString(encodedPoint) - if errD != nil { - return nil, errors.New("Error decoding point: " + errD.Error()) + decoded, err := base64.URLEncoding.DecodeString(encodedPoint) + if err != nil { + return nil, fmt.Errorf("error decoding point: %v", err) } point := SuiTe.Point() - errM := point.UnmarshalBinary(decoded) - if errM != nil { - return nil, errors.New("Error unmarshalling point: " + errM.Error()) + err = point.UnmarshalBinary(decoded) + if err != nil { + return nil, fmt.Errorf("error unmarshalling point: %v", err) } return point, nil @@ -681,15 +680,15 @@ func DeserializePoint(encodedPoint string) (kyber.Point, error) { // DeserializeScalar deserializes a scalar using base64 encoding func DeserializeScalar(encodedScalar string) (kyber.Scalar, error) { - decoded, errD := base64.URLEncoding.DecodeString(encodedScalar) - if errD != nil { - return nil, errors.New("Error decoding scalar: " + errD.Error()) + decoded, err := base64.URLEncoding.DecodeString(encodedScalar) + if err != nil { + return nil, fmt.Errorf("error decoding scalar: %v", err) } scalar := SuiTe.Scalar() - errM := scalar.UnmarshalBinary(decoded) - if errM != nil { - return nil, errors.New("Error unmarshalling scalar: " + errM.Error()) + err = scalar.UnmarshalBinary(decoded) + if err != nil { + return nil, fmt.Errorf("error unmarshalling scalar: %v", err) } return scalar, nil diff --git a/lib/deterministic_tag/deterministic_tag_proofs.go b/lib/deterministic_tag/deterministic_tag_proofs.go index 81822a2..09bea34 100644 --- a/lib/deterministic_tag/deterministic_tag_proofs.go +++ b/lib/deterministic_tag/deterministic_tag_proofs.go @@ -1,7 +1,7 @@ package libunlynxdetertag import ( - "errors" + "fmt" "math" "reflect" "sync" @@ -82,7 +82,7 @@ func DeterministicTagCrProofCreation(ctBef, ctAft libunlynx.CipherText, K kyber. prover := predicate.Prover(libunlynx.SuiTe, sval, pval, nil) // computes: commitment, challenge, response Proof, err := proof.HashProve(libunlynx.SuiTe, "proofTest", prover) if err != nil { - return PublishedDDTCreationProof{}, errors.New("---------Prover: " + err.Error()) + return PublishedDDTCreationProof{}, fmt.Errorf("---------prover: %v", err) } return PublishedDDTCreationProof{Proof: Proof, Ciminus11Si: ciminus11Si, CTbef: ctBef, CTaft: ctAft}, nil @@ -191,7 +191,7 @@ func DeterministicTagAdditionProofCreation(c1 kyber.Point, s kyber.Scalar, c2 ky prover := predicate.Prover(libunlynx.SuiTe, sval, pval, nil) // computes: commitment, challenge, response Proof, err := proof.HashProve(libunlynx.SuiTe, "proofTest", prover) if err != nil { - return PublishedDDTAdditionProof{}, errors.New("---------Prover: " + err.Error()) + return PublishedDDTAdditionProof{}, fmt.Errorf("---------prover: %v", err) } return PublishedDDTAdditionProof{Proof: Proof, C1: c1, C2: c2, R: r}, nil diff --git a/lib/deterministic_tag/deterministic_tag_test.go b/lib/deterministic_tag/deterministic_tag_test.go index 0fe2068..a0f25a6 100644 --- a/lib/deterministic_tag/deterministic_tag_test.go +++ b/lib/deterministic_tag/deterministic_tag_test.go @@ -19,8 +19,7 @@ func TestDeterministicTagSequence(t *testing.T) { target := []int64{-8358645081376817152, -8358645081376817152, 2, 3, 2, 5} cv := *libunlynx.EncryptIntVector(K, target) for n := 0; n < N; n++ { - tmp := libunlynxdetertag.DeterministicTagSequence(cv, private[n], secretPrivate[n]) - cv = tmp + cv = libunlynxdetertag.DeterministicTagSequence(cv, private[n], secretPrivate[n]) } assert.True(t, cv[0].C.Equal(cv[1].C)) diff --git a/lib/key_switch/key_switch_proofs.go b/lib/key_switch/key_switch_proofs.go index 3f03845..ff5ae54 100644 --- a/lib/key_switch/key_switch_proofs.go +++ b/lib/key_switch/key_switch_proofs.go @@ -1,7 +1,7 @@ package libunlynxkeyswitch import ( - "errors" + "fmt" "math" "sync" @@ -68,7 +68,7 @@ func KeySwitchProofCreation(K, Q kyber.Point, k kyber.Scalar, viB, ks2, rBNeg ky prover := predicate.Prover(libunlynx.SuiTe, sval, pval, nil) // computes: commitment, challenge, response proofKS, err := proof.HashProve(libunlynx.SuiTe, "proofTest", prover) if err != nil { - return PublishedKSProof{}, errors.New("---------Prover: " + err.Error()) + return PublishedKSProof{}, fmt.Errorf("---------prover: %v", err) } return PublishedKSProof{Proof: proofKS, K: K, ViB: viB, Ks2: ks2, RbNeg: rBNeg, Q: Q}, nil diff --git a/lib/shuffle/shuffle.go b/lib/shuffle/shuffle.go index a91414c..2044f7a 100644 --- a/lib/shuffle/shuffle.go +++ b/lib/shuffle/shuffle.go @@ -63,15 +63,15 @@ func shuffle(pi []int, i int, inputList, outputList []libunlynx.CipherVector, NQ wg := libunlynx.StartParallelize(NQ) for j := 0; j < NQ; j++ { var b kyber.Scalar - var tmpCipher libunlynx.CipherText + var ct libunlynx.CipherText if len(precomputedPoints[0]) == 0 { b = beta[index][j] } else { - tmpCipher = precomputedPoints[index][j] + ct = precomputedPoints[index][j] } go func(j int) { defer wg.Done() - outputList[i][j] = rerandomize(inputList[index], b, b, tmpCipher, g, h, j) + outputList[i][j] = rerandomize(inputList[index], b, b, ct, g, h, j) }(j) } libunlynx.EndParallelize(wg) @@ -80,19 +80,19 @@ func shuffle(pi []int, i int, inputList, outputList []libunlynx.CipherVector, NQ // rerandomize rerandomizes an element in a ciphervector at position j, following the Neff Shuffling algorithm func rerandomize(cv libunlynx.CipherVector, a, b kyber.Scalar, cipher libunlynx.CipherText, g, h kyber.Point, j int) libunlynx.CipherText { ct := libunlynx.NewCipherText() - var tmp1, tmp2 kyber.Point + var point1, point2 kyber.Point if cipher.C == nil { //no precomputed value - tmp1 = libunlynx.SuiTe.Point().Mul(a, g) - tmp2 = libunlynx.SuiTe.Point().Mul(b, h) + point1 = libunlynx.SuiTe.Point().Mul(a, g) + point2 = libunlynx.SuiTe.Point().Mul(b, h) } else { - tmp1 = cipher.K - tmp2 = cipher.C + point1 = cipher.K + point2 = cipher.C } - ct.K = libunlynx.SuiTe.Point().Add(cv[j].K, tmp1) - ct.C = libunlynx.SuiTe.Point().Add(cv[j].C, tmp2) + ct.K = libunlynx.SuiTe.Point().Add(cv[j].K, point1) + ct.C = libunlynx.SuiTe.Point().Add(cv[j].C, point2) return *ct } @@ -113,12 +113,12 @@ func CreatePrecomputedRandomize(g, h kyber.Point, rand cipher.Stream, lineSize, for w := range result[i].CipherV { mutex.Lock() - tmp := libunlynx.SuiTe.Scalar().Pick(rand) + scalar := libunlynx.SuiTe.Scalar().Pick(rand) mutex.Unlock() - result[i].S[w] = tmp - result[i].CipherV[w].K = libunlynx.SuiTe.Point().Mul(tmp, g) - result[i].CipherV[w].C = libunlynx.SuiTe.Point().Mul(tmp, h) + result[i].S[w] = scalar + result[i].CipherV[w].K = libunlynx.SuiTe.Point().Mul(scalar, g) + result[i].CipherV[w].C = libunlynx.SuiTe.Point().Mul(scalar, h) } }(i) diff --git a/lib/shuffle/shuffle_proofs.go b/lib/shuffle/shuffle_proofs.go index 956d0af..e0873b0 100644 --- a/lib/shuffle/shuffle_proofs.go +++ b/lib/shuffle/shuffle_proofs.go @@ -1,7 +1,7 @@ package libunlynxshuffle import ( - "errors" + "fmt" "math" "sync" @@ -84,7 +84,7 @@ func ShuffleProofCreation(originalList, shuffledList []libunlynx.CipherVector, g // do k-shuffle of ElGamal on the (Xhat,Yhat) and check it k = len(Xhat) if k != len(Yhat) { - return PublishedShufflingProof{}, errors.New("X,Y vectors have inconsistent lengths") + return PublishedShufflingProof{}, fmt.Errorf("X,Y vectors have inconsistent lengths") } ps := shuffleKyber.PairShuffle{} ps.Init(libunlynx.SuiTe, k) @@ -95,7 +95,7 @@ func ShuffleProofCreation(originalList, shuffledList []libunlynx.CipherVector, g prf, err := proof.HashProve(libunlynx.SuiTe, "PairShuffle", prover) if err != nil { - return PublishedShufflingProof{}, errors.New("Shuffle proof failed: " + err.Error()) + return PublishedShufflingProof{}, fmt.Errorf("shuffle proof failed: %v", err) } return PublishedShufflingProof{originalList, shuffledList, g, h, prf}, nil } @@ -293,7 +293,7 @@ func compressCipherVector(ciphervector libunlynx.CipherVector, e []kyber.Scalar) // check that e and cipher vectors have the same size if len(e) != k { - return libunlynx.CipherText{}, errors.New("e is not the right size") + return libunlynx.CipherText{}, fmt.Errorf("e is not the right size") } ciphertext := *libunlynx.NewCipherText() @@ -343,7 +343,7 @@ func compressCipherVectorMultiple(inputList, outputList []libunlynx.CipherVector wg := libunlynx.StartParallelize(2) go func() { defer wg.Done() - tmp, tmpErr := compressCipherVector(inputList[i], e) + cv, tmpErr := compressCipherVector(inputList[i], e) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -351,12 +351,12 @@ func compressCipherVectorMultiple(inputList, outputList []libunlynx.CipherVector return } - Xhat[i] = tmp.K - Yhat[i] = tmp.C + Xhat[i] = cv.K + Yhat[i] = cv.C }() go func() { defer wg.Done() - tmpBar, tmpErr := compressCipherVector(outputList[i], e) + cv, tmpErr := compressCipherVector(outputList[i], e) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -364,8 +364,8 @@ func compressCipherVectorMultiple(inputList, outputList []libunlynx.CipherVector return } - XhatBar[i] = tmpBar.K - YhatBar[i] = tmpBar.C + XhatBar[i] = cv.K + YhatBar[i] = cv.C }() libunlynx.EndParallelize(wg) @@ -388,8 +388,8 @@ func compressBeta(beta [][]kyber.Scalar, e []kyber.Scalar) []kyber.Scalar { go func(i int) { defer wg.Done() for j := 0; j < NQ; j++ { - tmp := libunlynx.SuiTe.Scalar().Mul(beta[i][j], e[j]) - betaCompressed[i] = libunlynx.SuiTe.Scalar().Add(betaCompressed[i], tmp) + betaMulE := libunlynx.SuiTe.Scalar().Mul(beta[i][j], e[j]) + betaCompressed[i] = libunlynx.SuiTe.Scalar().Add(betaCompressed[i], betaMulE) } }(i) } @@ -412,7 +412,7 @@ func (psp *PublishedShufflingProof) ToBytes() (PublishedShufflingProofBytes, err wg := libunlynx.StartParallelize(3) go func(data []libunlynx.CipherVector) { defer wg.Done() - tmp, tmpLength, tmpErr := libunlynx.ArrayCipherVectorToBytes(data) + cvBytes, cvLengthBytes, tmpErr := libunlynx.ArrayCipherVectorToBytes(data) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -420,14 +420,14 @@ func (psp *PublishedShufflingProof) ToBytes() (PublishedShufflingProofBytes, err return } - pspb.OriginalList = &tmp - pspb.OriginalListLength = &tmpLength + pspb.OriginalList = &cvBytes + pspb.OriginalListLength = &cvLengthBytes }(psp.OriginalList) // convert ShuffledList go func(data []libunlynx.CipherVector) { defer wg.Done() - tmp, tmpLength, tmpErr := libunlynx.ArrayCipherVectorToBytes(data) + cvBytes, cvLengthBytes, tmpErr := libunlynx.ArrayCipherVectorToBytes(data) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -435,8 +435,8 @@ func (psp *PublishedShufflingProof) ToBytes() (PublishedShufflingProofBytes, err return } - pspb.ShuffledList = &tmp - pspb.ShuffledListLength = &tmpLength + pspb.ShuffledList = &cvBytes + pspb.ShuffledListLength = &cvLengthBytes }(psp.ShuffledList) // convert 'the rest' @@ -450,8 +450,7 @@ func (psp *PublishedShufflingProof) ToBytes() (PublishedShufflingProofBytes, err mutex.Unlock() return } - tmpGBytes := dataG - pspb.G = &tmpGBytes + pspb.G = &dataG dataH, tmpErr := libunlynx.AbstractPointsToBytes([]kyber.Point{H}) if tmpErr != nil { @@ -460,8 +459,7 @@ func (psp *PublishedShufflingProof) ToBytes() (PublishedShufflingProofBytes, err mutex.Unlock() return } - tmpHBytes := dataH - pspb.H = &tmpHBytes + pspb.H = &dataH pspb.HashProof = psp.HashProof }(psp.G, psp.H, psp.HashProof) diff --git a/lib/store/store.go b/lib/store/store.go index 2fe0266..98bdc10 100644 --- a/lib/store/store.go +++ b/lib/store/store.go @@ -85,10 +85,10 @@ func (s *Store) InsertDpResponse(cr libunlynx.DpResponse, proofsB bool, groupBy, } else { value, ok := s.DpResponsesAggr[GroupingKeyTuple{libunlynx.Key(clearGrp), libunlynx.Key(clearWhr)}] if ok { - tmp := libunlynx.NewCipherVector(len(value.AggregatingAttributes)) - tmp.Add(value.AggregatingAttributes, newResp.AggregatingAttributes) + cv := libunlynx.NewCipherVector(len(value.AggregatingAttributes)) + cv.Add(value.AggregatingAttributes, newResp.AggregatingAttributes) mapValue := s.DpResponsesAggr[GroupingKeyTuple{libunlynx.Key(clearGrp), libunlynx.Key(clearWhr)}] - mapValue.AggregatingAttributes = *tmp + mapValue.AggregatingAttributes = *cv s.DpResponsesAggr[GroupingKeyTuple{libunlynx.Key(clearGrp), libunlynx.Key(clearWhr)}] = mapValue if proofsB { @@ -199,7 +199,7 @@ func AddInClear(s []libunlynx.DpClearResponse) []libunlynx.DpClearResponse { cpy = append(cpy, libunlynxtools.ConvertMapToData(elem.AggregatingAttributesClear, "s", 0)...) cpy = append(cpy, libunlynxtools.ConvertMapToData(elem.AggregatingAttributesEnc, "s", len(elem.AggregatingAttributesClear))...) - if _, ok := dataMap[key]; ok == false { + if _, ok := dataMap[key]; !ok { dataMap[key] = cpy } else { for i := 0; i < len(dataMap[key]); i = i + libunlynx.VPARALLELIZE { @@ -272,7 +272,7 @@ func (s *Store) PullCothorityAggregatedFilteredResponses(diffPri bool, noise lib s.GroupedDeterministicFilteredResponses = make(map[libunlynx.GroupingKey]libunlynx.FilteredResponse) - if diffPri == true { + if diffPri { for _, v := range aggregatedResults { for _, aggr := range v.AggregatingAttributes { aggr.Add(aggr, noise) @@ -293,7 +293,7 @@ func (s *Store) PullDeliverableResults(diffPri bool, noise libunlynx.CipherText) results := s.DeliverableResults s.DeliverableResults = s.DeliverableResults[:0] - if diffPri == true { + if diffPri { for _, v := range results { for _, aggr := range v.AggregatingAttributes { aggr.Add(aggr, noise) diff --git a/lib/structs.go b/lib/structs.go index 9bb1273..0e1a733 100644 --- a/lib/structs.go +++ b/lib/structs.go @@ -105,8 +105,8 @@ func AddInMap(s map[GroupingKey]FilteredResponse, key GroupingKey, added Filtere if localResult, ok := s[key]; !ok { s[key] = added } else { - tmp := NewFilteredResponse(len(added.GroupByEnc), len(added.AggregatingAttributes)) - s[key] = *tmp.Add(localResult, added) + nfr := NewFilteredResponse(len(added.GroupByEnc), len(added.AggregatingAttributes)) + s[key] = *nfr.Add(localResult, added) } } @@ -141,9 +141,9 @@ func (crd *FilteredResponseDet) FormatAggregationProofs(res map[GroupingKey][]Ci } else { // if no elements are in the map yet container := make([]CipherVector, len(crd.Fr.AggregatingAttributes)) for i, ct := range crd.Fr.AggregatingAttributes { - tmp := make(CipherVector, 0) - tmp = append(tmp, ct) - container[i] = tmp + cv := make(CipherVector, 0) + cv = append(cv, ct) + container[i] = cv res[crd.DetTagGroupBy] = container } } @@ -205,7 +205,7 @@ func Key(ga []int64) GroupingKey { return GroupingKey(strings.Join(key, "")) } -// UnKey permits to go from a tag non-encrypted grouping attributes to grouping attributes +// UnKey permits to go from a tag non-encrypted grouping attributes to grouping attributes func UnKey(gk GroupingKey) ([]int64, error) { tab := make([]int64, 0) count := 0 @@ -214,11 +214,11 @@ func UnKey(gk GroupingKey) ([]int64, error) { if a != ',' { nbrString[0] = string(a) } else { - tmp, err := strconv.Atoi(strings.Join(nbrString, "")) + key, err := strconv.Atoi(strings.Join(nbrString, "")) if err != nil { return nil, err } - tab = append(tab, int64(tmp)) + tab = append(tab, int64(key)) nbrString = make([]string, 1) count++ } diff --git a/lib/tools/tools.go b/lib/tools/tools.go index fed6829..0aa8f29 100644 --- a/lib/tools/tools.go +++ b/lib/tools/tools.go @@ -3,7 +3,6 @@ package libunlynxtools import ( "encoding/binary" "encoding/gob" - "errors" "fmt" "os" "strconv" @@ -27,7 +26,7 @@ func SendISMOthers(s *onet.ServiceProcessor, el *onet.Roster, msg interface{}) e } var err error if len(errStrs) > 0 { - err = errors.New(strings.Join(errStrs, "\n")) + err = fmt.Errorf(strings.Join(errStrs, "\n")) } return err } @@ -119,7 +118,7 @@ func WriteToGobFile(path string, object interface{}) error { return err } } else { - return errors.New("Could not write Gob file:" + err.Error()) + return fmt.Errorf("could not write Gob file: %v", err) } return nil @@ -137,7 +136,7 @@ func ReadFromGobFile(path string, object interface{}) error { return err } } else { - return errors.New("Could not read Gob file:" + err.Error()) + return fmt.Errorf("could not read Gob file: %v", err) } return nil diff --git a/protocols/collective_aggregation_protocol.go b/protocols/collective_aggregation_protocol.go index 5c4077d..40fb36b 100644 --- a/protocols/collective_aggregation_protocol.go +++ b/protocols/collective_aggregation_protocol.go @@ -8,8 +8,9 @@ package protocolsunlynx import ( - "errors" + "fmt" "sync" + "time" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/aggregation" @@ -117,16 +118,16 @@ func NewCollectiveAggregationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIn err := pap.RegisterChannel(&pap.DataReferenceChannel) if err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } err = pap.RegisterChannel(&pap.ChildDataChannel) if err != nil { - return nil, errors.New("couldn't register child-data channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register child-data channel: %v", err) } if err := pap.RegisterChannel(&pap.LengthNodeChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } return pap, nil @@ -136,7 +137,7 @@ func NewCollectiveAggregationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIn func (p *CollectiveAggregationProtocol) Start() error { log.Lvl1(p.ServerIdentity(), " started a Colective Aggregation Protocol") if err := p.SendToChildren(&DataReferenceMessage{}); err != nil { - return errors.New("Error sending :" + err.Error()) + return fmt.Errorf("error sending : %v", err) } return nil } @@ -195,11 +196,13 @@ func (p *CollectiveAggregationProtocol) Dispatch() error { // Announce forwarding down the tree. func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error { - dataReferenceMessage := <-p.DataReferenceChannel - if !p.IsLeaf() { + select { + case dataReferenceMessage := <-p.DataReferenceChannel: if err := p.SendToChildren(&dataReferenceMessage.DataReferenceMessage); err != nil { - return errors.New("Error sending :" + err.Error()) + return fmt.Errorf("error sending : %v", err) } + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") } return nil } @@ -235,10 +238,10 @@ func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libu } if ok { - tmp := libunlynx.NewCipherVector(len(localAggr.AggregatingAttributes)) - tmp.Add(localAggr.AggregatingAttributes, aggr.Fr.AggregatingAttributes) + cv := libunlynx.NewCipherVector(len(localAggr.AggregatingAttributes)) + cv.Add(localAggr.AggregatingAttributes, aggr.Fr.AggregatingAttributes) - localAggr.AggregatingAttributes = *tmp + localAggr.AggregatingAttributes = *cv } else { localAggr = aggr.Fr } @@ -280,10 +283,10 @@ func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libu } if err := p.SendToParent(&CADBLengthMessage{gacbLength, aabLength, dtbLength}); err != nil { - return nil, errors.New("Error sending :" + err.Error()) + return nil, fmt.Errorf("error sending : %v", err) } if err := p.SendToParent(&message); err != nil { - return nil, errors.New("Error sending :" + err.Error()) + return nil, fmt.Errorf("error sending : %v", err) } } @@ -294,10 +297,10 @@ func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libu func (p *CollectiveAggregationProtocol) checkData() error { // If no data is passed to the collection protocol if p.GroupedData == nil && p.SimpleData == nil { - return errors.New("no data reference is provided") + return fmt.Errorf("no data reference is provided") // If both data entry points are used } else if p.GroupedData != nil && p.SimpleData != nil { - return errors.New("two data references are given in the struct") + return fmt.Errorf("two data references are given in the struct") // If we are using the GroupedData keep everything as is } else if p.GroupedData != nil { return nil diff --git a/protocols/collective_aggregation_test.go b/protocols/collective_aggregation_test.go index f383620..120c0c3 100644 --- a/protocols/collective_aggregation_test.go +++ b/protocols/collective_aggregation_test.go @@ -62,7 +62,6 @@ func TestCollectiveAggregationGroup(t *testing.T) { resultData := make(map[libunlynx.GroupingKey][]int64) for k, v := range encryptedResult.GroupedData { resultData[k] = libunlynx.DecryptIntVector(clientPrivate, &v.AggregatingAttributes) - log.Lvl1(k, resultData[k]) } for k, v1 := range expectedGroups { @@ -139,8 +138,8 @@ func TestCollectiveAggregationSimple(t *testing.T) { case encryptedResult := <-feedback: log.Lvl1("Received results:") resultData := make([]int64, len(encryptedResult.GroupedData[protocolsunlynx.EMPTYKEY].AggregatingAttributes)) - tmp := encryptedResult.GroupedData[protocolsunlynx.EMPTYKEY].AggregatingAttributes - resultData = libunlynx.DecryptIntVector(clientPrivate, &tmp) + aggrAttr := encryptedResult.GroupedData[protocolsunlynx.EMPTYKEY].AggregatingAttributes + resultData = libunlynx.DecryptIntVector(clientPrivate, &aggrAttr) log.Lvl1(resultData) assert.Equal(t, expectedResults, resultData) case <-time.After(timeout): diff --git a/protocols/deterministic_tagging_protocol.go b/protocols/deterministic_tagging_protocol.go index f6f8dcd..a457f8c 100644 --- a/protocols/deterministic_tagging_protocol.go +++ b/protocols/deterministic_tagging_protocol.go @@ -7,7 +7,7 @@ package protocolsunlynx import ( - "errors" + "fmt" "sync" "time" @@ -101,10 +101,10 @@ func NewDeterministicTaggingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIns } if err := dsp.RegisterChannel(&dsp.PreviousNodeInPathChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } if err := dsp.RegisterChannel(&dsp.LengthNodeChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } var i int @@ -116,7 +116,6 @@ func NewDeterministicTaggingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIns break } } - return dsp, nil } @@ -126,10 +125,10 @@ func (p *DeterministicTaggingProtocol) Start() error { roundTotalStart := libunlynx.StartTimer(p.Name() + "_DetTagging(START)") if p.TargetOfSwitch == nil { - return errors.New("no data on which to do a deterministic tagging") + return fmt.Errorf("no data on which to do a deterministic tagging") } if p.SurveySecretKey == nil { - return errors.New("no survey secret key given") + return fmt.Errorf("no survey secret key given") } p.ExecTime = 0 @@ -156,7 +155,13 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { defer p.Done() //************ ----- first round, add value derivated from ephemeral secret to message ---- ******************** - deterministicTaggingTargetBytesBef := <-p.PreviousNodeInPathChannel + var deterministicTaggingTargetBytesBef deterministicTaggingBytesStruct + select { + case deterministicTaggingTargetBytesBef = <-p.PreviousNodeInPathChannel: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the (first round) on time") + } + deterministicTaggingTargetBef := DeterministicTaggingMessage{Data: make([]libunlynx.CipherText, 0)} err := deterministicTaggingTargetBef.FromBytes(deterministicTaggingTargetBytesBef.Data) if err != nil { @@ -173,9 +178,9 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { go func(i int) { defer wg.Done() for j := 0; j < libunlynx.VPARALLELIZE && (i+j) < len(deterministicTaggingTargetBef.Data); j++ { - tmp := libunlynx.SuiTe.Point().Add(deterministicTaggingTargetBef.Data[i+j].C, toAdd) + r := libunlynx.SuiTe.Point().Add(deterministicTaggingTargetBef.Data[i+j].C, toAdd) if p.Proofs { - _, tmpErr := libunlynxdetertag.DeterministicTagAdditionProofCreation(deterministicTaggingTargetBef.Data[i+j].C, *p.SurveySecretKey, toAdd, tmp) + _, tmpErr := libunlynxdetertag.DeterministicTagAdditionProofCreation(deterministicTaggingTargetBef.Data[i+j].C, *p.SurveySecretKey, toAdd, r) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -183,7 +188,7 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { return } } - deterministicTaggingTargetBef.Data[i+j].C = tmp + deterministicTaggingTargetBef.Data[i+j].C = r } }(i) } @@ -203,7 +208,13 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { } //************ ----- second round, deterministic tag creation ---- ******************** - deterministicTaggingTargetBytes := <-p.PreviousNodeInPathChannel + var deterministicTaggingTargetBytes deterministicTaggingBytesStruct + select { + case deterministicTaggingTargetBytes = <-p.PreviousNodeInPathChannel: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the (second round) on time") + } + deterministicTaggingTarget := DeterministicTaggingMessage{Data: make([]libunlynx.CipherText, 0)} err = deterministicTaggingTarget.FromBytes(deterministicTaggingTargetBytes.Data) if err != nil { @@ -222,15 +233,15 @@ func (p *DeterministicTaggingProtocol) Dispatch() error { if j > len(deterministicTaggingTarget.Data) { j = len(deterministicTaggingTarget.Data) } - tmp := deterministicTaggingTarget.Data[i:j] - tmpErr := TaggingDet(&tmp, p.Private(), *p.SurveySecretKey, p.Public(), p.Proofs) + cv := deterministicTaggingTarget.Data[i:j] + tmpErr := TaggingDet(&cv, p.Private(), *p.SurveySecretKey, p.Public(), p.Proofs) if tmpErr != nil { mutex.Lock() err = tmpErr mutex.Unlock() return } - copy(deterministicTaggingTarget.Data[i:j], tmp) + copy(deterministicTaggingTarget.Data[i:j], cv) }(i) } wg.Wait() @@ -383,9 +394,9 @@ func (dtm *DeterministicTaggingMessage) FromBytes(data []byte) error { go func(i int) { defer wg.Done() for j := 0; j < elementSize*libunlynx.VPARALLELIZE && i+j < len(data); j += elementSize { - tmp := make([]byte, elementSize) - copy(tmp, data[i+j:i+j+elementSize]) - tmpErr := (*dtm).Data[(i+j)/elementSize].FromBytes(tmp) + dataCopy := make([]byte, elementSize) + copy(dataCopy, data[i+j:i+j+elementSize]) + tmpErr := (*dtm).Data[(i+j)/elementSize].FromBytes(dataCopy) if tmpErr != nil { mutex.Lock() err = tmpErr diff --git a/protocols/key_switching_protocol.go b/protocols/key_switching_protocol.go index 5f9971a..a774605 100644 --- a/protocols/key_switching_protocol.go +++ b/protocols/key_switching_protocol.go @@ -7,7 +7,7 @@ package protocolsunlynx import ( - "errors" + "fmt" "time" "github.com/ldsec/unlynx/lib" @@ -125,16 +125,16 @@ func NewKeySwitchingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, e err := pap.RegisterChannel(&pap.DownChannel) if err != nil { - return nil, errors.New("couldn't register down channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register down channel: %v", err) } err = pap.RegisterChannel(&pap.ChildDataChannel) if err != nil { - return nil, errors.New("couldn't register child-data channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register child-data channel: %v", err) } if err := pap.RegisterChannel(&pap.LengthChannel); err != nil { - return nil, errors.New("couldn't register length channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register length channel: %v", err) } return pap, nil @@ -146,11 +146,11 @@ func (p *KeySwitchingProtocol) Start() error { keySwitchingStart := libunlynx.StartTimer(p.Name() + "_KeySwitching(START)") if p.TargetOfSwitch == nil { - return errors.New("no ciphertext given as key switching target") + return fmt.Errorf("no ciphertext given as key switching target") } if p.TargetPublicKey == nil { - return errors.New("no new public key to be switched on provided") + return fmt.Errorf("no new public key to be switched on provided") } log.Lvl2("[KEY SWITCHING PROTOCOL] Server", p.ServerIdentity(), " started a Key Switching Protocol") @@ -178,7 +178,7 @@ func (p *KeySwitchingProtocol) Start() error { } if err := p.SendToChildren(&DownMessageBytes{Data: data}); err != nil { - return errors.New("Root " + p.ServerIdentity().String() + " failed to broadcast DownMessageBytes: " + err.Error()) + return fmt.Errorf("Root "+p.ServerIdentity().String()+" failed to broadcast DownMessageBytes: %v", err) } libunlynx.EndTimer(keySwitchingStart) @@ -230,11 +230,15 @@ func (p *KeySwitchingProtocol) Dispatch() error { // Announce forwarding down the tree. func (p *KeySwitchingProtocol) announcementKSPhase() (kyber.Point, []kyber.Point, error) { - dataReferenceMessage := <-p.DownChannel - if !p.IsLeaf() { - if err := p.SendToChildren(&dataReferenceMessage.DownMessageBytes); err != nil { - return nil, nil, errors.New("Node " + p.ServerIdentity().String() + " failed to broadcast DownMessageBytes: " + err.Error()) - } + var dataReferenceMessage DownBytesStruct + select { + case dataReferenceMessage = <-p.DownChannel: + case <-time.After(libunlynx.TIMEOUT): + return nil, nil, fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") + } + + if err := p.SendToChildren(&dataReferenceMessage.DownMessageBytes); err != nil { + return nil, nil, fmt.Errorf("Node "+p.ServerIdentity().String()+" failed to broadcast DownMessageBytes: %v", err) } message, err := libunlynx.FromBytesToAbstractPoints(dataReferenceMessage.Data) if err != nil { @@ -276,7 +280,7 @@ func (p *KeySwitchingProtocol) ascendingKSPhase() (*libunlynx.CipherVector, erro if !p.IsRoot() { if err := p.SendToParent(&LengthMessage{Length: libunlynxtools.UnsafeCastIntsToBytes([]int{len(*p.NodeContribution)})}); err != nil { - return nil, errors.New("Node " + p.ServerIdentity().String() + " failed to broadcast LengthMessage ( " + err.Error() + " )") + return nil, fmt.Errorf("Node "+p.ServerIdentity().String()+" failed to broadcast LengthMessage: %v", err) } message, _, err := (*p.NodeContribution).ToBytes() if err != nil { @@ -284,7 +288,7 @@ func (p *KeySwitchingProtocol) ascendingKSPhase() (*libunlynx.CipherVector, erro } if err := p.SendToParent(&UpBytesMessage{Data: message}); err != nil { - return nil, errors.New("Node " + p.ServerIdentity().String() + " failed to broadcast UpBytesMessage: " + err.Error()) + return nil, fmt.Errorf("Node "+p.ServerIdentity().String()+" failed to broadcast UpBytesMessage: %v", err) } } diff --git a/protocols/shuffling+ddt_protocol.go b/protocols/shuffling+ddt_protocol.go index 989f908..369d0ac 100644 --- a/protocols/shuffling+ddt_protocol.go +++ b/protocols/shuffling+ddt_protocol.go @@ -1,8 +1,9 @@ package protocolsunlynx import ( - "errors" + "fmt" "sync" + "time" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/deterministic_tag" @@ -91,11 +92,11 @@ func NewShufflingPlusDDTProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstanc } if err := pi.RegisterChannel(&pi.PreviousNodeInPathChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } if err := pi.RegisterChannel(&pi.LengthNodeChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } // choose next node in circuit @@ -113,7 +114,7 @@ func NewShufflingPlusDDTProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstanc func (p *ShufflingPlusDDTProtocol) Start() error { if p.TargetData == nil { - return errors.New("no data is given") + return fmt.Errorf("no data is given") } nbrSqCVs := len(*p.TargetData) log.Lvl1("["+p.Name()+"]", " started a Shuffling+DDT Protocol (", nbrSqCVs, " responses)") @@ -152,12 +153,23 @@ func (p *ShufflingPlusDDTProtocol) Start() error { func (p *ShufflingPlusDDTProtocol) Dispatch() error { defer p.Done() - shufflingPlusDDTBytesMessageLength := <-p.LengthNodeChannel - tmp := <-p.PreviousNodeInPathChannel + var shufflingPlusDDTBytesMessageLength shufflingPlusDDTBytesLengthStruct + select { + case shufflingPlusDDTBytesMessageLength = <-p.LengthNodeChannel: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") + } + + var spDDTbs shufflingPlusDDTBytesStruct + select { + case spDDTbs = <-p.PreviousNodeInPathChannel: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") + } readData := libunlynx.StartTimer(p.Name() + "_ShufflingPlusDDT(ReadData)") sm := ShufflingPlusDDTMessage{} - err := sm.FromBytes(tmp.Data, tmp.ShuffKey, shufflingPlusDDTBytesMessageLength.CVLengths) + err := sm.FromBytes(spDDTbs.Data, spDDTbs.ShuffKey, shufflingPlusDDTBytesMessageLength.CVLengths) if err != nil { return err } @@ -190,9 +202,9 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { defer wg.Done() for j := 0; j < libunlynx.VPARALLELIZE && (i+j) < len(shuffledData); j++ { for k := range shuffledData[i+j] { - tmp := libunlynx.SuiTe.Point().Add(shuffledData[i+j][k].C, toAdd) + r := libunlynx.SuiTe.Point().Add(shuffledData[i+j][k].C, toAdd) if p.Proofs { - _, tmpErr := libunlynxdetertag.DeterministicTagAdditionProofCreation(shuffledData[i+j][k].C, *p.SurveySecretKey, toAdd, tmp) + _, tmpErr := libunlynxdetertag.DeterministicTagAdditionProofCreation(shuffledData[i+j][k].C, *p.SurveySecretKey, toAdd, r) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -200,7 +212,7 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { return } } - shuffledData[i+j][k].C = tmp + shuffledData[i+j][k].C = r } } }(i) @@ -223,10 +235,10 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { go func(i int) { defer wg.Done() for j := 0; j < libunlynx.VPARALLELIZE && (i+j) < len(shuffledData); j++ { - tmp := shuffledData[i+j] - switchedVect := libunlynxdetertag.DeterministicTagSequence(tmp, p.Private(), *p.SurveySecretKey) + vBef := shuffledData[i+j] + vAft := libunlynxdetertag.DeterministicTagSequence(vBef, p.Private(), *p.SurveySecretKey) if p.Proofs { - _, tmpErr := libunlynxdetertag.DeterministicTagCrListProofCreation(tmp, switchedVect, p.Public(), *p.SurveySecretKey, p.Private()) + _, tmpErr := libunlynxdetertag.DeterministicTagCrListProofCreation(vBef, vAft, p.Public(), *p.SurveySecretKey, p.Private()) if tmpErr != nil { mutex.Lock() err = tmpErr @@ -234,7 +246,7 @@ func (p *ShufflingPlusDDTProtocol) Dispatch() error { return } } - copy(shuffledData[i+j], switchedVect) + copy(shuffledData[i+j], vAft) } }(i) } diff --git a/protocols/shuffling_protocol.go b/protocols/shuffling_protocol.go index 8d82fff..acc6fc7 100644 --- a/protocols/shuffling_protocol.go +++ b/protocols/shuffling_protocol.go @@ -4,7 +4,7 @@ package protocolsunlynx import ( - "errors" + "fmt" "time" "github.com/ldsec/unlynx/lib" @@ -101,11 +101,11 @@ func NewShufflingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, erro } if err := dsp.RegisterChannel(&dsp.PreviousNodeInPathChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } if err := dsp.RegisterChannel(&dsp.LengthNodeChannel); err != nil { - return nil, errors.New("couldn't register data reference channel: " + err.Error()) + return nil, fmt.Errorf("couldn't register data reference channel: %v", err) } // choose next node in circuit @@ -116,6 +116,7 @@ func NewShufflingProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, erro break } } + return dsp, nil } @@ -125,7 +126,7 @@ func (p *ShufflingProtocol) Start() error { shufflingStart := libunlynx.StartTimer(p.Name() + "_Shuffling(START)") if p.ShuffleTarget == nil { - return errors.New("no map given as shuffling target") + return fmt.Errorf("no map given as shuffling target") } p.ExecTimeStart = 0 @@ -186,11 +187,22 @@ func (p *ShufflingProtocol) Start() error { func (p *ShufflingProtocol) Dispatch() error { defer p.Done() - shufflingBytesMessageLength := <-p.LengthNodeChannel + var shufflingBytesMessageLength shufflingBytesLengthStruct + select { + case shufflingBytesMessageLength = <-p.LengthNodeChannel: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") + } + + var sbs shufflingBytesStruct + select { + case sbs = <-p.PreviousNodeInPathChannel: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") + } - tmp := <-p.PreviousNodeInPathChannel sm := ShufflingMessage{} - if err := sm.FromBytes(tmp.Data, shufflingBytesMessageLength.CVLengths); err != nil { + if err := sm.FromBytes(sbs.Data, shufflingBytesMessageLength.CVLengths); err != nil { return err } shuffleTarget := sm.Data diff --git a/protocols/tools_protocol.go b/protocols/tools_protocol.go index 7474180..b882ecb 100644 --- a/protocols/tools_protocol.go +++ b/protocols/tools_protocol.go @@ -3,7 +3,7 @@ package protocolsunlynx import ( - "errors" + "fmt" "github.com/ldsec/unlynx/lib" ) @@ -13,7 +13,7 @@ import ( // RetrieveSimpleDataFromMap extract the data from a map into an array func RetrieveSimpleDataFromMap(groupedData map[libunlynx.GroupingKey]libunlynx.FilteredResponse) ([]libunlynx.CipherText, error) { if len(groupedData) != 1 { - return nil, errors.New("the map given in arguments is empty or have more than one key") + return nil, fmt.Errorf("the map given in arguments is empty or have more than one key") } filteredResp, present := groupedData[EMPTYKEY] @@ -25,7 +25,7 @@ func RetrieveSimpleDataFromMap(groupedData map[libunlynx.GroupingKey]libunlynx.F return result, nil } - return nil, errors.New("the map element doesn't have key with value EMPTYKEY") + return nil, fmt.Errorf("the map element doesn't have key with value EMPTYKEY") } // _____________________ DETERMINISTIC_TAGGING PROTOCOL _____________________ diff --git a/protocols/utils/addrm_server_protocol.go b/protocols/utils/addrm_server_protocol.go index 9cdd695..9fbcc91 100644 --- a/protocols/utils/addrm_server_protocol.go +++ b/protocols/utils/addrm_server_protocol.go @@ -4,8 +4,9 @@ package protocolsunlynxutils import ( - "errors" + "fmt" "sync" + "time" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/add_rm" @@ -78,7 +79,7 @@ func (p *AddRmServerProtocol) Start() error { roundProof = libunlynx.StartTimer(p.Name() + "_AddRmServer(PROOFSVerif)") if p.Proofs && len(proofs.List) == 0 { - return errors.New("something went wrong during the creation of the add/rm proofs") + return fmt.Errorf("something went wrong during the creation of the add/rm proofs") } libunlynxaddrm.AddRmListProofVerification(proofs, 1.0) @@ -92,8 +93,14 @@ func (p *AddRmServerProtocol) Start() error { func (p *AddRmServerProtocol) Dispatch() error { defer p.Done() - aux := <-finalResultAddrm - p.FeedbackChannel <- aux + var finalResultMessage []libunlynx.CipherText + select { + case finalResultMessage = <-finalResultAddrm: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") + } + + p.FeedbackChannel <- finalResultMessage return nil } @@ -116,13 +123,12 @@ func changeEncryption(cipherTexts []libunlynx.CipherText, serverAddRmKey kyber.S } func changeEncryptionKeyCipherTexts(cipherText libunlynx.CipherText, serverAddRmKey kyber.Scalar, toAdd bool) libunlynx.CipherText { - tmp := libunlynx.SuiTe.Point().Mul(serverAddRmKey, cipherText.K) result := libunlynx.CipherText{} result.K = cipherText.K if toAdd { - result.C = libunlynx.SuiTe.Point().Add(cipherText.C, tmp) + result.C = libunlynx.SuiTe.Point().Add(cipherText.C, libunlynx.SuiTe.Point().Mul(serverAddRmKey, cipherText.K)) } else { - result.C = libunlynx.SuiTe.Point().Sub(cipherText.C, tmp) + result.C = libunlynx.SuiTe.Point().Sub(cipherText.C, libunlynx.SuiTe.Point().Mul(serverAddRmKey, cipherText.K)) } return result } diff --git a/protocols/utils/local_aggregation_protocol.go b/protocols/utils/local_aggregation_protocol.go index 226af6a..665cb3b 100644 --- a/protocols/utils/local_aggregation_protocol.go +++ b/protocols/utils/local_aggregation_protocol.go @@ -3,10 +3,12 @@ package protocolsunlynxutils import ( + "fmt" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/aggregation" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "time" ) // LocalAggregationProtocolName is the registered name for the local aggregation protocol. @@ -41,7 +43,6 @@ func NewLocalAggregationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstanc TreeNodeInstance: n, FeedbackChannel: make(chan map[libunlynx.GroupingKey]libunlynx.FilteredResponse), } - return pvp, nil } @@ -83,7 +84,13 @@ func (p *LocalAggregationProtocol) Start() error { func (p *LocalAggregationProtocol) Dispatch() error { defer p.Done() - aux := <-finalResultAggr - p.FeedbackChannel <- aux + var finalResultMessage map[libunlynx.GroupingKey]libunlynx.FilteredResponse + select { + case finalResultMessage = <-finalResultAggr: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") + } + + p.FeedbackChannel <- finalResultMessage return nil } diff --git a/protocols/utils/local_clear_aggregation_protocol.go b/protocols/utils/local_clear_aggregation_protocol.go index 5924f0c..9e73549 100644 --- a/protocols/utils/local_clear_aggregation_protocol.go +++ b/protocols/utils/local_clear_aggregation_protocol.go @@ -3,10 +3,12 @@ package protocolsunlynxutils import ( + "fmt" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/store" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "time" ) // LocalClearAggregationProtocolName is the registered name for the local cleartext aggregation protocol. @@ -37,7 +39,6 @@ func NewLocalClearAggregationProtocol(n *onet.TreeNodeInstance) (onet.ProtocolIn TreeNodeInstance: n, FeedbackChannel: make(chan []libunlynx.DpClearResponse), } - return pvp, nil } @@ -57,7 +58,13 @@ func (p *LocalClearAggregationProtocol) Start() error { func (p *LocalClearAggregationProtocol) Dispatch() error { defer p.Done() - aux := <-finalResultClearAggr - p.FeedbackChannel <- aux + var finalResultMessage []libunlynx.DpClearResponse + select { + case finalResultMessage = <-finalResultClearAggr: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") + } + + p.FeedbackChannel <- finalResultMessage return nil } diff --git a/protocols/utils/proofs_verification_protocol.go b/protocols/utils/proofs_verification_protocol.go index 61cbaee..7cbf169 100644 --- a/protocols/utils/proofs_verification_protocol.go +++ b/protocols/utils/proofs_verification_protocol.go @@ -5,6 +5,7 @@ package protocolsunlynxutils import ( + "fmt" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/aggregation" "github.com/ldsec/unlynx/lib/deterministic_tag" @@ -12,6 +13,7 @@ import ( "github.com/ldsec/unlynx/lib/shuffle" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "time" ) // ProofsVerificationProtocolName is the registered name for the proof verification protocol. @@ -107,7 +109,13 @@ func (p *ProofsVerificationProtocol) Start() error { func (p *ProofsVerificationProtocol) Dispatch() error { defer p.Done() - aux := <-finalResult - p.FeedbackChannel <- aux + var finalResultMessage []bool + select { + case finalResultMessage = <-finalResult: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(p.ServerIdentity().String() + " didn't get the on time") + } + + p.FeedbackChannel <- finalResultMessage return nil } diff --git a/protocols/utils/proofs_verification_test.go b/protocols/utils/proofs_verification_test.go index 211dde2..07283e5 100644 --- a/protocols/utils/proofs_verification_test.go +++ b/protocols/utils/proofs_verification_test.go @@ -67,14 +67,14 @@ func TestProofsVerification(t *testing.T) { toAddWrong := libunlynx.SuiTe.Point().Mul(secKey, libunlynx.SuiTe.Point().Base()) for j := 0; j < 2; j++ { for i := range cipherVect { - tmp := libunlynx.SuiTe.Point() + point := libunlynx.SuiTe.Point() if j%2 == 0 { - tmp = libunlynx.SuiTe.Point().Add(cipherVect[i].C, toAdd) + point = libunlynx.SuiTe.Point().Add(cipherVect[i].C, toAdd) } else { - tmp = libunlynx.SuiTe.Point().Add(cipherVect[i].C, toAddWrong) + point = libunlynx.SuiTe.Point().Add(cipherVect[i].C, toAddWrong) } - prf, err := libunlynxdetertag.DeterministicTagAdditionProofCreation(cipherVect[i].C, secKeyNew, toAdd, tmp) + prf, err := libunlynxdetertag.DeterministicTagAdditionProofCreation(cipherVect[i].C, secKeyNew, toAdd, point) assert.NoError(t, err) deterministicTaggingAddProofs.List = append(deterministicTaggingAddProofs.List, prf) } diff --git a/services/service.go b/services/service.go index f342d1f..dddecc0 100644 --- a/services/service.go +++ b/services/service.go @@ -1,8 +1,10 @@ package servicesunlynx import ( - "errors" + "fmt" + "golang.org/x/xerrors" "strconv" + "time" "github.com/Knetic/govaluate" "github.com/fanliao/go-concurrentMap" @@ -126,17 +128,16 @@ type ServiceResult struct { // Service defines a service in unlynx with a survey. type Service struct { *onet.ServiceProcessor - Survey *concurrent.ConcurrentMap } func (s *Service) getSurvey(sid SurveyID) (Survey, error) { surv, err := s.Survey.Get(string(sid)) if err != nil { - return Survey{}, errors.New("Error" + err.Error() + "while getting surveyID" + string(sid)) + return Survey{}, fmt.Errorf("error while getting surveyID "+string(sid)+": %v", err) } if surv == nil { - return Survey{}, errors.New("Empty map entry while getting surveyID" + string(sid)) + return Survey{}, fmt.Errorf("empty map entry while getting surveyID " + string(sid)) } return surv.(Survey), nil } @@ -154,19 +155,19 @@ func NewService(c *onet.Context) (onet.Service, error) { } var cerr error if cerr = newUnLynxInstance.RegisterHandler(newUnLynxInstance.HandleSurveyCreationQuery); cerr != nil { - return nil, errors.New("Wrong Handler." + cerr.Error()) + return nil, fmt.Errorf("wrong Handler: %v", cerr) } if cerr = newUnLynxInstance.RegisterHandler(newUnLynxInstance.HandleSurveyResponseQuery); cerr != nil { - return nil, errors.New("Wrong Handler." + cerr.Error()) + return nil, fmt.Errorf("wrong Handler: %v", cerr) } if cerr = newUnLynxInstance.RegisterHandler(newUnLynxInstance.HandleSurveyResultsQuery); cerr != nil { - return nil, errors.New("Wrong Handler." + cerr.Error()) + return nil, fmt.Errorf("wrong Handler: %v", cerr) } if cerr = newUnLynxInstance.RegisterHandler(newUnLynxInstance.HandleDDTfinished); cerr != nil { - return nil, errors.New("Wrong Handler." + cerr.Error()) + return nil, fmt.Errorf("wrong Handler: %v", cerr) } if cerr = newUnLynxInstance.RegisterHandler(newUnLynxInstance.HandleQueryBroadcastFinished); cerr != nil { - return nil, errors.New("Wrong Handler." + cerr.Error()) + return nil, fmt.Errorf("wrong Handler: %v", cerr) } c.RegisterProcessor(newUnLynxInstance, msgTypes.msgSurveyCreationQuery) @@ -179,26 +180,26 @@ func NewService(c *onet.Context) (onet.Service, error) { // Process implements the processor interface and is used to recognize messages broadcasted between servers func (s *Service) Process(msg *network.Envelope) { if msg.MsgType.Equal(msgTypes.msgSurveyCreationQuery) { - tmp := (msg.Msg).(*SurveyCreationQuery) - _, err := s.HandleSurveyCreationQuery(tmp) + msgSurveyCreationQuery := (msg.Msg).(*SurveyCreationQuery) + _, err := s.HandleSurveyCreationQuery(msgSurveyCreationQuery) if err != nil { log.Error(err) } } else if msg.MsgType.Equal(msgTypes.msgSurveyResultsQuery) { - tmp := (msg.Msg).(*SurveyResultsQuery) - _, err := s.HandleSurveyResultsQuery(tmp) + msgSurveyResultsQuery := (msg.Msg).(*SurveyResultsQuery) + _, err := s.HandleSurveyResultsQuery(msgSurveyResultsQuery) if err != nil { log.Error(err) } } else if msg.MsgType.Equal(msgTypes.msgQueryBroadcastFinished) { - tmp := (msg.Msg).(*QueryBroadcastFinished) - _, err := s.HandleQueryBroadcastFinished(tmp) + msgQueryBroadcastFinished := (msg.Msg).(*QueryBroadcastFinished) + _, err := s.HandleQueryBroadcastFinished(msgQueryBroadcastFinished) if err != nil { log.Error(err) } } else if msg.MsgType.Equal(msgTypes.msgDDTfinished) { - tmp := (msg.Msg).(*DDTfinished) - _, err := s.HandleDDTfinished(tmp) + msgDDTfinished := (msg.Msg).(*DDTfinished) + _, err := s.HandleDDTfinished(msgDDTfinished) if err != nil { log.Error(err) } @@ -236,7 +237,7 @@ func (s *Service) HandleSurveyCreationQuery(recq *SurveyCreationQuery) (network. log.Lvl1(s.ServerIdentity().String(), " received a Survey Creation Query") // if this server is the one receiving the query from the client - if recq.IntraMessage == false { + if !recq.IntraMessage { id := uuid.NewV4() newID := SurveyID(id.String()) recq.SurveyID = newID @@ -270,7 +271,7 @@ func (s *Service) HandleSurveyCreationQuery(recq *SurveyCreationQuery) (network. } log.Lvl1(s.ServerIdentity(), " initiated the survey ", recq.SurveyID) - if recq.IntraMessage == false { + if !recq.IntraMessage { recq.IntraMessage = true recq.Source = s.ServerIdentity() // broadcasts the query @@ -317,7 +318,7 @@ func (s *Service) HandleSurveyCreationQuery(recq *SurveyCreationQuery) (network. survey.DpChannel <- 1 } - if recq.IntraMessage == false { + if !recq.IntraMessage { survey, err := s.getSurvey(recq.SurveyID) if err != nil { return nil, err @@ -361,7 +362,7 @@ func (s *Service) HandleSurveyResultsQuery(resq *SurveyResultsQuery) (network.Me return nil, err } - if resq.IntraMessage == false { + if !resq.IntraMessage { resq.IntraMessage = true err := libunlynxtools.SendISMOthers(s.ServiceProcessor, &survey.Query.Roster, resq) @@ -416,13 +417,7 @@ func (s *Service) HandleQueryBroadcastFinished(recq *QueryBroadcastFinished) (ne // NewProtocol creates a protocol instance executed by all nodes func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfig) (onet.ProtocolInstance, error) { - err := tn.SetConfig(conf) - if err != nil { - return nil, err - } - var pi onet.ProtocolInstance - target := SurveyID(string(conf.Data)) survey, err := s.getSurvey(SurveyID(conf.Data)) if err != nil { @@ -473,18 +468,18 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfi var queryWhereToTag []libunlynx.ProcessResponse for _, v := range survey.Query.Where { - tmp := libunlynx.CipherVector{v.Value} - queryWhereToTag = append(queryWhereToTag, libunlynx.ProcessResponse{WhereEnc: tmp, GroupByEnc: nil, AggregatingAttributes: nil}) + cv := libunlynx.CipherVector{v.Value} + queryWhereToTag = append(queryWhereToTag, libunlynx.ProcessResponse{WhereEnc: cv, GroupByEnc: nil, AggregatingAttributes: nil}) } shuffledClientResponses = append(queryWhereToTag, shuffledClientResponses...) - tmpDeterministicTOS := protocolsunlynx.ProcessResponseToCipherVector(shuffledClientResponses) + deterministicTOS := protocolsunlynx.ProcessResponseToCipherVector(shuffledClientResponses) survey.TargetOfSwitch = shuffledClientResponses err = s.putSurvey(target, survey) if err != nil { return nil, err } - hashCreation.TargetOfSwitch = &tmpDeterministicTOS + hashCreation.TargetOfSwitch = &deterministicTOS } case protocolsunlynx.CollectiveAggregationProtocolName: @@ -561,16 +556,16 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfi if tn.IsRoot() { var coaggr []libunlynx.FilteredResponse - if libunlynx.DIFFPRI == true { + if libunlynx.DIFFPRI { coaggr = survey.PullCothorityAggregatedFilteredResponses(true, survey.Noise) } else { coaggr = survey.PullCothorityAggregatedFilteredResponses(false, libunlynx.CipherText{}) } - var tmpKeySwitchingCV libunlynx.CipherVector - tmpKeySwitchingCV, survey.Lengths = protocolsunlynx.FilteredResponseToCipherVector(coaggr) - keySwitch.TargetOfSwitch = &tmpKeySwitchingCV - tmp := survey.Query.ClientPubKey - keySwitch.TargetPublicKey = &tmp + var cv libunlynx.CipherVector + cv, survey.Lengths = protocolsunlynx.FilteredResponseToCipherVector(coaggr) + keySwitch.TargetOfSwitch = &cv + cpk := survey.Query.ClientPubKey + keySwitch.TargetPublicKey = &cpk err = s.putSurvey(target, survey) if err != nil { @@ -578,28 +573,30 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfi } } default: - return nil, errors.New("Service attempts to start an unknown protocol: " + tn.ProtocolName() + ".") + return nil, fmt.Errorf("service attempts to start an unknown protocol: " + tn.ProtocolName()) } - return pi, nil } // StartProtocol starts a specific protocol (Pipeline, Shuffling, etc.) func (s *Service) StartProtocol(name string, targetSurvey SurveyID) (onet.ProtocolInstance, error) { - tmp, err := s.getSurvey(targetSurvey) + survey, err := s.getSurvey(targetSurvey) if err != nil { return nil, err } - tree := tmp.Query.Roster.GenerateNaryTreeWithRoot(2, s.ServerIdentity()) + tree := survey.Query.Roster.GenerateNaryTreeWithRoot(2, s.ServerIdentity()) var tn *onet.TreeNodeInstance tn = s.NewTreeNodeInstance(tree, tree.Root, name) conf := onet.GenericConfig{Data: []byte(string(targetSurvey))} + if err := tn.SetConfig(&conf); err != nil { + return nil, xerrors.Errorf("couldn't set config: %+v", err) + } pi, err := s.NewProtocol(tn, &conf) if err != nil { - return nil, errors.New("Error running " + name + " :" + err.Error()) + return nil, fmt.Errorf("error running "+name+" : %v", err) } err = s.RegisterProtocolInstance(pi) @@ -652,7 +649,7 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error { err = s.ShufflingPhase(survey.Query.SurveyID) if err != nil { - return errors.New("Error in the Shuffling Phase: " + err.Error()) + return fmt.Errorf("error in the Shuffling Phase: %v", err) } libunlynx.EndTimer(start) @@ -661,7 +658,7 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error { err = s.TaggingPhase(target.Query.SurveyID) if err != nil { - return errors.New("Error in the Tagging Phase: " + err.Error()) + return fmt.Errorf("error in the Tagging Phase: %v", err) } // broadcasts the query to unlock waiting channel @@ -674,36 +671,36 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error { libunlynx.EndTimer(start) // Aggregation Phase - if root == true { + if root { start := libunlynx.StartTimer(s.ServerIdentity().String() + "_AggregationPhase") err = s.AggregationPhase(target.Query.SurveyID) if err != nil { - return errors.New("Error in the Aggregation Phase: " + err.Error()) + return fmt.Errorf("error in the Aggregation Phase: %v", err) } libunlynx.EndTimer(start) } // DRO Phase - if root == true && libunlynx.DIFFPRI == true { + if root && libunlynx.DIFFPRI { start := libunlynx.StartTimer(s.ServerIdentity().String() + "_DROPhase") err := s.DROPhase(target.Query.SurveyID) if err != nil { - return errors.New("Error in the DRO Phase: " + err.Error()) + return fmt.Errorf("error in the DRO Phase: %v", err) } libunlynx.EndTimer(start) } // Key Switch Phase - if root == true { + if root { start := libunlynx.StartTimer(s.ServerIdentity().String() + "_KeySwitchingPhase") err := s.KeySwitchingPhase(target.Query.SurveyID) if err != nil { - return errors.New("Error in the Key Switching Phase: " + err.Error()) + return fmt.Errorf("error in the Key Switching Phase: %v", err) } libunlynx.EndTimer(start) @@ -728,7 +725,13 @@ func (s *Service) ShufflingPhase(targetSurvey SurveyID) error { if err != nil { return err } - tmpShufflingResult := <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel + + var tmpShufflingResult []libunlynx.CipherVector + select { + case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") + } survey, err = s.getSurvey(targetSurvey) if err != nil { @@ -758,7 +761,12 @@ func (s *Service) TaggingPhase(targetSurvey SurveyID) error { return err } - tmpDeterministicTaggingResult := <-pi.(*protocolsunlynx.DeterministicTaggingProtocol).FeedbackChannel + var tmpDeterministicTaggingResult []libunlynx.DeterministCipherText + select { + case tmpDeterministicTaggingResult = <-pi.(*protocolsunlynx.DeterministicTaggingProtocol).FeedbackChannel: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") + } survey, err = s.getSurvey(targetSurvey) if err != nil { @@ -791,14 +799,20 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error { if err != nil { return err } - cothorityAggregatedData := <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel + + var tmpAggreagtionResult protocolsunlynx.CothorityAggregatedData + select { + case tmpAggreagtionResult = <-pi.(*protocolsunlynx.CollectiveAggregationProtocol).FeedbackChannel: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") + } survey, err := s.getSurvey(targetSurvey) if err != nil { return err } - survey.PushCothorityAggregatedFilteredResponses(cothorityAggregatedData.GroupedData) + survey.PushCothorityAggregatedFilteredResponses(tmpAggreagtionResult.GroupedData) err = s.putSurvey(targetSurvey, survey) return err } @@ -815,7 +829,13 @@ func (s *Service) DROPhase(targetSurvey SurveyID) error { return err } - tmpShufflingResult := <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel + var tmpShufflingResult []libunlynx.CipherVector + select { + case tmpShufflingResult = <-pi.(*protocolsunlynx.ShufflingProtocol).FeedbackChannel: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") + } + shufflingResult := protocolsunlynx.MatrixCipherTextToProcessResponse(tmpShufflingResult, survey.Lengths) survey.Noise = shufflingResult[0].AggregatingAttributes[0] @@ -835,8 +855,14 @@ func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error { return err } - tmpKeySwitchedAggregatedResponses := <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel - keySwitchedAggregatedResponses := protocolsunlynx.CipherVectorToFilteredResponse(tmpKeySwitchedAggregatedResponses, survey.Lengths) + var tmpKeySwitchingResult libunlynx.CipherVector + select { + case tmpKeySwitchingResult = <-pi.(*protocolsunlynx.KeySwitchingProtocol).FeedbackChannel: + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf(s.ServerIdentity().String() + " didn't get the on time") + } + + keySwitchedAggregatedResponses := protocolsunlynx.CipherVectorToFilteredResponse(tmpKeySwitchingResult, survey.Lengths) survey.PushQuerierKeyEncryptedResponses(keySwitchedAggregatedResponses) err = s.putSurvey(targetSurvey, survey) diff --git a/simul/addrm_server_simul.go b/simul/addrm_server_simul.go index 970ebff..512a7ac 100644 --- a/simul/addrm_server_simul.go +++ b/simul/addrm_server_simul.go @@ -1,12 +1,14 @@ package main import ( + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/protocols/utils" "go.dedis.ch/kyber/v3/util/random" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "time" ) func init() { @@ -83,11 +85,14 @@ func (sim *AddRmSimulation) Run(config *onet.SimulationConfig) error { if err := root.Start(); err != nil { return err } - results := <-root.ProtocolInstance().(*protocolsunlynxutils.AddRmServerProtocol).FeedbackChannel - log.Lvl1("Number of aggregated lines: ", len(results)) - - libunlynx.EndTimer(round) + select { + case results := <-root.ProtocolInstance().(*protocolsunlynxutils.AddRmServerProtocol).FeedbackChannel: + log.Lvl1("Number of aggregated lines: ", len(results)) + libunlynx.EndTimer(round) + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf("simulation didn't finish in time") + } } return nil diff --git a/simul/collective_aggregation_simul.go b/simul/collective_aggregation_simul.go index 5a0fe40..aa65aff 100644 --- a/simul/collective_aggregation_simul.go +++ b/simul/collective_aggregation_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/aggregation" @@ -86,7 +86,7 @@ func (sim *CollectiveAggregationSimulation) Node(config *onet.SimulationConfig) func(tni *onet.TreeNodeInstance) (onet.ProtocolInstance, error) { return NewAggregationProtocolSimul(tni, sim) }); err != nil { - return errors.New("Error while registering :" + err.Error()) + return fmt.Errorf("error while registering : %v", err) } return sim.SimulationBFTree.Node(config) diff --git a/simul/deterministic_tagging_simul.go b/simul/deterministic_tagging_simul.go index 4af5050..9b8ac02 100644 --- a/simul/deterministic_tagging_simul.go +++ b/simul/deterministic_tagging_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/protocols" @@ -60,7 +60,7 @@ func (sim *DeterministicTaggingSimulation) Node(config *onet.SimulationConfig) e func(tni *onet.TreeNodeInstance) (onet.ProtocolInstance, error) { return NewDeterministicTaggingSimul(tni, sim) }); err != nil { - return errors.New("Error while registering :" + err.Error()) + return fmt.Errorf("error while registering : %v", err) } return sim.SimulationBFTree.Node(config) diff --git a/simul/local_aggregation_simul.go b/simul/local_aggregation_simul.go index 2e87629..8d90800 100644 --- a/simul/local_aggregation_simul.go +++ b/simul/local_aggregation_simul.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/protocols" @@ -8,6 +9,7 @@ import ( "go.dedis.ch/kyber/v3/util/random" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "time" ) func init() { @@ -82,9 +84,9 @@ func (sim *LocalAggregationSimulation) Run(config *onet.SimulationConfig) error groupCipherVect := *libunlynx.EncryptIntVector(pubKey, tabGr) detResponses := make([]libunlynx.FilteredResponseDet, 0) for i := 0; i < sim.NbrGroups; i++ { - tmp := libunlynx.NewCipherVector(sim.NbrGroupAttributes) - tmp.Add(groupCipherVect, groupCipherVect) - groupCipherVect = *tmp + cv := libunlynx.NewCipherVector(sim.NbrGroupAttributes) + cv.Add(groupCipherVect, groupCipherVect) + groupCipherVect = *cv cr := libunlynx.FilteredResponse{GroupByEnc: testCipherVect1, AggregatingAttributes: testCipherVect1} det1 := groupCipherVect if err := protocolsunlynx.TaggingDet(&det1, secKey, newSecKey, pubKey, sim.Proofs); err != nil { @@ -113,11 +115,14 @@ func (sim *LocalAggregationSimulation) Run(config *onet.SimulationConfig) error if err := root.Start(); err != nil { return err } - results := <-root.ProtocolInstance().(*protocolsunlynxutils.LocalAggregationProtocol).FeedbackChannel - log.Lvl1("Number of aggregated lines: ", len(results)) - - libunlynx.EndTimer(round) + select { + case results := <-root.ProtocolInstance().(*protocolsunlynxutils.LocalAggregationProtocol).FeedbackChannel: + log.Lvl1("Number of aggregated lines: ", len(results)) + libunlynx.EndTimer(round) + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf("simulation didn't finish in time") + } } return nil diff --git a/simul/local_clear_aggregation_simul.go b/simul/local_clear_aggregation_simul.go index 4029436..6fd7ef4 100644 --- a/simul/local_clear_aggregation_simul.go +++ b/simul/local_clear_aggregation_simul.go @@ -1,12 +1,15 @@ package main import ( + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/data" + libunlynx "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/protocols/utils" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" "go.dedis.ch/onet/v3/simul/monitor" + "time" ) func init() { @@ -83,16 +86,20 @@ func (sim *LocalClearAggregationSimulation) Run(config *onet.SimulationConfig) e if err := root.Start(); err != nil { return err } - results := <-root.ProtocolInstance().(*protocolsunlynxutils.LocalClearAggregationProtocol).FeedbackChannel - log.Lvl1("Number of aggregated lines (groups): ", len(results)) - - // Test Simulation - if dataunlynx.CompareClearResponses(dataunlynx.ComputeExpectedResult(testData, 1, false), results) { - log.Lvl1("Result is right! :)") - } else { - log.Lvl1("Result is wrong! :(") + + select { + case results := <-root.ProtocolInstance().(*protocolsunlynxutils.LocalClearAggregationProtocol).FeedbackChannel: + log.Lvl1("Number of aggregated lines (groups): ", len(results)) + // Test Simulation + if dataunlynx.CompareClearResponses(dataunlynx.ComputeExpectedResult(testData, 1, false), results) { + log.Lvl1("Result is right! :)") + } else { + log.Lvl1("Result is wrong! :(") + } + round.Record() + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf("simulation didn't finish in time") } - round.Record() } return nil diff --git a/simul/proofs_verification_simul.go b/simul/proofs_verification_simul.go index feefbb1..f2e75a4 100644 --- a/simul/proofs_verification_simul.go +++ b/simul/proofs_verification_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/aggregation" @@ -14,6 +14,7 @@ import ( "go.dedis.ch/kyber/v3/util/random" "go.dedis.ch/onet/v3" "go.dedis.ch/onet/v3/log" + "time" ) func init() { @@ -55,7 +56,6 @@ func (sim *ProofsVerificationSimulation) Setup(dir string, hosts []string) (*one // Run starts the simulation. func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) error { - for round := 0; round < sim.Rounds; round++ { log.Lvl1("Starting round", round) rooti, err := config.Overlay.CreateProtocol("ProofsVerification", config.Tree, onet.NilServiceID) @@ -115,8 +115,8 @@ func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) erro toAdd := libunlynx.SuiTe.Point().Mul(secKeyNew, libunlynx.SuiTe.Point().Base()) for i := range cipherVect { - tmp := libunlynx.SuiTe.Point().Add(cipherVect[i].C, toAdd) - prf, err := libunlynxdetertag.DeterministicTagAdditionProofCreation(cipherVect[i].C, secKeyNew, toAdd, tmp) + r := libunlynx.SuiTe.Point().Add(cipherVect[i].C, toAdd) + prf, err := libunlynxdetertag.DeterministicTagAdditionProofCreation(cipherVect[i].C, secKeyNew, toAdd, r) if err != nil { return err } @@ -145,10 +145,10 @@ func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) erro detResponses := make([]libunlynx.FilteredResponseDet, 0) for i := 0; i < sim.NbrGroups; i++ { - tmp := libunlynx.NewCipherVector(sim.NbrGroupAttributes) - tmp.Add(cipherVectGr, cipherVectGr) + cv := libunlynx.NewCipherVector(sim.NbrGroupAttributes) + cv.Add(cipherVectGr, cipherVectGr) - cipherVectGr = *tmp + cipherVectGr = *cv det1 := cipherVectGr if err := protocolsunlynx.TaggingDet(&det1, secKey, secKey, pubKey, false); err != nil { return err @@ -231,23 +231,27 @@ func (sim *ProofsVerificationSimulation) Run(config *onet.SimulationConfig) erro if err := root.Start(); err != nil { return err } - results := <-root.ProtocolInstance().(*protocolsunlynxutils.ProofsVerificationProtocol).FeedbackChannel - libunlynx.EndTimer(round) - - log.Lvl1(len(results), " proofs verified") - - if results[0] == false { - return errors.New("key switching proofs failed") - } else if results[1] == false { - return errors.New("deterministic tagging (creation) proofs failed") - } else if results[2] == false { - return errors.New("deterministic tagging (addition) proofs failed") - } else if results[3] == false { - return errors.New("local aggregation proofs failed") - } else if results[4] == false { - return errors.New("shuffling proofs failed") - } else if results[5] == false { - return errors.New("collective aggregation proofs failed") + select { + case results := <-root.ProtocolInstance().(*protocolsunlynxutils.ProofsVerificationProtocol).FeedbackChannel: + libunlynx.EndTimer(round) + + log.Lvl1(len(results), " proofs verified") + + if !results[0] { + return fmt.Errorf("key switching proofs failed") + } else if !results[1] { + return fmt.Errorf("deterministic tagging (creation) proofs failed") + } else if !results[2] { + return fmt.Errorf("deterministic tagging (addition) proofs failed") + } else if !results[3] { + return fmt.Errorf("local aggregation proofs failed") + } else if !results[4] { + return fmt.Errorf("shuffling proofs failed") + } else if !results[5] { + return fmt.Errorf("collective aggregation proofs failed") + } + case <-time.After(libunlynx.TIMEOUT): + return fmt.Errorf("simulation didn't finish in time") } } return nil diff --git a/simul/shuffling+ddt_simul.go b/simul/shuffling+ddt_simul.go index 9927471..2552fdc 100644 --- a/simul/shuffling+ddt_simul.go +++ b/simul/shuffling+ddt_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/shuffle" @@ -54,7 +54,7 @@ func (sim *ShufflingPlusDDTSimulation) Node(config *onet.SimulationConfig) error func(tni *onet.TreeNodeInstance) (onet.ProtocolInstance, error) { return NewShufflingPlusDDTSimul(tni, sim) }); err != nil { - return errors.New("Error while registering :" + err.Error()) + return fmt.Errorf("error while registering : %v", err) } return sim.SimulationBFTree.Node(config) diff --git a/simul/shuffling_simul.go b/simul/shuffling_simul.go index d1f60c5..b0be658 100644 --- a/simul/shuffling_simul.go +++ b/simul/shuffling_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/BurntSushi/toml" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/shuffle" @@ -56,7 +56,7 @@ func (sim *ShufflingSimulation) Node(config *onet.SimulationConfig) error { func(tni *onet.TreeNodeInstance) (onet.ProtocolInstance, error) { return NewShufflingSimul(tni, sim) }); err != nil { - return errors.New("Error while registering :" + err.Error()) + return fmt.Errorf("error while registering : %v", err) } return sim.SimulationBFTree.Node(config) diff --git a/simul/test_data/time_data/parse_time_data.go b/simul/test_data/time_data/parse_time_data.go index 3862ca0..f97de1b 100644 --- a/simul/test_data/time_data/parse_time_data.go +++ b/simul/test_data/time_data/parse_time_data.go @@ -56,7 +56,7 @@ func ReadTomlSetup(filename string, setupNbr int) (map[string]string, error) { c := strings.Split(line, ", ") - if flag == true { + if flag { if pos == setupNbr { for i, el := range c { setup[parameters[i]] = el diff --git a/simul/unlynx_simul.go b/simul/unlynx_simul.go index dcbdfc3..12053b0 100644 --- a/simul/unlynx_simul.go +++ b/simul/unlynx_simul.go @@ -1,7 +1,7 @@ package main import ( - "errors" + "fmt" "github.com/ldsec/unlynx/data" "github.com/ldsec/unlynx/lib" "github.com/ldsec/unlynx/lib/tools" @@ -74,7 +74,7 @@ func (sim *SimulationUnLynx) Run(config *onet.SimulationConfig) error { // Does not make sense to have more servers than clients!! if nbrHosts > sim.NbrDPs { - return errors.New("hosts: " + strconv.FormatInt(int64(nbrHosts), 10) + " must be the same or lower as num_clients " + strconv.FormatInt(int64(sim.NbrDPs), 10)) + return fmt.Errorf("hosts: " + strconv.FormatInt(int64(nbrHosts), 10) + " must be the same or lower as num_clients " + strconv.FormatInt(int64(sim.NbrDPs), 10)) } el := (*config.Tree).Roster @@ -155,7 +155,7 @@ func (sim *SimulationUnLynx) Run(config *onet.SimulationConfig) error { client = servicesunlynx.NewUnLynxClient(server, strconv.Itoa(i+1)) if tmpErr := client.SendSurveyResponseQuery(*surveyID, dataCollection, el.Aggregate, sim.DataRepetitions, count); tmpErr != nil { mutex.Lock() - err = errors.New("Error while sending DP (" + client.String() + ") responses:" + err.Error()) + err = fmt.Errorf("Error while sending DP ("+client.String()+") responses: %v", err) log.Error(err) mutex.Unlock() } @@ -174,7 +174,7 @@ func (sim *SimulationUnLynx) Run(config *onet.SimulationConfig) error { grp, aggr, err := client.SendSurveyResultsQuery(*surveyID) if err != nil { - return errors.New("Service could not output the results: " + err.Error()) + return fmt.Errorf("service could not output the results: %v", err) } libunlynx.EndTimer(start)