Add FBPortForwarding source code
Summary: See FBPortForwarding/README.md for an explanation of what this is. It's required for the upcoming support for physical iOS devices. To simplify development of the JS app, We're going to bundle the pre-built PortForwardingMacApp inside the repo, and inside the electron app (static/PortForwardingMacApp.app). Adding this source so users can build it from source if they choose to. Reviewed By: danielbuechele Differential Revision: D13276022 fbshipit-source-id: 99b18e0412cf443bb4a67eb4846cc780e0014de1
This commit is contained in:
committed by
Facebook Github Bot
parent
98110bc230
commit
8d93946739
66
iOS/FlipperKit/FKPortForwarding/README.md
Normal file
66
iOS/FlipperKit/FKPortForwarding/README.md
Normal file
@@ -0,0 +1,66 @@
|
||||
# FKPortForwarding
|
||||
|
||||
FKPortForwarding 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. FKPortForwarding
|
||||
uses [Peertalk](https://github.com/rsms/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, FKPortForwarding 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.
|
||||
Reference in New Issue
Block a user