Commit 176c9dcb authored by AfirSraftGarrier's avatar AfirSraftGarrier

格式

parent aeb91d74
...@@ -37,9 +37,6 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> { ...@@ -37,9 +37,6 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) { protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
// TODO Auto-generated method stub
SocketChannel channel = (SocketChannel) ctx.channel(); SocketChannel channel = (SocketChannel) ctx.channel();
InetSocketAddress socketAddr = (InetSocketAddress) ctx.channel().remoteAddress(); InetSocketAddress socketAddr = (InetSocketAddress) ctx.channel().remoteAddress();
String remoteIp = socketAddr.getHostString(); String remoteIp = socketAddr.getHostString();
...@@ -47,19 +44,13 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> { ...@@ -47,19 +44,13 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
DeviceProtocol protocol = (DeviceProtocol) msg; DeviceProtocol protocol = (DeviceProtocol) msg;
String channelId = channel.id().asLongText(); String channelId = channel.id().asLongText();
log.debug("设备服务器,channelRead0:{},{}", channelId, HexUtil.bytes2hex(protocol.getContent())); log.debug("设备服务器,channelRead0:{},{}", channelId, HexUtil.bytes2hex(protocol.getContent()));
/* /* TODO: 1.透传前先进行鉴权 2.鉴权通过后,创建桥接客户端,非鉴权消息全部放行 3.未鉴权的不能进行透传,强制下线 */
TODO:
1.透传前先进行鉴权
2.鉴权通过后,创建桥接客户端,非鉴权消息全部放行
3.未鉴权的不能进行透传,强制下线
*/
byte cmd = protocol.getCmd(); byte cmd = protocol.getCmd();
int cmdInt = cmd & 0xFF; int cmdInt = cmd & 0xFF;
boolean auth = false; boolean auth = false;
if (cmdInt == Consts.CMD_LICENSE) { if (cmdInt == Consts.CMD_LICENSE) {
auth = handlerCheckAuth(channel, remoteIp, remotePort, protocol); auth = handlerCheckAuth(channel, remoteIp, remotePort, protocol);
} else { } else {
auth = handlerCheckAuthStatus(channel); auth = handlerCheckAuthStatus(channel);
if (auth) { if (auth) {
...@@ -67,7 +58,7 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> { ...@@ -67,7 +58,7 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
} }
} }
//TODO 以下为正式代码 // TODO 以下为正式代码
if (auth == false) { if (auth == false) {
channel.close(); channel.close();
} }
...@@ -75,21 +66,18 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> { ...@@ -75,21 +66,18 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
@Override @Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception { public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
// TODO Auto-generated method stub
super.channelRegistered(ctx); super.channelRegistered(ctx);
log.debug("设备服务器,channelRegistered:{}", ctx.channel().id().asLongText()); log.debug("设备服务器,channelRegistered:{}", ctx.channel().id().asLongText());
} }
@Override @Override
public synchronized void channelActive(ChannelHandlerContext ctx) throws Exception { public synchronized void channelActive(ChannelHandlerContext ctx) throws Exception {
// TODO Auto-generated method stub
super.channelActive(ctx); super.channelActive(ctx);
log.debug("设备服务器,channelActive:{}", ctx.channel().id().asLongText()); log.debug("设备服务器,channelActive:{}", ctx.channel().id().asLongText());
} }
@Override @Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception { public void channelInactive(ChannelHandlerContext ctx) throws Exception {
// TODO Auto-generated method stub
super.channelInactive(ctx); super.channelInactive(ctx);
SocketChannel channel = (SocketChannel) ctx.channel(); SocketChannel channel = (SocketChannel) ctx.channel();
String channelId = channel.id().asLongText(); String channelId = channel.id().asLongText();
...@@ -103,23 +91,19 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> { ...@@ -103,23 +91,19 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
@Override @Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
// TODO Auto-generated method stub
super.channelReadComplete(ctx); super.channelReadComplete(ctx);
log.debug("设备服务器,channelReadComplete:{}", ctx.channel().id().asLongText()); log.debug("设备服务器,channelReadComplete:{}", ctx.channel().id().asLongText());
} }
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception{ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
// TODO Auto-generated method stub
super.exceptionCaught(ctx, cause); super.exceptionCaught(ctx, cause);
log.debug("设备服务器,exceptionCaught:{}", ctx.channel().id().asLongText()); log.debug("设备服务器,exceptionCaught:{}", ctx.channel().id().asLongText());
ctx.close(); ctx.close();
} }
private boolean handlerCheckAuth(SocketChannel channel, String remoteIp, int remotePort, DeviceProtocol protocol) { private boolean handlerCheckAuth(SocketChannel channel, String remoteIp, int remotePort, DeviceProtocol protocol) {
// TODO 正式代码要放开
//TODO 正式代码要放开
LibHelper libHelper = SpringUtil.getBean(LibHelper.class); LibHelper libHelper = SpringUtil.getBean(LibHelper.class);
byte[] bytes = libHelper.decodeExtendedPayload(protocol.getContent(), 0, protocol.getContent().length); byte[] bytes = libHelper.decodeExtendedPayload(protocol.getContent(), 0, protocol.getContent().length);
if (bytes == null) { if (bytes == null) {
...@@ -154,7 +138,7 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> { ...@@ -154,7 +138,7 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
DeviceManager deviceManager = SpringUtil.getBean(DeviceManager.class); DeviceManager deviceManager = SpringUtil.getBean(DeviceManager.class);
deviceManager.putSession(appId, session); deviceManager.putSession(appId, session);
//TODO 创建透传的客户端 // TODO 创建透传的客户端
CreateForwarClientEvent event = new CreateForwarClientEvent(); CreateForwarClientEvent event = new CreateForwarClientEvent();
event.setAppId(appId); event.setAppId(appId);
eventPublisher.publishEvent(event); eventPublisher.publishEvent(event);
...@@ -175,6 +159,4 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> { ...@@ -175,6 +159,4 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
forwardClientRequestEvent.setProtocol(protocol); forwardClientRequestEvent.setProtocol(protocol);
eventPublisher.publishEvent(forwardClientRequestEvent); eventPublisher.publishEvent(forwardClientRequestEvent);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment