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
9eaa8a21
Commit
9eaa8a21
authored
Nov 11, 2022
by
AfirSraftGarrier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
格式并加些打印
parent
eb48ade2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
31 deletions
+13
-31
DeviceDecoder.java
...c/main/java/iot/sixiang/license/device/DeviceDecoder.java
+1
-1
DeviceProtocol.java
.../main/java/iot/sixiang/license/device/DeviceProtocol.java
+2
-4
DeviceServerHandler.java
.../java/iot/sixiang/license/device/DeviceServerHandler.java
+9
-23
ForwardClientRequestEvent.java
.../iot/sixiang/license/event/ForwardClientRequestEvent.java
+0
-2
ForwardMessageResponseEvent.java
...ot/sixiang/license/event/ForwardMessageResponseEvent.java
+1
-1
No files found.
license/src/main/java/iot/sixiang/license/device/DeviceDecoder.java
View file @
9eaa8a21
...
@@ -39,7 +39,7 @@ public class DeviceDecoder extends ByteToMessageDecoder {
...
@@ -39,7 +39,7 @@ public class DeviceDecoder extends ByteToMessageDecoder {
return
;
return
;
}
}
// buffer.resetReaderIndex();
// buffer.resetReaderIndex();
byte
[]
content
=
new
byte
[
real_len
-
cmd_ack_len
];
byte
[]
content
=
new
byte
[
real_len
-
cmd_ack_len
];
buffer
.
readBytes
(
content
);
buffer
.
readBytes
(
content
);
...
...
license/src/main/java/iot/sixiang/license/device/DeviceProtocol.java
View file @
9eaa8a21
...
@@ -4,8 +4,7 @@ import lombok.Data;
...
@@ -4,8 +4,7 @@ import lombok.Data;
@Data
@Data
public
class
DeviceProtocol
{
public
class
DeviceProtocol
{
// |STX |LEN |CMD |ACK |DATA |END
// |STX |LEN |CMD |ACK |DATA |END
private
short
stx
;
//
private
short
stx
;
//
private
int
len
;
//
private
int
len
;
//
...
@@ -15,7 +14,7 @@ public class DeviceProtocol {
...
@@ -15,7 +14,7 @@ public class DeviceProtocol {
private
byte
[]
content
;
// 数据
private
byte
[]
content
;
// 数据
private
byte
end
;
private
byte
end
;
public
DeviceProtocol
(
short
stx
,
int
len
,
byte
cmd
,
byte
ack
,
byte
[]
content
,
byte
end
)
{
public
DeviceProtocol
(
short
stx
,
int
len
,
byte
cmd
,
byte
ack
,
byte
[]
content
,
byte
end
)
{
super
();
super
();
this
.
stx
=
stx
;
this
.
stx
=
stx
;
this
.
len
=
len
;
this
.
len
=
len
;
...
@@ -24,5 +23,4 @@ public class DeviceProtocol {
...
@@ -24,5 +23,4 @@ public class DeviceProtocol {
this
.
content
=
content
;
this
.
content
=
content
;
this
.
end
=
end
;
this
.
end
=
end
;
}
}
}
}
\ No newline at end of file
license/src/main/java/iot/sixiang/license/device/DeviceServerHandler.java
View file @
9eaa8a21
...
@@ -27,7 +27,6 @@ import java.net.InetSocketAddress;
...
@@ -27,7 +27,6 @@ import java.net.InetSocketAddress;
@ChannelHandler
.
Sharable
@ChannelHandler
.
Sharable
@Slf4j
@Slf4j
public
class
DeviceServerHandler
extends
SimpleChannelInboundHandler
<
Object
>
{
public
class
DeviceServerHandler
extends
SimpleChannelInboundHandler
<
Object
>
{
@Autowired
@Autowired
EventPublisher
eventPublisher
;
EventPublisher
eventPublisher
;
@Autowired
@Autowired
...
@@ -39,9 +38,7 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
...
@@ -39,9 +38,7 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
@Override
@Override
protected
void
channelRead0
(
ChannelHandlerContext
ctx
,
Object
msg
)
{
protected
void
channelRead0
(
ChannelHandlerContext
ctx
,
Object
msg
)
{
log
.
info
(
"come read..."
);
// 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
();
...
@@ -49,49 +46,43 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
...
@@ -49,49 +46,43 @@ 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
)
{
log
.
info
(
"come auth..."
);
auth
=
handlerCheckAuth
(
channel
,
remoteIp
,
remotePort
,
protocol
);
auth
=
handlerCheckAuth
(
channel
,
remoteIp
,
remotePort
,
protocol
);
}
else
{
}
else
{
log
.
info
(
"no auth..."
);
auth
=
handlerCheckAuthStatus
(
channel
,
remoteIp
,
remotePort
,
protocol
);
auth
=
handlerCheckAuthStatus
(
channel
,
remoteIp
,
remotePort
,
protocol
);
if
(
auth
)
{
if
(
auth
)
{
handlerForward
(
channel
,
remoteIp
,
remotePort
,
protocol
);
handlerForward
(
channel
,
remoteIp
,
remotePort
,
protocol
);
}
}
}
}
//TODO 以下为正式代码
//
TODO 以下为正式代码
if
(
auth
==
false
)
{
if
(
auth
==
false
)
{
log
.
info
(
"close..."
);
channel
.
close
();
channel
.
close
();
}
}
}
}
@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
();
...
@@ -105,29 +96,26 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
...
@@ -105,29 +96,26 @@ 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 正式代码要放开
byte
[]
bytes
=
safety
.
decodeExtendedPayload
(
protocol
.
getContent
(),
0
,
protocol
.
getContent
().
length
);
byte
[]
bytes
=
safety
.
decodeExtendedPayload
(
protocol
.
getContent
(),
0
,
protocol
.
getContent
().
length
);
if
(
bytes
==
null
)
{
if
(
bytes
==
null
)
{
return
false
;
return
false
;
}
}
String
decodeInfo
=
CommonUtil
.
bytesToStr
(
bytes
);
String
decodeInfo
=
CommonUtil
.
bytesToStr
(
bytes
);
log
.
info
(
"byte to string:"
+
decodeInfo
);
if
(
decodeInfo
==
null
)
{
if
(
decodeInfo
==
null
)
{
return
false
;
return
false
;
}
}
...
@@ -176,6 +164,4 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
...
@@ -176,6 +164,4 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
forwardClientRequestEvent
.
setProtocol
(
protocol
);
forwardClientRequestEvent
.
setProtocol
(
protocol
);
eventPublisher
.
publishEvent
(
forwardClientRequestEvent
);
eventPublisher
.
publishEvent
(
forwardClientRequestEvent
);
}
}
}
}
license/src/main/java/iot/sixiang/license/event/ForwardClientRequestEvent.java
View file @
9eaa8a21
package
iot
.
sixiang
.
license
.
event
;
package
iot
.
sixiang
.
license
.
event
;
import
io.netty.channel.socket.SocketChannel
;
import
iot.sixiang.license.device.DeviceProtocol
;
import
iot.sixiang.license.device.DeviceProtocol
;
import
lombok.Data
;
import
lombok.Data
;
...
@@ -9,5 +8,4 @@ public class ForwardClientRequestEvent extends BaseEvent {
...
@@ -9,5 +8,4 @@ public class ForwardClientRequestEvent extends BaseEvent {
private
String
appId
;
private
String
appId
;
private
String
deviceChannelId
;
private
String
deviceChannelId
;
private
DeviceProtocol
protocol
;
private
DeviceProtocol
protocol
;
}
}
\ No newline at end of file
license/src/main/java/iot/sixiang/license/event/ForwardMessageResponseEvent.java
View file @
9eaa8a21
...
@@ -6,7 +6,7 @@ import lombok.Data;
...
@@ -6,7 +6,7 @@ import lombok.Data;
@Data
@Data
public
class
ForwardMessageResponseEvent
extends
BaseEvent
{
public
class
ForwardMessageResponseEvent
extends
BaseEvent
{
// private String appId;
// private String appId;
private
String
channelId
;
private
String
channelId
;
private
SocketChannel
channel
;
private
SocketChannel
channel
;
private
DeviceProtocol
protocol
;
private
DeviceProtocol
protocol
;
...
...
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