Skip to content

Commit

Permalink
Reverted if conditions to the correct way
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoAndreSa committed Mar 16, 2020
1 parent e9c05b5 commit e5509ba
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 56 deletions.
8 changes: 4 additions & 4 deletions cmd/unlynx/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group
whereRegex := "{(w[0-9]+(,\\s*[0-9]+))*(,\\s*w[0-9]+(,\\s*[0-9]+))*}"
groupByRegex := "{g[0-9]+(,\\s*g[0-9]+)*}"

if checkRegex(sum, sumRegex) == false {
if !checkRegex(sum, sumRegex) {
return nil, false, nil, "", nil, fmt.Errorf("error parsing the sum parameter(s)")
}
sum = strings.Replace(sum, " ", "", -1)
Expand All @@ -114,12 +114,12 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group
}
}

if check == false {
if !check {
return nil, false, nil, "", nil, fmt.Errorf("no 'count' attribute in the sum variables")
}
}

if checkRegex(where, whereRegex) == false {
if !checkRegex(where, whereRegex) {
return nil, false, nil, "", nil, fmt.Errorf("error parsing the where parameter(s)")
}
where = strings.Replace(where, " ", "", -1)
Expand All @@ -144,7 +144,7 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group
}
}

if checkRegex(groupBy, groupByRegex) == false {
if !checkRegex(groupBy, groupByRegex) {
return nil, false, nil, "", nil, fmt.Errorf("error parsing the groupBy parameter(s)")
}
groupBy = strings.Replace(groupBy, " ", "", -1)
Expand Down
4 changes: 2 additions & 2 deletions data/handle_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func GenerateData(numDPs, numEntries, numEntriesFiltered, numGroupsClear, numGro

testData := make(map[string][]libunlynx.DpClearResponse)

if randomGroups == false {
if !randomGroups {
numElem := 1
for _, el := range numType {
numElem = numElem * int(el)
Expand Down Expand Up @@ -362,7 +362,7 @@ func CompareClearResponses(x []libunlynx.DpClearResponse, y []libunlynx.DpClearR
}
}

if test == false {
if !test {
break
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ func discreteLog(P kyber.Point, checkNeg bool) (int64, error) {
guessIntMinus := int64(0)

start := true
for i := guessInt; i < MaxHomomorphicInt && foundPos == false && foundNeg == false; i = i + 1 {
for i := guessInt; i < MaxHomomorphicInt && !foundPos && !foundNeg; i = i + 1 {
// check for 0 first
if start == false {
if !start {
guess = SuiTe.Point().Add(guess, B)
}
start = false
Expand All @@ -365,15 +365,15 @@ func discreteLog(P kyber.Point, checkNeg bool) (int64, error) {
foundNeg = true
}
}
if foundNeg == false && guess.Equal(P) {
if !foundNeg && guess.Equal(P) {
foundPos = true
}
}
currentGreatestM = guess
currentGreatestInt = guessInt
mutex.Unlock()

if foundPos == false && foundNeg == false {
if !foundPos && !foundNeg {
log.Error("out of bound encryption, bound is ", MaxHomomorphicInt)
return 0, nil
}
Expand Down Expand Up @@ -451,7 +451,7 @@ func (cv *CipherVector) Equal(cv2 *CipherVector) bool {
}

for i := range *cv2 {
if (*cv)[i].Equal(&(*cv2)[i]) == false {
if !(*cv)[i].Equal(&(*cv2)[i]) {
return false
}
}
Expand Down Expand Up @@ -490,7 +490,7 @@ func (dcv *DeterministCipherVector) Equal(dcv2 *DeterministCipherVector) bool {
}

for i := range *dcv2 {
if (*dcv)[i].Equal(&(*dcv2)[i]) == false {
if !(*dcv)[i].Equal(&(*dcv2)[i]) {
return false
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ func TestNullCipherVector(t *testing.T) {
nullVectDec := libunlynx.DecryptIntVector(secKey, &nullVectEnc)

target := []int64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
if reflect.DeepEqual(nullVectDec, target) == false {
if !reflect.DeepEqual(nullVectDec, target) {
t.Fatal("Null vector of dimension 4 should be ", target, "got", nullVectDec)
}

twoTimesNullEnc := libunlynx.NewCipherVector(10)
twoTimesNullEnc.Add(nullVectEnc, nullVectEnc)
twoTimesNullDec := libunlynx.DecryptIntVector(secKey, twoTimesNullEnc)

if reflect.DeepEqual(twoTimesNullDec, target) == false {
if !reflect.DeepEqual(twoTimesNullDec, target) {
t.Fatal("Null vector + Null vector should be ", target, "got", twoTimesNullDec)
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestAbstractPointsConverter(t *testing.T) {
}

for i, el := range aps {
if reflect.DeepEqual(el.String(), newAps[i].String()) == false {
if !reflect.DeepEqual(el.String(), newAps[i].String()) {
t.Fatal("Wrong results, expected", el, "but got", newAps[i])
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/shuffle/shuffle.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func PrecomputationWritingForShuffling(appFlag bool, gobFile, serverName string,

// ReadPrecomputedFile reads the precomputation data from a .gob file
func ReadPrecomputedFile(fileName string) ([]CipherVectorScalar, error) {
if _, err := os.Stat(fileName); os.IsNotExist(err) == false {
if _, err := os.Stat(fileName); !os.IsNotExist(err) {
var encoded []CipherVectorScalarBytes
err := libunlynxtools.ReadFromGobFile(fileName, &encoded)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions lib/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func proccessParameters(data []string, clear map[string]int64, encrypted map[str
// all where and group by attributes are in clear
if noEnc {
containerClear = append(containerClear, clear[v])
} else if noEnc == false {
} else if !noEnc {
if value, ok := encrypted[v]; ok {
containerEnc = append(containerEnc, value)
} else {
Expand All @@ -80,7 +80,7 @@ func (s *Store) InsertDpResponse(cr libunlynx.DpResponse, proofsB bool, groupBy,
clearWhr, newResp.WhereEnc = proccessParameters(whereStrings, cr.WhereClear, cr.WhereEnc, noEnc)
_, newResp.AggregatingAttributes = proccessParameters(sum, cr.AggregatingAttributesClear, cr.AggregatingAttributesEnc, false)

if noEnc == false {
if !noEnc {
s.DpResponses = append(s.DpResponses, newResp)
} else {
value, ok := s.DpResponsesAggr[GroupingKeyTuple{libunlynx.Key(clearGrp), libunlynx.Key(clearWhr)}]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (cv *FilteredResponse) Add(cv1, cv2 FilteredResponse) *FilteredResponse {

// AddInMap permits to add a filtered response with its deterministic tag in a map
func AddInMap(s map[GroupingKey]FilteredResponse, key GroupingKey, added FilteredResponse) {
if localResult, ok := s[key]; ok == false {
if localResult, ok := s[key]; !ok {
s[key] = added
} else {
nfr := NewFilteredResponse(len(added.GroupByEnc), len(added.AggregatingAttributes))
Expand Down
2 changes: 1 addition & 1 deletion lib/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func SendISMOthers(s *onet.ServiceProcessor, el *onet.Roster, msg interface{}) error {
var errStrs []string
for _, e := range el.List {
if e.ID.Equal(s.ServerIdentity().ID) == false {
if !e.ID.Equal(s.ServerIdentity().ID) {
log.Lvl3("Sending to", e)
err := s.SendRaw(e, msg)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions protocols/collective_aggregation_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (p *CollectiveAggregationProtocol) Dispatch() error {
}

// 1. Aggregation announcement phase
if p.IsRoot() == false {
if !p.IsRoot() {
err := p.aggregationAnnouncementPhase()
if err != nil {
return err
Expand Down Expand Up @@ -211,7 +211,7 @@ func (p *CollectiveAggregationProtocol) aggregationAnnouncementPhase() error {
func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libunlynx.GroupingKey][]libunlynx.CipherVector) (*map[libunlynx.GroupingKey]libunlynx.FilteredResponse, error) {
roundTotComput := libunlynx.StartTimer(p.Name() + "_CollectiveAggregation(ascendingAggregation)")

if p.IsLeaf() == false {
if !p.IsLeaf() {
length := make([]cadmbLengthStruct, 0)
for _, v := range <-p.LengthNodeChannel {
length = append(length, v)
Expand Down Expand Up @@ -257,7 +257,7 @@ func (p *CollectiveAggregationProtocol) ascendingAggregationPhase(cvMap map[libu

libunlynx.EndTimer(roundTotComput)

if p.IsRoot() == false {
if !p.IsRoot() {
detAggrResponses := make([]libunlynx.FilteredResponseDet, len(*p.GroupedData))
count := 0
for i, v := range *p.GroupedData {
Expand Down
2 changes: 1 addition & 1 deletion protocols/deterministic_tagging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestDeterministicTagging(t *testing.T) {
present = true
}
}
if present == false {
if !present {
t.Fatal("DP responses changed and shouldn't")
}
}
Expand Down
6 changes: 3 additions & 3 deletions protocols/key_switching_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (p *KeySwitchingProtocol) Dispatch() error {
defer p.Done()

// 1. Key switching announcement phase
if p.IsRoot() == false {
if !p.IsRoot() {
targetPublicKey, rbs, err := p.announcementKSPhase()
if err != nil {
return err
Expand Down Expand Up @@ -253,7 +253,7 @@ func (p *KeySwitchingProtocol) ascendingKSPhase() (*libunlynx.CipherVector, erro

keySwitchingAscendingAggregation := libunlynx.StartTimer(p.Name() + "_KeySwitching(ascendingAggregation)")

if p.IsLeaf() == false {
if !p.IsLeaf() {
length := make([]LengthStruct, 0)
for _, v := range <-p.LengthChannel {
length = append(length, v)
Expand All @@ -278,7 +278,7 @@ func (p *KeySwitchingProtocol) ascendingKSPhase() (*libunlynx.CipherVector, erro
}
libunlynx.EndTimer(keySwitchingAscendingAggregation)

if p.IsRoot() == false {
if !p.IsRoot() {
if err := p.SendToParent(&LengthMessage{Length: libunlynxtools.UnsafeCastIntsToBytes([]int{len(*p.NodeContribution)})}); err != nil {
return nil, fmt.Errorf("Node "+p.ServerIdentity().String()+" failed to broadcast LengthMessage: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion protocols/key_switching_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestCTKS(t *testing.T) {
res := libunlynx.DecryptIntVector(clientPrivate, &cv1)
log.Lvl2("Received results (attributes) ", res)

if reflect.DeepEqual(res, append(data1, data2...)) == false {
if !reflect.DeepEqual(res, append(data1, data2...)) {
t.Fatal("Wrong results, expected", data1, "but got", res)
} else {
t.Log("Good results")
Expand Down
2 changes: 1 addition & 1 deletion protocols/shuffling_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (p *ShufflingProtocol) Dispatch() error {
var pi []int
var beta [][]kyber.Scalar

if p.IsRoot() == false {
if !p.IsRoot() {
shufflingDispatchNoProof := libunlynx.StartTimer(p.Name() + "_Shuffling(DISPATCH-noProof)")

shuffledData, pi, beta = libunlynxshuffle.ShuffleSequence(shuffleTarget, libunlynx.SuiTe.Point().Base(), collectiveKey, p.Precomputed)
Expand Down
16 changes: 8 additions & 8 deletions services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,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
Expand Down Expand Up @@ -271,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
Expand Down Expand Up @@ -318,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
Expand Down Expand Up @@ -362,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)
Expand Down Expand Up @@ -556,7 +556,7 @@ 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{})
Expand Down Expand Up @@ -671,7 +671,7 @@ 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)
Expand All @@ -683,7 +683,7 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error {
}

// 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)
Expand All @@ -695,7 +695,7 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error {
}

// Key Switch Phase
if root == true {
if root {
start := libunlynx.StartTimer(s.ServerIdentity().String() + "_KeySwitchingPhase")

err := s.KeySwitchingPhase(target.Query.SurveyID)
Expand Down
Loading

0 comments on commit e5509ba

Please sign in to comment.