-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
85 lines (62 loc) · 2.37 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
let Node = require("./node").Node;
let faker = require("faker");
let SearchRequest = require("./controllers/SearchRequest");
let SearchResponder = require("./controllers/SearchResponder");
let stringSimilarity = require("string-similarity");
let node = new Node((channel)=>{
console.info("connection received!");
console.info(channel);
},{});
// let name = faker.name.firstName();
// while (name.charAt(0) !== 'K') {
// name = faker.name.firstName();
// }
let name = `${Math.floor(Math.random()*200)},${Math.floor(Math.random()*200)}`;
node.registerList("list#name", (a, b) =>{
let x1 = a.split(",")[0];
let y1 = a.split(",")[1];
let x2 = b.split(",")[0];
let y2 = b.split(",")[1];
return 1/Math.sqrt(Math.pow(Math.abs(x1-x2),2)+Math.pow(Math.abs(y1-y2),2));
},0.2);
node.setEntries("list#name", [name]);
node.name= name;
window.document.title = name;
node.startNode();
// let clientInfoService = new ClientInfoService(persistentStorage);
let neighbourSet = node.__cyclonNode.getNeighbourSet();
let currWindow = [];
window.onload = function () {
document.getElementById("name").innerText = name;
};
let response_ids = {};
global.runTest = function () {
console.info("running search");
// let searchRequest = new SearchRequest(node, document.getElementById("new_name").value,"list#name");
document.getElementById("results").innerHTML="";
// response_ids = {};
// searchRequest.on("search_result", (packet) => {
// if (!response_ids[packet.packet_id]){
// response_ids[packet.packet_id]= 1;
// }else {
// response_ids[packet.packet_id]++;
// }
// });
// node.attachController(searchRequest);
// node.statsRecorder.addEventEmitter(searchRequest);
// searchRequest.initiateSearch();
node.search("list#name", document.getElementById("new_name").value, 60, (value) => {
console.info("called");
let point = JSON.stringify(value);
document.getElementById("results").innerHTML +=
`<div> ${JSON.stringify(value)} </div>`;
});
};
global.connectBtnClicked = function () {
// console.info(document.getElementById("pointer").innerText);
let pointer = JSON.parse(document.getElementById("pointer").value);
node.connectToNode(pointer).then((rtcDataChannel) => {
console.info("connected!");
console.info(rtcDataChannel);
});
};