Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengtianlai3
ioc_sixiang_license
Commits
cbc275bf
Commit
cbc275bf
authored
Nov 15, 2022
by
AfirSraftGarrier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
格式并加些打印
parent
30fc1001
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
DeviceServerHandler.java
.../java/iot/sixiang/license/device/DeviceServerHandler.java
+10
-7
No files found.
license/src/main/java/iot/sixiang/license/device/DeviceServerHandler.java
View file @
cbc275bf
...
...
@@ -38,13 +38,14 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
@Override
protected
void
channelRead0
(
ChannelHandlerContext
ctx
,
Object
msg
)
{
log
.
info
(
"read..."
);
SocketChannel
channel
=
(
SocketChannel
)
ctx
.
channel
();
InetSocketAddress
socketAddr
=
(
InetSocketAddress
)
ctx
.
channel
().
remoteAddress
();
String
remoteIp
=
socketAddr
.
getHostString
();
int
remotePort
=
socketAddr
.
getPort
();
DeviceProtocol
protocol
=
(
DeviceProtocol
)
msg
;
String
channelId
=
channel
.
id
().
asLongText
();
log
.
debug
(
"设备服务器,channelRead0:{},{}"
,
channelId
,
HexUtil
.
bytes2hex
(
protocol
.
getContent
()));
log
.
info
(
"设备服务器,channelRead0:{},{}"
,
channelId
,
HexUtil
.
bytes2hex
(
protocol
.
getContent
()));
/* 1.透传前先进行鉴权 2.鉴权通过后,创建桥接客户端,非鉴权消息全部放行 3.未鉴权的不能进行透传,强制下线 */
byte
cmd
=
protocol
.
getCmd
();
int
cmdInt
=
cmd
&
0xFF
;
...
...
@@ -55,12 +56,14 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
}
else
{
auth
=
handlerCheckAuthStatus
(
channel
,
remoteIp
,
remotePort
,
protocol
);
if
(
auth
)
{
log
.
info
(
"auth valid..."
);
handlerForward
(
channel
,
remoteIp
,
remotePort
,
protocol
);
}
}
// 以下为正式代码
if
(
auth
==
false
)
{
log
.
info
(
"close"
);
channel
.
close
();
}
}
...
...
@@ -68,13 +71,13 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
@Override
public
void
channelRegistered
(
ChannelHandlerContext
ctx
)
throws
Exception
{
super
.
channelRegistered
(
ctx
);
log
.
debug
(
"设备服务器,channelRegistered:{}"
,
ctx
.
channel
().
id
().
asLongText
());
log
.
info
(
"设备服务器,channelRegistered:{}"
,
ctx
.
channel
().
id
().
asLongText
());
}
@Override
public
synchronized
void
channelActive
(
ChannelHandlerContext
ctx
)
throws
Exception
{
super
.
channelActive
(
ctx
);
log
.
debug
(
"设备服务器,channelActive:{}"
,
ctx
.
channel
().
id
().
asLongText
());
log
.
info
(
"设备服务器,channelActive:{}"
,
ctx
.
channel
().
id
().
asLongText
());
}
@Override
...
...
@@ -82,7 +85,7 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
super
.
channelInactive
(
ctx
);
SocketChannel
channel
=
(
SocketChannel
)
ctx
.
channel
();
String
channelId
=
channel
.
id
().
asLongText
();
log
.
debug
(
"设备服务器,channelInactive:{}"
,
channelId
);
log
.
info
(
"设备服务器,channelInactive:{}"
,
channelId
);
DeviceClientInactiveEvent
deviceClientInactiveEvent
=
new
DeviceClientInactiveEvent
();
deviceClientInactiveEvent
.
setChannelId
(
channelId
);
...
...
@@ -93,18 +96,18 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
@Override
public
void
channelReadComplete
(
ChannelHandlerContext
ctx
)
throws
Exception
{
super
.
channelReadComplete
(
ctx
);
log
.
debug
(
"设备服务器,channelReadComplete:{}"
,
ctx
.
channel
().
id
().
asLongText
());
log
.
info
(
"设备服务器,channelReadComplete:{}"
,
ctx
.
channel
().
id
().
asLongText
());
}
@Override
public
void
exceptionCaught
(
ChannelHandlerContext
ctx
,
Throwable
cause
)
throws
Exception
{
super
.
exceptionCaught
(
ctx
,
cause
);
log
.
debug
(
"设备服务器,exceptionCaught:{}"
,
ctx
.
channel
().
id
().
asLongText
());
log
.
info
(
"设备服务器,exceptionCaught:{}"
,
ctx
.
channel
().
id
().
asLongText
());
ctx
.
close
();
}
private
boolean
handlerCheckAuth
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
//
TODO
正式代码要放开
// 正式代码要放开
byte
[]
bytes
=
safety
.
decodeExtendedPayload
(
protocol
.
getContent
(),
0
,
protocol
.
getContent
().
length
);
if
(
bytes
==
null
)
{
return
false
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment