This commit is contained in:
Pritesh Nandgaonkar
2018-06-05 17:02:01 -04:00
parent 43086d9c93
commit 541a4f1b98
8 changed files with 228 additions and 228 deletions

View File

@@ -68,7 +68,7 @@ SPEC CHECKSUMS:
glog: fdb5d40eb83acd6a4d5d61d95ecc583f5970a119
OpenSSL-Universal: 401888162f11c33ebbd46f782d9229da35c61327
PeerTalk: aadc42bc7d7f19e89f817b59ef8196305a711504
RSocket: 38b24504db9efbfb018a3b2b23a2d9500140a2a7
RSocket: e9ee232080f995ba8f403ccf4cb61238a5646cb6
Sonar: 29d8fb9b010e56fa1358be996d68d4b436dd8c21
PODFILE CHECKSUM: a6a7b2201d324f787ef4956b045f021e7152fddf

View File

@@ -10,9 +10,9 @@ PODS:
- CocoaLibEvent (~> 1.0)
- DoubleConversion
- glog
- OpenSSL-Universal (~> 1.0)
- OpenSSL-Static (= 1.0.2.c1)
- glog (0.3.5)
- OpenSSL-Universal (1.0.2.13)
- OpenSSL-Static (1.0.2.c1)
- PeerTalk (1.0.0)
- RSocket (0.10.0):
- Folly
@@ -22,7 +22,7 @@ PODS:
- SonarKit (0.0.1):
- CocoaAsyncSocket (~> 7.6)
- Folly
- OpenSSL-Universal (~> 1.0)
- OpenSSL-Static (= 1.0.2.c1)
- PeerTalk
- Sonar
- SonarKit/SKIOSNetworkPlugin (= 0.0.1)
@@ -33,7 +33,7 @@ PODS:
- SonarKit/SKIOSNetworkPlugin (0.0.1):
- CocoaAsyncSocket (~> 7.6)
- Folly
- OpenSSL-Universal (~> 1.0)
- OpenSSL-Static (= 1.0.2.c1)
- PeerTalk
- Sonar
- SonarKit/SonarKitNetworkPlugin
@@ -41,7 +41,7 @@ PODS:
- CocoaAsyncSocket (~> 7.6)
- ComponentKit
- Folly
- OpenSSL-Universal (~> 1.0)
- OpenSSL-Static (= 1.0.2.c1)
- PeerTalk
- Sonar
- SonarKit/SonarKitLayoutPlugin
@@ -49,7 +49,7 @@ PODS:
- SonarKit/SonarKitLayoutPlugin (0.0.1):
- CocoaAsyncSocket (~> 7.6)
- Folly
- OpenSSL-Universal (~> 1.0)
- OpenSSL-Static (= 1.0.2.c1)
- PeerTalk
- Sonar
- Yoga (~> 1.8)
@@ -57,7 +57,7 @@ PODS:
- SonarKit/SonarKitNetworkPlugin (0.0.1):
- CocoaAsyncSocket (~> 7.6)
- Folly
- OpenSSL-Universal (~> 1.0)
- OpenSSL-Static (= 1.0.2.c1)
- PeerTalk
- Sonar
- Yoga (1.8.1)
@@ -82,7 +82,7 @@ SPEC REPOS:
- boost-for-react-native
- CocoaAsyncSocket
- CocoaLibEvent
- OpenSSL-Universal
- OpenSSL-Static
- Yoga
- YogaKit
@@ -127,13 +127,13 @@ SPEC CHECKSUMS:
CocoaLibEvent: 2fab71b8bd46dd33ddb959f7928ec5909f838e3f
ComponentKit: 7bd0ad508946aeb68dd52ed8739ced9846ff3671
DoubleConversion: 9bd61b1134a393694e95e0950c5bf3f99534817f
Folly: ce1c216bcb099ca6cda58fefbba02bf2e9fe0381
Folly: 551752534f77d816ebf69195405d9d0fbd3efcc0
glog: fdb5d40eb83acd6a4d5d61d95ecc583f5970a119
OpenSSL-Universal: 401888162f11c33ebbd46f782d9229da35c61327
OpenSSL-Static: bd17e34564a8591ad76b740318683a6caa19a13e
PeerTalk: aadc42bc7d7f19e89f817b59ef8196305a711504
RSocket: 38b24504db9efbfb018a3b2b23a2d9500140a2a7
RSocket: e9ee232080f995ba8f403ccf4cb61238a5646cb6
Sonar: 29d8fb9b010e56fa1358be996d68d4b436dd8c21
SonarKit: 748eeb4e6f10af7abe946e11d087dd2a2d5b514c
SonarKit: f127bb6582dd1d2590e91937bea9793e95d8a159
Yoga: e6f1fed82138c17da5332e15e5770abf0e9cc386
YogaKit: bb90d11e297e06abef7e0cfb20e035a6bd00cdc4

