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

[breaking] {Local,Remote,Socks}Forward: rename EndPoint property to ListenEndPoint #360

Merged
merged 1 commit into from
Feb 19, 2025
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 src/Tmds.Ssh/LocalForward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal LocalForward(ILogger<LocalForward> logger)
internal ValueTask StartAsync(SshSession session, EndPoint bindEP, RemoteEndPoint remoteEndPoint, CancellationToken cancellationToken)
=> _forwarder.StartDirectForwardAsync(session, bindEP, remoteEndPoint, cancellationToken);

public EndPoint LocalEndPoint
public EndPoint ListenEndPoint
=> _forwarder.LocalEndPoint;

public CancellationToken Stopped
Expand Down
2 changes: 1 addition & 1 deletion src/Tmds.Ssh/RemoteForward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal RemoteForward(ILogger<RemoteForward> logger)
internal ValueTask StartAsync(SshSession session, RemoteEndPoint bindEP, EndPoint localEndPoint, CancellationToken cancellationToken)
=> _forwarder.StartDirectForwardAsync(session, bindEP, localEndPoint, cancellationToken);

public RemoteEndPoint RemoteEndPoint
public RemoteEndPoint ListenEndPoint
=> _forwarder.RemoteEndPoint;

public CancellationToken Stopped
Expand Down
2 changes: 1 addition & 1 deletion src/Tmds.Ssh/SocksForward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal SocksForward(ILogger<SocksForward> logger)
internal ValueTask StartAsync(SshSession session, EndPoint bindEP, CancellationToken cancellationToken)
=> _forwarder.StartSocksForwardAsync(session, bindEP, cancellationToken);

public EndPoint LocalEndPoint
public EndPoint ListenEndPoint
=> _forwarder.LocalEndPoint;

