ISession.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System;
  2. using System.Net.Sockets;
  3. using System.Threading;
  4. using Renci.SshNet.Channels;
  5. using Renci.SshNet.Common;
  6. using Renci.SshNet.Messages;
  7. using Renci.SshNet.Messages.Authentication;
  8. using Renci.SshNet.Messages.Connection;
  9. namespace Renci.SshNet
  10. {
  11. /// <summary>
  12. /// Provides functionality to connect and interact with SSH server.
  13. /// </summary>
  14. internal interface ISession
  15. {
  16. ///// <summary>
  17. ///// Gets or sets the connection info.
  18. ///// </summary>
  19. ///// <value>The connection info.</value>
  20. IConnectionInfo ConnectionInfo { get; }
  21. /// <summary>
  22. /// Gets a value indicating whether the session is connected.
  23. /// </summary>
  24. /// <value>
  25. /// <c>true</c> if the session is connected; otherwise, <c>false</c>.
  26. /// </value>
  27. bool IsConnected { get; }
  28. /// <summary>
  29. /// Gets the next channel number.
  30. /// </summary>
  31. /// <value>
  32. /// The next channel number.
  33. /// </value>
  34. uint NextChannelNumber { get; }
  35. /// <summary>
  36. /// Gets the session semaphore that controls session channels.
  37. /// </summary>
  38. /// <value>
  39. /// The session semaphore.
  40. /// </value>
  41. SemaphoreLight SessionSemaphore { get; }
  42. /// <summary>
  43. /// Create a new SSH session channel.
  44. /// </summary>
  45. /// <returns>
  46. /// A new SSH session channel.
  47. /// </returns>
  48. IChannelSession CreateChannelSession();
  49. /// <summary>
  50. /// Create a new channel for a locally forwarded TCP/IP port.
  51. /// </summary>
  52. /// <returns>
  53. /// A new channel for a locally forwarded TCP/IP port.
  54. /// </returns>
  55. IChannelDirectTcpip CreateChannelDirectTcpip();
  56. /// <summary>
  57. /// Creates a "forwarded-tcpip" SSH channel.
  58. /// </summary>
  59. /// <returns>
  60. /// A new "forwarded-tcpip" SSH channel.
  61. /// </returns>
  62. IChannelForwardedTcpip CreateChannelForwardedTcpip(uint remoteChannelNumber, uint remoteWindowSize, uint remoteChannelDataPacketSize);
  63. /// <summary>
  64. /// Registers SSH message with the session.
  65. /// </summary>
  66. /// <param name="messageName">The name of the message to register with the session.</param>
  67. void RegisterMessage(string messageName);
  68. /// <summary>
  69. /// Sends a message to the server.
  70. /// </summary>
  71. /// <param name="message">The message to send.</param>
  72. /// <exception cref="SshConnectionException">The client is not connected.</exception>
  73. /// <exception cref="SshOperationTimeoutException">The operation timed out.</exception>
  74. /// <exception cref="InvalidOperationException">The size of the packet exceeds the maximum size defined by the protocol.</exception>
  75. void SendMessage(Message message);
  76. /// <summary>
  77. /// Unregister SSH message from the session.
  78. /// </summary>
  79. /// <param name="messageName">The name of the message to unregister with the session.</param>
  80. void UnRegisterMessage(string messageName);
  81. /// <summary>
  82. /// Waits for the specified handle or the exception handle for the receive thread
  83. /// to signal within the connection timeout.
  84. /// </summary>
  85. /// <param name="waitHandle">The wait handle.</param>
  86. /// <exception cref="SshConnectionException">A received package was invalid or failed the message integrity check.</exception>
  87. /// <exception cref="SshOperationTimeoutException">None of the handles are signaled in time and the session is not disconnecting.</exception>
  88. /// <exception cref="SocketException">A socket error was signaled while receiving messages from the server.</exception>
  89. /// <remarks>
  90. /// When neither handles are signaled in time and the session is not closing, then the
  91. /// session is disconnected.
  92. /// </remarks>
  93. void WaitOnHandle(WaitHandle waitHandle);
  94. /// <summary>
  95. /// Occurs when <see cref="ChannelCloseMessage"/> message received
  96. /// </summary>
  97. event EventHandler<MessageEventArgs<ChannelCloseMessage>> ChannelCloseReceived;
  98. /// <summary>
  99. /// Occurs when <see cref="ChannelDataMessage"/> message received
  100. /// </summary>
  101. event EventHandler<MessageEventArgs<ChannelDataMessage>> ChannelDataReceived;
  102. /// <summary>
  103. /// Occurs when <see cref="ChannelEofMessage"/> message received
  104. /// </summary>
  105. event EventHandler<MessageEventArgs<ChannelEofMessage>> ChannelEofReceived;
  106. /// <summary>
  107. /// Occurs when <see cref="ChannelExtendedDataMessage"/> message received
  108. /// </summary>
  109. event EventHandler<MessageEventArgs<ChannelExtendedDataMessage>> ChannelExtendedDataReceived;
  110. /// <summary>
  111. /// Occurs when <see cref="ChannelFailureMessage"/> message received
  112. /// </summary>
  113. event EventHandler<MessageEventArgs<ChannelFailureMessage>> ChannelFailureReceived;
  114. /// <summary>
  115. /// Occurs when <see cref="ChannelOpenConfirmationMessage"/> message received
  116. /// </summary>
  117. event EventHandler<MessageEventArgs<ChannelOpenConfirmationMessage>> ChannelOpenConfirmationReceived;
  118. /// <summary>
  119. /// Occurs when <see cref="ChannelOpenFailureMessage"/> message received
  120. /// </summary>
  121. event EventHandler<MessageEventArgs<ChannelOpenFailureMessage>> ChannelOpenFailureReceived;
  122. /// <summary>
  123. /// Occurs when <see cref="ChannelOpenMessage"/> message received
  124. /// </summary>
  125. event EventHandler<MessageEventArgs<ChannelOpenMessage>> ChannelOpenReceived;
  126. /// <summary>
  127. /// Occurs when <see cref="ChannelRequestMessage"/> message received
  128. /// </summary>
  129. event EventHandler<MessageEventArgs<ChannelRequestMessage>> ChannelRequestReceived;
  130. /// <summary>
  131. /// Occurs when <see cref="ChannelSuccessMessage"/> message received
  132. /// </summary>
  133. event EventHandler<MessageEventArgs<ChannelSuccessMessage>> ChannelSuccessReceived;
  134. /// <summary>
  135. /// Occurs when <see cref="ChannelWindowAdjustMessage"/> message received
  136. /// </summary>
  137. event EventHandler<MessageEventArgs<ChannelWindowAdjustMessage>> ChannelWindowAdjustReceived;
  138. /// <summary>
  139. /// Occurs when session has been disconnected from the server.
  140. /// </summary>
  141. event EventHandler<EventArgs> Disconnected;
  142. /// <summary>
  143. /// Occurs when an error occurred.
  144. /// </summary>
  145. event EventHandler<ExceptionEventArgs> ErrorOccured;
  146. /// <summary>
  147. /// Occurs when <see cref="RequestSuccessMessage"/> message received
  148. /// </summary>
  149. event EventHandler<MessageEventArgs<RequestSuccessMessage>> RequestSuccessReceived;
  150. /// <summary>
  151. /// Occurs when <see cref="RequestFailureMessage"/> message received
  152. /// </summary>
  153. event EventHandler<MessageEventArgs<RequestFailureMessage>> RequestFailureReceived;
  154. /// <summary>
  155. /// Occurs when <see cref="BannerMessage"/> message is received from the server.
  156. /// </summary>
  157. event EventHandler<MessageEventArgs<BannerMessage>> UserAuthenticationBannerReceived;
  158. }
  159. }