Skip to content
Snippets Groups Projects
Commit 6701facb authored by arshiam2's avatar arshiam2
Browse files

udpated leaving

parent b9c3ac4b
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,8 @@ npm run start ...@@ -41,6 +41,8 @@ npm run start
``` ```
## Introducer ## Introducer
The introducer has a list of all VMs up, and gets messages when anotehr machine joins and leaves. Based on that, it updates all the nodes membership lists. The introducer has a list of all VMs up, and gets messages when anotehr machine joins and leaves. Based on that, it updates all the nodes membership lists.
......
...@@ -18,6 +18,19 @@ const process = require("process"); ...@@ -18,6 +18,19 @@ const process = require("process");
const socket = dgram.createSocket({ type: "udp4", reuseAddr: true }); const socket = dgram.createSocket({ type: "udp4", reuseAddr: true });
const machineToIps = {
"0": "172.16.138.158",
"1": "172.22.156.15",
"2": "172.22.158.15",
"3": "172.22.154.16",
"4": "172.22.156.16",
"5": "172.22.158.16",
"6": "172.22.154.17",
"8": "172.22.158.17",
"9": "172.22.154.18",
"10": "172.22.156.18"
};
socket.bind(PORT); socket.bind(PORT);
function sendMessage(number) { function sendMessage(number) {
...@@ -25,9 +38,16 @@ function sendMessage(number) { ...@@ -25,9 +38,16 @@ function sendMessage(number) {
socket.send(message, 0, message.length, PORT, HOST, function() {}); socket.send(message, 0, message.length, PORT, HOST, function() {});
} }
function sendMessageToNode(number) {
const message = Buffer.from(`leave ${number}`);
socket.send(message, 0, message.length, PORT, machineToIps[number], function() {});
}
module.exports.handler = handleErrors(async (argv: {}) => { module.exports.handler = handleErrors(async (argv: {}) => {
console.log("Sending message to introducer") console.log("Sending message to introducer");
let number = argv.number let number = argv.number;
await sendMessage(number); await sendMessage(number);
sendMessageToNode(number)
process.exit(0); process.exit(0);
}); });
...@@ -57,19 +57,6 @@ socket.on("listening", function() { ...@@ -57,19 +57,6 @@ socket.on("listening", function() {
); );
}); });
function syn(machineNumberBeingChecked) {
console.log(machineNumberBeingChecked);
console.log("my machien number" + machineNumber);
const message = Buffer.from(`check ${machineToIps[machineNumber]}`);
socket.send(
message,
0,
message.length,
PORT,
machineToIps[machineNumberBeingChecked],
function() {}
);
}
function initialize(machineNumber, connectedTo) { function initialize(machineNumber, connectedTo) {
const message = Buffer.from(`initialize [${connectedTo}]`); const message = Buffer.from(`initialize [${connectedTo}]`);
......
...@@ -163,6 +163,15 @@ socket.on("message", function(message, rinfo) { ...@@ -163,6 +163,15 @@ socket.on("message", function(message, rinfo) {
if (text[0] === "ack") { if (text[0] === "ack") {
updateTimeStamp(text[1]) updateTimeStamp(text[1])
updateStatuses() updateStatuses()
}
if (text[0] === "leave") {
console.log(text[1])
const deletedConnection = Object.keys(connections).filter(c => c.toString()[0] === text[1]);
console.log(deletedConnection)
// delete myArray["lastname"];
} }
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment