Skip to content

Commit 427401f

Browse files
authored
Merge pull request #14 from lca1/homoProto
unlynx_v2 the big and great cleanup
2 parents 2c30724 + 4f75d95 commit 427401f

File tree

104 files changed

+5307
-5605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+5307
-5605
lines changed

.gitignore

+2-14
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,17 @@ _testmain.go
3030

3131
.idea/
3232

33-
services/default/data/*.txt
34-
services/unlynxMedCo/*.toml
33+
data/*.txt
3534

3635
simul/test_data/*.csv
3736
simul/test_data/graphs/*.pdf
3837
simul/test_data/time_data/*.txt
3938
simul/build/
4039
simul/deploy/
4140
simul/simul
42-
simul/deter.toml
43-
44-
app/default/*.toml
45-
app/default/test
46-
app/default/service_storage
47-
app/unlynxMedCo/*.toml
48-
app/unlynxMedCo/loader/files/*
49-
app/unlynxMedCo/loader/26-load-data.sh
50-
app/unlynxMedCo/loader/*.toml
51-
app/unlynxMedCo/loader/*.txt
52-
app/unlynxMedCo/graphs/*.pdf
5341

5442
unlynx
55-
#unlynxMedCo
43+
app/unlynx
5644
server_list
5745

5846
pre_compute_multiplications.gob

.travis.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ go:
66
env:
77
- GO111MODULE=on
88

9-
install:
10-
- go get -t ./...
11-
129
script:
13-
- make test
10+
- env GO111MODULE=on make test
1411

1512
after_success:
1613
- $GOPATH/bin/goveralls -coverprofile=profile.cov -service=travis-ci
1714

1815
notifications:
19-
email: false
16+
email: false

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test_lint:
2727
}
2828

2929
test_local:
30-
go test -v -race -short -p=1 -tags vartime ./...
30+
go test -v -race -short -p=1 ./...
3131

3232
test_codecov:
3333
./coveralls.sh

app/client.go

+33-34
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
11
package appunlynx
22

33
import (
4+
"errors"
45
"os"
6+
"regexp"
7+
"strconv"
8+
"strings"
59

6-
"github.com/btcsuite/goleveldb/leveldb/errors"
710
"github.com/lca1/unlynx/lib"
8-
"github.com/lca1/unlynx/services/default"
11+
"github.com/lca1/unlynx/services"
912
"go.dedis.ch/onet/v3"
1013
"go.dedis.ch/onet/v3/app"
1114
"go.dedis.ch/onet/v3/log"
1215
"gopkg.in/urfave/cli.v1"
13-
"regexp"
14-
"strconv"
15-
"strings"
1616
)
1717

1818
// BEGIN CLIENT: QUERIER ----------
19-
func startQuery(el *onet.Roster, proofs bool, sum []string, count bool, whereQueryValues []libunlynx.WhereQueryAttribute, predicate string, groupBy []string) {
20-
client := servicesunlynxdefault.NewUnLynxClient(el.List[0], strconv.Itoa(0))
19+
func startQuery(el *onet.Roster, proofs bool, sum []string, count bool, whereQueryValues []libunlynx.WhereQueryAttribute, predicate string, groupBy []string) error {
20+
client := servicesunlynx.NewUnLynxClient(el.List[0], strconv.Itoa(0))
2121

22-
// Generate Survey Data
2322
nbrDPs := make(map[string]int64)
2423
//how many data providers for each server
2524
for _, server := range el.List {
2625
nbrDPs[server.String()] = 1 // 1 DP for each server
2726
}
2827

29-
surveyID, err := client.SendSurveyCreationQuery(el, servicesunlynxdefault.SurveyID(""), nil, nbrDPs, proofs, true, sum, count, whereQueryValues, predicate, groupBy)
28+
surveyID, err := client.SendSurveyCreationQuery(el, servicesunlynx.SurveyID(""), nil, nbrDPs, proofs, true, sum, count, whereQueryValues, predicate, groupBy)
3029
if err != nil {
31-
log.Fatal("Service did not start.", err)
30+
return err
3231
}
3332

3433
grp, aggr, err := client.SendSurveyResultsQuery(*surveyID)
3534
if err != nil {
36-
log.Fatal("Service could not output the results.")
35+
return errors.New("service could not output the results: " + err.Error())
3736
}
3837

3938
// Print Output
@@ -43,9 +42,10 @@ func startQuery(el *onet.Roster, proofs bool, sum []string, count bool, whereQue
4342
for i := range tabVerify {
4443
log.Lvl1(i, ")", (*grp)[i], "->", (*aggr)[i])
4544
}
45+
return nil
4646
}
4747

48-
func runUnLynx(c *cli.Context) error {
48+
func runUnLynx(c *cli.Context) {
4949
tomlFileName := c.String("file")
5050

5151
proofs := c.Bool("proofs")
@@ -58,14 +58,12 @@ func runUnLynx(c *cli.Context) error {
5858
groupBy := c.String("groupBy")
5959

6060
el, err := openGroupToml(tomlFileName)
61-
if err != nil {
62-
return err
63-
}
61+
log.ErrFatal(err, "Could not open group toml.")
6462

65-
sumFinal, countFinal, whereFinal, predicateFinal, groupByFinal := parseQuery(el, sum, count, whereQueryValues, predicate, groupBy)
66-
startQuery(el, proofs, sumFinal, countFinal, whereFinal, predicateFinal, groupByFinal)
63+
sumFinal, countFinal, whereFinal, predicateFinal, groupByFinal, err := parseQuery(el, sum, count, whereQueryValues, predicate, groupBy)
6764

68-
return nil
65+
err = startQuery(el, proofs, sumFinal, countFinal, whereFinal, predicateFinal, groupByFinal)
66+
log.ErrFatal(err)
6967
}
7068

7169
func openGroupToml(tomlFileName string) (*onet.Roster, error) {
@@ -79,33 +77,30 @@ func openGroupToml(tomlFileName string) (*onet.Roster, error) {
7977
}
8078

8179
if len(el.Roster.List) <= 0 {
82-
return nil, errors.New("Empty or invalid unlynx group file:" + tomlFileName)
80+
return nil, errors.New("empty or invalid unlynx group file:" + tomlFileName)
8381
}
8482

8583
return el.Roster, nil
8684
}
8785

88-
func checkRegex(input, expression, errorMessage string) {
86+
func checkRegex(input, expression string) bool {
8987
var aux = regexp.MustCompile(expression)
90-
91-
correct := aux.MatchString(input)
92-
93-
if !correct {
94-
log.Fatal(errorMessage)
95-
}
88+
return aux.MatchString(input)
9689
}
9790

98-
func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, groupBy string) ([]string, bool, []libunlynx.WhereQueryAttribute, string, []string) {
91+
func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, groupBy string) ([]string, bool, []libunlynx.WhereQueryAttribute, string, []string, error) {
9992

10093
if sum == "" || (where != "" && predicate == "") || (where == "" && predicate != "") {
101-
log.Fatal("Wrong query! Please check the sum, where and the predicate parameters")
94+
return nil, false, nil, "", nil, errors.New("wrong query! please check the sum, where and the predicate parameters")
10295
}
10396

10497
sumRegex := "{s[0-9]+(,\\s*s[0-9]+)*}"
10598
whereRegex := "{(w[0-9]+(,\\s*[0-9]+))*(,\\s*w[0-9]+(,\\s*[0-9]+))*}"
10699
groupByRegex := "{g[0-9]+(,\\s*g[0-9]+)*}"
107100

108-
checkRegex(sum, sumRegex, "Error parsing the sum parameter(s)")
101+
if !checkRegex(sum, sumRegex) {
102+
return nil, false, nil, "", nil, errors.New("error parsing the sum parameter(s)")
103+
}
109104
sum = strings.Replace(sum, " ", "", -1)
110105
sum = strings.Replace(sum, "{", "", -1)
111106
sum = strings.Replace(sum, "}", "", -1)
@@ -120,11 +115,13 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group
120115
}
121116

122117
if !check {
123-
log.Fatal("No 'count' attribute in the sum variables")
118+
return nil, false, nil, "", nil, errors.New("no 'count' attribute in the sum variables")
124119
}
125120
}
126121

127-
checkRegex(where, whereRegex, "Error parsing the where parameter(s)")
122+
if !checkRegex(where, whereRegex) {
123+
return nil, false, nil, "", nil, errors.New("error parsing the where parameter(s)")
124+
}
128125
where = strings.Replace(where, " ", "", -1)
129126
where = strings.Replace(where, "{", "", -1)
130127
where = strings.Replace(where, "}", "", -1)
@@ -140,20 +137,22 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group
140137
} else { // if it is a value
141138
value, err := strconv.Atoi(tmp[i])
142139
if err != nil {
143-
log.Fatal("Something wrong with the where value")
140+
return nil, false, nil, "", nil, err
144141
}
145142

146143
whereFinal = append(whereFinal, libunlynx.WhereQueryAttribute{Name: variable, Value: *libunlynx.EncryptInt(el.Aggregate, int64(value))})
147144
}
148145
}
149146

150-
checkRegex(groupBy, groupByRegex, "Error parsing the groupBy parameter(s)")
147+
if !checkRegex(groupBy, groupByRegex) {
148+
return nil, false, nil, "", nil, errors.New("error parsing the groupBy parameter(s)")
149+
}
151150
groupBy = strings.Replace(groupBy, " ", "", -1)
152151
groupBy = strings.Replace(groupBy, "{", "", -1)
153152
groupBy = strings.Replace(groupBy, "}", "", -1)
154153
groupByFinal := strings.Split(groupBy, ",")
155154

156-
return sumFinal, count, whereFinal, predicate, groupByFinal
155+
return sumFinal, count, whereFinal, predicate, groupByFinal, nil
157156
}
158157

159158
// CLIENT END: QUERIER ----------

app/server.go

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
// Empty imports to have the init-functions called which should
88
// register the protocol
99
_ "github.com/lca1/unlynx/protocols"
10-
_ "github.com/lca1/unlynx/services/default"
1110
)
1211

1312
func runServer(ctx *cli.Context) error {

app/setup.sh

-18
This file was deleted.

app/test.sh

-119
This file was deleted.

0 commit comments

Comments
 (0)