提交 29d8b52f 编写于 作者: J Jason

重命名 Client 为 Tunnel

上级 42de342f
......@@ -2,7 +2,7 @@ package base
import "github.com/zgwit/dtu-admin/packet"
type Client interface {
type Tunnel interface {
CLose() error
Send(msg *packet.Packet) error
Write(b []byte) error
......
package dbus
import (
"github.com/zgwit/dtu-admin/base"
"github.com/zgwit/dtu-admin/packet"
"log"
"net"
......@@ -41,7 +40,10 @@ func (p *baseClient) Write(b []byte) error {
return nil
}
func NewClient() base.Client {
//根据类型
return nil
func (p *baseClient) SendError(err string) error {
return p.Send(&packet.Packet{
Type: packet.TypeError,
Status: 0,
Data: []byte(err),
})
}
\ No newline at end of file
......@@ -16,7 +16,8 @@ type Peer struct {
func (p *Peer) Handle(msg *packet.Packet) {
switch msg.Type {
case packet.TypeConnect:
p.handleConnect(msg)
_ = p.SendError("duplicate register")
_ = p.CLose()
case packet.TypeHeartBeak:
case packet.TypePing:
_ = p.Send(&packet.Packet{Type: packet.TypePong})
......@@ -27,13 +28,6 @@ func (p *Peer) Handle(msg *packet.Packet) {
}
}
func (p *Peer) handleConnect(msg *packet.Packet) {
//p.Key = string(msg.Data)
//TODO 检查Key,获取对应的 通道,连接号
//TODO 在link中设置peer
}
func (p *Peer) handleTransfer(msg *packet.Packet) {
//_, _ = p.link.Send(msg.Data)
//TODO 判断link是否为空
......
......@@ -12,7 +12,9 @@ type Plugin struct {
func (p *Plugin) Handle(msg *packet.Packet) {
switch msg.Type {
case packet.TypeConnect:
p.handleConnect(msg)
_ = p.SendError("duplicate register")
_ = p.CLose()
//p.handleConnect(msg)
case packet.TypeHeartBeak:
case packet.TypePing:
_ = p.Send(&packet.Packet{Type: packet.TypePong})
......@@ -23,11 +25,6 @@ func (p *Plugin) Handle(msg *packet.Packet) {
}
}
func (p *Plugin) handleConnect(msg *packet.Packet) {
//TODO 根据appkey, secret校验身份,注册插件到对应通道和链接上
}
func (p *Plugin) handleTransfer(msg *packet.Packet) {
//TODO 找到对应链接,发送之
//TODO 使用 int64 还是 int32
......
......@@ -93,7 +93,7 @@ func (s *Server) receive(conn net.Conn) {
_ = c.CLose()
}
func (s *Server) createTunnel(p *packet.Packet) (base.Client, error) {
func (s *Server) createTunnel(p *packet.Packet) (base.Tunnel, error) {
if p.Type != packet.TypeConnect {
//告诉客户端,第一个包必须是注册包
return nil, errors.New("first packet must be connect")
......
......@@ -24,9 +24,9 @@ type Link struct {
cache [][]byte
//透传链接
peer base.Client
peer base.Tunnel
plugin base.Client
plugin base.Tunnel
//监视器连接,
monitor *Monitor
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册