Use EventEmitter for remote client connections #11
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
First, read the full README of proxy-packer for context: https://git.coolaj86.com/coolaj86/proxy-packer.js
All of the packerHandlers (see near https://git.coolaj86.com/coolaj86/telebit.js/src/branch/master/lib/remote.js#L267), especially
onconnection
,onmessage
, andonerror
(see https://git.coolaj86.com/coolaj86/telebit.js/src/branch/master/lib/remote.js#L343), but excludingoncontrol
(which is a relay server message, not a client message), should be converted to select from a map of EventEmmiters.We need to be using
on('readable')
andread()
instead ofon('data')
.However, the pause and resume events cannot directly apply backpressure - because there is a single TCP stream and multiple clients that may need individual backpressure applied, as if they had their own TCP stream. There will need to be a buffer of a certain number of bytes (let's start with 16kb as it's about 10 * 1500 - assuming non-jumbo packets). If the data raises above the "waterline" the client should fire the pause event. When it goes some amount, say 50%, below the waterline we'll want to fire the resume event.
The actual numbers on that may need to be way different. In fact, I'd say it'll probably be best to base it on the amount of memory available and the number of clients connected - the goal being to avoid the latency introduced by pausing and resuming, when reasonable.
That area of code definitely needs a refactor, but converting to event emitters without changing anything else that isn't necessary is a good start.
This could be developed in isolation by creating a test based on https://git.coolaj86.com/coolaj86/proxy-packer.js/src/branch/master/test/parse.js but I think it's probably best just to wing it and then do a manual test by restarting telebit and uploading and downloading a few files of several megabytes (i.e. create an app to run on port 3000 and then run
telebit http 3000
)