Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide a way to listen to progress and logger messages #741

Merged
merged 4 commits into from Jan 26, 2024

Conversation

gkc
Copy link
Contributor

@gkc gkc commented Jan 26, 2024

- What I did

- How I did it

  • See annotations on this PR's "Files changed" tab

- How to verify it

  • run the sshnp in non-verbose mode, you should see messages like this
    bin/sshnp -f @garycasey -d mbp -i /Users/gary/.ssh/noports -t @baboonblue18 -h @barracudacandle -u gary
    2024-01-26 14:40:04.141027 : Resolving remote username for user session
    2024-01-26 14:40:04.141046 : Resolving remote username for tunnel session
    2024-01-26 14:40:04.141279 : Fetching host and port from srvd
    2024-01-26 14:40:06.358007 : Sending session request to device daemon
    2024-01-26 14:40:07.262328 : Waiting for response from the device daemon
    2024-01-26 14:40:08.476658 : Received response from the device daemon
    2024-01-26 14:40:08.476975 : Creating connection to socket rendezvous
    2024-01-26 14:40:08.653433 : Starting tunnel session
    2024-01-26 14:40:10.866631 : Starting user session
    Last login: Fri Jan 26 14:40:11 2024 from 127.0.0.1
    gary@gkc2019-2 ~ % exit
    Connection to localhost closed.
    

feat: provide a way to listen to logger messages
feat: Make SshnpCore, SshnpDartPureImpl and SshnpOpensshLocalImpl emit progress messages
refactor: Swapped around clientPort and daemonPort for the legacy reverse ssh impl, for consistency
@gkc gkc changed the title feat: provide a way to listen to progress messages feat: provide a way to listen to progress and logger messages Jan 26, 2024
import 'package:at_utils/at_logger.dart';
import 'package:logging/logging.dart';

class StreamingLoggingHandler implements LoggingHandler {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new at_logger LoggingHandler so we have a way to provide a stream of log messages

@@ -90,7 +91,7 @@ class SshnpUnsignedImpl extends SshnpCore
..sharedBy = params.clientAtSign
..sharedWith = params.sshnpdAtSign
..metadata = (Metadata()..ttl = 10000),
'$localPort ${srvdChannel.clientPort} ${keyUtil.username} ${srvdChannel.host} $sessionId',
'$localPort ${srvdChannel.daemonPort} ${keyUtil.username} ${srvdChannel.host} $sessionId',
Copy link
Contributor Author

@gkc gkc Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the legacy impl code consistent with the current impls (dart, openssh)

Stream<List<int>> get stdout;
}

abstract interface class Sshnp {
static final StreamingLoggingHandler _slh =
StreamingLoggingHandler(AtSignLogger.defaultLoggingHandler);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make one of our StreamingLoggingHandlers, and wrap the current defaultLoggingHandler in it

/// Legacy v3.x.x client
@Deprecated(
'Legacy unsigned client - only for connecting with ^3.0.0 daemons')
factory Sshnp.unsigned({
required AtClient atClient,
required SshnpParams params,
}) {
return SshnpUnsignedImpl(atClient: atClient, params: params);
AtSignLogger.defaultLoggingHandler = _slh;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set the defaultLoggingHandler to our StreamingLoggingHandler

@@ -122,7 +122,7 @@ abstract class SrvdChannel<T> with AsyncInitialization, AtClientBindings {
if (params.host.startsWith('@')) {
srv = srvGenerator(
host,
daemonPort!, // everything was backwards back then
clientPort,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the legacy impl code consistent with the current impls (dart, openssh)

}

sshnp.progressStream?.listen((s) => logProgress(s));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a simple progress listener into the sshnp CLI so that, if run in non-verbose mode, the user will get enough output to keep them from wondering what is going on and why. (If run in verbose mode, a normal user gets too much information)

@XavierChanth XavierChanth merged commit ac23723 into trunk Jan 26, 2024
6 checks passed
@gkc gkc deleted the gkc/feat/progress-and-logger-listeners branch February 7, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a way for a program using an Sshnp to observe what is going on while sessions are being created
2 participants