Monday, July 12, 2021

What's a decent protocol/FOSS implementation for naive multiplexing of multiple tcp streams over one port?

Hi. Long time lurker, first time poster. Wasn't sure if this would be more suited to /r/networking, /r/linux, /r/cpp, /r/programming or others, so I'm starting here.

Hopefully one of you kind souls will have a simple solution.

What's a decent, free, off the shelf, method to multiplex multiple TCP streams on the same IP over one stream/port number?

I could implement my own library without TOO much thinking (and w/ plenty of time), but I'm trying to get out of the habit of rolling-my-own just because I can. It's a bad habit.

What I have:

  • Working server code which implements several off-the-shelf TCP based services, as well as a custom one. Less vague: VNC (port 5900), Chrome DevTools (port 9222), custom-thingie (port 9999).

  • Working client code which connects to the server, and all 3 services, given all 3 port numbers.

What I want:

  • Some sort of middleware (stand alone or library), which lets me put all of the server protocols "under" a single port number (aka multiplex), and a counterpart for the client. From an admin perspective it's easier to manage a single port number than several, and it's more correct to have my service use a single port number, than a tuple of them, where the tuple might change as implementation progresses.

  • For this middleware/library to be LOW OVERHEAD and trivially cross platform. I only touch Linux, but I've taken care, so far, to write cross platform code and use protocols and libraries which work on other platforms, and I'd hate to sacrifice that now.

What I'm considering/am aware of:

  • vtun?

    • overkill? it encapsulates at the IP (tun) or Ethernet (tap) layer, and I don't want all that. I just need to multiplex multiple TCP streams over one. Also, I have no idea if it works cross platform or how much work it would be to make it a library.
  • ssh?

    • even more overkill? Authentication is already handled out of bound, so I'd need to disable all of that in ssh.. somehow. And encryption. I have no idea how easy it is to use as a library. Also using ssh SIMPLY for it's port forwarding-multiplexing abilities seems bloated, but maybe I'm wrong.

TL;DR: I could write it myself, but what's a free and easy way to wrap multiple existing TCP-based services, both client and server (which I control the code of) so that they can use a single port number instead of several. I'm thinking something like socat except with fan-out.

Thanks for your time.



No comments:

Post a Comment