| 1 | |
package org.jscsi.target.connection.stage.login; |
| 2 | |
|
| 3 | |
|
| 4 | |
import java.io.IOException; |
| 5 | |
import java.security.DigestException; |
| 6 | |
import java.util.List; |
| 7 | |
import java.util.Vector; |
| 8 | |
|
| 9 | |
import org.jscsi.exception.InternetSCSIException; |
| 10 | |
import org.jscsi.parser.BasicHeaderSegment; |
| 11 | |
import org.jscsi.parser.ProtocolDataUnit; |
| 12 | |
import org.jscsi.parser.login.LoginStage; |
| 13 | |
import org.jscsi.parser.login.LoginStatus; |
| 14 | |
import org.jscsi.target.connection.phase.TargetLoginPhase; |
| 15 | |
import org.jscsi.target.settings.SettingsException; |
| 16 | |
import org.jscsi.target.settings.TextParameter; |
| 17 | |
import org.slf4j.Logger; |
| 18 | |
import org.slf4j.LoggerFactory; |
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
public final class LoginOperationalParameterNegotiationStage extends TargetLoginStage { |
| 27 | |
|
| 28 | 0 | private static final Logger LOGGER = LoggerFactory.getLogger(LoginOperationalParameterNegotiationStage.class); |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
public LoginOperationalParameterNegotiationStage (TargetLoginPhase targetLoginPhase) { |
| 36 | 0 | super(targetLoginPhase, LoginStage.LOGIN_OPERATIONAL_NEGOTIATION); |
| 37 | 0 | } |
| 38 | |
|
| 39 | |
@Override |
| 40 | |
public void execute (ProtocolDataUnit pdu) throws IOException , InterruptedException , InternetSCSIException , DigestException , IllegalArgumentException , SettingsException { |
| 41 | 0 | LOGGER.debug("Entering LOPN Stage"); |
| 42 | |
|
| 43 | 0 | BasicHeaderSegment bhs = pdu.getBasicHeaderSegment(); |
| 44 | 0 | initiatorTaskTag = bhs.getInitiatorTaskTag(); |
| 45 | |
|
| 46 | 0 | String keyValuePairProposal = receivePduSequence(pdu); |
| 47 | |
|
| 48 | |
|
| 49 | 0 | final List<String> requestKeyValuePairs = TextParameter.tokenizeKeyValuePairs(keyValuePairProposal); |
| 50 | 0 | final List<String> responseKeyValuePairs = new Vector<String>(); |
| 51 | 0 | if (!negotiator.negotiate(session.getTargetServer(), stageNumber, connection.isLeadingConnection(), ((TargetLoginPhase) targetPhase).getFirstPduAndSetToFalse(), requestKeyValuePairs, responseKeyValuePairs)) { |
| 52 | |
|
| 53 | 0 | sendRejectPdu(LoginStatus.INITIATOR_ERROR); |
| 54 | |
|
| 55 | 0 | return; |
| 56 | |
} |
| 57 | |
|
| 58 | |
|
| 59 | 0 | if (LOGGER.isDebugEnabled()) { |
| 60 | 0 | final StringBuilder sb = new StringBuilder(); |
| 61 | 0 | sb.append("request: "); |
| 62 | 0 | for (String s : requestKeyValuePairs) { |
| 63 | 0 | sb.append("\n "); |
| 64 | 0 | sb.append(s); |
| 65 | 0 | } |
| 66 | 0 | sb.append("\nresponse: "); |
| 67 | 0 | for (String s : responseKeyValuePairs) { |
| 68 | 0 | sb.append("\n "); |
| 69 | 0 | sb.append(s); |
| 70 | 0 | } |
| 71 | 0 | LOGGER.debug(sb.toString()); |
| 72 | |
} |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | 0 | if (requestedNextStageNumber != LoginStage.FULL_FEATURE_PHASE) { |
| 77 | 0 | sendRejectPdu(LoginStatus.INITIATOR_ERROR); |
| 78 | 0 | throw new InternetSCSIException(); |
| 79 | |
} |
| 80 | |
|
| 81 | |
|
| 82 | 0 | final String keyValuePairReply = TextParameter.concatenateKeyValuePairs(responseKeyValuePairs); |
| 83 | |
|
| 84 | |
|
| 85 | 0 | sendPduSequence(keyValuePairReply, LoginStage.FULL_FEATURE_PHASE); |
| 86 | 0 | negotiator.finishNegotiation(true); |
| 87 | 0 | nextStageNumber = LoginStage.FULL_FEATURE_PHASE; |
| 88 | 0 | } |
| 89 | |
} |