]> git.sesse.net Git - greproxy/commitdiff
Make Reorderer into a Protocol.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 7 Feb 2015 00:28:57 +0000 (01:28 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 7 Feb 2015 00:28:57 +0000 (01:28 +0100)
greprotocol.cpp
greprotocol.h
protocol.h
reorderer.cpp
reorderer.h
tunprotocol.cpp
tunprotocol.h

index b826a521d7828c4e18421250f07c8a3ee8d09d9d..4a634156789f0aa3848d8ac1aaf5172a65d0bd4d 100644 (file)
@@ -44,7 +44,7 @@ GREProtocol::GREProtocol(const in6_addr &src, const in6_addr &dst)
        }
 }
 
-void GREProtocol::send_packet(uint16_t proto, const string &data)
+void GREProtocol::send_packet(uint16_t proto, const string &data, int incoming_seq)
 {
        char buf[4096];
        gre_header *gre = (gre_header *)buf;
@@ -55,7 +55,7 @@ void GREProtocol::send_packet(uint16_t proto, const string &data)
        gre->protocol_type = htons(proto);
 
        char *ptr = buf + sizeof(*gre);
-       int seq_be = htonl(seq++);
+       int seq_be = htonl(seq++);  // Ignore incoming_seq.
        memcpy(ptr, &seq_be, sizeof(seq_be));
        ptr += sizeof(seq_be);
 
@@ -72,7 +72,7 @@ int GREProtocol::fd() const
        return sock;
 }
 
-void GREProtocol::read_packet(Reorderer *sender)
+void GREProtocol::read_packet(Protocol *sender)
 {
        struct sockaddr_storage addr;
        socklen_t addrlen = sizeof(addr);
@@ -107,6 +107,6 @@ void GREProtocol::read_packet(Reorderer *sender)
 
        //printf("gre packet: proto=%x\n", ntohs(gre->protocol_type));
 
-       sender->handle_packet(ntohs(gre->protocol_type), string(ptr, buf + ret), seq);
+       sender->send_packet(ntohs(gre->protocol_type), string(ptr, buf + ret), seq);
 }
 
index 6930f20b601a9c932ea9d27384a970e4ecc2435d..621553400ca2365fc3636fe4cebd746a492da5e3 100644 (file)
@@ -12,9 +12,9 @@ class Reorderer;
 class GREProtocol : public Protocol {
 public:
        GREProtocol(const in6_addr &myaddr, const in6_addr &dst);
-       virtual void send_packet(uint16_t proto, const std::string &data);
+       virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq);
        virtual int fd() const;
-       void read_packet(Reorderer* sender);
+       void read_packet(Protocol* sender);
 
 private:
        int seq;
index a6d33094af8c40f05222cf17325bbe459d961a1d..8b06f0a34be907fcd5cc1ef51d06ab43458a32f5 100644 (file)
@@ -6,7 +6,7 @@
 
 class Protocol {
 public:
-       virtual void send_packet(uint16_t proto, const std::string &data) = 0;
+       virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq) = 0;
        virtual int fd() const = 0;
 };
 
index fe3b7b64cd98027b4be2b49eab8399ec8618d89c..b6ac6a9079906b8aaac5944ef8398f88fdc341e9 100644 (file)
@@ -12,7 +12,7 @@ Reorderer::Reorderer(Protocol* sender)
 {
 }
 
-void Reorderer::handle_packet(uint16_t proto, const string& data, int seq)
+void Reorderer::send_packet(uint16_t proto, const string& data, int seq)
 {
        bool silence = false;
        if (packet_buffer.size() >= PACKET_BUFFER_SIZE) {
@@ -43,7 +43,8 @@ void Reorderer::handle_packet(uint16_t proto, const string& data, int seq)
                //      printf("seq=%d\n", front_seq);
                //}
                const string &data = packet_buffer.top().data;
-               send_packet(packet_buffer.top().proto, data, silence);
+               check_ts_discontinuity(packet_buffer.top().proto, data, silence);
+               sender->send_packet(proto, data, seq);
                packet_buffer.pop();
                last_seq = front_seq;
                if (!silence && !packet_buffer.empty()) {
@@ -53,7 +54,7 @@ void Reorderer::handle_packet(uint16_t proto, const string& data, int seq)
        }
 }
 
-void Reorderer::send_packet(uint16_t proto, const string &data, bool silence)
+void Reorderer::check_ts_discontinuity(uint16_t proto, const string &data, bool silence)
 {
        if (data.size() == 1344) {
                for (int i = 0; i < 7; ++i) {
@@ -74,6 +75,5 @@ void Reorderer::send_packet(uint16_t proto, const string &data, bool silence)
                        }
                }
        }
-       sender->send_packet(proto, data);
 }
 
index 476093fc5e8e136d9fc4d3008d5f6eb81e82e489..393e327f7dbe86053fb374fd9601720c3a9e8195 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _REORDERER_H
 #define _REORDERER_H 1
 
+#include <assert.h>
 #include <stdint.h>
 
 #include <algorithm>
@@ -9,7 +10,7 @@
 #include <string>
 #include <vector>
 
-class Protocol;
+#include "protocol.h"
 
 struct GREPacket {
        int seq;
@@ -21,13 +22,14 @@ struct GREPacket {
        }
 };
 
-class Reorderer {
+class Reorderer : public Protocol {
 public:
        Reorderer(Protocol* sender);
-       void handle_packet(uint16_t proto, const std::string& data, int seq);
+       void send_packet(uint16_t proto, const std::string& data, int seq);
+       virtual int fd() const { assert(false); }
 
 private:
-       void send_packet(uint16_t proto, const std::string &data, bool silence);
+       void check_ts_discontinuity(uint16_t proto, const std::string &data, bool silence);
 
        Protocol* sender;
        int last_seq;
index b8b63a3736f02dfd1d5c84259a97050b59d1e70c..cc1065169b2235dff022abe2ba883829be0e0a25 100644 (file)
@@ -41,7 +41,7 @@ TUNProtocol::TUNProtocol(const char *devname)
        : tunfd(tun_open(devname)) {
 }
 
-void TUNProtocol::send_packet(uint16_t proto, const string &data)
+void TUNProtocol::send_packet(uint16_t proto, const string &data, int incoming_seq)
 {
        char buf[4096];
 
@@ -88,6 +88,6 @@ void TUNProtocol::read_packet(Protocol *sender)
        ptr += 2;
        //fprintf(stderr, "tun packet: flags=%x proto=%x len=%d\n",
        //      flags, proto, ret - 4);
-       sender->send_packet(proto, string(ptr, buf + ret));
+       sender->send_packet(proto, string(ptr, buf + ret), -1);
 }
 
index cfe3b46ef47bfcd1333cd2ec4eddec905314d318..9af2e78149787815e9d1994757b2f0c1c9639a3c 100644 (file)
@@ -9,7 +9,7 @@
 class TUNProtocol : public Protocol {
 public:
        TUNProtocol(const char *devname);
-       virtual void send_packet(uint16_t proto, const std::string &data);
+       virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq);
        virtual int fd() const;
        void read_packet(Protocol* sender);