react-native/Tools/FBPortForwarding
Alex Kotliarskyi c4699d8b73 Open source FBPortForwarding
Summary:FBPortForwarding is incomplete and flaky implementation of `adb reverse`
functionality for iOS. We haven't worked on it internally for a while now,
but I think it might be a very usefull tool for the community. Some external
contributors (hello philikon!) expressed interest in maintaining it.

This diff moves it over to OSS RN `Libraries` folder.

Reviewed By: vjeux

Differential Revision: D3056293

fb-gh-sync-id: 9ced61fa8480a923771bba26fe09337c344ab3b3
shipit-source-id: 9ced61fa8480a923771bba26fe09337c344ab3b3
2016-03-24 10:51:34 -07:00
..
Apps Open source FBPortForwarding 2016-03-24 10:51:34 -07:00
FBPortForwarding Open source FBPortForwarding 2016-03-24 10:51:34 -07:00
FBPortForwardingTests Open source FBPortForwarding 2016-03-24 10:51:34 -07:00
README.md Open source FBPortForwarding 2016-03-24 10:51:34 -07:00

README.md

FBPortForwarding

FBPortForwarding lets you expose your Mac's port to iOS device via lightning cable. The typical usecase is connecting to a TCP server that runs on OS X from an iPhone app without common WiFi network.

Benefits:

  1. No need to be on the same WiFi, worry about firewalls (fbguest) or VPN
  2. iOS app doesn't have to know your Mac's IP address
  3. Secure - communication is possible only when connected via USB

How it works

iOS provides a way to connect to device's TCP server from Mac via USBHub, but there is no API to connect from iOS to TCP server running on Mac. FBPortForwarding uses Peertalk to establish communication channel from Mac to iOS, creates a TCP server on iOS and multiplexes all connections to that server via the peertalk channel. Helper app running on Mac listens for commands on the peertalk channel and initializes TCP connections to local port and forwards all communication back via the same peertalk channel.

                                                   |
                                      iOS Device   |   Mac
                                                   |
                             +----------------+            +----------------+
                             |Peertalk Server |  connect   |Peertalk Client |
                             |                <------------+                |
                             |                |            |                |
                             |       Port 8025|            |                |
                             +----+-----------+            +---------^------+
                                  |                                  |
                                  |                                  |
incoming     +----------------+   |                                  |                 +--------------+
connections  |Proxy Server    |   |                                  |                 |Real Server   |

------------->> | | +-------------+ commands | | | | Port 8081| | create | | stream | | Port 8081| +-+--------------+ +---------> Peertalk <----------+ +-^------------+ | | Channel | ^ | +--------+ | | +--------+ | outgoing | | | onConnect | | connect | | | connections +---> Client +---------------> OpenPipe +---------------> Client +-----+ | #[tag] | onRead | | write | #[tag] | | +---------------> WriteToPipe +---------------> | | | onDisconnect | | disconnect | | | +---------------> ClosePipe +---------------> | | | | | | | | | write | | onRead | | | <---------------+ WriteToPipe <---------------+ | | | close | | onDisconnect | | | <---------------+ ClosePipe <---------------+ | | | | | | | +--------+ | | +--------+ +-------------+

First, the library on iOS device creates a TCP server on the port we want to forward (let's say 8081) and a special Peertalk server on port 8025. Mac helper app looks for connected iOS devices, and once it finds one it connects to its peertalk server. Only one channel is created that's going to be used for multiplexing data.

When a socket connects to local proxy server, FBPortForwarding is going to assign a tag to the connection and use peertalk channel to tell Mac helper app to connect to TCP port 8081 on Mac. Now events and data on both sides of the wire are going to be multiplexed and transferred via the peertalk channel.