代码拉取完成,页面将自动刷新
同步操作将从 coco/go808 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package go808
import (
"fmt"
"gitee.com/coco/go808/protocol"
"github.com/funny/link"
log "github.com/sirupsen/logrus"
"io/ioutil"
"reflect"
"strconv"
)
// Session处理
type sessionHandler struct {
server *Server
autoMergePacket bool
}
func (handler sessionHandler) HandleSession(sess *link.Session) {
log.WithFields(log.Fields{
"id": sess.ID(),
}).Debug("[JT/T 808] new session created")
// 创建Session
session := newSession(handler.server, sess)
handler.server.mutex.Lock()
handler.server.sessions[sess.ID()] = session
handler.server.mutex.Unlock()
handler.server.timer.Update(strconv.FormatUint(session.ID(), 10))
sess.AddCloseCallback(nil, nil, func() {
handler.server.handleClose(session)
})
for {
// 接收消息
msg, err := sess.Receive()
if err != nil {
sess.Close()
break
}
// 分发消息
message := msg.(protocol.Message)
if message.Body == nil || reflect.ValueOf(message.Body).IsNil() {
session.Reply(&message, protocol.T808_0x8001ResultUnsupported)
continue
}
if !handler.autoMergePacket || !message.Header.Property.IsEnablePacket() {
session.message(&message)
handler.server.dispatchMessage(session, &message)
continue
}
// 处理分包消息
entityPacket, ok := interface{}(message.Body).(protocol.EntityPacket)
if !ok {
session.message(&message)
handler.server.dispatchMessage(session, &message)
continue
}
multipartFile := MultipartFile{
IccID: message.Header.IccID,
MsgID: message.Header.MsgID,
Tag: entityPacket.GetTag(),
Sum: message.Header.Packet.Sum,
}
buf, err := ioutil.ReadAll(entityPacket.GetReader())
if err != nil {
log.WithFields(log.Fields{
"iccid": message.Header.IccID,
"msgid": fmt.Sprintf("0x%x", message.Header.MsgID),
"seq": message.Header.Packet.Seq,
"reason": err,
}).Warn("[JT/T 808] failed to read packet data")
session.Reply(&message, protocol.T808_0x8001ResultFail)
continue
}
err = multipartFile.Write(message.Header.Packet.Seq, buf)
if err != nil {
log.WithFields(log.Fields{
"iccid": message.Header.IccID,
"msgid": fmt.Sprintf("0x%x", message.Header.MsgID),
"seq": message.Header.Packet.Seq,
"reason": err,
}).Warn("[JT/T 808] failed to write packet data to file")
session.Reply(&message, protocol.T808_0x8001ResultFail)
continue
}
session.Reply(&message, protocol.T808_0x8001ResultSuccess)
if message.Header.Packet.Seq != message.Header.Packet.Sum || !multipartFile.IsFull() {
continue
}
reader, err := multipartFile.Merge()
if err != nil {
log.WithFields(log.Fields{
"iccid": message.Header.IccID,
"msgid": fmt.Sprintf("0x%x", message.Header.MsgID),
"reason": err,
}).Warn("[JT/T 808] failed to merge packet file parts")
continue
}
// 分发分包消息
entityPacket.SetReader(reader)
session.message(&message)
handler.server.dispatchMessage(session, &message)
reader.Close()
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。