Skip to content
Snippets Groups Projects
Commit d0acb5fa authored by Patrick Wahl's avatar Patrick Wahl
Browse files

Add buffer and delay to manager

parent 0a6a1679
Branches
No related tags found
No related merge requests found
...@@ -4,10 +4,15 @@ function Manager(self) { ...@@ -4,10 +4,15 @@ function Manager(self) {
this.ports = []; this.ports = [];
this.numports = 0; this.numports = 0;
this.addr_table = {}; this.addr_table = {};
this.buffer = [];
this.maxBufferSize = 252;
this.delay = 100; //ms
this.setup = function(numports) { this.setup = function(numports) {
this.numports = numports; this.numports = numports;
this.ports = new Array(numports).fill(-1); this.ports = new Array(numports).fill(-1);
setInterval(this.checkBuffer, this.delay);
}; };
this.printPorts = function() { this.printPorts = function() {
...@@ -17,7 +22,6 @@ function Manager(self) { ...@@ -17,7 +22,6 @@ function Manager(self) {
this.connect = function(port, id) { this.connect = function(port, id) {
if (!(port < this.numports)) { if (!(port < this.numports)) {
console.log('fuck');
return; return;
} }
...@@ -31,9 +35,6 @@ function Manager(self) { ...@@ -31,9 +35,6 @@ function Manager(self) {
this.ports[port] = id; this.ports[port] = id;
self.connect(id); self.connect(id);
} else {
console.log('double fuck');
}
}; };
this.disconnect = function(port) { this.disconnect = function(port) {
...@@ -92,6 +93,16 @@ function Manager(self) { ...@@ -92,6 +93,16 @@ function Manager(self) {
} }
var packet = o.obj; var packet = o.obj;
if (this.buffer.length < this.maxBufferSize) {
this.buffer.push(packet);
}
};
this.checkBuffer = function() {
if (this.buffer.length > 0) {
let packet = this.buffer.shift();
packet.edges += 1; packet.edges += 1;
if (!this.addr_table.hasOwnProperty(packet.src)) { if (!this.addr_table.hasOwnProperty(packet.src)) {
...@@ -104,7 +115,7 @@ function Manager(self) { ...@@ -104,7 +115,7 @@ function Manager(self) {
} }
this.handlePacket(packet); this.handlePacket(packet);
}
}; };
this.handlePacket = function(packet) { this.handlePacket = function(packet) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment