ConnectionParameters.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. internal class TransferEntry
  15. {
  16. public SCSICommandPDU Command;
  17. public uint NextR2TSN;
  18. public TransferEntry(SCSICommandPDU command, uint nextR2TSN)
  19. {
  20. Command = command;
  21. NextR2TSN = nextR2TSN;
  22. }
  23. }
  24. internal class ConnectionParameters
  25. {
  26. public ushort CID; // connection ID, generated by the initiator
  27. public string InitiatorName = String.Empty;
  28. public IPEndPoint InitiatorEndPoint;
  29. public int InitiatorMaxRecvDataSegmentLength = DefaultParameters.Connection.MaxRecvDataSegmentLength;
  30. public int TargetMaxRecvDataSegmentLength = ISCSIServer.DeclaredParameters.MaxRecvDataSegmentLength;
  31. public uint StatSN = 0; // Initial StatSN, any number will do
  32. private Dictionary<uint, string> m_textSequences = new Dictionary<uint, string>();
  33. // Dictionary of current transfers: <transfer-tag, TransferEntry>
  34. private Dictionary<uint, TransferEntry> n_transfers = new Dictionary<uint, TransferEntry>();
  35. public string AddTextToSequence(uint initiatorTaskTag, string text)
  36. {
  37. string precedingText;
  38. if (m_textSequences.TryGetValue(initiatorTaskTag, out precedingText))
  39. {
  40. string sequence = precedingText + text;
  41. m_textSequences[initiatorTaskTag] = sequence;
  42. return sequence;
  43. }
  44. else
  45. {
  46. m_textSequences.Add(initiatorTaskTag, text);
  47. return text;
  48. }
  49. }
  50. public void RemoveTextSequence(uint initiatorTaskTag)
  51. {
  52. m_textSequences.Remove(initiatorTaskTag);
  53. }
  54. public TransferEntry AddTransfer(uint transferTag, SCSICommandPDU command, uint nextR2TSN)
  55. {
  56. TransferEntry entry = new TransferEntry(command, nextR2TSN);
  57. n_transfers.Add(transferTag, entry);
  58. return entry;
  59. }
  60. public TransferEntry GetTransferEntry(uint transferTag)
  61. {
  62. TransferEntry result;
  63. n_transfers.TryGetValue(transferTag, out result);
  64. return result;
  65. }
  66. public void RemoveTransfer(uint transferTag)
  67. {
  68. n_transfers.Remove(transferTag);
  69. }
  70. }
  71. }