return sock;
}
-void GREProtocol::read_packet(Protocol *sender)
+void GREProtocol::read_packet(Sender *sender)
{
struct sockaddr_storage addr;
socklen_t addrlen = sizeof(addr);
#include "protocol.h"
-class Reorderer;
-
-class GREProtocol : public Protocol {
+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 int fd() const;
- void read_packet(Protocol* sender);
+ virtual void read_packet(Sender* sender);
private:
int seq;
#include <stdint.h>
#include <string>
-class Protocol {
+class Sender {
public:
virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq) = 0;
+};
+
+class Reader {
+public:
virtual int fd() const = 0;
+ virtual void read_packet(Sender* sender) = 0;
};
#endif // !defined(_PROTOCOL_H)
using namespace std;
-Reorderer::Reorderer(Protocol* sender)
+Reorderer::Reorderer(Sender* sender)
: sender(sender), last_seq(-1)
{
}
}
};
-class Reorderer : public Protocol {
+class Reorderer : public Sender {
public:
- Reorderer(Protocol* sender);
+ Reorderer(Sender* sender);
void send_packet(uint16_t proto, const std::string& data, int seq);
- virtual int fd() const { assert(false); }
private:
void check_ts_discontinuity(uint16_t proto, const std::string &data, bool silence);
- Protocol* sender;
+ Sender* sender;
int last_seq;
std::priority_queue<GREPacket, std::vector<GREPacket>, std::greater<GREPacket>> packet_buffer;
return tunfd;
}
-void TUNProtocol::read_packet(Protocol *sender)
+void TUNProtocol::read_packet(Sender *sender)
{
char buf[4096];
int ret = read(tunfd, buf, sizeof(buf));
#include <stdint.h>
#include <string>
-class TUNProtocol : public Protocol {
+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 int fd() const;
- void read_packet(Protocol* sender);
+ virtual void read_packet(Sender* sender);
private:
int tunfd;