ConnectionParameters.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 uint NextOffset;
  19. public uint TotalR2Ts; // Numbers of R2Ts that will be sent during this transfer
  20. public TransferEntry(SCSICommandPDU command, uint nextR2TSN, uint nextOffset, uint totalR2Ts)
  21. {
  22. Command = command;
  23. NextR2TSN = nextR2TSN;
  24. NextOffset = nextOffset;
  25. TotalR2Ts = totalR2Ts;
  26. }
  27. }
  28. internal class ConnectionParameters
  29. {
  30. public ISCSISession Session;
  31. public ushort CID; // connection ID, generated by the initiator
  32. public IPEndPoint InitiatorEndPoint;
  33. public int InitiatorMaxRecvDataSegmentLength = DefaultParameters.Connection.MaxRecvDataSegmentLength;
  34. public int TargetMaxRecvDataSegmentLength = ISCSIServer.DeclaredParameters.MaxRecvDataSegmentLength;
  35. public uint StatSN = 0; // Initial StatSN, any number will do
  36. private Dictionary<uint, string> m_textSequences = new Dictionary<uint, string>();
  37. // Dictionary of current transfers: <transfer-tag, TransferEntry>
  38. private Dictionary<uint, TransferEntry> n_transfers = new Dictionary<uint, TransferEntry>();
  39. public string AddTextToSequence(uint initiatorTaskTag, string text)
  40. {
  41. string precedingText;
  42. if (m_textSequences.TryGetValue(initiatorTaskTag, out precedingText))
  43. {
  44. string sequence = precedingText + text;
  45. m_textSequences[initiatorTaskTag] = sequence;
  46. return sequence;
  47. }
  48. else
  49. {
  50. m_textSequences.Add(initiatorTaskTag, text);
  51. return text;
  52. }
  53. }
  54. public void RemoveTextSequence(uint initiatorTaskTag)
  55. {
  56. m_textSequences.Remove(initiatorTaskTag);
  57. }
  58. public TransferEntry AddTransfer(uint transferTag, SCSICommandPDU command, uint nextR2TSN, uint nextOffset, uint totalR2Ts)
  59. {
  60. TransferEntry entry = new TransferEntry(command, nextR2TSN, nextOffset, totalR2Ts);
  61. n_transfers.Add(transferTag, entry);
  62. return entry;
  63. }
  64. public TransferEntry GetTransferEntry(uint transferTag)
  65. {
  66. TransferEntry result;
  67. n_transfers.TryGetValue(transferTag, out result);
  68. return result;
  69. }
  70. public void RemoveTransfer(uint transferTag)
  71. {
  72. n_transfers.Remove(transferTag);
  73. }
  74. public string ConnectionIdentifier
  75. {
  76. get
  77. {
  78. if (Session != null)
  79. {
  80. return Session.SessionIdentifier + String.Format(",CID={0}", this.CID.ToString("x"));
  81. }
  82. else
  83. {
  84. return String.Format("ISID=0,TSIH=0,CID={0}", this.CID.ToString("x"));
  85. }
  86. }
  87. }
  88. }
  89. }