123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /* Copyright (C) 2012-2018 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
- *
- * You can redistribute this program and/or modify it under the terms of
- * the GNU Lesser Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- */
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Net;
- using Utilities;
- namespace ISCSI.Server
- {
- internal class TransferEntry
- {
- public SCSICommandPDU Command;
- public uint NextR2TSN;
- public uint NextOffset;
- public uint TotalR2Ts; // Numbers of R2Ts that will be sent during this transfer
- public TransferEntry(SCSICommandPDU command, uint nextR2TSN, uint nextOffset, uint totalR2Ts)
- {
- Command = command;
- NextR2TSN = nextR2TSN;
- NextOffset = nextOffset;
- TotalR2Ts = totalR2Ts;
- }
- }
- internal class ConnectionParameters
- {
- public ISCSISession Session;
- public ushort CID; // connection ID, generated by the initiator
- public IPEndPoint InitiatorEndPoint;
- public int InitiatorMaxRecvDataSegmentLength = DefaultParameters.Connection.MaxRecvDataSegmentLength;
- public int TargetMaxRecvDataSegmentLength = ISCSIServer.DeclaredParameters.MaxRecvDataSegmentLength;
- public uint StatSN = 0; // Initial StatSN, any number will do
- private Dictionary<uint, string> m_textSequences = new Dictionary<uint, string>();
- private Dictionary<uint, uint> m_taskTagToTransferTag = new Dictionary<uint, uint>();
- // Dictionary of current transfers: <transfer-tag, TransferEntry>
- private Dictionary<uint, TransferEntry> m_transfers = new Dictionary<uint, TransferEntry>();
- public string AddTextToSequence(uint initiatorTaskTag, string text)
- {
- string precedingText;
- if (m_textSequences.TryGetValue(initiatorTaskTag, out precedingText))
- {
- string sequence = precedingText + text;
- m_textSequences[initiatorTaskTag] = sequence;
- return sequence;
- }
- else
- {
- m_textSequences.Add(initiatorTaskTag, text);
- return text;
- }
- }
- public void RemoveTextSequence(uint initiatorTaskTag)
- {
- m_textSequences.Remove(initiatorTaskTag);
- }
- public TransferEntry AddTransfer(uint initiatorTaskTag, uint transferTag, SCSICommandPDU command, uint nextR2TSN, uint nextOffset, uint totalR2Ts)
- {
- m_taskTagToTransferTag.Add(initiatorTaskTag, transferTag);
- TransferEntry entry = new TransferEntry(command, nextR2TSN, nextOffset, totalR2Ts);
- m_transfers.Add(transferTag, entry);
- return entry;
- }
- public TransferEntry GetTransferEntryUsingTaskTag(uint initiatorTaskTag)
- {
- uint transferTag;
- if (m_taskTagToTransferTag.TryGetValue(initiatorTaskTag, out transferTag))
- {
- return GetTransferEntry(transferTag);
- }
- return null;
- }
- public TransferEntry GetTransferEntry(uint transferTag)
- {
- TransferEntry result;
- m_transfers.TryGetValue(transferTag, out result);
- return result;
- }
- public void RemoveTransfer(uint initiatorTaskTag, uint transferTag)
- {
- m_taskTagToTransferTag.Remove(initiatorTaskTag);
- m_transfers.Remove(transferTag);
- }
- public string ConnectionIdentifier
- {
- get
- {
- if (Session != null)
- {
- return Session.SessionIdentifier + String.Format(",CID={0}", this.CID.ToString("x"));
- }
- else
- {
- return String.Format("ISID=0,TSIH=0,CID={0}", this.CID.ToString("x"));
- }
- }
- }
- }
- }
|