-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecondProbeGetDataStuff_prior_corrected.js
52 lines (50 loc) · 1.8 KB
/
secondProbeGetDataStuff_prior_corrected.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//Xavier's first app
function init(config) {
// useless for the time being
'use strict';
config.requireProvider('akamai_object_delivery');
config.requireProvider('aws_ec2_us_east_va');
config.requireProvider('cloudflare_cdn');
}
function lowestRTT(rtt_info) {
'use strict';
var aliases = Object.keys(rtt_info);
var aliasesLength = aliases.length;
var currentLowestRTT = Infinity;
var answer = null;
for (var i = 0; i< aliasesLength; i += 1) {
if (currentLowestRTT > rtt_info[aliases[i]].http_rtt){
answer = aliases[i];
currentLowestRTT = rtt_info[aliase[i]].http_rtt;
}
}
return answer;
}
function onRequest(request, response) {
'use strict';
//looking for rtt of the providers stated above in init.
var rtt = request.getProbe('http_rtt');
var choiceCDN = lowestRTT(rtt);
if (choiceCDN == 'akamai_object_delivery') {
response.setProvider('akamai_object_delivery');
// response.respond('akamai_object_delivery', '4.4.4.4');
response.addARecord('1.1.1.1');
response.addARecord('2.2.2.2');
response.addARecord('3.3.3.3');
response.addARecord('4.4.4.4');
response.setTTL(20);
} else if (choiceCDN == 'aws_ec2_us_east_va') {
// why is specifying the provider alias important?
response.respond('aws_ec2_us_east_va', '8.8.8.8');
response.setTTL(30);
} else if (choiceCDN == 'cloudflare_cdn') {
//response.respond('akamai_object_delivery', '8.8.4.4');
//response.setTTL(20);
response.setProvider('cloudflare_cdn');
response.addCName('bar.foo.com');
response.setTTL(25);
} else if (choiceCDN == null) {
response.respond('aws_ec2_us_east_va', '2.4.6.8');
response.setTTL(40);
}
}