]> git.sesse.net Git - greproxy/blobdiff - rsdecoder.cpp
Fix another crippling RS decoding bug.
[greproxy] / rsdecoder.cpp
index 20297bf53230e77e84bfd9bd2f8aab98c114b9b6..9ba69a504ef98cf9bcd971e06b93f59e4e60103a 100644 (file)
@@ -15,7 +15,10 @@ extern "C" {
 using namespace std;
 
 RSDecoder::RSDecoder(Sender *sender)
-       : sender(sender) {}
+       : sender(sender)
+{
+       rs = init_rs_char(RS_SYM_SIZE, RS_GF_POLY, 1, 1, RS_PARITY_SIZE, RS_PAD);
+}
 
 void RSDecoder::send_packet(uint16_t proto, const std::string &data, int incoming_seq)
 {
@@ -92,13 +95,18 @@ void RSDecoder::send_packet(uint16_t proto, const std::string &data, int incomin
                                const auto it = group.packets.find(packet_num);
                                if (it == group.packets.end()) {
                                        missing_packets.push_back(i);
-                               } else {
+                               } else if (i < RS_PAYLOAD_SIZE) {
+                                       // Regular packet.
                                        const GREPacket &packet = it->second;
                                        uint16_t proto_be = htons(packet.proto);
                                        memcpy(&p[0], &proto_be, sizeof(uint16_t));
                                        uint16_t len_be = htons(packet.data.size());
                                        memcpy(&p[2], &len_be, sizeof(uint16_t));
                                        memcpy(&p[4], packet.data.data(), packet.data.size());
+                               } else {
+                                       // RS packet.
+                                       const GREPacket &packet = it->second;
+                                       memcpy(&p[0], packet.data.data(), packet.data.size());
                                }
                                padded_packets.push_back(p);
                        }
@@ -109,8 +117,7 @@ void RSDecoder::send_packet(uint16_t proto, const std::string &data, int incomin
                                for (int j = 0; j < RS_GROUP_SIZE; ++j) {
                                        ch[j] = padded_packets[j][i];
                                }
-                               int ret = decode_rs_8(ch, &missing_packets[0], missing_packets.size(),
-                                       RS_PAD);
+                               int ret = decode_rs_char(rs, ch, &missing_packets[0], missing_packets.size());
                                if (ret == -1) {
                                        printf("Failed reconstruction!\n");
                                        // We might get more data later, so don't remove it.