(dwrMsg *common.DWRMsg, conn *DBConn)
| 1170 | } |
| 1171 | |
| 1172 | func (s *UdpServer) ProcessDataPrivateKeyWrapping(dwrMsg *common.DWRMsg, conn *DBConn) (dwaMsg *common.DWAMsg, err error) { |
| 1173 | if dwrMsg == nil || conn == nil { |
| 1174 | log.Critical("processACOperation with nil input argument") |
| 1175 | err = common.ErrInvalidInput |
| 1176 | return |
| 1177 | } |
| 1178 | |
| 1179 | dbAddrStr := conn.DBPeer.RecvAddr().String() |
| 1180 | |
| 1181 | dwrBytes, _ := json.Marshal(dwrMsg) |
| 1182 | |
| 1183 | dwrMd := &core.MsgData{ |
| 1184 | ConnData: conn.ConnData, |
| 1185 | HeaderType: core.NHP_DWR, |
| 1186 | CipherScheme: conn.DBCipherScheme, |
| 1187 | TransactionId: s.device.NextCounterIndex(), |
| 1188 | Compress: true, |
| 1189 | PeerPk: conn.DBPeer.PublicKey(), |
| 1190 | Message: dwrBytes, |
| 1191 | ResponseMsgCh: make(chan *core.PacketParserData), |
| 1192 | } |
| 1193 | |
| 1194 | dwaMsg = &common.DWAMsg{} |
| 1195 | |
| 1196 | if !s.IsRunning() { |
| 1197 | log.Error("server-agent-db(%s#%d@%s)[ProcessDataPrivateKeyWrapping] MsgData channel closed or being closed, skip sending", conn.DBId, dwrMd.TransactionId, dbAddrStr) |
| 1198 | err = common.ErrPacketToMessageRoutineStopped |
| 1199 | errCode, _ := strconv.Atoi(common.ErrPacketToMessageRoutineStopped.ErrorCode()) |
| 1200 | dwaMsg.ErrCode = errCode |
| 1201 | dwaMsg.ErrMsg = err.Error() |
| 1202 | return |
| 1203 | } |
| 1204 | |
| 1205 | s.sendMsgCh <- dwrMd |
| 1206 | |
| 1207 | // wait for ac sending back operation result |
| 1208 | // block until transaction completes |
| 1209 | dbPpd := <-dwrMd.ResponseMsgCh |
| 1210 | close(dwrMd.ResponseMsgCh) |
| 1211 | |
| 1212 | err = json.Unmarshal(dbPpd.BodyMessage, dwaMsg) |
| 1213 | if err != nil { |
| 1214 | log.Error("server-agent-db(%s#%d@%s)[ProcessDataPrivateKeyWrapping] failed to parse %s message: %v", conn.DBId, dwrMd.TransactionId, dbAddrStr, core.HeaderTypeToString(dbPpd.HeaderType), err) |
| 1215 | errCode, _ := strconv.Atoi(common.ErrJsonParseFailed.ErrorCode()) |
| 1216 | dwaMsg.ErrCode = errCode |
| 1217 | dwaMsg.ErrMsg = err.Error() |
| 1218 | return |
| 1219 | } |
| 1220 | |
| 1221 | return dwaMsg, nil |
| 1222 | } |
no test coverage detected