Commit 7875d463 authored by terrymanu's avatar terrymanu
Browse files

remove PacketHeader

parent 861e49b7
Loading
Loading
Loading
Loading
+19 −15
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import io.shardingsphere.proxy.backend.netty.future.FutureRegistry;
import io.shardingsphere.proxy.config.RuleRegistry;
import io.shardingsphere.proxy.runtime.ChannelRegistry;
import io.shardingsphere.proxy.transport.mysql.constant.CapabilityFlag;
import io.shardingsphere.proxy.transport.mysql.constant.PacketHeader;
import io.shardingsphere.proxy.transport.mysql.constant.ServerInfo;
import io.shardingsphere.proxy.transport.mysql.packet.MySQLPacketPayload;
import io.shardingsphere.proxy.transport.mysql.packet.command.query.ColumnDefinition41Packet;
@@ -66,15 +65,12 @@ public final class MySQLResponseHandler extends ResponseHandler {
    @Override
    public void channelRead(final ChannelHandlerContext context, final Object message) {
        MySQLPacketPayload payload = new MySQLPacketPayload((ByteBuf) message);
        payload.getByteBuf().markReaderIndex();
        payload.readInt1();
        int header = payload.readInt1();
        payload.getByteBuf().resetReaderIndex();
        int header = getHeader(payload);
        if (AuthType.UN_AUTH == authType) {
            auth(context, payload);
            authType = AuthType.AUTHING;
        } else if (AuthType.AUTHING == authType) {
            if (PacketHeader.OK.getValue() == header) {
            if (OKPacket.HEADER == header) {
                okPacket(context, payload);
                authType = AuthType.AUTH_SUCCESS;
            } else {
@@ -84,11 +80,11 @@ public final class MySQLResponseHandler extends ResponseHandler {
        } else if (AuthType.AUTH_FAILED == authType) {
            log.error("mysql auth failed, cannot handle channel read message");
        } else {
            if (PacketHeader.EOF.getValue() == header) {
            if (EofPacket.HEADER == header) {
                eofPacket(context, payload);
            } else if (PacketHeader.OK.getValue() == header) {
            } else if (OKPacket.HEADER == header) {
                okPacket(context, payload);
            } else if (PacketHeader.ERR.getValue() == header) {
            } else if (ErrPacket.HEADER == header) {
                errPacket(context, payload);
            } else {
                commonPacket(context, payload);
@@ -96,6 +92,14 @@ public final class MySQLResponseHandler extends ResponseHandler {
        }
    }
    
    private int getHeader(final MySQLPacketPayload payload) {
        payload.getByteBuf().markReaderIndex();
        payload.readInt1();
        int result = payload.readInt1();
        payload.getByteBuf().resetReaderIndex();
        return result;
    }
    
    @Override
    protected void auth(final ChannelHandlerContext context, final MySQLPacketPayload payload) {
        try {
@@ -169,12 +173,6 @@ public final class MySQLResponseHandler extends ResponseHandler {
        }
    }
    
    @Override
    public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
        //TODO delete connection map.
        super.channelInactive(ctx);
    }
    
    private byte[] securePasswordAuthentication(final byte[] password, final byte[] authPluginData) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
@@ -200,4 +198,10 @@ public final class MySQLResponseHandler extends ResponseHandler {
            FutureRegistry.getInstance().get(connectionId).setResponse(resultMap.get(connectionId));
        }
    }
    
    @Override
    public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
        //TODO delete connection map.
        super.channelInactive(ctx);
    }
}
+0 −39
Original line number Diff line number Diff line
/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */

package io.shardingsphere.proxy.transport.mysql.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * Generic Packet Header.
 *
 * @author linjiaqi
 */
@RequiredArgsConstructor
@Getter
public enum PacketHeader {
    
    OK(0x00),
    
    EOF(0xfe),
    
    ERR(0xff);
    
    private final int value;
}
+4 −1
Original line number Diff line number Diff line
@@ -36,7 +36,10 @@ import lombok.RequiredArgsConstructor;
@Getter
public final class EofPacket implements MySQLPacket {
    
    private static final int HEADER = 0xfe;
    /**
     * Header of EOF packet.
     */
    public static final int HEADER = 0xfe;
    
    private final int sequenceId;
    
+4 −1
Original line number Diff line number Diff line
@@ -38,7 +38,10 @@ import java.sql.SQLException;
@Getter
public final class ErrPacket implements MySQLPacket {
    
    private static final int HEADER = 0xff;
    /**
     * Header of ERR packet.
     */
    public static final int HEADER = 0xff;
    
    private static final String SQL_STATE_MARKER = "#";
    
+4 −1
Original line number Diff line number Diff line
@@ -36,7 +36,10 @@ import lombok.RequiredArgsConstructor;
@Getter
public final class OKPacket implements MySQLPacket {
    
    private static final int HEADER = 0x00;
    /**
     * Header of OK packet.
     */
    public static final int HEADER = 0x00;
    
    private static final int STATUS_FLAG = StatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue();