}
}
-void GREProtocol::send_packet(uint16_t proto, const string &data, int incoming_seq)
+void GREProtocol::send_packet(uint16_t proto, const string &data, uint32_t incoming_seq)
{
char buf[4096];
gre_header *gre = (gre_header *)buf;
gre->protocol_type = htons(proto);
char *ptr = buf + sizeof(*gre);
- int seq_be = htonl(incoming_seq);
+ uint32_t seq_be = htonl(incoming_seq);
memcpy(ptr, &seq_be, sizeof(seq_be));
ptr += sizeof(seq_be);
class GREProtocol : public Sender, public Reader {
public:
GREProtocol(const in6_addr &myaddr, const in6_addr &dst);
- virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq);
+ virtual void send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq);
virtual int fd() const;
virtual void read_packet(Sender* sender);
seconds_per_byte = 1.0 / max_rate_byte_per_sec;
}
-void Pacer::send_packet(uint16_t proto, const string &data, int incoming_seq)
+void Pacer::send_packet(uint16_t proto, const string &data, uint32_t incoming_seq)
{
waiting_packets.push_back(GREPacket{incoming_seq, proto, data, {0, 0}});
possibly_flush_packets();
struct Pacer : public Sender {
public:
Pacer(Sender *sender, int max_rate_kbit_per_sec, int burst_num_packets);
- virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq);
+ virtual void send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq);
void possibly_adjust_tv(timeval *tv);
void possibly_flush_packets();
class Sender {
public:
- virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq) = 0;
+ virtual void send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq) = 0;
};
class Reader {
}
}
-void Reorderer::send_packet(uint16_t proto, const string& data, int seq)
+void Reorderer::send_packet(uint16_t proto, const string& data, uint32_t seq)
{
timeval now;
gettimeofday(&now, NULL);
if (packet_buffer.empty() &&
seq < last_seq &&
tdiff(last_sent_packet, now) > 5.0) {
- printf("No good data for five seconds, resetting sequence to %d\n", seq);
+ printf("No good data for five seconds, resetting sequence to %u\n", seq);
last_seq = seq - 1;
}
while (!packet_buffer.empty() &&
(last_seq == -1 || packet_buffer.top().seq <= last_seq + 1)) {
- int front_seq = packet_buffer.top().seq;
+ uint32_t front_seq = packet_buffer.top().seq;
if (front_seq < last_seq + 1) {
- printf("Duplicate packet or way out-of-order: seq=%d front_seq=%d\n",
+ printf("Duplicate packet or way out-of-order: seq=%u front_seq=%u\n",
front_seq, last_seq + 1);
packet_buffer.pop();
continue;
#include "protocol.h"
struct GREPacket {
- int seq;
+ uint32_t seq;
uint16_t proto;
std::string data;
timeval ts;
class Reorderer : public Sender {
public:
Reorderer(Sender* sender);
- void send_packet(uint16_t proto, const std::string& data, int seq);
+ void send_packet(uint16_t proto, const std::string& data, uint32_t seq);
void possibly_adjust_tv(timeval *tv);
int get_reorders() const { return num_reorders; }
{
}
-void RSDecoder::send_packet(uint16_t proto, const std::string &data, int incoming_seq)
+void RSDecoder::send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq)
{
int rs_group;
if (proto == 0xffff) {
vector<string> padded_packets;
std::map<size_t, const fecpp::byte *> shares;
for (const auto &packet_pair : group.packets) {
- int packet_seq = packet_pair.first;
+ uint32_t packet_seq = packet_pair.first;
int share_num;
string p;
p.resize(max_length);
class RSDecoder : public Sender {
public:
RSDecoder(Sender *sender);
- virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq);
+ virtual void send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq);
int get_recovered_packets() const { return num_recovered_packets; }
{
}
-void RSEncoder::send_packet(uint16_t proto, const std::string &data, int incoming_seq)
+void RSEncoder::send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq)
{
if (!packet_history.empty() &&
incoming_seq <= packet_history.back().seq) {
}
if (debug_drop_packet) {
const unsigned char *ptr = reinterpret_cast<const unsigned char *>(data.data());
- printf("DEBUG: Dropping packet seq=%d proto=0x%04x len=%d data=%02x %02x %02x %02x %02x %02x %02x %02x ...\n",
+ printf("DEBUG: Dropping packet seq=%u proto=0x%04x len=%d data=%02x %02x %02x %02x %02x %02x %02x %02x ...\n",
incoming_seq, proto, data.size(), ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7]);
} else {
sender->send_packet(proto, data, incoming_seq);
}
const char *sdata = reinterpret_cast<const char *>(data);
- int start_seq = packet_history[0].seq - 1;
+ uint32_t start_seq = packet_history[0].seq - 1;
sender->send_packet(0xffff, string(sdata, size), start_seq - (packet_num - RS_PAYLOAD_SIZE));
});
class RSEncoder : public Sender {
public:
RSEncoder(Sender* sender);
- virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq);
+ virtual void send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq);
private:
void finish_group();
: tunfd(tun_open(devname)), seq(0) {
}
-void TUNProtocol::send_packet(uint16_t proto, const string &data, int incoming_seq)
+void TUNProtocol::send_packet(uint16_t proto, const string &data, uint32_t incoming_seq)
{
char buf[4096];
class TUNProtocol : public Sender, public Reader {
public:
TUNProtocol(const char *devname);
- virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq);
+ virtual void send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq);
virtual int fd() const;
virtual void read_packet(Sender* sender);
private:
int tunfd;
- int seq;
+ uint32_t seq;
int received_packets = 0, sent_packets = 0;
};