IChannel.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using Renci.SshNet.Common;
  3. using Renci.SshNet.Messages.Connection;
  4. namespace Renci.SshNet.Channels
  5. {
  6. /// <summary>
  7. /// Represents SSH channel.
  8. /// </summary>
  9. internal interface IChannel : IDisposable
  10. {
  11. /// <summary>
  12. /// Occurs when <see cref="ChannelDataMessage"/> is received.
  13. /// </summary>
  14. event EventHandler<ChannelDataEventArgs> DataReceived;
  15. /// <summary>
  16. /// Occurs when an exception is thrown when processing channel messages.
  17. /// </summary>
  18. event EventHandler<ExceptionEventArgs> Exception;
  19. /// <summary>
  20. /// Occurs when <see cref="ChannelExtendedDataMessage"/> is received.
  21. /// </summary>
  22. event EventHandler<ChannelExtendedDataEventArgs> ExtendedDataReceived;
  23. /// <summary>
  24. /// Occurs when <see cref="ChannelRequestMessage"/> is received.
  25. /// </summary>
  26. event EventHandler<ChannelRequestEventArgs> RequestReceived;
  27. /// <summary>
  28. /// Occurs when <see cref="ChannelCloseMessage"/> is received.
  29. /// </summary>
  30. event EventHandler<ChannelEventArgs> Closed;
  31. /// <summary>
  32. /// Gets the local channel number.
  33. /// </summary>
  34. /// <value>
  35. /// The local channel number.
  36. /// </value>
  37. uint LocalChannelNumber { get; }
  38. /// <summary>
  39. /// Gets the maximum size of a data packet that we can receive using the channel.
  40. /// </summary>
  41. /// <value>
  42. /// The maximum size of a packet.
  43. /// </value>
  44. /// <remarks>
  45. /// <para>
  46. /// This is the maximum size (in bytes) we support for the data (payload) of a
  47. /// <c>SSH_MSG_CHANNEL_DATA</c> message we receive.
  48. /// </para>
  49. /// <para>
  50. /// We currently do not enforce this limit.
  51. /// </para>
  52. uint LocalPacketSize { get; }
  53. /// <summary>
  54. /// Gets the maximum size of a data packet that can be sent using the channel.
  55. /// </summary>
  56. /// <value>
  57. /// The maximum size of data that can be sent using a <see cref="ChannelDataMessage"/>
  58. /// on the current channel.
  59. /// </value>
  60. /// <exception cref="InvalidOperationException">The channel has not been opened, or the open has not yet been confirmed.</exception>
  61. uint RemotePacketSize { get; }
  62. /// <summary>
  63. /// Gets a value indicating whether this channel is open.
  64. /// </summary>
  65. /// <value>
  66. /// <c>true</c> if this channel is open; otherwise, <c>false</c>.
  67. /// </value>
  68. bool IsOpen { get; }
  69. /// <summary>
  70. /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload.
  71. /// </summary>
  72. /// <param name="data">The payload to send.</param>
  73. void SendData(byte[] data);
  74. /// <summary>
  75. /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload.
  76. /// </summary>
  77. /// <param name="data">An array of <see cref="byte"/> containing the payload to send.</param>
  78. /// <param name="offset">The zero-based offset in <paramref name="data"/> at which to begin taking data from.</param>
  79. /// <param name="size">The number of bytes of <paramref name="data"/> to send.</param>
  80. /// <remarks>
  81. /// <para>
  82. /// When the size of the data to send exceeds the maximum packet size or the remote window
  83. /// size does not allow the full data to be sent, then this method will send the data in
  84. /// multiple chunks and will wait for the remote window size to be adjusted when it's zero.
  85. /// </para>
  86. /// <para>
  87. /// This is done to support SSH servers will a small window size that do not agressively
  88. /// increase their window size. We need to take into account that there may be SSH servers
  89. /// that only increase their window size when it has reached zero.
  90. /// </para>
  91. /// </remarks>
  92. void SendData(byte[] data, int offset, int size);
  93. /// <summary>
  94. /// Sends a SSH_MSG_CHANNEL_EOF message to the remote server.
  95. /// </summary>
  96. /// <exception cref="InvalidOperationException">The channel is closed.</exception>
  97. void SendEof();
  98. }
  99. }