A libp2p load balancer that allows forwarding to other peers based on Libp2p protocol ID
Nodes A & B want to share a peer ID via a Load Balancer Node LB. Node LB will route all traffic for protocols A1 & A2 to node A, while Node LB will route all traffic for protocols B1 & B2 to Node B.
Nodes A & B will not be publicly reachable
Nodes A, B, and LB have high internal trust of each other (i.e. they are run by the same actual person/operation), but may or may not be on the same machine
Node A connects and opens a stream to Node LB on the load balancer routing request protocol and sends a request to route protocols A1 & A2.
Node LB responds with an acknowledgement accepting the request on the load balancer routing request protocol. The acknowledgement includes a TTL specifying when the routing will expire.
Node LB begins accepting new streams on Protocols A1 & A2
(node B similarly performs setup for protocols B1 & B2)
Incoming new stream:
Node LB receives an incoming stream on protocol A1 from Node D
It opens a new stream to node A on the load balancer forwarding protocol
Prior to any data, node LB sends a load balancer metadata packet to node A indicating the stream is originally from node D on protocol A1. Prior to any data, node A sends a metadata packet to node LB accepting the stream
Subsequently, this stream now behaves like the original protocol A1, with the LB forwarding all reads & writes on this stream between nodes A & D until close
Outgoing new stream:
Node B wants to send data to Node E on either protocol B1 or protocol B2 via the Load Balancer Node B opens a new stream on the load balancer forwarding protocol to the load balancer Prior to any data, Node B sends a load balancer metadata packet to node LB indicating the stream is intended for node E on either protocol B1 or protocol B2. Node LB attempts to open a stream to Node E on either protocol B1 or protocol B2 Node E accepts on protocol B2
Node LB sends a metadata packet to node B accepting the stream and indicating the accepted protocol is B2 Subsequently, this stream now behaves like the original protocol B2, with the LB forwarding all reads & writes on this stream between nodes B & E until close
Extend Routing:
Protocol ID: /libp2p/balancer/routing-request