1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /* Copyright (C) 2012-2016 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 ushort CID; // connection ID, generated by the initiator
- public string InitiatorName = String.Empty;
- 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>();
- // Dictionary of current transfers: <transfer-tag, TransferEntry>
- private Dictionary<uint, TransferEntry> n_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 transferTag, SCSICommandPDU command, uint nextR2TSN, uint nextOffset, uint totalR2Ts)
- {
- TransferEntry entry = new TransferEntry(command, nextR2TSN, nextOffset, totalR2Ts);
- n_transfers.Add(transferTag, entry);
- return entry;
- }
- public TransferEntry GetTransferEntry(uint transferTag)
- {
- TransferEntry result;
- n_transfers.TryGetValue(transferTag, out result);
- return result;
- }
- public void RemoveTransfer(uint transferTag)
- {
- n_transfers.Remove(transferTag);
- }
- }
- }
|