StateObject.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Copyright (C) 2012-2016 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Net.Sockets;
  10. using System.Text;
  11. using Utilities;
  12. namespace ISCSI.Server
  13. {
  14. /// <summary>
  15. /// iSCSI Connection state object
  16. /// </summary>
  17. public class StateObject
  18. {
  19. public Socket ClientSocket = null;
  20. /// <summary>
  21. /// DataSegmentLength MUST not exceed MaxRecvDataSegmentLength for the direction it is sent and the total of all the DataSegmentLength of all PDUs in a sequence MUST not exceed MaxBurstLength (or FirstBurstLength for unsolicited data).
  22. /// </summary>
  23. public const int ReceiveBufferSize = 131072; // Note: FirstBurstLength, MaxBurstLength and MaxRecvDataSegmentLength put a cap on DataSegmentLength, NOT on the PDU length.
  24. public byte[] ReceiveBuffer = new byte[ReceiveBufferSize]; // immediate receive buffer
  25. public byte[] ConnectionBuffer = new byte[0]; // we append the receive buffer here until we have a complete PDU
  26. public ISCSITarget Target; // Across all connections within a session, an initiator sees one and the same target.
  27. public SessionParameters SessionParameters = new SessionParameters();
  28. public ConnectionParameters ConnectionParameters = new ConnectionParameters();
  29. public CountdownLatch RunningSCSICommands = new CountdownLatch();
  30. public string ConnectionIdentifier
  31. {
  32. get
  33. {
  34. return GetConnectionIdentifier(SessionParameters, ConnectionParameters);
  35. }
  36. }
  37. public static string GetConnectionIdentifier(SessionParameters session, ConnectionParameters connection)
  38. {
  39. return String.Format("ISID={0},TSIH={1},CID={2}", session.ISID.ToString("x"), session.TSIH.ToString("x"), connection.CID.ToString("x"));
  40. }
  41. }
  42. }