View File

@@ -1,18 +1,18 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import <Foundation/Foundation.h>
@interface SKPortForwardingServer : NSObject
- (instancetype)init;
- (void)listenForMultiplexingChannelOnPort:(NSUInteger)port;
- (void)forwardConnectionsFromPort:(NSUInteger)port;
- (void)close;
@end
// /*
// * Copyright (c) 2018-present, Facebook, Inc.
// *
// * This source code is licensed under the MIT license found in the LICENSE
// * file in the root directory of this source tree.
// *
// */
// #import <Foundation/Foundation.h>
//
// @interface SKPortForwardingServer : NSObject
//
// - (instancetype)init;
//
// - (void)listenForMultiplexingChannelOnPort:(NSUInteger)port;
// - (void)forwardConnectionsFromPort:(NSUInteger)port;
// - (void)close;
//
// @end

View File

@@ -1,190 +1,190 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#import "SKPortForwardingServer.h"
#import <UIKit/UIKit.h>
#import <CocoaAsyncSocket/GCDAsyncSocket.h>
#import <peertalk/PTChannel.h>
#import "SKMacros.h"
#import "SKPortForwardingCommon.h"
@interface SKPortForwardingServer () <PTChannelDelegate, GCDAsyncSocketDelegate>
@property (nonatomic, weak) PTChannel *serverChannel;
@property (nonatomic, weak) PTChannel *peerChannel;
@property (nonatomic, strong) GCDAsyncSocket *serverSocket;
@property (nonatomic, strong) NSMutableDictionary *clientSockets;
@property (nonatomic, assign) UInt32 lastClientSocketTag;
@property (nonatomic, strong) dispatch_queue_t socketQueue;
@property (nonatomic, strong) PTProtocol *protocol;
@end
@implementation SKPortForwardingServer
- (instancetype)init
{
if (self = [super init]) {
_socketQueue = dispatch_queue_create("SKPortForwardingServer", DISPATCH_QUEUE_SERIAL);
_lastClientSocketTag = 0;
_clientSockets = [NSMutableDictionary dictionary];
_protocol = [[PTProtocol alloc] initWithDispatchQueue:_socketQueue];
}
return self;
}
- (void)dealloc
{
[self close];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)forwardConnectionsFromPort:(NSUInteger)port
{
[self _forwardConnectionsFromPort:port reportError:YES];
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
[self _forwardConnectionsFromPort:port reportError:NO];
}];
}
- (void)_forwardConnectionsFromPort:(NSUInteger)port reportError:(BOOL)shouldReportError
{
GCDAsyncSocket *serverSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:_socketQueue];
NSError *listenError;
if ([serverSocket acceptOnPort:port error:&listenError]) {
self.serverSocket = serverSocket;
} else {
if (shouldReportError) {
SKLog(@"Failed to listen: %@", listenError);
}
}
}
- (void)listenForMultiplexingChannelOnPort:(NSUInteger)port
{
[self _listenForMultiplexingChannelOnPort:port reportError:YES];
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
[self _listenForMultiplexingChannelOnPort:port reportError:NO];
}];
}
- (void)_listenForMultiplexingChannelOnPort:(NSUInteger)port reportError:(BOOL)shouldReportError
{
PTChannel *channel = [[PTChannel alloc] initWithProtocol:_protocol delegate:self];
[channel listenOnPort:port IPv4Address:INADDR_LOOPBACK callback:^(NSError *error) {
if (error) {
if (shouldReportError) {
SKLog(@"Failed to listen on 127.0.0.1:%lu: %@", (unsigned long)port, error);
}
} else {
SKTrace(@"Listening on 127.0.0.1:%lu", (unsigned long)port);
self.serverChannel = channel;
}
}];
}
- (void)close
{
if (self.serverChannel) {
[self.serverChannel close];
self.serverChannel = nil;
}
[self.serverSocket disconnect];
}
#pragma mark - PTChannelDelegate
- (void)ioFrameChannel:(PTChannel *)channel didAcceptConnection:(PTChannel *)otherChannel fromAddress:(PTAddress *)address {
// Cancel any other connection. We are FIFO, so the last connection
// established will cancel any previous connection and "take its place".
if (self.peerChannel) {
[self.peerChannel cancel];
}
// Weak pointer to current connection. Connection objects live by themselves
// (owned by its parent dispatch queue) until they are closed.
self.peerChannel = otherChannel;
self.peerChannel.userInfo = address;
SKTrace(@"Connected to %@", address);
}
- (void)ioFrameChannel:(PTChannel *)channel didReceiveFrameOfType:(uint32_t)type tag:(uint32_t)tag payload:(PTData *)payload {
//NSLog(@"didReceiveFrameOfType: %u, %u, %@", type, tag, payload);
if (type == SKPortForwardingFrameTypeWriteToPipe) {
GCDAsyncSocket *sock = self.clientSockets[@(tag)];
[sock writeData:[NSData dataWithBytes:payload.data length:payload.length] withTimeout:-1 tag:0];
SKTrace(@"channel -> socket (%d), %zu bytes", tag, payload.length);
}
if (type == SKPortForwardingFrameTypeClosePipe) {
GCDAsyncSocket *sock = self.clientSockets[@(tag)];
[sock disconnectAfterWriting];
}
}
- (void)ioFrameChannel:(PTChannel *)channel didEndWithError:(NSError *)error {
for (GCDAsyncSocket *sock in [_clientSockets objectEnumerator]) {
[sock setDelegate:nil];
[sock disconnect];
}
[self.clientSockets removeAllObjects];
SKTrace(@"Disconnected from %@, error = %@", channel.userInfo, error);
}
#pragma mark - GCDAsyncSocketDelegate
- (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket
{
dispatch_block_t block = ^() {
if (!self.peerChannel) {
[newSocket setDelegate:nil];
[newSocket disconnect];
}
UInt32 tag = ++self->_lastClientSocketTag;
newSocket.userData = @(tag);
newSocket.delegate = self;
self.clientSockets[@(tag)] = newSocket;
[self.peerChannel sendFrameOfType:SKPortForwardingFrameTypeOpenPipe tag:self->_lastClientSocketTag withPayload:nil callback:^(NSError *error) {
SKTrace(@"open socket (%d), error = %@", (unsigned int)tag, error);
[newSocket readDataWithTimeout:-1 tag:0];
}];
};
if (_peerChannel) {
block();
} else {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), _socketQueue, block);
}
}
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)_
{
UInt32 tag = [[sock userData] unsignedIntValue];
SKTrace(@"Incoming data on socket (%d) - %lu bytes", (unsigned int)tag, (unsigned long)data.length);
[_peerChannel sendFrameOfType:SKPortForwardingFrameTypeWriteToPipe tag:tag withPayload:NSDataToGCDData(data) callback:^(NSError *error) {
SKTrace(@"socket (%d) -> channel %lu bytes, error = %@", (unsigned int)tag, (unsigned long)data.length, error);
[sock readDataWithTimeout:-1 tag:_];
}];
}
- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err
{
UInt32 tag = [sock.userData unsignedIntValue];
[_clientSockets removeObjectForKey:@(tag)];
[_peerChannel sendFrameOfType:SKPortForwardingFrameTypeClosePipe tag:tag withPayload:nil callback:^(NSError *error) {
SKTrace(@"socket (%d) disconnected, err = %@, peer error = %@", (unsigned int)tag, err, error);
}];
}
@end
// /*
// * Copyright (c) 2018-present, Facebook, Inc.
// *
// * This source code is licensed under the MIT license found in the LICENSE
// * file in the root directory of this source tree.
// *
// */
// #import "SKPortForwardingServer.h"
//
// #import <UIKit/UIKit.h>
//
// #import <CocoaAsyncSocket/GCDAsyncSocket.h>
// #import <peertalk/PTChannel.h>
//
// #import "SKMacros.h"
// #import "SKPortForwardingCommon.h"
//
// @interface SKPortForwardingServer () <PTChannelDelegate, GCDAsyncSocketDelegate>
//
// @property (nonatomic, weak) PTChannel *serverChannel;
// @property (nonatomic, weak) PTChannel *peerChannel;
//
// @property (nonatomic, strong) GCDAsyncSocket *serverSocket;
// @property (nonatomic, strong) NSMutableDictionary *clientSockets;
// @property (nonatomic, assign) UInt32 lastClientSocketTag;
// @property (nonatomic, strong) dispatch_queue_t socketQueue;
// @property (nonatomic, strong) PTProtocol *protocol;
//
// @end
//
// @implementation SKPortForwardingServer
//
// - (instancetype)init
// {
// if (self = [super init]) {
// _socketQueue = dispatch_queue_create("SKPortForwardingServer", DISPATCH_QUEUE_SERIAL);
// _lastClientSocketTag = 0;
// _clientSockets = [NSMutableDictionary dictionary];
// _protocol = [[PTProtocol alloc] initWithDispatchQueue:_socketQueue];
// }
// return self;
// }
//
// - (void)dealloc
// {
// [self close];
// [[NSNotificationCenter defaultCenter] removeObserver:self];
// }
//
// - (void)forwardConnectionsFromPort:(NSUInteger)port
// {
// [self _forwardConnectionsFromPort:port reportError:YES];
// [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
// [self _forwardConnectionsFromPort:port reportError:NO];
// }];
// }
//
// - (void)_forwardConnectionsFromPort:(NSUInteger)port reportError:(BOOL)shouldReportError
// {
// GCDAsyncSocket *serverSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:_socketQueue];
// NSError *listenError;
// if ([serverSocket acceptOnPort:port error:&listenError]) {
// self.serverSocket = serverSocket;
// } else {
// if (shouldReportError) {
// SKLog(@"Failed to listen: %@", listenError);
// }
// }
// }
//
// - (void)listenForMultiplexingChannelOnPort:(NSUInteger)port
// {
// [self _listenForMultiplexingChannelOnPort:port reportError:YES];
// [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
// [self _listenForMultiplexingChannelOnPort:port reportError:NO];
// }];
// }
//
// - (void)_listenForMultiplexingChannelOnPort:(NSUInteger)port reportError:(BOOL)shouldReportError
// {
// PTChannel *channel = [[PTChannel alloc] initWithProtocol:_protocol delegate:self];
// [channel listenOnPort:port IPv4Address:INADDR_LOOPBACK callback:^(NSError *error) {
// if (error) {
// if (shouldReportError) {
// SKLog(@"Failed to listen on 127.0.0.1:%lu: %@", (unsigned long)port, error);
// }
// } else {
// SKTrace(@"Listening on 127.0.0.1:%lu", (unsigned long)port);
// self.serverChannel = channel;
// }
// }];
// }
//
// - (void)close
// {
// if (self.serverChannel) {
// [self.serverChannel close];
// self.serverChannel = nil;
// }
// [self.serverSocket disconnect];
// }
//
// #pragma mark - PTChannelDelegate
//
// - (void)ioFrameChannel:(PTChannel *)channel didAcceptConnection:(PTChannel *)otherChannel fromAddress:(PTAddress *)address {
// // Cancel any other connection. We are FIFO, so the last connection
// // established will cancel any previous connection and "take its place".
// if (self.peerChannel) {
// [self.peerChannel cancel];
// }
//
// // Weak pointer to current connection. Connection objects live by themselves
// // (owned by its parent dispatch queue) until they are closed.
// self.peerChannel = otherChannel;
// self.peerChannel.userInfo = address;
// SKTrace(@"Connected to %@", address);
// }
//
// - (void)ioFrameChannel:(PTChannel *)channel didReceiveFrameOfType:(uint32_t)type tag:(uint32_t)tag payload:(PTData *)payload {
// //NSLog(@"didReceiveFrameOfType: %u, %u, %@", type, tag, payload);
// if (type == SKPortForwardingFrameTypeWriteToPipe) {
// GCDAsyncSocket *sock = self.clientSockets[@(tag)];
// [sock writeData:[NSData dataWithBytes:payload.data length:payload.length] withTimeout:-1 tag:0];
// SKTrace(@"channel -> socket (%d), %zu bytes", tag, payload.length);
// }
//
// if (type == SKPortForwardingFrameTypeClosePipe) {
// GCDAsyncSocket *sock = self.clientSockets[@(tag)];
// [sock disconnectAfterWriting];
// }
// }
//
// - (void)ioFrameChannel:(PTChannel *)channel didEndWithError:(NSError *)error {
// for (GCDAsyncSocket *sock in [_clientSockets objectEnumerator]) {
// [sock setDelegate:nil];
// [sock disconnect];
// }
// [self.clientSockets removeAllObjects];
// SKTrace(@"Disconnected from %@, error = %@", channel.userInfo, error);
// }
//
//
// #pragma mark - GCDAsyncSocketDelegate
//
// - (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket
// {
// dispatch_block_t block = ^() {
// if (!self.peerChannel) {
// [newSocket setDelegate:nil];
// [newSocket disconnect];
// }
//
// UInt32 tag = ++self->_lastClientSocketTag;
// newSocket.userData = @(tag);
// newSocket.delegate = self;
// self.clientSockets[@(tag)] = newSocket;
// [self.peerChannel sendFrameOfType:SKPortForwardingFrameTypeOpenPipe tag:self->_lastClientSocketTag withPayload:nil callback:^(NSError *error) {
// SKTrace(@"open socket (%d), error = %@", (unsigned int)tag, error);
// [newSocket readDataWithTimeout:-1 tag:0];
// }];
// };
//
// if (_peerChannel) {
// block();
// } else {
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), _socketQueue, block);
// }
// }
//
// - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)_
// {
// UInt32 tag = [[sock userData] unsignedIntValue];
// SKTrace(@"Incoming data on socket (%d) - %lu bytes", (unsigned int)tag, (unsigned long)data.length);
// [_peerChannel sendFrameOfType:SKPortForwardingFrameTypeWriteToPipe tag:tag withPayload:NSDataToGCDData(data) callback:^(NSError *error) {
// SKTrace(@"socket (%d) -> channel %lu bytes, error = %@", (unsigned int)tag, (unsigned long)data.length, error);
// [sock readDataWithTimeout:-1 tag:_];
// }];
// }
//
// - (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err
// {
// UInt32 tag = [sock.userData unsignedIntValue];
// [_clientSockets removeObjectForKey:@(tag)];
// [_peerChannel sendFrameOfType:SKPortForwardingFrameTypeClosePipe tag:tag withPayload:nil callback:^(NSError *error) {
// SKTrace(@"socket (%d) disconnected, err = %@, peer error = %@", (unsigned int)tag, err, error);
// }];
// }
//
//
// @end

