提交 7875d463 编写于 作者: T terrymanu

remove PacketHeader

上级 861e49b7
...@@ -27,7 +27,6 @@ import io.shardingsphere.proxy.backend.netty.future.FutureRegistry; ...@@ -27,7 +27,6 @@ import io.shardingsphere.proxy.backend.netty.future.FutureRegistry;
import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.proxy.config.RuleRegistry;
import io.shardingsphere.proxy.runtime.ChannelRegistry; import io.shardingsphere.proxy.runtime.ChannelRegistry;
import io.shardingsphere.proxy.transport.mysql.constant.CapabilityFlag; 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.constant.ServerInfo;
import io.shardingsphere.proxy.transport.mysql.packet.MySQLPacketPayload; import io.shardingsphere.proxy.transport.mysql.packet.MySQLPacketPayload;
import io.shardingsphere.proxy.transport.mysql.packet.command.query.ColumnDefinition41Packet; import io.shardingsphere.proxy.transport.mysql.packet.command.query.ColumnDefinition41Packet;
...@@ -66,15 +65,12 @@ public final class MySQLResponseHandler extends ResponseHandler { ...@@ -66,15 +65,12 @@ public final class MySQLResponseHandler extends ResponseHandler {
@Override @Override
public void channelRead(final ChannelHandlerContext context, final Object message) { public void channelRead(final ChannelHandlerContext context, final Object message) {
MySQLPacketPayload payload = new MySQLPacketPayload((ByteBuf) message); MySQLPacketPayload payload = new MySQLPacketPayload((ByteBuf) message);
payload.getByteBuf().markReaderIndex(); int header = getHeader(payload);
payload.readInt1();
int header = payload.readInt1();
payload.getByteBuf().resetReaderIndex();
if (AuthType.UN_AUTH == authType) { if (AuthType.UN_AUTH == authType) {
auth(context, payload); auth(context, payload);
authType = AuthType.AUTHING; authType = AuthType.AUTHING;
} else if (AuthType.AUTHING == authType) { } else if (AuthType.AUTHING == authType) {
if (PacketHeader.OK.getValue() == header) { if (OKPacket.HEADER == header) {
okPacket(context, payload); okPacket(context, payload);
authType = AuthType.AUTH_SUCCESS; authType = AuthType.AUTH_SUCCESS;
} else { } else {
...@@ -84,11 +80,11 @@ public final class MySQLResponseHandler extends ResponseHandler { ...@@ -84,11 +80,11 @@ public final class MySQLResponseHandler extends ResponseHandler {
} else if (AuthType.AUTH_FAILED == authType) { } else if (AuthType.AUTH_FAILED == authType) {
log.error("mysql auth failed, cannot handle channel read message"); log.error("mysql auth failed, cannot handle channel read message");
} else { } else {
if (PacketHeader.EOF.getValue() == header) { if (EofPacket.HEADER == header) {
eofPacket(context, payload); eofPacket(context, payload);
} else if (PacketHeader.OK.getValue() == header) { } else if (OKPacket.HEADER == header) {
okPacket(context, payload); okPacket(context, payload);
} else if (PacketHeader.ERR.getValue() == header) { } else if (ErrPacket.HEADER == header) {
errPacket(context, payload); errPacket(context, payload);
} else { } else {
commonPacket(context, payload); commonPacket(context, payload);
...@@ -96,6 +92,14 @@ public final class MySQLResponseHandler extends ResponseHandler { ...@@ -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 @Override
protected void auth(final ChannelHandlerContext context, final MySQLPacketPayload payload) { protected void auth(final ChannelHandlerContext context, final MySQLPacketPayload payload) {
try { try {
...@@ -169,12 +173,6 @@ public final class MySQLResponseHandler extends ResponseHandler { ...@@ -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) { private byte[] securePasswordAuthentication(final byte[] password, final byte[] authPluginData) {
try { try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
...@@ -200,4 +198,10 @@ public final class MySQLResponseHandler extends ResponseHandler { ...@@ -200,4 +198,10 @@ public final class MySQLResponseHandler extends ResponseHandler {
FutureRegistry.getInstance().get(connectionId).setResponse(resultMap.get(connectionId)); FutureRegistry.getInstance().get(connectionId).setResponse(resultMap.get(connectionId));
} }
} }
@Override
public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
//TODO delete connection map.
super.channelInactive(ctx);
}
} }
/*
* 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;
}
...@@ -36,7 +36,10 @@ import lombok.RequiredArgsConstructor; ...@@ -36,7 +36,10 @@ import lombok.RequiredArgsConstructor;
@Getter @Getter
public final class EofPacket implements MySQLPacket { 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; private final int sequenceId;
......
...@@ -38,7 +38,10 @@ import java.sql.SQLException; ...@@ -38,7 +38,10 @@ import java.sql.SQLException;
@Getter @Getter
public final class ErrPacket implements MySQLPacket { 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 = "#"; private static final String SQL_STATE_MARKER = "#";
......
...@@ -36,7 +36,10 @@ import lombok.RequiredArgsConstructor; ...@@ -36,7 +36,10 @@ import lombok.RequiredArgsConstructor;
@Getter @Getter
public final class OKPacket implements MySQLPacket { 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(); private static final int STATUS_FLAG = StatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册