Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Renci.SshNet/GlobalRequests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using Renci.SshNet.Common;
using Renci.SshNet.Messages.Connection;

namespace Renci.SshNet
{
/// <summary>
/// Responds to SSH Global Requests (https://tools.ietf.org/html/rfc4254#section-4)
/// </summary>
class GlobalRequests {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Specify the access modifier (public/internal/private...)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please add a unit test for this new class and functionality.

/// <summary>
/// Handles Global Request Events. By default, it replies with a failure message which is appropriate to
/// support server keepalives (https://tools.ietf.org/html/rfc4254#section-4)
/// </summary>
internal static void GlobalRequestHandler(Object sender, EventArgs e)
{
var session = (ISession) sender;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Safer if programmed as
(sender as ISession)?.SendMessage(new RequestFailureMessage());

or

if (sender is  ISession session)
{
    session.SendMessage(new RequestFailureMessage());
}

session.SendMessage(new RequestFailureMessage());
}
}
}
3 changes: 3 additions & 0 deletions src/Renci.SshNet/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,9 @@ public void Connect()
ConnectionInfo.Authenticate(this, _serviceFactory);
_isAuthenticated = true;

// Start Listening for Server Global Keepalives
this.GlobalRequestReceived += GlobalRequests.GlobalRequestHandler;

// Register Connection messages
RegisterMessage("SSH_MSG_REQUEST_SUCCESS");
RegisterMessage("SSH_MSG_REQUEST_FAILURE");
Expand Down