Skip to content

Commit e354b49

Browse files
committed
Refactores unlynx service & cleaned the .gitignore
1 parent 83621ac commit e354b49

File tree

3 files changed

+144
-65
lines changed

3 files changed

+144
-65
lines changed

.gitignore

+1-13
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,16 @@ _testmain.go
3131
.idea/
3232

3333
data/*.txt
34-
services/unlynxMedCo/*.toml
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

services/service.go

+84-27
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ type MsgTypes struct {
8282
var msgTypes = MsgTypes{}
8383

8484
func init() {
85-
onet.RegisterNewService(ServiceName, NewService)
85+
if _, err := onet.RegisterNewService(ServiceName, NewService); err != nil {
86+
log.Fatal("Error registering service unlynx:", err)
87+
}
8688

8789
msgTypes.msgSurveyCreationQuery = network.RegisterMessage(&SurveyCreationQuery{})
8890
network.RegisterMessage(&SurveyResponseQuery{})
@@ -158,13 +160,19 @@ func NewService(c *onet.Context) (onet.Service, error) {
158160
func (s *Service) Process(msg *network.Envelope) {
159161
if msg.MsgType.Equal(msgTypes.msgSurveyCreationQuery) {
160162
tmp := (msg.Msg).(*SurveyCreationQuery)
161-
s.HandleSurveyCreationQuery(tmp)
163+
if _, cerr := s.HandleSurveyCreationQuery(tmp); cerr != nil {
164+
log.Fatal("Error in HandleSurveyCreationQuery():", cerr)
165+
}
162166
} else if msg.MsgType.Equal(msgTypes.msgSurveyResultsQuery) {
163167
tmp := (msg.Msg).(*SurveyResultsQuery)
164-
s.HandleSurveyResultsQuery(tmp)
168+
if _, cerr := s.HandleSurveyResultsQuery(tmp); cerr != nil {
169+
log.Fatal("Error in HandleSurveyResultsQuery():", cerr)
170+
}
165171
} else if msg.MsgType.Equal(msgTypes.msgDDTfinished) {
166172
tmp := (msg.Msg).(*DDTfinished)
167-
s.HandleDDTfinished(tmp)
173+
if _, cerr := s.HandleDDTfinished(tmp); cerr != nil {
174+
log.Fatal("Error in HandleDDTfinished():", cerr)
175+
}
168176
}
169177
}
170178

@@ -176,7 +184,9 @@ func (s *Service) PushData(resp *SurveyResponseQuery, proofs bool) {
176184
dr.FromDpResponseToSend(v)
177185
survey.InsertDpResponse(dr, proofs, survey.Query.GroupBy, survey.Query.Sum, survey.Query.Where)
178186
}
179-
s.Survey.Put(string(resp.SurveyID), survey)
187+
if _, err := s.Survey.Put(string(resp.SurveyID), survey); err != nil {
188+
log.Fatal(err)
189+
}
180190

181191
log.Lvl1(s.ServerIdentity(), " uploaded response data for survey ", resp.SurveyID)
182192
}
@@ -213,7 +223,7 @@ func (s *Service) HandleSurveyCreationQuery(recq *SurveyCreationQuery) (network.
213223
precomputeShuffle := libunlynxshuffle.PrecomputationWritingForShuffling(recq.AppFlag, gobFile, s.ServerIdentity().String(), surveySecret, recq.Roster.Aggregate, lineSize)
214224

215225
// survey instantiation
216-
s.Survey.Put((string)(recq.SurveyID), Survey{
226+
if _, err := s.Survey.Put((string)(recq.SurveyID), Survey{
217227
Store: libunlynxstore.NewStore(),
218228
Query: *recq,
219229
SurveySecretKey: surveySecret,
@@ -222,7 +232,9 @@ func (s *Service) HandleSurveyCreationQuery(recq *SurveyCreationQuery) (network.
222232
SurveyChannel: make(chan int, 100),
223233
DpChannel: make(chan int, 100),
224234
DDTChannel: make(chan int, 100),
225-
})
235+
}); err != nil {
236+
log.Fatal(err)
237+
}
226238

227239
log.Lvl1(s.ServerIdentity(), " created the survey ", recq.SurveyID)
228240
// if it is a app download the data from the test file
@@ -285,7 +297,9 @@ func (s *Service) HandleSurveyResultsQuery(resq *SurveyResultsQuery) (network.Me
285297

286298
survey := castToSurvey(s.Survey.Get((string)(resq.SurveyID)))
287299
survey.Query.ClientPubKey = resq.ClientPublic
288-
s.Survey.Put(string(resq.SurveyID), survey)
300+
if _, err := s.Survey.Put(string(resq.SurveyID), survey); err != nil {
301+
log.Fatal(err)
302+
}
289303

290304
if resq.IntraMessage == false {
291305
resq.IntraMessage = true
@@ -294,18 +308,24 @@ func (s *Service) HandleSurveyResultsQuery(resq *SurveyResultsQuery) (network.Me
294308
if err != nil {
295309
log.Error("broadcasting error ", err)
296310
}
297-
s.StartService(resq.SurveyID, true)
311+
if err := s.StartService(resq.SurveyID, true); err != nil {
312+
log.Fatal("Server (", s.ServerIdentity().String(), ") error during StartService():", err)
313+
}
298314

299315
log.Lvl1(s.ServerIdentity(), " completed the query processing...")
300316

301317
survey := castToSurvey(s.Survey.Get((string)(resq.SurveyID)))
302318
results := survey.PullDeliverableResults(false, libunlynx.CipherText{})
303-
s.Survey.Put(string(resq.SurveyID), survey)
319+
if _, err := s.Survey.Put(string(resq.SurveyID), survey); err != nil {
320+
log.Fatal(err)
321+
}
304322

305323
return &ServiceResult{Results: results}, nil
306324
}
307325

308-
s.StartService(resq.SurveyID, false)
326+
if err := s.StartService(resq.SurveyID, false); err != nil {
327+
log.Fatal("Server (", s.ServerIdentity().String(), ") error during StartService():", err)
328+
}
309329
return nil, nil
310330
}
311331

@@ -320,7 +340,9 @@ func (s *Service) HandleDDTfinished(recq *DDTfinished) (network.Message, error)
320340

321341
// NewProtocol creates a protocol instance executed by all nodes
322342
func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfig) (onet.ProtocolInstance, error) {
323-
tn.SetConfig(conf)
343+
if err := tn.SetConfig(conf); err != nil {
344+
log.Fatal("Error during SetConfig in the NewProtocol():", err)
345+
}
324346

325347
var pi onet.ProtocolInstance
326348
var err error
@@ -348,7 +370,9 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfi
348370
toShuffleCV, survey.Lengths = protocolsunlynx.ProcessResponseToMatrixCipherText(dpResponses)
349371
shuffle.ShuffleTarget = &toShuffleCV
350372

351-
s.Survey.Put(string(target), survey)
373+
if _, err := s.Survey.Put(string(target), survey); err != nil {
374+
log.Fatal(err)
375+
}
352376
}
353377

354378
case protocolsunlynx.DeterministicTaggingProtocolName:
@@ -372,7 +396,9 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfi
372396
shuffledClientResponses = append(queryWhereToTag, shuffledClientResponses...)
373397
tmpDeterministicTOS := protocolsunlynx.ProcessResponseToCipherVector(shuffledClientResponses)
374398
survey.TargetOfSwitch = shuffledClientResponses
375-
s.Survey.Put(string(target), survey)
399+
if _, err := s.Survey.Put(string(target), survey); err != nil {
400+
log.Fatal(err)
401+
}
376402

377403
hashCreation.TargetOfSwitch = &tmpDeterministicTOS
378404
}
@@ -385,7 +411,9 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfi
385411

386412
// waits for all other nodes to finish the tagging phase
387413
groupedData := survey.PullLocallyAggregatedResponses()
388-
s.Survey.Put(string(target), survey)
414+
if _, err := s.Survey.Put(string(target), survey); err != nil {
415+
log.Fatal(err)
416+
}
389417

390418
collectiveAggr := pi.(*protocolsunlynx.CollectiveAggregationProtocol)
391419
collectiveAggr.GroupedData = &groupedData
@@ -453,7 +481,9 @@ func (s *Service) NewProtocol(tn *onet.TreeNodeInstance, conf *onet.GenericConfi
453481
tmp := survey.Query.ClientPubKey
454482
keySwitch.TargetPublicKey = &tmp
455483

456-
s.Survey.Put(string(target), survey)
484+
if _, err := s.Survey.Put(string(target), survey); err != nil {
485+
log.Fatal(err)
486+
}
457487
}
458488
default:
459489
return nil, errors.New("Service attempts to start an unknown protocol: " + tn.ProtocolName() + ".")
@@ -474,12 +504,23 @@ func (s *Service) StartProtocol(name string, targetSurvey SurveyID) (onet.Protoc
474504

475505
pi, err := s.NewProtocol(tn, &conf)
476506
if err != nil {
477-
log.Fatal("Error running"+name+":", err)
507+
log.Fatal("Error running "+name+" :", err)
478508
}
479509

480-
s.RegisterProtocolInstance(pi)
481-
go pi.Dispatch()
482-
go pi.Start()
510+
if err := s.RegisterProtocolInstance(pi); err != nil {
511+
log.Fatal("Error registering protocol <", name, ">:", err)
512+
}
513+
514+
go func() {
515+
if err := pi.Dispatch(); err != nil {
516+
log.Fatal("Error in Dispatch for protocol <", name, ">:", err)
517+
}
518+
}()
519+
go func() {
520+
if err := pi.Start(); err != nil {
521+
log.Fatal("Error in Start for protocol <", name, ">:", err)
522+
}
523+
}()
483524

484525
return pi, err
485526
}
@@ -549,7 +590,10 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error {
549590
if root == true && libunlynx.DIFFPRI == true {
550591
start := libunlynx.StartTimer(s.ServerIdentity().String() + "_DROPhase")
551592

552-
s.DROPhase(target.Query.SurveyID)
593+
err := s.DROPhase(target.Query.SurveyID)
594+
if err != nil {
595+
log.Fatal("Error in the DRO Phase:", err)
596+
}
553597

554598
libunlynx.EndTimer(start)
555599
}
@@ -558,7 +602,10 @@ func (s *Service) StartService(targetSurvey SurveyID, root bool) error {
558602
if root == true {
559603
start := libunlynx.StartTimer(s.ServerIdentity().String() + "_KeySwitchingPhase")
560604

561-
s.KeySwitchingPhase(target.Query.SurveyID)
605+
err := s.KeySwitchingPhase(target.Query.SurveyID)
606+
if err != nil {
607+
log.Fatal("Error in the KeySwitching Phase:", err)
608+
}
562609

563610
libunlynx.EndTimer(start)
564611
}
@@ -583,7 +630,9 @@ func (s *Service) ShufflingPhase(targetSurvey SurveyID) error {
583630
shufflingResult := protocolsunlynx.MatrixCipherTextToProcessResponse(tmpShufflingResult, castToSurvey(s.Survey.Get((string)(targetSurvey))).Lengths)
584631

585632
survey.PushShuffledProcessResponses(shufflingResult)
586-
s.Survey.Put(string(targetSurvey), survey)
633+
if _, err := s.Survey.Put(string(targetSurvey), survey); err != nil {
634+
log.Fatal(err)
635+
}
587636
return err
588637
}
589638

@@ -619,7 +668,9 @@ func (s *Service) TaggingPhase(targetSurvey SurveyID) error {
619668
}
620669

621670
survey.PushDeterministicFilteredResponses(filteredResponses, s.ServerIdentity().String(), survey.Query.Proofs)
622-
s.Survey.Put(string(targetSurvey), survey)
671+
if _, err := s.Survey.Put(string(targetSurvey), survey); err != nil {
672+
log.Fatal(err)
673+
}
623674
return err
624675
}
625676

@@ -633,7 +684,9 @@ func (s *Service) AggregationPhase(targetSurvey SurveyID) error {
633684

634685
survey := castToSurvey(s.Survey.Get((string)(targetSurvey)))
635686
survey.PushCothorityAggregatedFilteredResponses(cothorityAggregatedData.GroupedData)
636-
s.Survey.Put(string(targetSurvey), survey)
687+
if _, err := s.Survey.Put(string(targetSurvey), survey); err != nil {
688+
log.Fatal(err)
689+
}
637690
return nil
638691
}
639692

@@ -650,7 +703,9 @@ func (s *Service) DROPhase(targetSurvey SurveyID) error {
650703
shufflingResult := protocolsunlynx.MatrixCipherTextToProcessResponse(tmpShufflingResult, survey.Lengths)
651704

652705
survey.Noise = shufflingResult[0].AggregatingAttributes[0]
653-
s.Survey.Put(string(targetSurvey), survey)
706+
if _, err := s.Survey.Put(string(targetSurvey), survey); err != nil {
707+
log.Fatal(err)
708+
}
654709
return nil
655710
}
656711

@@ -667,7 +722,9 @@ func (s *Service) KeySwitchingPhase(targetSurvey SurveyID) error {
667722
keySwitchedAggregatedResponses := protocolsunlynx.CipherVectorToFilteredResponse(tmpKeySwitchedAggregatedResponses, survey.Lengths)
668723

669724
survey.PushQuerierKeyEncryptedResponses(keySwitchedAggregatedResponses)
670-
s.Survey.Put(string(targetSurvey), survey)
725+
if _, err := s.Survey.Put(string(targetSurvey), survey); err != nil {
726+
log.Fatal(err)
727+
}
671728
return err
672729
}
673730

0 commit comments

Comments
 (0)