public CancellationToken Stopped
Expand Down
14 changes: 7 additions & 7 deletions test/Tmds.Ssh.Tests/LocalForwardTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private async Task AssertForwards(LocalForward directForward)
byte[] receiveBuffer = new byte[128];
for (int i = 0; i < 2; i++)
{
EndPoint endPoint = directForward.LocalEndPoint!;
EndPoint endPoint = directForward.ListenEndPoint!;
using var socket = new Socket(endPoint.AddressFamily, SocketType.Stream, endPoint.AddressFamily == AddressFamily.InterNetwork ? ProtocolType.Tcp : ProtocolType.Unspecified);
if (socket.ProtocolType == ProtocolType.Tcp)
{
Expand Down Expand Up @@ -110,7 +110,7 @@ private async Task AssertForwards(SocksForward socksForward, IPAddress? remoteIP
byte[] helloWorldBytes = Encoding.UTF8.GetBytes("hello world");
byte[] receiveBuffer = new byte[128];

EndPoint endPoint = socksForward.LocalEndPoint!;
EndPoint endPoint = socksForward.ListenEndPoint!;
using var socket = new Socket(endPoint.AddressFamily, SocketType.Stream, endPoint.AddressFamily == AddressFamily.InterNetwork ? ProtocolType.Tcp : ProtocolType.Unspecified);
if (socket.ProtocolType == ProtocolType.Tcp)
{
Expand Down Expand Up @@ -203,15 +203,15 @@ public async Task StopsWhenDisposed()

using var directForward = await client.StartForwardAsync(new IPEndPoint(IPAddress.Loopback, 0), new RemoteHostEndPoint("localhost", 5000));
CancellationToken ct = directForward.Stopped;
EndPoint? endPoint = directForward.LocalEndPoint;
EndPoint? endPoint = directForward.ListenEndPoint;

Assert.False(ct.IsCancellationRequested);
Assert.NotNull(endPoint);

directForward.Dispose();

Assert.True(ct.IsCancellationRequested);
Assert.Throws<ObjectDisposedException>(() => directForward.LocalEndPoint);
Assert.Throws<ObjectDisposedException>(() => directForward.ListenEndPoint);
Assert.Throws<ObjectDisposedException>(() => directForward.Stopped);
Assert.Throws<ObjectDisposedException>(() => directForward.ThrowIfStopped());

Expand All @@ -226,15 +226,15 @@ public async Task StopsWhenClientDisconnects()

using var directForward = await client.StartForwardAsync(new IPEndPoint(IPAddress.Loopback, 0), new RemoteHostEndPoint("localhost", 5000));
CancellationToken ct = directForward.Stopped;
EndPoint? endPoint = directForward.LocalEndPoint;
EndPoint? endPoint = directForward.ListenEndPoint;

Assert.False(ct.IsCancellationRequested);
Assert.NotNull(endPoint);

client.Dispose();

Assert.True(ct.IsCancellationRequested);
endPoint = directForward.LocalEndPoint;
endPoint = directForward.ListenEndPoint;
Assert.NotNull(endPoint);
Assert.True(directForward.Stopped.IsCancellationRequested);
Assert.Throws<SshConnectionClosedException>(() => directForward.ThrowIfStopped());
Expand All @@ -252,6 +252,6 @@ public async Task IPv6IsDualMode()

using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, (directForward.LocalEndPoint as IPEndPoint)!.Port));
await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, (directForward.ListenEndPoint as IPEndPoint)!.Port));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace Tmds.Ssh
public delegate bool LocalFileEntryPredicate(ref Tmds.Ssh.LocalFileEntry entry);
public sealed class LocalForward : System.IDisposable
{
public System.Net.EndPoint LocalEndPoint { get; }
public System.Net.EndPoint ListenEndPoint { get; }
public System.Threading.CancellationToken Stopped { get; }
public void Dispose() { }
public void ThrowIfStopped() { }
Expand Down Expand Up @@ -150,7 +150,7 @@ namespace Tmds.Ssh
public class RemoteEndPoint { }
public sealed class RemoteForward : System.IDisposable
{
public Tmds.Ssh.RemoteEndPoint RemoteEndPoint { get; }
public Tmds.Ssh.RemoteEndPoint ListenEndPoint { get; }
public System.Threading.CancellationToken Stopped { get; }
public void Dispose() { }
public void ThrowIfStopped() { }
Expand Down Expand Up @@ -387,7 +387,7 @@ namespace Tmds.Ssh
public delegate T SftpFileEntryTransform<T>(ref Tmds.Ssh.SftpFileEntry entry);
public sealed class SocksForward : System.IDisposable
{
public System.Net.EndPoint LocalEndPoint { get; }
public System.Net.EndPoint ListenEndPoint { get; }
public System.Threading.CancellationToken Stopped { get; }
public void Dispose() { }
public void ThrowIfStopped() { }
Expand Down
10 changes: 5 additions & 5 deletions test/Tmds.Ssh.Tests/RemoteForwardTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private async Task AssertForwards(SshClient client, RemoteForward remoteForward)
byte[] receiveBuffer = new byte[128];
for (int i = 0; i < 2; i++)
{
RemoteEndPoint endPoint = remoteForward.RemoteEndPoint;
RemoteEndPoint endPoint = remoteForward.ListenEndPoint;
SshDataStream? clientStream = null;
if (endPoint is RemoteIPListenEndPoint ipEndPoint)
{
Expand Down Expand Up @@ -92,15 +92,15 @@ public async Task StopsWhenDisposed()

using var remoteForward = await client.StartRemoteForwardAsync(new RemoteIPListenEndPoint("localhost", 0), new IPEndPoint(IPAddress.Loopback, 5000));
CancellationToken ct = remoteForward.Stopped;
RemoteIPListenEndPoint? endPoint = remoteForward.RemoteEndPoint as RemoteIPListenEndPoint;
RemoteIPListenEndPoint? endPoint = remoteForward.ListenEndPoint as RemoteIPListenEndPoint;

Assert.False(ct.IsCancellationRequested);
Assert.NotNull(endPoint);

remoteForward.Dispose();

Assert.True(ct.IsCancellationRequested);
Assert.Throws<ObjectDisposedException>(() => remoteForward.RemoteEndPoint);
Assert.Throws<ObjectDisposedException>(() => remoteForward.ListenEndPoint);
Assert.Throws<ObjectDisposedException>(() => remoteForward.Stopped);
Assert.Throws<ObjectDisposedException>(() => remoteForward.ThrowIfStopped());

Expand All @@ -114,15 +114,15 @@ public async Task StopsWhenClientDisconnects()

using var remoteForward = await client.StartRemoteForwardAsync(new RemoteIPListenEndPoint("localhost", 0), new IPEndPoint(IPAddress.Loopback, 5000));
CancellationToken ct = remoteForward.Stopped;
RemoteIPListenEndPoint? endPoint = remoteForward.RemoteEndPoint as RemoteIPListenEndPoint;
RemoteIPListenEndPoint? endPoint = remoteForward.ListenEndPoint as RemoteIPListenEndPoint;

Assert.False(ct.IsCancellationRequested);
Assert.NotNull(endPoint);

client.Dispose();

Assert.True(ct.IsCancellationRequested);
Assert.NotNull(remoteForward.RemoteEndPoint);
Assert.NotNull(remoteForward.ListenEndPoint);
Assert.True(remoteForward.Stopped.IsCancellationRequested);
Assert.Throws<SshConnectionClosedException>(() => remoteForward.ThrowIfStopped());
}
Expand Down