Skip to content

Commit e0b00e4

Browse files
committed
making route changes
1 parent ebc96c9 commit e0b00e4

File tree

4 files changed

+220
-4
lines changed

4 files changed

+220
-4
lines changed

client/app/controllers/unmaskController.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
define(['helper/mpc', 'controllers/tableController', 'filesaver'], function (mpc, tableController, filesaver) {
1111

1212
// Takes callback(true|false, data).
13-
function aggregate_and_unmask(mOut, privateKey, session, password, callback) {
13+
function aggregate_and_unmask(mOut, analyticsMasks, privateKey, session, password, callback) {
14+
15+
aMOut = JSON.parse(analyticsMasks.data);
16+
17+
console.log('analytics mask',aMOut);
1418

1519
mOut = JSON.parse(mOut.data);
1620
console.log(mOut);
@@ -57,6 +61,10 @@ define(['helper/mpc', 'controllers/tableController', 'filesaver'], function (mpc
5761
// Request service to aggregate its shares and send us the result
5862
var serviceResultShare = getServiceResultShare(session, password);
5963

64+
var analyticsShares = getAnalyticsShares(session, password);
65+
66+
console.log(analyticsShares);
67+
6068
Promise.all([analystResultShare, serviceResultShare, questions_public])
6169
.then(function (resultShares) {
6270
var analystResult = resultShares[0],
@@ -85,6 +93,21 @@ define(['helper/mpc', 'controllers/tableController', 'filesaver'], function (mpc
8593
// });
8694
}
8795

96+
97+
function getAnalyticsShares(session, password) {
98+
return $.ajax({
99+
type: 'POST',
100+
url: '/get_analytics',
101+
contentType: 'application/json',
102+
data: JSON.stringify({
103+
session: session,
104+
password: password
105+
}),
106+
dataType: 'json'
107+
});
108+
}
109+
110+
88111
function getServiceResultShare(session, password) {
89112
return $.ajax({
90113
type: 'POST',

client/app/views/unmaskView.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ define(['jquery', 'controllers/unmaskController', 'controllers/clientController'
2626

2727
}
2828

29+
function getAnalyticsMasks(sK, sP, pK, masks, callB) {
30+
$.ajax({
31+
type: 'POST',
32+
url: '/get_analytics_masks',
33+
contentType: 'application/json',
34+
data: JSON.stringify({session: sK, password: sP}),
35+
success: function (analyticsMasks) {
36+
unmaskController.aggregate_and_unmask(masks, analyticsMasks, pK, sK, sP, callB);
37+
},
38+
error: function(e) {
39+
error(e.responseText);
40+
}
41+
})
42+
43+
}
2944

3045
function getMasks(sK, sP, pK) {
3146
$.ajax({
@@ -34,7 +49,7 @@ define(['jquery', 'controllers/unmaskController', 'controllers/clientController'
3449
contentType: 'application/json',
3550
data: JSON.stringify({session: sK, password: sP}),
3651
success: function (data) {
37-
unmaskController.aggregate_and_unmask(data, pK, sK, sP, callb);
52+
getAnalyticsMasks(sK, sP, pK, data, callb);
3853
},
3954
error: function (e) {
4055
error(e.responseText);

client/unmask.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ <h2 class="text-center">Unmask Aggregate Data</h2>
133133
<form>
134134
<div class="form-group">
135135
<label class="control-label" for="session">Session Key</label>
136-
<input type="text" id="session" class="form-control" placeholder="Session Key" pattern="^[a-zA-Z0-9]{26}$" autocomplete="off" required/>
136+
<input type="text" id="session" value="3wcd7hgekettex9qmk55h6t798" class="form-control" placeholder="Session Key" pattern="^[a-zA-Z0-9]{26}$" autocomplete="off" required/>
137137
<span id="session-success" class="success-icon glyphicon glyphicon-ok form-control-feedback hidden"
138138
aria-hidden="true"></span>
139139
<span id="session-fail" class="fail-icon glyphicon glyphicon-remove form-control-feedback hidden"
@@ -145,7 +145,7 @@ <h2 class="text-center">Unmask Aggregate Data</h2>
145145
</div>
146146
<div class="form-group">
147147
<label class="control-label" for="session-password">Session Password</label>
148-
<input type="text" id="session-password" class="form-control" placeholder="Session Password"
148+
<input type="text" value="2ywayksw257g56xrdrza1yszrw" id="session-password" class="form-control" placeholder="Session Password"
149149
pattern="^[a-zA-Z0-9]{26}$"
150150
autocomplete="off" required>
151151
<span id="session-password-success" class="success-icon glyphicon glyphicon-ok form-control-feedback hidden" aria-hidden="true"></span>

server/index.js

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,124 @@ app.post('/generate_client_urls', function (req, res) {
620620
});
621621
});
622622

623+
app.post('/get_analytics_masks', function (req, res) {
624+
console.log('GET to get_analytics_masks.');
625+
console.log(req.body);
626+
627+
var schema = {
628+
session: joi.string().alphanum().required(),
629+
password: joi.string().alphanum().required()
630+
};
631+
632+
joi.validate(req.body, schema, function (valErr, body) {
633+
if (valErr) {
634+
console.log(valErr);
635+
res.status(500).send('Invalid or missing fields.');
636+
return;
637+
}
638+
639+
var fail = function (err) {
640+
console.log(err);
641+
res.status(500).send(err);
642+
};
643+
var success = function () {
644+
AnalyticsMask.where({session: body.session}).find(function (err, data) {
645+
if (err) {
646+
console.log(err);
647+
res.status(500).send('Error getting analytics masks.');
648+
return;
649+
}
650+
if (!data || data.length === 0) {
651+
res.status(500).send('No submissions yet. Please come back later.');
652+
return;
653+
}
654+
else {
655+
console.log(data);
656+
res.send({data: JSON.stringify(data)});
657+
return;
658+
}
659+
});
660+
};
661+
662+
verify_password(body.session, body.password, function () {
663+
verify_status(body.session, "STOP", success, fail);
664+
}, fail);
665+
});
666+
667+
});
668+
669+
// endpoint for getting all of the cubes for a specific session
670+
app.post('/get_cubes', function (req, res) {
671+
console.log('POST to get_cubes.');
672+
console.log(req.body);
673+
674+
var schema = {
675+
session: joi.string().alphanum().required(),
676+
password: joi.string().alphanum().required()
677+
};
678+
679+
joi.validate(req.body, schema, function (valErr, body) {
680+
if (valErr) {
681+
console.log(valErr);
682+
res.status(500).send('Invalid or missing fields.');
683+
return;
684+
}
685+
686+
var fail = function (err) {
687+
console.log(err);
688+
res.status(500).send(err);
689+
};
690+
var success = function () {
691+
Cube.where({session: body.session}).find(function (err, data) {
692+
if (err) {
693+
console.log(err);
694+
res.status(500).send('Error getting cubes.');
695+
return;
696+
}
697+
if (!data || data.length === 0) {
698+
res.status(500).send('No submissions yet. Please come back later.');
699+
return;
700+
}
701+
else {
702+
console.log(data.length);
703+
var result = {};
704+
for (var i = 0; i < 5; i++) {
705+
for (var j = i + 1; j < 5; j++) {
706+
result[i + ":" + j] = [];
707+
}
708+
}
709+
710+
for (var d = 0; d < data.length; d++) {
711+
var one_submission = data[d].fields;
712+
for (var i = 0; i < 5; i++) {
713+
for (var j = i + 1; j < 5; j++) {
714+
result[i + ":" + j].push(one_submission[i + ":" + j]);
715+
}
716+
}
717+
}
718+
719+
// Sort (to shuffle/remove order) pairs
720+
// now it cannot be inferred which pairs are from the same submission.
721+
for (var i = 0; i < 5; i++) {
722+
for (var j = i + 1; j < 5; j++) {
723+
result[i + ":" + j] = result[i + ":" + j].sort();
724+
}
725+
}
726+
727+
res.send(result);
728+
return;
729+
}
730+
});
731+
};
732+
733+
verify_password(body.session, body.password, function () {
734+
verify_status(body.session, "STOP", success, fail);
735+
}, fail);
736+
});
737+
738+
});
739+
740+
623741
// endpoint for getting already generated client unique urls
624742
app.post('/get_client_urls', function (req, res) {
625743
console.log('POST /get_client_urls');
@@ -830,6 +948,66 @@ app.post('/get_cubes', function (req, res) {
830948

831949
});
832950

951+
952+
// endpoint for getting the service share of the result of the aggregation
953+
app.post('/get_analytics', function (req, res) {
954+
console.log('POST /get_analytics');
955+
console.log(req.body);
956+
957+
var schema = {
958+
session: joi.string().alphanum().required(),
959+
password: joi.string().alphanum().required()
960+
};
961+
962+
joi.validate(req.body, schema, function (valErr, body) {
963+
if (valErr) {
964+
console.log(valErr);
965+
res.status(500).send('Invalid or missing fields.');
966+
return;
967+
}
968+
969+
var fail = function (err) {
970+
console.log(err);
971+
res.status(500).send(err);
972+
};
973+
var success = function () {
974+
Analytics.where({session: body.session}).find(function (err, data) {
975+
if (err) {
976+
console.log(err);
977+
res.status(500).send('Error computing aggregate.');
978+
return;
979+
}
980+
981+
// make sure query result is not empty
982+
if (data.length >= 1) {
983+
console.log('Computing share of aggregate.');
984+
985+
var invalidShareCount = mpc.countInvalidShares(data, true),
986+
serviceShare = mpc.aggregateShares(data, true);
987+
988+
// TODO: we should set a threshold and abort if there are too
989+
// many invalid shares
990+
console.log('Invalid share count:', invalidShareCount);
991+
992+
console.log('Sending aggregate.');
993+
console.log('SERVICE SHARE', serviceShare);
994+
res.json(serviceShare);
995+
996+
return;
997+
}
998+
else {
999+
res.status(500).send('No submissions yet. Please come back later.');
1000+
return;
1001+
}
1002+
});
1003+
};
1004+
1005+
verify_password(body.session, body.password, function () {
1006+
verify_status(body.session, "STOP", success, fail);
1007+
}, fail);
1008+
});
1009+
});
1010+
8331011
// endpoint for getting the service share of the result of the aggregation
8341012
app.post('/get_aggregate', function (req, res) {
8351013
console.log('POST /get_aggregate');

0 commit comments

Comments
 (0)