Skip to content

Commit

Permalink
fix: add flood protect to the queue servicer
Browse files Browse the repository at this point in the history
  • Loading branch information
edfletcher committed Jun 17, 2023
1 parent 46214c6 commit 9b670d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ module.exports = class IrcClient extends EventEmitter {
sasl_disconnect_on_fail: false,
transport: default_transport,
websocket_protocol: 'text.ircv3.net',
serialize_writes: false
serialize_writes: false,
serialized_writes_flood_protect_ms: 100
};

const props = Object.keys(defaults);
Expand Down
5 changes: 4 additions & 1 deletion src/transports/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const SOCK_DISCONNECTED = 0;
const SOCK_CONNECTING = 1;
const SOCK_CONNECTED = 2;

const FLOOD_PROTECT_WAIT_MS = 100;

module.exports = class Connection extends EventEmitter {
constructor(options) {
super();
Expand Down Expand Up @@ -91,6 +93,7 @@ module.exports = class Connection extends EventEmitter {
this.incoming_buffer = Buffer.from('');

if (options.serialize_writes) {
const flood_protect_wait_ms = options.serialized_writes_flood_protect_ms || FLOOD_PROTECT_WAIT_MS;
this.write_queue = [];
this.write_queue_servicer = () => {
if (this.write_queue.length) {
Expand All @@ -100,7 +103,7 @@ module.exports = class Connection extends EventEmitter {
}

this.write_queue = this.write_queue.slice(1);
process.nextTick(this.write_queue_servicer);
setTimeout(this.write_queue_servicer, flood_protect_wait_ms);
});
}
};
Expand Down

0 comments on commit 9b670d3

Please sign in to comment.