View File

@@ -11,8 +11,8 @@ Pod::Spec.new do |spec|
spec.dependency 'boost-for-react-native'
spec.dependency 'DoubleConversion'
spec.dependency 'glog'
spec.dependency 'OpenSSL-Universal', '~> 1.0'
spec.dependency 'CocoaLibEvent', '~> 1.0'
#spec.dependency 'OpenSSL-Static', '1.0.2.c1'
#spec.dependency 'CocoaLibEvent', '~> 1.0'
spec.compiler_flags = '-DFOLLY_HAVE_PTHREAD=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_HAVE_LIBGFLAGS=0 -DFOLLY_HAVE_LIBJEMALLOC=0 -DFOLLY_HAVE_PREADV=0 -DFOLLY_HAVE_PWRITEV=0 -DFOLLY_HAVE_TFO=0 -DFOLLY_USE_SYMBOLIZER=0 -frtti
-fexceptions
-std=c++14

View File

@@ -43,8 +43,8 @@ Pod::Spec.new do |spec|
'yarpl/utils/*.h',
'yarpl/*.h',
'**/*.h'
spec.header_mappings_dir = './*'
spec.header_dir = './*'
spec.header_mappings_dir = 'rsocket'
spec.header_dir = 'rsocket'
spec.pod_target_xcconfig = { "USE_HEADERMAP" => "NO",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)\"/** \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/glog\" \"$(PODS_ROOT)/DoubleConversion\"/**" }