fix: submit cmpp2 packets for cmpp2 channels
This commit is contained in:
@@ -390,8 +390,10 @@ type connection struct {
|
||||
}
|
||||
|
||||
type submitPartResponse struct {
|
||||
rsp *cmpp.Cmpp3SubmitRspPkt
|
||||
err error
|
||||
seqID uint32
|
||||
msgID uint64
|
||||
result uint32
|
||||
err error
|
||||
}
|
||||
|
||||
func (c *connection) matches(config queue.UpstreamConfig) bool {
|
||||
@@ -419,25 +421,7 @@ func (c *connection) ensureConnected() (bool, error) {
|
||||
|
||||
func (c *connection) submitPart(ctx context.Context, cmd queue.SubmitCommand, part submitPart) (uint32, string, queue.SubmitResult, error) {
|
||||
rspCh := make(chan submitPartResponse, 1)
|
||||
pkt := &cmpp.Cmpp3SubmitReqPkt{
|
||||
PkTotal: part.PkTotal,
|
||||
PkNumber: part.PkNumber,
|
||||
TpUdhi: part.TpUdhi,
|
||||
RegisteredDelivery: uint8(cmd.CMPP.RegisteredDelivery),
|
||||
MsgLevel: 1,
|
||||
ServiceId: cmd.CMPP.ServiceID,
|
||||
FeeUserType: uint8(defaultInt(cmd.CMPP.FeeUserType, 2)),
|
||||
FeeTerminalId: cmd.PhoneNumber,
|
||||
MsgFmt: uint8(cmd.CMPP.MsgFmt),
|
||||
MsgSrc: c.config.Account,
|
||||
FeeType: defaultString(cmd.CMPP.FeeType, "02"),
|
||||
FeeCode: defaultString(cmd.CMPP.FeeCode, "0"),
|
||||
SrcId: cmd.CMPP.SrcID,
|
||||
DestUsrTl: 1,
|
||||
DestTerminalId: []string{cmd.PhoneNumber},
|
||||
MsgLength: uint8(len(part.MsgContent)),
|
||||
MsgContent: part.MsgContent,
|
||||
}
|
||||
pkt := c.submitRequestPacket(cmd, part)
|
||||
|
||||
c.sendMu.Lock()
|
||||
seq, err := c.client.SendReqPkt(pkt)
|
||||
@@ -468,29 +452,106 @@ func (c *connection) submitPart(ctx context.Context, cmd queue.SubmitCommand, pa
|
||||
result := submitResult(cmd, seq, "", "timeout", "CONNECTION_LOST", rsp.err.Error())
|
||||
return seq, "", result, rsp.err
|
||||
}
|
||||
if rsp.rsp == nil {
|
||||
err := fmt.Errorf("submit response is empty")
|
||||
result := submitResult(cmd, seq, "", "timeout", "EMPTY_SUBMIT_RESPONSE", err.Error())
|
||||
return seq, "", result, err
|
||||
}
|
||||
gatewayMessageID := fmt.Sprint(rsp.rsp.MsgId)
|
||||
gatewayMessageID := fmt.Sprint(rsp.msgID)
|
||||
status := "accepted"
|
||||
errorCode := ""
|
||||
errorMessage := ""
|
||||
if rsp.rsp.Result != 0 {
|
||||
if rsp.result != 0 {
|
||||
status = "rejected"
|
||||
errorCode = fmt.Sprint(rsp.rsp.Result)
|
||||
errorMessage = fmt.Sprintf("upstream submit rejected with result %d", rsp.rsp.Result)
|
||||
errorCode = fmt.Sprint(rsp.result)
|
||||
errorMessage = fmt.Sprintf("upstream submit rejected with result %d", rsp.result)
|
||||
}
|
||||
if rsp.rsp.Result == 0 {
|
||||
if rsp.result == 0 {
|
||||
c.mu.Lock()
|
||||
c.tracker[rsp.rsp.MsgId] = cmd
|
||||
c.tracker[rsp.msgID] = cmd
|
||||
c.mu.Unlock()
|
||||
}
|
||||
return seq, gatewayMessageID, submitResult(cmd, seq, gatewayMessageID, status, errorCode, errorMessage), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *connection) submitRequestPacket(cmd queue.SubmitCommand, part submitPart) cmpp.Packer {
|
||||
base := submitRequestFields{
|
||||
PkTotal: part.PkTotal,
|
||||
PkNumber: part.PkNumber,
|
||||
TpUdhi: part.TpUdhi,
|
||||
RegisteredDelivery: uint8(cmd.CMPP.RegisteredDelivery),
|
||||
MsgLevel: 1,
|
||||
ServiceId: cmd.CMPP.ServiceID,
|
||||
FeeUserType: uint8(defaultInt(cmd.CMPP.FeeUserType, 2)),
|
||||
FeeTerminalId: cmd.PhoneNumber,
|
||||
MsgFmt: uint8(cmd.CMPP.MsgFmt),
|
||||
MsgSrc: c.config.Account,
|
||||
FeeType: defaultString(cmd.CMPP.FeeType, "02"),
|
||||
FeeCode: defaultString(cmd.CMPP.FeeCode, "0"),
|
||||
SrcId: cmd.CMPP.SrcID,
|
||||
DestUsrTl: 1,
|
||||
DestTerminalId: []string{cmd.PhoneNumber},
|
||||
MsgLength: uint8(len(part.MsgContent)),
|
||||
MsgContent: part.MsgContent,
|
||||
}
|
||||
if protocolVersion(c.config.CMPPVersion) == cmpp.V20 {
|
||||
return &cmpp.Cmpp2SubmitReqPkt{
|
||||
PkTotal: base.PkTotal,
|
||||
PkNumber: base.PkNumber,
|
||||
RegisteredDelivery: base.RegisteredDelivery,
|
||||
MsgLevel: base.MsgLevel,
|
||||
ServiceId: base.ServiceId,
|
||||
FeeUserType: base.FeeUserType,
|
||||
FeeTerminalId: base.FeeTerminalId,
|
||||
TpUdhi: base.TpUdhi,
|
||||
MsgFmt: base.MsgFmt,
|
||||
MsgSrc: base.MsgSrc,
|
||||
FeeType: base.FeeType,
|
||||
FeeCode: base.FeeCode,
|
||||
SrcId: base.SrcId,
|
||||
DestUsrTl: base.DestUsrTl,
|
||||
DestTerminalId: base.DestTerminalId,
|
||||
MsgLength: base.MsgLength,
|
||||
MsgContent: base.MsgContent,
|
||||
}
|
||||
}
|
||||
return &cmpp.Cmpp3SubmitReqPkt{
|
||||
PkTotal: base.PkTotal,
|
||||
PkNumber: base.PkNumber,
|
||||
RegisteredDelivery: base.RegisteredDelivery,
|
||||
MsgLevel: base.MsgLevel,
|
||||
ServiceId: base.ServiceId,
|
||||
FeeUserType: base.FeeUserType,
|
||||
FeeTerminalId: base.FeeTerminalId,
|
||||
TpUdhi: base.TpUdhi,
|
||||
MsgFmt: base.MsgFmt,
|
||||
MsgSrc: base.MsgSrc,
|
||||
FeeType: base.FeeType,
|
||||
FeeCode: base.FeeCode,
|
||||
SrcId: base.SrcId,
|
||||
DestUsrTl: base.DestUsrTl,
|
||||
DestTerminalId: base.DestTerminalId,
|
||||
MsgLength: base.MsgLength,
|
||||
MsgContent: base.MsgContent,
|
||||
}
|
||||
}
|
||||
|
||||
type submitRequestFields struct {
|
||||
PkTotal uint8
|
||||
PkNumber uint8
|
||||
RegisteredDelivery uint8
|
||||
MsgLevel uint8
|
||||
ServiceId string
|
||||
FeeUserType uint8
|
||||
FeeTerminalId string
|
||||
TpUdhi uint8
|
||||
MsgFmt uint8
|
||||
MsgSrc string
|
||||
FeeType string
|
||||
FeeCode string
|
||||
SrcId string
|
||||
DestUsrTl uint8
|
||||
DestTerminalId []string
|
||||
MsgLength uint8
|
||||
MsgContent string
|
||||
}
|
||||
|
||||
func (c *connection) tryAcquireWindow() bool {
|
||||
if c.window == nil {
|
||||
c.window = make(chan struct{}, defaultWindowSize)
|
||||
@@ -530,12 +591,19 @@ func (c *connection) readLoop() {
|
||||
continue
|
||||
}
|
||||
switch p := pkt.(type) {
|
||||
case *cmpp.Cmpp2SubmitRspPkt:
|
||||
c.mu.Lock()
|
||||
ch := c.pending[p.SeqId]
|
||||
c.mu.Unlock()
|
||||
if ch != nil {
|
||||
ch <- submitPartResponse{seqID: p.SeqId, msgID: p.MsgId, result: uint32(p.Result)}
|
||||
}
|
||||
case *cmpp.Cmpp3SubmitRspPkt:
|
||||
c.mu.Lock()
|
||||
ch := c.pending[p.SeqId]
|
||||
c.mu.Unlock()
|
||||
if ch != nil {
|
||||
ch <- submitPartResponse{rsp: p}
|
||||
ch <- submitPartResponse{seqID: p.SeqId, msgID: p.MsgId, result: p.Result}
|
||||
}
|
||||
case *cmpp.Cmpp3DeliverReqPkt:
|
||||
c.handleDeliver(p)
|
||||
|
||||
Reference in New Issue
Block a user