ConnectionParameters.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 ushort CID; // connection ID, generated by the initiator
  31. public string InitiatorName = String.Empty;
  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. }
  75. }