ChannelOpenConfirmationMessage.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. namespace Renci.SshNet.Messages.Connection
  2. {
  3. /// <summary>
  4. /// Represents SSH_MSG_CHANNEL_OPEN_CONFIRMATION message.
  5. /// </summary>
  6. [Message("SSH_MSG_CHANNEL_OPEN_CONFIRMATION", 91)]
  7. public class ChannelOpenConfirmationMessage : ChannelMessage
  8. {
  9. /// <summary>
  10. /// Gets the remote channel number.
  11. /// </summary>
  12. public uint RemoteChannelNumber { get; private set; }
  13. /// <summary>
  14. /// Gets the initial size of the window.
  15. /// </summary>
  16. /// <value>
  17. /// The initial size of the window.
  18. /// </value>
  19. public uint InitialWindowSize { get; private set; }
  20. /// <summary>
  21. /// Gets the maximum size of the packet.
  22. /// </summary>
  23. /// <value>
  24. /// The maximum size of the packet.
  25. /// </value>
  26. public uint MaximumPacketSize { get; private set; }
  27. /// <summary>
  28. /// Gets the size of the message in bytes.
  29. /// </summary>
  30. /// <value>
  31. /// The size of the messages in bytes.
  32. /// </value>
  33. protected override int BufferCapacity
  34. {
  35. get
  36. {
  37. var capacity = base.BufferCapacity;
  38. capacity += 4; // RemoteChannelNumber
  39. capacity += 4; // InitialWindowSize
  40. capacity += 4; // MaximumPacketSize
  41. return capacity;
  42. }
  43. }
  44. /// <summary>
  45. /// Initializes a new instance of the <see cref="ChannelOpenConfirmationMessage"/> class.
  46. /// </summary>
  47. public ChannelOpenConfirmationMessage()
  48. {
  49. }
  50. /// <summary>
  51. /// Initializes a new instance of the <see cref="ChannelOpenConfirmationMessage"/> class.
  52. /// </summary>
  53. /// <param name="localChannelNumber">The local channel number.</param>
  54. /// <param name="initialWindowSize">Initial size of the window.</param>
  55. /// <param name="maximumPacketSize">Maximum size of the packet.</param>
  56. /// <param name="remoteChannelNumber">The remote channel number.</param>
  57. public ChannelOpenConfirmationMessage(uint localChannelNumber, uint initialWindowSize, uint maximumPacketSize, uint remoteChannelNumber)
  58. : base(localChannelNumber)
  59. {
  60. InitialWindowSize = initialWindowSize;
  61. MaximumPacketSize = maximumPacketSize;
  62. RemoteChannelNumber = remoteChannelNumber;
  63. }
  64. /// <summary>
  65. /// Called when type specific data need to be loaded.
  66. /// </summary>
  67. protected override void LoadData()
  68. {
  69. base.LoadData();
  70. RemoteChannelNumber = ReadUInt32();
  71. InitialWindowSize = ReadUInt32();
  72. MaximumPacketSize = ReadUInt32();
  73. }
  74. /// <summary>
  75. /// Called when type specific data need to be saved.
  76. /// </summary>
  77. protected override void SaveData()
  78. {
  79. base.SaveData();
  80. Write(RemoteChannelNumber);
  81. Write(InitialWindowSize);
  82. Write(MaximumPacketSize);
  83. }
  84. internal override void Process(Session session)
  85. {
  86. session.OnChannelOpenConfirmationReceived(this);
  87. }
  88. }
  89. }