Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Sync Update - 66c9272
Browse files Browse the repository at this point in the history
Attempt Fix #41 #42
  • Loading branch information
Lakr233 committed Mar 15, 2022
1 parent d614128 commit 0ed9353
Show file tree
Hide file tree
Showing 22 changed files with 513 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,12 @@ struct MachineCreateView: View {
mainActorProgressView(show: true)

func createRemote() -> NSRemoteShell {
NSRemoteShell()
let shell = NSRemoteShell()
.setupConnectionHost(serverLocation)
.setupConnectionPort(NSNumber(value: Int(serverPort) ?? 0))
.setupConnectionTimeout(RayonStore.shared.timeoutNumber)
.requestConnectAndWait()
shell.requestConnectAndWait()
return shell
}

var remote = createRemote()
Expand Down Expand Up @@ -206,7 +207,7 @@ struct MachineCreateView: View {
.setupConnectionHost(serverLocation)
.setupConnectionPort(NSNumber(value: Int(serverPort) ?? 0))
.setupConnectionTimeout(RayonStore.shared.timeoutNumber)
.requestConnectAndWait()
remote.requestConnectAndWait()
identity.callAuthenticationWith(remote: remote)
debugPrint(remote.isAuthenicated)
guard remote.isAuthenicated else {
Expand Down
2 changes: 1 addition & 1 deletion Application/Rayon/Interface/Menubar/StatusItem+Loop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extension MenubarStatusItem {
.setupConnectionHost(machine.remoteAddress)
.setupConnectionPort(NSNumber(value: Int(machine.remotePort) ?? 0))
.setupConnectionTimeout(RayonStore.shared.timeoutNumber)
.requestConnectAndWait()
shell.requestConnectAndWait()
representedShell = shell
identity.callAuthenticationWith(remote: shell)
while loopContinue, shell.isConnected, shell.isAuthenicated {
Expand Down
8 changes: 7 additions & 1 deletion Application/Rayon/Rayon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
PRESERVE_DEAD_CODE_INITS_AND_TERMS = NO;
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
Expand Down Expand Up @@ -604,8 +607,11 @@
GCC_WARN_UNUSED_VARIABLE = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRESERVE_DEAD_CODE_INITS_AND_TERMS = NO;
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Release;
};
Expand Down
5 changes: 5 additions & 0 deletions Application/Rayon/macOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<dict>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSSupportsAutomaticTermination</key>
<false/>
<key>NSSupportsSuddenTermination</key>
Expand Down
8 changes: 8 additions & 0 deletions Application/mRayon/mRayon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand All @@ -513,7 +514,10 @@
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
PRESERVE_DEAD_CODE_INITS_AND_TERMS = NO;
SDKROOT = iphoneos;
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
Expand Down Expand Up @@ -553,6 +557,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -567,7 +572,10 @@
IPHONEOS_DEPLOYMENT_TARGET = 15.2;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRESERVE_DEAD_CODE_INITS_AND_TERMS = NO;
SDKROOT = iphoneos;
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
VALIDATE_PRODUCT = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableASanStackUseAfterReturn = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
5 changes: 5 additions & 0 deletions Application/mRayon/mRayon/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
</dict>
Expand Down
18 changes: 6 additions & 12 deletions Application/mRayon/mRayon/Interface/Terminal/TerminalContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ class TerminalContext: ObservableObject, Identifiable, Equatable {
defer { bufferAccessLock.unlock() }
guard !closed else { return }
_dataBuffer += str
TerminalContext.queue.async { [weak self] in
self?.shell.explicitRequestStatusPickup()
}
shell.explicitRequestStatusPickup()
}

var continueDecision: Bool = true {
Expand All @@ -100,17 +98,12 @@ class TerminalContext: ObservableObject, Identifiable, Equatable {

let termInterface: STerminalView = .init()

private static let queue = DispatchQueue(
label: "wiki.qaq.terminal",
attributes: .concurrent
)

init(machine: RDMachine) {
self.machine = machine
command = nil
remoteType = .machine
title = machine.name
TerminalContext.queue.async {
DispatchQueue.global().async {
self.processBootstrap()
}
}
Expand All @@ -126,7 +119,7 @@ class TerminalContext: ObservableObject, Identifiable, Equatable {
self.command = command
title = command.command
remoteType = .machine
TerminalContext.queue.async {
DispatchQueue.global().async {
self.processBootstrap()
}
}
Expand Down Expand Up @@ -289,8 +282,9 @@ class TerminalContext: ObservableObject, Identifiable, Equatable {
putInformation(" " + lastError)
}
continueDecision = false
TerminalContext.queue.async {
self.shell.requestDisconnectAndWait()
let shell = shell
DispatchQueue.global().async { [weak shell] in
shell?.requestDisconnectAndWait()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ struct TerminalView: View {
}
makeKeyboardFloatingButton("trash", disableWhenClosed: false) {
if context.closed {
TerminalManager.shared.end(for: context.id)
presentationMode.wrappedValue.dismiss()
context.destroyedSession = true
TerminalManager.shared.end(for: context.id)
} else {
UIBridge.requiresConfirmation(
message: "Are you sure you want to close this session?"
Expand Down
14 changes: 7 additions & 7 deletions External/NSRemoteShell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ There is two authenticate method provided. Authenticate is required after connec
For various session property, see property list.

```
@property(nonatomic, readwrite, nullable, strong) NSString *resolvedRemoteIpAddress;
@property(nonatomic, readwrite, nullable, strong) NSString *remoteBanner;
@property(nonatomic, readwrite, nullable, strong) NSString *remoteFingerPrint;
@property (nonatomic, readwrite, nullable, strong) NSString *resolvedRemoteIpAddress;
@property (nonatomic, readwrite, nullable, strong) NSString *remoteBanner;
@property (nonatomic, readwrite, nullable, strong) NSString *remoteFingerPrint;
@property(nonatomic, readwrite, getter=isConnected) BOOL connected;
@property(nonatomic, readwrite, getter=isAuthenicated) BOOL authenticated;
@property (nonatomic, readwrite, getter=isConnected) BOOL connected;
@property (nonatomic, readwrite, getter=isAuthenicated) BOOL authenticated;
```

Request either command channel or shell channel with designated API, and do not access unexposed values. It may break the ARC or crash the app.
Expand Down Expand Up @@ -107,7 +107,7 @@ We implemented thread safe by using NSEventLoop to serialize single NSRemoteShel
The event loop will guarantee status pickup is thread safe, called several times per second. To improve the performance and user experience, we use a dispatch source of your session's socket to trigger the event loop handler when you have at least one channel opened when data arrived. Check following code to see how it works.

```
- (void)uncheckedConcurrencyDispatchSourceMakeDecision
- (void)unsafeDispatchSourceMakeDecision
```

All event loop will call a NSRemoteShell objects' handleRequestsIfNeeded method, we deal with control blocks first, and then iterate over all channel to see if data available.
Expand All @@ -127,7 +127,7 @@ ARC will take place to disconnect if a shell object is no longer holds. You can
```
- (void)dealloc {
NSLog(@"shell object at %p deallocating", self);
[self uncheckedConcurrencyDisconnect];
[self unsafeDisconnect];
}
```

Expand Down
8 changes: 4 additions & 4 deletions External/NSRemoteShell/Sources/NSRemoteShell/GenericHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

/*
the interval for sending keep alive packet, count in second
[NSRemoteShell uncheckedConcurrencyKeepAliveCheck] will skip
[NSRemoteShell unsafeKeepAliveCheck] will skip
if last success attempt was within the interval
*/
#define KEEPALIVE_INTERVAL 1
Expand Down Expand Up @@ -87,13 +87,13 @@
// used in event loop call, it's time to handle operations inside this object
// eg: NSRemoteChannel should read/write to socket, set changes and do anything else
// is designed to be thread safe when calling
- (void)uncheckedConcurrencyCallNonblockingOperations;
- (void)unsafeCallNonblockingOperations;

// used to evaluate if this object should be close and release
// if a check failed, disconnect is immediately called
- (BOOL)uncheckedConcurrencyInsanityCheckAndReturnDidSuccess;
- (BOOL)unsafeInsanityCheckAndReturnDidSuccess;

// shutdown any associated resources and will soon be release
- (void)uncheckedConcurrencyDisconnectAndPrepareForRelease;
- (void)unsafeDisconnectAndPrepareForRelease;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ + (int)createSocketWithTargetHost:(NSString *)targetHost
close(forwardsock);
continue;
}
NSLog(@"created socket %d", forwardsock);
NSLog(@"created socket %d to address %s", forwardsock, str);
return forwardsock;
} else if ([candidateHostData length] == sizeof(struct sockaddr_in6)) {
struct sockaddr_in6 address6;
Expand All @@ -144,7 +144,7 @@ + (int)createSocketWithTargetHost:(NSString *)targetHost
close(forwardsock);
continue;
}
NSLog(@"created socket %d", forwardsock);
NSLog(@"created socket %d to address %s", forwardsock, str);
return forwardsock;
} else {
NSLog(@"unrecognized address candidate size");
Expand Down
6 changes: 3 additions & 3 deletions External/NSRemoteShell/Sources/NSRemoteShell/NSLocalForward.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ typedef BOOL (^NSRemoteChannelContinuationBlock)(void);
- (void)onTermination:(dispatch_block_t)terminationHandler;
- (void)setContinuationChain:(NSRemoteChannelContinuationBlock)continuation;

- (void)uncheckedConcurrencyCallNonblockingOperations;
- (BOOL)uncheckedConcurrencyInsanityCheckAndReturnDidSuccess;
- (void)uncheckedConcurrencyDisconnectAndPrepareForRelease;
- (void)unsafeCallNonblockingOperations;
- (BOOL)unsafeInsanityCheckAndReturnDidSuccess;
- (void)unsafeDisconnectAndPrepareForRelease;

@end

Expand Down
34 changes: 17 additions & 17 deletions External/NSRemoteShell/Sources/NSRemoteShell/NSLocalForward.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ - (void)setContinuationChain:(NSRemoteChannelContinuationBlock _Nonnull)continua
- (void)setForwardCompleted:(BOOL)channelCompleted {
if (_forwardCompleted != channelCompleted) {
_forwardCompleted = channelCompleted;
[self uncheckedConcurrencyDisconnectAndPrepareForRelease];
[self unsafeDisconnectAndPrepareForRelease];
}
}

Expand All @@ -67,32 +67,32 @@ - (BOOL)seatbeltCheckPassed {
return YES;
}

- (void)uncheckedConcurrencyCallNonblockingOperations {
- (void)unsafeCallNonblockingOperations {
if (self.forwardCompleted) { return; }
if (![self seatbeltCheckPassed]) { return; }
[self uncheckedConcurrencyChannelMainSocketAccept];
[self uncheckedConcurrencyProcessAllSocket];
[self uncheckedConcurrencyChannelShouldTerminate];
[self unsafeChannelMainSocketAccept];
[self unsafeProcessAllSocket];
[self unsafeChannelShouldTerminate];
}

- (void)uncheckedConcurrencyProcessAllSocket {
- (void)unsafeProcessAllSocket {
NSMutableArray *newArray = [[NSMutableArray alloc] init];
for (NSRemoteChannelSocketPair *pair in self.forwardSocketPair) {
if (![pair uncheckedConcurrencyInsanityCheckAndReturnDidSuccess]) {
[pair uncheckedConcurrencyDisconnectAndPrepareForRelease];
if (![pair unsafeInsanityCheckAndReturnDidSuccess]) {
[pair unsafeDisconnectAndPrepareForRelease];
continue;
}
[pair uncheckedConcurrencyCallNonblockingOperations];
if (![pair uncheckedConcurrencyInsanityCheckAndReturnDidSuccess]) {
[pair uncheckedConcurrencyDisconnectAndPrepareForRelease];
[pair unsafeCallNonblockingOperations];
if (![pair unsafeInsanityCheckAndReturnDidSuccess]) {
[pair unsafeDisconnectAndPrepareForRelease];
continue;
}
[newArray addObject:pair];
}
self.forwardSocketPair = newArray;
}

- (void)uncheckedConcurrencyChannelMainSocketAccept {
- (void)unsafeChannelMainSocketAccept {
while (1) {
struct sockaddr_in peeraddr;
socklen_t peeraddrlen = sizeof(peeraddr);
Expand Down Expand Up @@ -125,7 +125,7 @@ - (void)uncheckedConcurrencyChannelMainSocketAccept {
if (!channel) {
NSLog(@"accepted connection failed to open channel");
close(forwardsock);
[self uncheckedConcurrencyDisconnectAndPrepareForRelease];
[self unsafeDisconnectAndPrepareForRelease];
return;
}
NSLog(@"created channel for forward socket %d %p", forwardsock, channel);
Expand All @@ -135,7 +135,7 @@ - (void)uncheckedConcurrencyChannelMainSocketAccept {
}
}

- (BOOL)uncheckedConcurrencyChannelShouldTerminate {
- (BOOL)unsafeChannelShouldTerminate {
do {
if (self.continuationDecisionBlock && !self.continuationDecisionBlock()) {
break;
Expand All @@ -146,7 +146,7 @@ - (BOOL)uncheckedConcurrencyChannelShouldTerminate {
return YES;
}

- (BOOL)uncheckedConcurrencyInsanityCheckAndReturnDidSuccess {
- (BOOL)unsafeInsanityCheckAndReturnDidSuccess {
do {
if (self.forwardCompleted) { break; }
if (![self seatbeltCheckPassed]) { break; }
Expand All @@ -155,7 +155,7 @@ - (BOOL)uncheckedConcurrencyInsanityCheckAndReturnDidSuccess {
return NO;
}

- (void)uncheckedConcurrencyDisconnectAndPrepareForRelease {
- (void)unsafeDisconnectAndPrepareForRelease {
if (!self.forwardCompleted) { self.forwardCompleted = YES; }
if (!self.representedSession) { return; }
if (!self.representedSocket) { return; }
Expand All @@ -164,7 +164,7 @@ - (void)uncheckedConcurrencyDisconnectAndPrepareForRelease {
self.representedSession = NULL;
self.representedSocket = NULL;
for (NSRemoteChannelSocketPair *pair in self.forwardSocketPair) {
[pair uncheckedConcurrencyDisconnectAndPrepareForRelease];
[pair unsafeDisconnectAndPrepareForRelease];
}
self.forwardSocketPair = [[NSMutableArray alloc] init];
if (self.terminationBlock) { self.terminationBlock(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ typedef CGSize (^NSRemoteChannelTerminalSizeBlock)(void);
- (void)setChannelTimeoutWith:(double)timeoutValueFromNowInSecond;
- (void)setChannelTimeoutWithScheduled:(NSDate*)timeoutDate;

- (void)uncheckedConcurrencyChannelTerminalSizeUpdate;
- (void)unsafeChannelTerminalSizeUpdate;

- (void)uncheckedConcurrencyCallNonblockingOperations;
- (BOOL)uncheckedConcurrencyInsanityCheckAndReturnDidSuccess;
- (void)uncheckedConcurrencyDisconnectAndPrepareForRelease;
- (void)unsafeCallNonblockingOperations;
- (BOOL)unsafeInsanityCheckAndReturnDidSuccess;
- (void)unsafeDisconnectAndPrepareForRelease;

@end

Expand Down
Loading

0 comments on commit 0ed9353

Please sign in to comment.