HTML5 Web Workers allow multi-threaded apps in the browser.
This page outlines the thread structure of NFD-js.
For an exploration of thread managment at a higher level, see the worker management section in NFD-js Component Modules
Main (UI) Thread
Though we desire that as little code be executed in the main thread as possible, the limited scope of Webworkers imposes upon us the need to keep some functions and handlers in userspace:
- WebRTC Peerconnections are defined as properties of the window object.
- Forge (used for generation of public and private keys) references the window object. So keys must be generated once and passed into the daemon for persistence (this will necessitate some creative signaling to evaluate the presence of a keypair in the lower thread and generate only when necessary)
NFD thread
The main forwarding plane will exist in its own thread, managing multiple facades on the upstream interfaces representing each peerconnection. This will require a Worker Transport class for use with the NDN-js Face constructor
The forwarder interperets and forwards Interest and Data packets according to FIB/PIT lookup and interacts with the cache.
Since the PIT, FIB and cache will potentially hold very large data sets upon which lookups may be computationally expensive compared to the actual forwarding, we will place the PIT, FIB and cache each within their own discreet sub worker and consult them asynchronously
We also require two additional subworkers: One to hold the IndexedDB for the repository, and one to manage content verification, which is very computationaly intensive
NFD Sub workers