<commit_before>//
// libtgvoip is free and unencumbered public domain software.
// For more information, see http://unlicense.org or the UNLICENSE file
// you should have received with this source code distribution.
//

#ifndef __VOIPCONTROLLER_H
#define __VOIPCONTROLLER_H

#ifndef _WIN32
#include <arpa/inet.h>
#include <netinet/in.h>
#endif
#ifdef __APPLE__
#include <TargetConditionals.h>
#include "os/darwin/AudioUnitIO.h"
#endif
#include <stdint.h>
#include <vector>
#include <string>
#include <unordered_map>
#include <memory>
#include "audio/AudioInput.h"
#include "BlockingQueue.h"
#include "audio/AudioOutput.h"
#include "JitterBuffer.h"
#include "OpusDecoder.h"
#include "OpusEncoder.h"
#include "EchoCanceller.h"
#include "CongestionControl.h"
#include "NetworkSocket.h"
#include "Buffers.h"
#include "PacketReassembler.h"

#define LIBTGVOIP_VERSION "2.1"

#ifdef _WIN32
#undef GetCurrentTime
#undef ERROR_TIMEOUT
#endif

#define TGVOIP_PEER_CAP_GROUP_CALLS 1

namespace tgvoip{

	enum{
		PROXY_NONE=0,
		PROXY_SOCKS5,
		//PROXY_HTTP
	};

	enum{
		STATE_WAIT_INIT=1,
		STATE_WAIT_INIT_ACK,
		STATE_ESTABLISHED,
		STATE_FAILED,
		STATE_RECONNECTING
	};

	enum{
		ERROR_UNKNOWN=0,
		ERROR_INCOMPATIBLE,
		ERROR_TIMEOUT,
		ERROR_AUDIO_IO,
		ERROR_PROXY
	};

	enum{
		NET_TYPE_UNKNOWN=0,
		NET_TYPE_GPRS,
		NET_TYPE_EDGE,
		NET_TYPE_3G,
		NET_TYPE_HSPA,
		NET_TYPE_LTE,
		NET_TYPE_WIFI,
		NET_TYPE_ETHERNET,
		NET_TYPE_OTHER_HIGH_SPEED,
		NET_TYPE_OTHER_LOW_SPEED,
		NET_TYPE_DIALUP,
		NET_TYPE_OTHER_MOBILE
	};

	enum{
		DATA_SAVING_NEVER=0,
		DATA_SAVING_MOBILE,
		DATA_SAVING_ALWAYS
	};

	struct CryptoFunctions{
		void (*rand_bytes)(uint8_t* buffer, size_t length);
		void (*sha1)(uint8_t* msg, size_t length, uint8_t* output);
		void (*sha256)(uint8_t* msg, size_t length, uint8_t* output);
		void (*aes_ige_encrypt)(uint8_t* in, uint8_t* out, size_t length, uint8_t* key, uint8_t* iv);
		void (*aes_ige_decrypt)(uint8_t* in, uint8_t* out, size_t length, uint8_t* key, uint8_t* iv);
		void (*aes_ctr_encrypt)(uint8_t* inout, size_t length, uint8_t* key, uint8_t* iv, uint8_t* ecount, uint32_t* num);
		void (*aes_cbc_encrypt)(uint8_t* in, uint8_t* out, size_t length, uint8_t* key, uint8_t* iv);
		void (*aes_cbc_decrypt)(uint8_t* in, uint8_t* out, size_t length, uint8_t* key, uint8_t* iv);
	};

	class Endpoint{
		friend class VoIPController;
		friend class VoIPGroupController;
	public:

		enum{
			TYPE_UDP_P2P_INET=1,
			TYPE_UDP_P2P_LAN,
			TYPE_UDP_RELAY,
			TYPE_TCP_RELAY
		};

		Endpoint(int64_t id, uint16_t port, IPv4Address& address, IPv6Address& v6address, char type, unsigned char* peerTag);
		Endpoint();
		~Endpoint();
		NetworkAddress& GetAddress();
		bool IsIPv6Only();
		int64_t id;
		uint16_t port;
		IPv4Address address;
		IPv6Address v6address;
		char type;
		unsigned char peerTag[16];

	private:
		double lastPingTime;
		uint32_t lastPingSeq;
		double rtts[6];
		double averageRTT;
		NetworkSocket* socket;
		int udpPongCount;
	};

	class AudioDevice{
	public:
		std::string id;
		std::string displayName;
	};

	class AudioOutputDevice : public AudioDevice{

	};

	class AudioInputDevice : public AudioDevice{

	};

	struct EncodedVideoFrame{
		unsigned char* data;
		size_t size;
		uint32_t flags;

		EncodedVideoFrame(size_t size){
			this->size=size;
			data=(unsigned char*)malloc(size);
		}

		~EncodedVideoFrame(){
			free(data);
		}
	};

