This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Base64Encode mem leak fix Switched DNS to TADNS
- Loading branch information
Showing
43 changed files
with
2,650 additions
and
823 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,72 @@ | ||
cmake_minimum_required (VERSION 2.6) | ||
project (LIVEPROXIES) | ||
project (LiveProxies) | ||
set(CMAKE_BUILD_TYPE Debug) | ||
|
||
set (CMAKE_C_FLAGS "--std=gnu99 -pthread ${CMAKE_C_FLAGS}") | ||
if (WIN32) | ||
set (CMAKE_C_FLAGS "--std=gnu99 -Wall ${CMAKE_C_FLAGS}") | ||
ELSE() | ||
set (CMAKE_C_FLAGS "--std=gnu99 -Wall -pthread ${CMAKE_C_FLAGS}") | ||
ENDIF() | ||
|
||
add_executable(LiveProxies Base64.c Global.c Harvester.c Interface.c IPv6Map.c LiveProxies.c Logger.c ProxyLists.c ProxyRemove.c ProxyRequest.c Server.c PBKDF2.c SingleCheck.c HtmlTemplate.c Websocket.c Stats.c) | ||
target_link_libraries(LiveProxies event GeoIP crypto ssl python2.7 pcre config m util anl curl) | ||
add_executable(LiveProxies Base64.c Global.c Harvester.c Interface.c IPv6Map.c LiveProxies.c Logger.c ProxyLists.c ProxyRemove.c ProxyRequest.c Server.c PBKDF2.c SingleCheck.c HtmlTemplate.c Websocket.c Stats.c DNS.c CPH_Threads.c | ||
Base64.h Global.h Harvester.h Interface.h IPv6Map.h LiveProxies.h Logger.h ProxyLists.h ProxyRemove.h ProxyRequest.h Server.h PBKDF2.h SingleCheck.h HtmlTemplate.h Websocket.h Stats.h DNS.h CPH_Threads.h | ||
PortableEndian.h | ||
tadns.c tadns.h llist.h | ||
) | ||
|
||
if (WIN32) | ||
include_directories( | ||
C:/LIB/openssl/include | ||
C:/LIB/libevent/cmake__/include | ||
C:/LIB/libconfig/libconfig-1.5/lib | ||
C:/Python27/include | ||
C:/LIB/libmaxminddb/include | ||
"C:/Program Files (x86)/GnuWin32/include" | ||
C:/LIB/curl-7.45.0/builds/libcurl-vc-x86-release-dll-ssl-dll-zlib-dll-ipv6-sspi/include | ||
) | ||
#link_directories( | ||
# C:/LIB/openssl/lib | ||
# C:/LIB/openssl/lib | ||
# C:/LIB/libevent/bin/lib/Release | ||
# C:/LIB/libconfig/libconfig-1.5/Release | ||
# C:/LIB/libmaxminddb/projects/VS12/Release | ||
# C:/LIB/unbound-1.5.5/.libs/libunbound.a | ||
# C:/Python27/libs | ||
# "C:/Program Files (x86)/GnuWin32/lib" | ||
# C:/LIB/curl-7.45.0/builds/libcurl-vc-x86-release-dll-ssl-dll-zlib-dll-ipv6-sspi/lib | ||
#) | ||
IF (MINGW) | ||
# MINGW | ||
target_link_libraries( | ||
LiveProxies | ||
C:/LIB/libevent/cmake__/lib/libevent.a | ||
C:/LIB/libmaxminddb/projects/VS12/Release/libmaxminddb.a | ||
C:/LIB/openssl-1.0.2d/libssl.a | ||
C:/LIB/openssl-1.0.2d/libcrypto.a | ||
C:/Python27/libs/libpython27.a | ||
"C:/Program Files (x86)/GnuWin32/lib/libpcre.dll.a" | ||
C:/LIB/libconfig/libconfig-1.5/lib/.libs/libconfig.dll.a | ||
C:/LIB/curl-7.45.0/lib/.libs/libcurl.dll.a | ||
Ws2_32 | ||
Shlwapi | ||
) | ||
ELSE() | ||
# MSVC | ||
target_link_libraries( | ||
LiveProxies | ||
C:/LIB/libevent/bin/lib/Release/event.lib | ||
C:/LIB/libmaxminddb/projects/VS12/Release/libmaxminddb.lib | ||
C:/OpenSSL-Win32/lib/libeay32.lib | ||
C:/Python27/libs/python27.lib | ||
"C:/Program Files (x86)/GnuWin32/lib/pcre.lib" | ||
C:/LIB/libconfig/libconfig-1.5/Release/libconfig.lib | ||
C:/LIB/curl-7.45.0/builds/libcurl-vc-x86-release-dll-ssl-dll-zlib-dll-ipv6-sspi/lib/libcurl.lib | ||
Ws2_32 | ||
Shlwapi | ||
) | ||
ENDIF() | ||
|
||
add_definitions(-DWIN32_LEAN_AND_MEAN) | ||
ELSE() | ||
target_link_libraries(LiveProxies event maxminddb crypto ssl python2.7 pcre config m util anl curl) | ||
ENDIF() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "CPH_Threads.h" | ||
#if defined _WIN32 || defined _WIN64 | ||
#include <windows.h> | ||
const DWORD MS_VC_EXCEPTION = 0x406D1388; | ||
|
||
#pragma pack(push,8) | ||
typedef struct tagTHREADNAME_INFO { | ||
DWORD dwType; // Must be 0x1000. | ||
LPCSTR szName; // Pointer to name (in user addr space). | ||
DWORD dwThreadID; // Thread ID (-1=caller thread). | ||
DWORD dwFlags; // Reserved for future use, must be zero. | ||
} THREADNAME_INFO; | ||
#pragma pack(pop) | ||
|
||
int pthread_create(pthread_t *thread, void *attr, void *(*start_routine) (void *), void *arg) | ||
{ | ||
*thread = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)start_routine, arg, NULL, NULL); | ||
return thread == NULL ? GetLastError() : ERROR_SUCCESS; | ||
} | ||
|
||
void pthread_setname_np(pthread_t thread, char* threadName) | ||
{ | ||
THREADNAME_INFO info; | ||
info.dwType = 0x1000; | ||
info.szName = threadName; | ||
info.dwThreadID = thread; | ||
info.dwFlags = 0; | ||
|
||
/*__try { | ||
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info); | ||
} __except (EXCEPTION_EXECUTE_HANDLER) { }*/ | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#ifdef __linux__ | ||
#include <pthread.h> | ||
#elif defined _WIN32 || defined _WIN64 | ||
#include <windows.h> | ||
typedef HANDLE pthread_mutex_t; | ||
typedef HANDLE pthread_t; | ||
|
||
#define pthread_mutex_init(x, a) *x = CreateMutex(NULL, FALSE, NULL) | ||
#define pthread_mutex_lock(x) WaitForSingleObject(*x, INFINITE); | ||
#define pthread_mutex_unlock(x) ReleaseMutex(*x); | ||
#define pthread_mutex_destroy(x) CloseHandle(*x); | ||
|
||
#define pthread_detach(x) CloseHandle(x); | ||
int pthread_create(pthread_t *thread, void *attr, void *(*start_routine) (void *), void *arg); | ||
void pthread_setname_np(pthread_t thread, char* threadName); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "DNS.h" | ||
#include "Logger.h" | ||
#include <stdlib.h> | ||
#include <event2/event.h> | ||
#ifdef __linux__ | ||
#include <unistd.h> | ||
#endif | ||
#include <stdbool.h> | ||
#include <assert.h> | ||
#include "ProxyRequest.h" | ||
#include "Config.h" | ||
|
||
static void DNSResolveCallError(DNS_LOOKUP_ASYNC_EX *Ex) | ||
{ | ||
// void *context, DNS_RR_TYPE qtype, const char *name, const unsigned char *addr, size_t addrlen | ||
struct dns_cb_data data; | ||
data.name = NULL; | ||
data.addr = NULL; | ||
data.addr_len = 0; | ||
data.context = Ex; | ||
data.error = DNS_ERROR; | ||
data.query_type = 0; | ||
Ex->fxDone(&data); | ||
} | ||
|
||
static void DNSResolveLevEventToDNSProcess(evutil_socket_t fd, short what, void *arg) | ||
{ | ||
DNS_LOOKUP_ASYNC_EX *ex = (DNS_LOOKUP_ASYNC_EX*)arg; | ||
Log(LOG_LEVEL_DEBUG, "DNS process WHAT %d", what); | ||
if (what == EV_TIMEOUT) { | ||
DNSResolveCallError(ex); | ||
goto free; | ||
} | ||
|
||
dns_poll(ex->dnsCtx); | ||
|
||
if (ex->resolveDone) | ||
goto free; | ||
|
||
Log(LOG_LEVEL_DEBUG, "DNS process WHAT %d END", what); | ||
|
||
return; | ||
free: | ||
dns_fini(ex->dnsCtx); | ||
if (ex->evDNS != NULL) | ||
event_del(ex->evDNS); | ||
free(ex); | ||
} | ||
|
||
void DNSResolveAsync(void *Ex, char *Domain, bool IPv6, dns_callback_t fxDone) | ||
{ | ||
DNS_LOOKUP_ASYNC_EX *ex = malloc(sizeof(DNS_LOOKUP_ASYNC_EX)); | ||
ex->object = Ex; | ||
ex->dnsCtx = NULL; | ||
ex->evDNS = NULL; | ||
ex->resolveDone = false; | ||
ex->fxDone = fxDone; | ||
|
||
struct dns *dnsCtx = dns_init(); | ||
if (!dnsCtx) { | ||
Log(LOG_LEVEL_ERROR, "Failed to initialize tadns context"); | ||
DNSResolveCallError(ex); | ||
free(ex); | ||
return; | ||
} | ||
ex->dnsCtx = dnsCtx; | ||
|
||
dns_queue(dnsCtx, ex, Domain, IPv6 ? DNS_RR_TYPE_AAAA : DNS_RR_TYPE_A, fxDone); | ||
|
||
Log(LOG_LEVEL_DEBUG, "DNS FD %d", dns_get_fd(dnsCtx)); | ||
|
||
struct event *fdEvent = event_new(levRequestBase, dns_get_fd(dnsCtx), EV_READ | EV_PERSIST, DNSResolveLevEventToDNSProcess, ex); | ||
ex->evDNS = fdEvent; | ||
event_add(fdEvent, &GlobalTimeoutTV); | ||
} |
Oops, something went wrong.