Blob Blame Raw
#ifndef TUNNEL_H
#define TUNNEL_H


#include "crypt.h"
#include "socket.h"
#include "connection.h"

#include <map>
#include <set>



class Tunnel {
public:
	typedef std::map<ConnId, Connection> ConnMap;
	typedef std::map<ConnId, Time> ClosedConnMap;
	typedef std::set<ConnId> ConnSet;
	
public:
	Time time;
	Time udpSendDuration;
	Time udpPartialSendDuration;
	Time udpResendDuration;
	Time udpConfirmDuration;
	Time udpSilenceDuration;
	Time udpKeepAliveDuration;
	Time timeQwant;
	Time pollDuration;
	
	ConnMap connections;
	ClosedConnMap closedConnections;
	ConnSet termQueue;
	
private:
	Crypt crypt;
	Poll poll;
	int udpSockId;
	int tcpSockId;
	Address remoteUdpAddress;
	Address remoteTcpAddress;
	Time nextTermSendTime;
	
public:
	Tunnel();
	~Tunnel();
	
	void initSpeed(unsigned long long bytesPerSecond);
	
	bool initUdpServer(const Address &address, const Address &remoteTcpAddress, const char *key);
	bool initTcpServer(const Address &address, const Address &remoteUdpAddress);
	
	void closeTcpServer();
	void closeUdpServer();
	void close();
	
	bool recvUdpPacket();
	void sendUdpPacket(const Address &address, const Packet &packet);
	
	void initTime();
	bool iteration();
	
	void run();
};


#endif