	class VoIPController{
		friend class VoIPGroupController;
	public:
		struct Config{
			Config(double initTimeout, double recvTimeout, int dataSaving=DATA_SAVING_NEVER, bool enableAEC=false, bool enableNS=false, bool enableAGC=false, bool enableCallUpgrade=false){
				this->initTimeout=initTimeout;
				this->recvTimeout=recvTimeout;
				this->dataSaving=dataSaving;
				this->enableAEC=enableAEC;
				this->enableNS=enableNS;
				this->enableAGC=enableAGC;
				this->enableCallUpgrade=enableCallUpgrade;<commit_msg>Fix of a fix<commit_after>//
// libtgvoip is free and unencumbered public domain software.
// For more information, see http://unlicense.org or the UNLICENSE file
// you should have received with this source code distribution.
//

#ifndef __VOIPCONTROLLER_H
#define __VOIPCONTROLLER_H

#ifndef _WIN32
#include <arpa/inet.h>
#include <netinet/in.h>
#endif
#ifdef __APPLE__
#include <TargetConditionals.h>
#include "os/darwin/AudioUnitIO.h"
#endif
#include <stdint.h>
#include <vector>
#include <string>
#include <unordered_map>
#include <memory>
#include "audio/AudioInput.h"
#include "BlockingQueue.h"
#include "audio/AudioOutput.h"
#include "JitterBuffer.h"
#include "OpusDecoder.h"
#include "OpusEncoder.h"
#include "EchoCanceller.h"
#include "CongestionControl.h"
#include "NetworkSocket.h"
#include "Buffers.h"
#include "PacketReassembler.h"

#define LIBTGVOIP_VERSION "2.1"

#ifdef _WIN32
#undef GetCurrentTime
#undef ERROR_TIMEOUT
#endif

#define TGVOIP_PEER_CAP_GROUP_CALLS 1

namespace tgvoip{

	enum{
		PROXY_NONE=0,
		PROXY_SOCKS5,
		//PROXY_HTTP
	};

	enum{
		STATE_WAIT_INIT=1,
		STATE_WAIT_INIT_ACK,
		STATE_ESTABLISHED,
		STATE_FAILED,
		STATE_RECONNECTING
	};

	enum{
		ERROR_UNKNOWN=0,
		ERROR_INCOMPATIBLE,
		ERROR_TIMEOUT,
		ERROR_AUDIO_IO,
		ERROR_PROXY
	};

	enum{
		NET_TYPE_UNKNOWN=0,
		NET_TYPE_GPRS,
		NET_TYPE_EDGE,
		NET_TYPE_3G,
		NET_TYPE_HSPA,
		NET_TYPE_LTE,
		NET_TYPE_WIFI,
		NET_TYPE_ETHERNET,
		NET_TYPE_OTHER_HIGH_SPEED,
		NET_TYPE_OTHER_LOW_SPEED,
		NET_TYPE_DIALUP,
		NET_TYPE_OTHER_MOBILE
	};

	enum{
		DATA_SAVING_NEVER=0,
		DATA_SAVING_MOBILE,
		DATA_SAVING_ALWAYS
	};

	struct CryptoFunctions{
		void (*rand_bytes)(uint8_t* buffer, size_t length);
		void (*sha1)(uint8_t* msg, size_t length, uint8_t* output);
		void (*sha256)(uint8_t* msg, size_t length, uint8_t* output);
		void (*aes_ige_encrypt)(uint8_t* in, uint8_t* out, size_t length, uint8_t* key, uint8_t* iv);
		void (*aes_ige_decrypt)(uint8_t* in, uint8_t* out, size_t length, uint8_t* key, uint8_t* iv);
		void (*aes_ctr_encrypt)(uint8_t* inout, size_t length, uint8_t* key, uint8_t* iv, uint8_t* ecount, uint32_t* num);
		void (*aes_cbc_encrypt)(uint8_t* in, uint8_t* out, size_t length, uint8_t* key, uint8_t* iv);
		void (*aes_cbc_decrypt)(uint8_t* in, uint8_t* out, size_t length, uint8_t* key, uint8_t* iv);
	};

	class Endpoint{
		friend class VoIPController;
		friend class VoIPGroupController;
	public:

		enum{
			TYPE_UDP_P2P_INET=1,
			TYPE_UDP_P2P_LAN,
			TYPE_UDP_RELAY,
			TYPE_TCP_RELAY
		};

		Endpoint(int64_t id, uint16_t port, IPv4Address& address, IPv6Address& v6address, char type, unsigned char* peerTag);
		Endpoint();
		~Endpoint();
		NetworkAddress& GetAddress();
		bool IsIPv6Only();
		int64_t id;
		uint16_t port;
		IPv4Address address;
		IPv6Address v6address;
		char type;
		unsigned char peerTag[16];

	private:
		double lastPingTime;
		uint32_t lastPingSeq;
		double rtts[6];
		double averageRTT;
		NetworkSocket* socket;
		int udpPongCount;
	};

	class AudioDevice{
	public:
		std::string id;
		std::string displayName;
	};

	class AudioOutputDevice : public AudioDevice{

	};

	class AudioInputDevice : public AudioDevice{

	};

	struct EncodedVideoFrame{
		unsigned char* data;
		size_t size;
		uint32_t flags;

		EncodedVideoFrame(size_t size){
			this->size=size;
			data=(unsigned char*)malloc(size);
		}

		~EncodedVideoFrame(){
			free(data);
		}
	};

	class VoIPController{
		friend class VoIPGroupController;
	public:
		struct Config{
			Config(double initTimeout=30.0, double recvTimeout=20.0, int dataSaving=DATA_SAVING_NEVER, bool enableAEC=false, bool enableNS=false, bool enableAGC=false, bool enableCallUpgrade=false){
				this->initTimeout=initTimeout;
				this->recvTimeout=recvTimeout;
				this->dataSaving=dataSaving;
				this->enableAEC=enableAEC;
				this->enableNS=enableNS;
				this->enableAGC=enableAGC;
				this->enableCallUpgrade=enableCallUpgrade;
{'fraction_non_alphanumeric': 0.1070559610705596, 'fraction_numerical': 0.018696375976437443, 'mean_word_length': 5.17879746835443, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6225531', 'n_tokens_mistral': 3376, 'n_tokens_neox': 3088, 'n_words': 646}