ConnectionParameters.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.Text;
  10. using System.Net;
  11. using Utilities;
  12. namespace ISCSI.Server
  13. {
  14. public class TransferEntry
  15. {
  16. public SCSICommandPDU Command;
  17. public uint NextR2NSN;
  18. public TransferEntry(SCSICommandPDU command, uint nextR2NSN)
  19. {
  20. Command = command;
  21. NextR2NSN = nextR2NSN;
  22. }
  23. }
  24. public class ConnectionParameters
  25. {
  26. /// <summary>
  27. /// The default MaxRecvDataSegmentLength is used during Login
  28. /// </summary>
  29. public const int DefaultMaxRecvDataSegmentLength = 8192;
  30. public static int DeclaredMaxRecvDataSegmentLength = 262144;
  31. public ushort CID; // connection ID, generated by the initiator
  32. public string InitiatorName = String.Empty;
  33. public IPEndPoint InitiatorEndPoint;
  34. /// <summary>
  35. /// per direction parameter that the target or initator declares.
  36. /// maximum data segment length that the target (or initator) can receive in a single iSCSI PDU.
  37. /// </summary>
  38. public int InitiatorMaxRecvDataSegmentLength = DefaultMaxRecvDataSegmentLength;
  39. public int TargetMaxRecvDataSegmentLength = DeclaredMaxRecvDataSegmentLength;
  40. public uint StatSN = 0; // Initial StatSN, any number will do
  41. // Dictionary of current transfers: <transfer-tag, TransferEntry>
  42. private Dictionary<uint, TransferEntry> n_transfers = new Dictionary<uint, TransferEntry>();
  43. public TransferEntry AddTransfer(uint transferTag, SCSICommandPDU command, uint nextR2NSN)
  44. {
  45. TransferEntry entry = new TransferEntry(command, nextR2NSN);
  46. n_transfers.Add(transferTag, entry);
  47. return entry;
  48. }
  49. public TransferEntry GetTransferEntry(uint transferTag)
  50. {
  51. TransferEntry result;
  52. n_transfers.TryGetValue(transferTag, out result);
  53. return result;
  54. }
  55. public void RemoveTransfer(uint transferTag)
  56. {
  57. n_transfers.Remove(transferTag);
  58. }
  59. }
  60. }