Above that layer sits a transport layer, so this is like UDP or TCP are examples of protocol implementations of this layer, and these provide things like reliability, like preventing double-received packets, automatically retrying drop packets, or handling streaming, like TCP does.
And then above the transport layer sits the application layer, which we all know and love, and it's just really easy to work with as a developer. It gives us a bunch of nice developer, end-user developer tools like giving HTTP methods, or headers, or cookies, or encryption, or user-readable addressing, which is like when DNS translates a website URL to the IP address that you're trying to target. And we decided to borrow all of this for our stack, which looks like this.
It's not very creatively named. It's pretty much just the same layer names. But at the bottom, we have the link layer, which, just like the link layer at the TCP IP stack, our link layer handles picking the correct messaging API supplied by the browser. So one example is like Chrome Runtime.sendMessage. Another example is window.postMessage. We just kind of pick what is the right messaging API based on the source and the destination.
The layer above that is the packet layer, which, just like the internet layer and IP packets, we handle routing at this layer via our routing table. Our routing table is much simpler because the structure of our browser extension is pretty well-defined. You don't have to have an algorithm like BGP to determine it. So our routing table is hard-coded. Above the packet layer sits the datagram layer, which is what we ended up implementing the chunking that we needed to for incognito at this layer. We still made use of object URL fetching, but we basically determine which protocol to use at this layer, like whether we need chunking or whether we can use object URLs, and by whether the sender and receiver are both in the same incognito context.
And then above the datagram layer is the application layer, which is where we implemented a broker-style pattern, which you can use for sending and receiving messages, and it's very convenient. You can think of it kind of like HTTP. You don't have to think about any of these other layers whenever you're working on the application layer. This basically solved all our problems. So here's our problems and here's our solutions. For different underlying messaging APIs, we abstracted this with the link layer, which handles those. With size constraints for messages, we handled this by chunking at the datagram layer. Components not being able to communicate directly, we handled this by packet-forwarding at the packet layer, so we can hop over components as we want to reach the host script. Having multiple tabs or pop-ups, this was handled with independent addressing at the packet layer too. Messages being dropped, we handled this via packet retries at the datagram layer, and memory sharing not being allowed. This is that dynamic switching between chunking versus another protocol at the datagram layer based on if the sender or receiver is incognito. And that's pretty much it. Looking back at this project, this was somewhere around eight months ago. We had some big benefits from this.
Comments