2
0

IBaseClient.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #nullable enable
  2. using System;
  3. using System.Net.Sockets;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using Renci.SshNet.Common;
  7. namespace Renci.SshNet
  8. {
  9. /// <summary>
  10. /// Serves as base class for client implementations, provides common client functionality.
  11. /// </summary>
  12. public interface IBaseClient : IDisposable
  13. {
  14. /// <summary>
  15. /// Gets the connection info.
  16. /// </summary>
  17. /// <value>
  18. /// The connection info.
  19. /// </value>
  20. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  21. ConnectionInfo ConnectionInfo { get; }
  22. /// <summary>
  23. /// Gets a value indicating whether this client is connected to the server.
  24. /// </summary>
  25. /// <value>
  26. /// <see langword="true"/> if this client is connected; otherwise, <see langword="false"/>.
  27. /// </value>
  28. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  29. bool IsConnected { get; }
  30. /// <summary>
  31. /// Gets or sets the keep-alive interval.
  32. /// </summary>
  33. /// <value>
  34. /// The keep-alive interval. Specify negative one (-1) milliseconds to disable the
  35. /// keep-alive. This is the default value.
  36. /// </value>
  37. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  38. TimeSpan KeepAliveInterval { get; set; }
  39. /// <summary>
  40. /// Occurs when an error occurred.
  41. /// </summary>
  42. event EventHandler<ExceptionEventArgs> ErrorOccurred;
  43. /// <summary>
  44. /// Occurs when host key received.
  45. /// </summary>
  46. event EventHandler<HostKeyEventArgs> HostKeyReceived;
  47. /// <summary>
  48. /// Occurs when server identification received.
  49. /// </summary>
  50. event EventHandler<SshIdentificationEventArgs>? ServerIdentificationReceived;
  51. /// <summary>
  52. /// Connects client to the server.
  53. /// </summary>
  54. /// <exception cref="InvalidOperationException">The client is already connected.</exception>
  55. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  56. /// <exception cref="SocketException">Socket connection to the SSH server or proxy server could not be established, or an error occurred while resolving the hostname.</exception>
  57. /// <exception cref="SshConnectionException">SSH session could not be established.</exception>
  58. /// <exception cref="SshAuthenticationException">Authentication of SSH session failed.</exception>
  59. /// <exception cref="ProxyException">Failed to establish proxy connection.</exception>
  60. void Connect();
  61. /// <summary>
  62. /// Asynchronously connects client to the server.
  63. /// </summary>
  64. /// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
  65. /// <returns>A <see cref="Task"/> that represents the asynchronous connect operation.
  66. /// </returns>
  67. /// <exception cref="InvalidOperationException">The client is already connected.</exception>
  68. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  69. /// <exception cref="SocketException">Socket connection to the SSH server or proxy server could not be established, or an error occurred while resolving the hostname.</exception>
  70. /// <exception cref="SshConnectionException">SSH session could not be established.</exception>
  71. /// <exception cref="SshAuthenticationException">Authentication of SSH session failed.</exception>
  72. /// <exception cref="ProxyException">Failed to establish proxy connection.</exception>
  73. Task ConnectAsync(CancellationToken cancellationToken);
  74. /// <summary>
  75. /// Disconnects client from the server.
  76. /// </summary>
  77. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  78. void Disconnect();
  79. /// <summary>
  80. /// Sends a keep-alive message to the server.
  81. /// </summary>
  82. /// <remarks>
  83. /// Use <see cref="KeepAliveInterval"/> to configure the client to send a keep-alive at regular
  84. /// intervals.
  85. /// </remarks>
  86. /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
  87. void SendKeepAlive();
  88. }
  89. }