Update L7 APIs to be transport agnostic#42
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently each L7 API (
@tcpip/http,@tcpip/dns,@tcpip/dhcp) depends on atcpipNetworkStackas the transport layer that their protocols operate on top of (@tcpip/httpusesstack.connectTcp(),@tcpip/dnsusesstack.openUdp(), etc).This PR does a number of API changes to make these L7 APIs transport agnostic - meaning that a
tcpipNetworkStackis only one implementation of TCP/UDP, but you can plug in your own transport if you want. In the future we'll add helpers that would allow you to use these L7 APIs on top of Node and Deno TCP/UDP APIs.The core change is that each L7 factory function accepts transport interface instead of a
NetworkStack. The stateful TCP-style transport is calledStreamTransportwithconnect()andlisten()methods, and the connectionless UDP-style transport is calledDatagramTransportwith anopen()method. Anyone can implement these methods to provide the underlying stream or datagram style transport that the higher level protocol operates on top of.@tcpip/httpusesStreamTransport,@tcpip/dnsand@tcpip/dhcpuseDatagramTransport.To make
tcpipmatch these transport interfaces, we changedNetworkStackto nest protocol methods within their own objects:It is arguably a better API anyway, because it groups methods within each protocol vs a flat list of methods between all protocols. Because
stack.tcpimplementsStreamTransport, using it in@tcpip/httpis as simple as:And the same applies to other L7 APIs (e.g.
@tcpip/dnswithstack.udp).This is a breaking change for most packages.