Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cs/build/build.props
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<ReportGeneratorVersion>5.3.9</ReportGeneratorVersion>
<SystemTextEncodingsWebPackageVersion>4.7.2</SystemTextEncodingsWebPackageVersion>
<VisualStudioValidationVersion>15.5.31</VisualStudioValidationVersion>
<DevTunnelsSshPackageVersion>3.12.8</DevTunnelsSshPackageVersion>
<DevTunnelsSshPackageVersion>3.12.11</DevTunnelsSshPackageVersion>
<XunitRunnerVisualStudioVersion>2.4.0</XunitRunnerVisualStudioVersion>
<XunitVersion>2.4.0</XunitVersion>
</PropertyGroup>
Expand Down
12 changes: 11 additions & 1 deletion cs/src/Connections/ITunnelClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ Task ConnectAsync(
/// configured <see cref="TunnelConnectionOptions.KeepAliveIntervalInSeconds"/>. This callback is only invoked
/// if the keep-alive interval is greater than 0.
/// </remarks>
public event EventHandler<SshKeepAliveFailureEventArgs>? KeepAliveFailed;
public event EventHandler<SshKeepAliveEventArgs>? KeepAliveFailed;

/// <summary>
/// Event raised when a keep-alive message response is received.
/// </summary>
/// <remarks>
/// The event args provide the count of keep-alive messages that got a response within the
/// configured <see cref="TunnelConnectionOptions.KeepAliveIntervalInSeconds"/>. This callback is only invoked
/// if the keep-alive interval is greater than 0.
/// </remarks>
public event EventHandler<SshKeepAliveEventArgs>? KeepAliveSucceeded;
}

14 changes: 12 additions & 2 deletions cs/src/Connections/ITunnelHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Task ConnectAsync(
/// ForwardedPortConnecting event will be raised.
/// </remarks>
event EventHandler<ForwardedPortConnectingEventArgs>? ForwardedPortConnecting;

/// <summary>
/// Event raised when a keep-alive message response is not received.
/// </summary>
Expand All @@ -136,5 +136,15 @@ Task ConnectAsync(
/// configured <see cref="TunnelConnectionOptions.KeepAliveIntervalInSeconds"/>. This callback is only invoked
/// if the keep-alive interval is greater than 0.
/// </remarks>
public event EventHandler<SshKeepAliveFailureEventArgs>? KeepAliveFailed;
public event EventHandler<SshKeepAliveEventArgs>? KeepAliveFailed;

/// <summary>
/// Event raised when a keep-alive message response is received.
/// </summary>
/// <remarks>
/// The event args provide the count of keep-alive messages that got a response within the
/// configured <see cref="TunnelConnectionOptions.KeepAliveIntervalInSeconds"/>. This callback is only invoked
/// if the keep-alive interval is greater than 0.
/// </remarks>
public event EventHandler<SshKeepAliveEventArgs>? KeepAliveSucceeded;
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// <copyright file="SshKeepAliveFailureEventArgs.cs" company="Microsoft">
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
// </copyright>
using System;
namespace Microsoft.DevTunnels.Connections;
/// <summary>
/// Event raised when a keep-alive message respose is not received.
/// </summary>
public class SshKeepAliveFailureEventArgs : EventArgs
{
/// <summary>
/// Create a new instance of <see cref="SshKeepAliveFailureEventArgs"/>.
/// </summary>
public SshKeepAliveFailureEventArgs(int count)
{
Count = count;
}
/// <summary>
/// The number of keep-alive messages that have been sent without a response.
/// </summary>
public int Count { get; }
}
// <copyright file="SshKeepAliveFailureEventArgs.cs" company="Microsoft">
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
// </copyright>

using System;

namespace Microsoft.DevTunnels.Connections;

/// <summary>
/// Event raised when a keep-alive message respose is or is not received.
/// </summary>
public class SshKeepAliveEventArgs : EventArgs
Comment thread
JacobRoberts marked this conversation as resolved.
{
/// <summary>
/// Create a new instance of <see cref="SshKeepAliveEventArgs"/>.
/// </summary>
public SshKeepAliveEventArgs(int count)
{
Count = count;
}

/// <summary>
/// The number of keep-alive messages that have been sent with the same state.
/// </summary>
public int Count { get; }
}
6 changes: 5 additions & 1 deletion cs/src/Connections/TunnelClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,14 @@ protected async Task StartSshSessionAsync(Stream stream, TunnelConnectionOptions

session = new SshClientSession(clientConfig, Trace.WithName("SSH"));
SshSession = session;
session.KeepAliveRequestFailed += (_, e) =>
session.KeepAliveFailed += (_, e) =>
{
OnKeepAliveFailed(e.Count);
};
session.KeepAliveSucceeded += (_, e) =>
{
OnKeepAliveSucceeded(e.Count);
};
SshPortForwardingService = session.ActivateService<PortForwardingService>();
ConfigurePortForwardingService();
SubscribeSessionEvents(session);
Expand Down
22 changes: 20 additions & 2 deletions cs/src/Connections/TunnelConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,17 @@ protected virtual void ValidateAccessToken()
/// configured <see cref="TunnelConnectionOptions.KeepAliveIntervalInSeconds"/>. This callback is only invoked
/// if the keep-alive interval is greater than 0.
/// </remarks>
public event EventHandler<SshKeepAliveFailureEventArgs>? KeepAliveFailed;
public event EventHandler<SshKeepAliveEventArgs>? KeepAliveFailed;

/// <summary>
/// Event raised when a keep-alive message response is received.
/// </summary>
/// <remarks>
/// The event args provide the count of keep-alive messages that got a response within the
/// configured <see cref="TunnelConnectionOptions.KeepAliveIntervalInSeconds"/>. This callback is only invoked
/// if the keep-alive interval is greater than 0.
/// </remarks>
public event EventHandler<SshKeepAliveEventArgs>? KeepAliveSucceeded;

/// <summary>
/// Fetch the tunnel from the service if <see cref="ManagementClient"/> and <see cref="Tunnel"/> are not null.
Expand Down Expand Up @@ -360,7 +370,15 @@ protected virtual async Task<bool> OnRefreshingTunnelAccessTokenAsync(Cancellati
/// </summary>
protected virtual void OnKeepAliveFailed(int count)
{
KeepAliveFailed?.Invoke(this, new SshKeepAliveFailureEventArgs(count));
KeepAliveFailed?.Invoke(this, new SshKeepAliveEventArgs(count));
}

/// <summary>
/// Event raised when a keep-alive message response is not received.
/// </summary>
protected virtual void OnKeepAliveSucceeded(int count)
{
KeepAliveSucceeded?.Invoke(this, new SshKeepAliveEventArgs(count));
}

/// <inheritdoc />
Expand Down
6 changes: 5 additions & 1 deletion cs/src/Connections/TunnelRelayTunnelHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,14 @@ protected override async Task ConfigureSessionAsync(Stream stream, bool isReconn
hostPfs.MessageFactory = this;
}

session.KeepAliveRequestFailed += (_, e) =>
session.KeepAliveFailed += (_, e) =>
{
OnKeepAliveFailed(e.Count);
};
session.KeepAliveSucceeded += (_, e) =>
{
OnKeepAliveSucceeded(e.Count);
};

SshSession = session;
SubscribeSessionEvents(session);
Expand Down