Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
rudern
物联大师
提交
9f60b189
物
物联大师
项目概览
rudern
/
物联大师
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
物
物联大师
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9f60b189
编写于
8月 28, 2020
作者:
J
Jason
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
仍
上级
f82efca2
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
43 addition
and
12 deletion
+43
-12
api/connection.go
api/connection.go
+1
-0
api/router.go
api/router.go
+20
-6
dtu/channel.go
dtu/channel.go
+18
-2
dtu/conn.go
dtu/conn.go
+4
-4
未找到文件。
api/connection.go
0 → 100644
浏览文件 @
9f60b189
package
api
api/router.go
浏览文件 @
9f60b189
...
@@ -24,12 +24,26 @@ type paramId2 struct {
...
@@ -24,12 +24,26 @@ type paramId2 struct {
func
RegisterRoutes
(
app
*
gin
.
RouterGroup
)
{
func
RegisterRoutes
(
app
*
gin
.
RouterGroup
)
{
app
.
GET
(
"/channels"
,
channelList
)
app
.
POST
(
"/channels"
,
channelList
)
app
.
POST
(
"/login"
,
authLogin
)
app
.
POST
(
"/channel"
,
channelCreate
)
app
.
DELETE
(
"/logout"
,
authLogout
)
app
.
DELETE
(
"/channel/:id"
,
channelDelete
)
app
.
POST
(
"/password"
,
authPassword
)
app
.
PUT
(
"/channel/:id"
,
channelEdit
)
app
.
GET
(
"/channel/:id"
,
channelGet
)
//TODO 转移至子目录,并使用中间件,检查session及权限
app
.
GET
(
"/channels"
)
app
.
POST
(
"/channels"
)
app
.
POST
(
"/channel"
)
app
.
DELETE
(
"/channel/:id"
)
app
.
PUT
(
"/channel/:id"
)
app
.
GET
(
"/channel/:id"
)
app
.
GET
(
"/channel/:id/start"
)
app
.
GET
(
"/channel/:id/stop"
)
app
.
GET
(
"/channel/:id/connections"
)
app
.
POST
(
"/channel/:id/connections"
)
app
.
DELETE
(
"/channel/:id/connection/:id2"
)
//关闭连接
app
.
GET
(
"/channel/:id/connection/:id2/statistic"
)
}
}
...
...
dtu/channel.go
浏览文件 @
9f60b189
...
@@ -18,12 +18,15 @@ type Channel struct {
...
@@ -18,12 +18,15 @@ type Channel struct {
listener
net
.
Listener
listener
net
.
Listener
packetConn
net
.
PacketConn
packetConn
net
.
PacketConn
packetIndexes
sync
.
Map
packetIndexes
sync
.
Map
connections
sync
.
Map
//自增ID
increment
int
}
}
func
NewChannel
(
channel
*
storage
.
Channel
)
*
Channel
{
func
NewChannel
(
channel
*
storage
.
Channel
)
*
Channel
{
return
&
Channel
{
return
&
Channel
{
Channel
:
*
channel
,
Channel
:
*
channel
,
//connections: make([]Connection, 0),
}
}
}
}
...
@@ -105,7 +108,7 @@ func (c *Channel) accept() {
...
@@ -105,7 +108,7 @@ func (c *Channel) accept() {
func
(
c
*
Channel
)
receive
(
conn
net
.
Conn
)
{
func
(
c
*
Channel
)
receive
(
conn
net
.
Conn
)
{
client
:=
newConnection
(
conn
)
client
:=
newConnection
(
conn
)
client
.
channel
=
c
client
.
channel
=
c
//c.connections = append(c.connections,
client)
c
.
storeConnection
(
client
)
buf
:=
make
([]
byte
,
1024
)
buf
:=
make
([]
byte
,
1024
)
for
client
.
conn
!=
nil
{
for
client
.
conn
!=
nil
{
...
@@ -121,6 +124,14 @@ func (c *Channel) receive(conn net.Conn) {
...
@@ -121,6 +124,14 @@ func (c *Channel) receive(conn net.Conn) {
}
}
func
(
c
*
Channel
)
storeConnection
(
conn
*
Connection
)
{
c
.
increment
++
conn
.
ID
=
c
.
increment
//根据ID保存
c
.
connections
.
Store
(
c
.
ID
,
conn
)
}
func
(
c
*
Channel
)
receivePacket
()
{
func
(
c
*
Channel
)
receivePacket
()
{
buf
:=
make
([]
byte
,
1024
)
buf
:=
make
([]
byte
,
1024
)
for
c
.
packetConn
!=
nil
{
for
c
.
packetConn
!=
nil
{
...
@@ -140,6 +151,11 @@ func (c *Channel) receivePacket() {
...
@@ -140,6 +151,11 @@ func (c *Channel) receivePacket() {
}
else
{
}
else
{
client
=
newPacketConnection
(
c
.
packetConn
,
addr
)
client
=
newPacketConnection
(
c
.
packetConn
,
addr
)
client
.
channel
=
c
client
.
channel
=
c
//根据ID保存
c
.
storeConnection
(
client
)
//根据地址保存,收到UDP包之后,方便索引
c
.
packetIndexes
.
Store
(
key
,
client
)
c
.
packetIndexes
.
Store
(
key
,
client
)
}
}
...
...
dtu/conn.go
浏览文件 @
9f60b189
...
@@ -11,6 +11,8 @@ import (
...
@@ -11,6 +11,8 @@ import (
)
)
type
Connection
struct
{
type
Connection
struct
{
ID
int
Error
string
Error
string
Serial
string
Serial
string
RemoteAddr
net
.
Addr
RemoteAddr
net
.
Addr
...
@@ -84,7 +86,6 @@ func (c *Connection) Send(buf []byte) (int, error) {
...
@@ -84,7 +86,6 @@ func (c *Connection) Send(buf []byte) (int, error) {
return
0
,
errors
.
New
(
"错误的链接类型"
)
return
0
,
errors
.
New
(
"错误的链接类型"
)
}
}
func
(
c
*
Connection
)
Close
()
error
{
func
(
c
*
Connection
)
Close
()
error
{
return
c
.
conn
.
(
net
.
Conn
)
.
Close
()
return
c
.
conn
.
(
net
.
Conn
)
.
Close
()
}
}
...
@@ -96,7 +97,6 @@ func newConnection(conn net.Conn) *Connection {
...
@@ -96,7 +97,6 @@ func newConnection(conn net.Conn) *Connection {
}
}
}
}
func
newPacketConnection
(
conn
net
.
PacketConn
,
addr
net
.
Addr
)
*
Connection
{
func
newPacketConnection
(
conn
net
.
PacketConn
,
addr
net
.
Addr
)
*
Connection
{
return
&
Connection
{
return
&
Connection
{
RemoteAddr
:
addr
,
RemoteAddr
:
addr
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录