summaryrefslogtreecommitdiff
path: root/protocols/Tox/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Tox/src')
-rw-r--r--protocols/Tox/src/resource.hbin1460 -> 1644 bytes
-rw-r--r--protocols/Tox/src/tox/tox.h43
-rw-r--r--protocols/Tox/src/tox_account.cpp50
-rw-r--r--protocols/Tox/src/tox_bootstrap.h18
-rw-r--r--protocols/Tox/src/tox_events.cpp3
-rw-r--r--protocols/Tox/src/tox_instances.cpp14
-rw-r--r--protocols/Tox/src/tox_options.cpp34
-rw-r--r--protocols/Tox/src/tox_proto.cpp33
-rw-r--r--protocols/Tox/src/tox_proto.h4
9 files changed, 127 insertions, 72 deletions
diff --git a/protocols/Tox/src/resource.h b/protocols/Tox/src/resource.h
index dbd8559738..2c58072de5 100644
--- a/protocols/Tox/src/resource.h
+++ b/protocols/Tox/src/resource.h
Binary files differ
diff --git a/protocols/Tox/src/tox/tox.h b/protocols/Tox/src/tox/tox.h
index 8caa01e05f..c9a6bc709c 100644
--- a/protocols/Tox/src/tox/tox.h
+++ b/protocols/Tox/src/tox/tox.h
@@ -603,39 +603,54 @@ uint64_t tox_file_data_remaining(const Tox *tox, int32_t friendnumber, uint8_t f
*/
/* Resolves address into an IP address. If successful, sends a "get nodes"
- * request to the given node with ip, port (in network byte order, HINT: use htons())
+ * request to the given node with ip, port (in host byte order).
* and public_key to setup connections
*
* address can be a hostname or an IP address (IPv4 or IPv6).
- * if ipv6enabled is 0 (zero), the resolving sticks STRICTLY to IPv4 addresses
- * if ipv6enabled is not 0 (zero), the resolving looks for IPv6 addresses first,
- * then IPv4 addresses.
*
* returns 1 if the address could be converted into an IP address
* returns 0 otherwise
*/
-int tox_bootstrap_from_address(Tox *tox, const char *address, uint8_t ipv6enabled,
- uint16_t port, const uint8_t *public_key);
+int tox_bootstrap_from_address(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key);
/* return 0 if we are not connected to the DHT.
* return 1 if we are.
*/
int tox_isconnected(const Tox *tox);
+typedef struct {
+ /*
+ * The type of UDP socket created depends on ipv6enabled:
+ * If set to 0 (zero), creates an IPv4 socket which subsequently only allows
+ * IPv4 communication
+ * If set to anything else (default), creates an IPv6 socket which allows both IPv4 AND
+ * IPv6 communication
+ */
+ uint8_t ipv6enabled;
+
+ /* Set to 1 to disable udp support. (default: 0)
+ This will force Tox to use TCP only which may slow things down.
+ Disabling udp support is necessary when using anonymous proxies or Tor.*/
+ uint8_t udp_disabled;
+
+ /* Enable proxy support. (only basic TCP socks5 proxy currently supported.) (default: 0 (disabled))*/
+ uint8_t proxy_enabled;
+ char proxy_address[256]; /* Proxy ip or domain in NULL terminated string format. */
+ uint16_t proxy_port; /* Proxy port: in host byte order. */
+} Tox_Options;
+
/*
* Run this function at startup.
*
- * Initializes a tox structure
- * The type of communication socket depends on ipv6enabled:
- * If set to 0 (zero), creates an IPv4 socket which subsequently only allows
- * IPv4 communication
- * If set to anything else, creates an IPv6 socket which allows both IPv4 AND
- * IPv6 communication
+ * Options are some options that can be passed to the Tox instance (see above struct).
*
+ * If options is NULL, tox_new() will use default settings.
+ *
+ * Initializes a tox structure
* return allocated instance of tox on success.
- * return 0 if there are problems.
+ * return NULL on failure.
*/
-Tox *tox_new(uint8_t ipv6enabled);
+Tox *tox_new(Tox_Options *options);
/* Run this before closing shop.
* Free all datastructures. */
diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp
index 77a8095dd2..a517673398 100644
--- a/protocols/Tox/src/tox_account.cpp
+++ b/protocols/Tox/src/tox_account.cpp
@@ -6,6 +6,54 @@ bool CToxProto::IsOnline()
return isConnected && m_iStatus > ID_STATUS_OFFLINE;
}
+void CToxProto::InitToxCore()
+{
+ Tox_Options options = { 0 };
+ options.udp_disabled = getByte("DisableUDP", 0);
+ options.ipv6enabled = !getByte("DisableIPv6", 0);
+
+ if (hNetlibUser)
+ {
+ NETLIBUSERSETTINGS nlus = { sizeof(NETLIBUSERSETTINGS) };
+ CallService(MS_NETLIB_GETUSERSETTINGS, (WPARAM)hNetlibUser, (LPARAM)&nlus);
+
+ if (nlus.useProxy)
+ {
+ if (nlus.proxyType == PROXYTYPE_SOCKS4 || nlus.proxyType == PROXYTYPE_SOCKS5)
+ {
+ debugLogA("Setting socks user proxy config");
+ options.proxy_enabled = 1;
+ strcpy(&options.proxy_address[0], nlus.szProxyServer);
+ options.proxy_port = nlus.wProxyPort;
+ }
+ }
+ }
+
+ tox = tox_new(&options);
+ tox_callback_friend_request(tox, OnFriendRequest, this);
+ tox_callback_friend_message(tox, OnFriendMessage, this);
+ tox_callback_friend_action(tox, OnAction, this);
+ tox_callback_name_change(tox, OnFriendNameChange, this);
+ tox_callback_status_message(tox, OnStatusMessageChanged, this);
+ tox_callback_user_status(tox, OnUserStatusChanged, this);
+ tox_callback_read_receipt(tox, OnReadReceipt, this);
+ tox_callback_connection_status(tox, OnConnectionStatusChanged, this);
+
+ LoadToxData();
+
+ std::vector<uint8_t> username(TOX_MAX_NAME_LENGTH);
+ tox_get_self_name(tox, &username[0]);
+ std::string nick(username.begin(), username.end());
+ setString("Nick", nick.c_str());
+}
+
+void CToxProto::UninitToxCore()
+{
+ SaveToxData();
+
+ tox_kill(tox);
+}
+
void CToxProto::DoBootstrap()
{
static int j = 0;
@@ -13,7 +61,7 @@ void CToxProto::DoBootstrap()
while (i < 2)
{
struct bootstrap_node *d = &bootstrap_nodes[j % SIZEOF(bootstrap_nodes)];
- tox_bootstrap_from_address(tox, d->address, TOX_ENABLE_IPV6_DEFAULT, d->port, d->key);
+ tox_bootstrap_from_address(tox, d->address, d->port, d->key);
i++; j++;
}
}
diff --git a/protocols/Tox/src/tox_bootstrap.h b/protocols/Tox/src/tox_bootstrap.h
index 420fa83f2c..4c128ab000 100644
--- a/protocols/Tox/src/tox_bootstrap.h
+++ b/protocols/Tox/src/tox_bootstrap.h
@@ -3,8 +3,6 @@
#include "common.h"
-#define _HTONS(x) (uint16_t)((x << 8) | (x >> 8))
-
struct bootstrap_node {
char *address;
uint16_t port;
@@ -12,7 +10,7 @@ struct bootstrap_node {
} bootstrap_nodes[] = {
{
"192.254.75.98",
- _HTONS(33445),
+ 33445,
{
0x95, 0x1C, 0x88, 0xB7, 0xE7, 0x5C, 0x86, 0x74, 0x18, 0xAC, 0xDB, 0x5D, 0x27, 0x38, 0x21, 0x37,
0x2B, 0xB5, 0xBD, 0x65, 0x27, 0x40, 0xBC, 0xDF, 0x62, 0x3A, 0x4F, 0xA2, 0x93, 0xE7, 0x5D, 0x2F
@@ -21,7 +19,7 @@ struct bootstrap_node {
{
"37.187.46.132",
- _HTONS(33445),
+ 33445,
{
0xA9, 0xD9, 0x82, 0x12, 0xB3, 0xF9, 0x72, 0xBD, 0x11, 0xDA, 0x52, 0xBE, 0xB0, 0x65, 0x8C, 0x32,
0x6F, 0xCC, 0xC1, 0xBF, 0xD4, 0x9F, 0x34, 0x7F, 0x9C, 0x2D, 0x3D, 0x8B, 0x61, 0xE1, 0xB9, 0x27
@@ -30,7 +28,7 @@ struct bootstrap_node {
{
"144.76.60.215",
- _HTONS(33445),
+ 33445,
{
0x04, 0x11, 0x9E, 0x83, 0x5D, 0xF3, 0xE7, 0x8B, 0xAC, 0xF0, 0xF8, 0x42, 0x35, 0xB3, 0x00, 0x54,
0x6A, 0xF8, 0xB9, 0x36, 0xF0, 0x35, 0x18, 0x5E, 0x2A, 0x8E, 0x9E, 0x0A, 0x67, 0xC8, 0x92, 0x4F
@@ -39,7 +37,7 @@ struct bootstrap_node {
{
"23.226.230.47",
- _HTONS(33445),
+ 33445,
{
0xA0, 0x91, 0x62, 0xD6, 0x86, 0x18, 0xE7, 0x42, 0xFF, 0xBC, 0xA1, 0xC2, 0xC7, 0x03, 0x85, 0xE6,
0x67, 0x96, 0x04, 0xB2, 0xD8, 0x0E, 0xA6, 0xE8, 0x4A, 0xD0, 0x99, 0x6A, 0x1A, 0xC8, 0xA0, 0x74
@@ -48,7 +46,7 @@ struct bootstrap_node {
{
"54.199.139.199",
- _HTONS(33445),
+ 33445,
{
0x7F, 0x9C, 0x31, 0xFE, 0x85, 0x0E, 0x97, 0xCE, 0xFD, 0x4C, 0x45, 0x91, 0xDF, 0x93, 0xFC, 0x75,
0x7C, 0x7C, 0x12, 0x54, 0x9D, 0xDD, 0x55, 0xF8, 0xEE, 0xAE, 0xCC, 0x34, 0xFE, 0x76, 0xC0, 0x29
@@ -57,7 +55,7 @@ struct bootstrap_node {
{
"109.169.46.133",
- _HTONS(33445),
+ 33445,
{
0x7F, 0x31, 0xBF, 0xC9, 0x3B, 0x8E, 0x40, 0x16, 0xA9, 0x02, 0x14, 0x4D, 0x0B, 0x11, 0x0C, 0x3E,
0xA9, 0x7C, 0xB7, 0xD4, 0x3F, 0x1C, 0x4D, 0x21, 0xBC, 0xAE, 0x99, 0x8A, 0x7C, 0x83, 0x88, 0x21
@@ -66,7 +64,7 @@ struct bootstrap_node {
{
"192.210.149.121",
- _HTONS(33445),
+ 33445,
{
0xF4, 0x04, 0xAB, 0xAA, 0x1C, 0x99, 0xA9, 0xD3, 0x7D, 0x61, 0xAB, 0x54, 0x89, 0x8F, 0x56, 0x79,
0x3E, 0x1D, 0xEF, 0x8B, 0xD4, 0x6B, 0x10, 0x38, 0xB9, 0xD8, 0x22, 0xE8, 0x46, 0x0F, 0xAB, 0x67
@@ -74,6 +72,4 @@ struct bootstrap_node {
},
};
-#undef _HTONS
-
#endif //_TOX_BOOTSTRAP_H_ \ No newline at end of file
diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp
index 1c32597ce4..10f3c29701 100644
--- a/protocols/Tox/src/tox_events.cpp
+++ b/protocols/Tox/src/tox_events.cpp
@@ -2,7 +2,6 @@
int CToxProto::OnModulesLoaded(WPARAM, LPARAM)
{
- InitNetlib();
HookEventObj(ME_OPT_INITIALISE, OnOptionsInit, this);
return 0;
@@ -10,8 +9,6 @@ int CToxProto::OnModulesLoaded(WPARAM, LPARAM)
int CToxProto::OnPreShutdown(WPARAM, LPARAM)
{
- UninitNetlib();
-
return 0;
}
diff --git a/protocols/Tox/src/tox_instances.cpp b/protocols/Tox/src/tox_instances.cpp
index ea010f894a..414cd7b767 100644
--- a/protocols/Tox/src/tox_instances.cpp
+++ b/protocols/Tox/src/tox_instances.cpp
@@ -10,14 +10,14 @@ int CToxProto::CompareProtos(const CToxProto *p1, const CToxProto *p2)
CToxProto* CToxProto::InitProtoInstance(const char* protoName, const wchar_t* userName)
{
CToxProto *ppro = new CToxProto(protoName, userName);
- CToxProto::instanceList.insert(ppro);
+ instanceList.insert(ppro);
return ppro;
}
int CToxProto::UninitProtoInstance(CToxProto* ppro)
{
- CToxProto::instanceList.remove(ppro);
+ instanceList.remove(ppro);
delete ppro;
@@ -26,19 +26,19 @@ int CToxProto::UninitProtoInstance(CToxProto* ppro)
void CToxProto::UninitInstances()
{
- CToxProto::instanceList.destroy();
+ instanceList.destroy();
}
CToxProto* CToxProto::GetContactInstance(MCONTACT hContact)
{
- char *proto = (char *)::CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
+ char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
if (proto == NULL)
return NULL;
- for (int i = 0; i < CToxProto::instanceList.getCount(); i++)
- if ( !::strcmp(proto, CToxProto::instanceList[i]->m_szModuleName))
- return CToxProto::instanceList[i];
+ for (int i = 0; i < instanceList.getCount(); i++)
+ if ( !::strcmp(proto, instanceList[i]->m_szModuleName))
+ return instanceList[i];
return NULL;
} \ No newline at end of file
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp
index 33d73604c6..975a59a241 100644
--- a/protocols/Tox/src/tox_options.cpp
+++ b/protocols/Tox/src/tox_options.cpp
@@ -28,11 +28,16 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,
SetDlgItemText(hwnd, IDC_GROUP, groupName);
SendDlgItemMessage(hwnd, IDC_GROUP, EM_LIMITTEXT, 64, 0);
- /*if (proto->IsOnline())
+ CheckDlgButton(hwnd, IDC_DISABLE_UDP, proto->getByte("DisableUDP", 0));
+ CheckDlgButton(hwnd, IDC_DISABLE_IPV6, proto->getByte("DisableIPv6", 0));
+
+ if (proto->IsOnline())
{
EnableWindow(GetDlgItem(hwnd, IDC_USERNAME), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_DATAPATH), FALSE);
- }*/
+ EnableWindow(GetDlgItem(hwnd, IDC_DISABLE_UDP), FALSE);
+ EnableWindow(GetDlgItem(hwnd, IDC_DISABLE_IPV6), FALSE);
+ }
}
return TRUE;
@@ -43,7 +48,7 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,
case IDC_USERNAME:
if ((HWND)lParam == GetFocus())
{
- //EnableWindow(GetDlgItem(hwnd, IDC_USERNAME), !proto->IsOnline());
+ EnableWindow(GetDlgItem(hwnd, IDC_USERNAME), !proto->IsOnline());
if (HIWORD(wParam) != EN_CHANGE) return 0;
char username[128];
GetDlgItemTextA(hwnd, IDC_USERNAME, username, SIZEOF(username));
@@ -54,7 +59,7 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,
case IDC_DATAPATH:
if ((HWND)lParam == GetFocus())
{
- //EnableWindow(GetDlgItem(hwnd, IDC_DATAPATH), !proto->IsOnline());
+ EnableWindow(GetDlgItem(hwnd, IDC_DATAPATH), !proto->IsOnline());
if (HIWORD(wParam) != EN_CHANGE) return 0;
char dataPath[128];
GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
@@ -94,6 +99,14 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
}
break;
+
+ case IDC_DISABLE_UDP:
+ SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
+ break;
+
+ case IDC_DISABLE_IPV6:
+ SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
+ break;
}
}
break;
@@ -101,20 +114,23 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,
case WM_NOTIFY:
if (reinterpret_cast<NMHDR*>(lParam)->code == PSN_APPLY)
{
- //if (!proto->IsOnline())
+ if (!proto->IsOnline())
{
char username[128];
GetDlgItemTextA(hwnd, IDC_USERNAME, username, SIZEOF(username));
proto->setString("Username", username);
+ tox_set_name(proto->tox, (uint8_t*)&username[0], strlen(username));
- if (tox_set_name(proto->tox, (uint8_t*)&username[0], strlen(username)) == 0)
- {
- proto->SaveToxData();
- }
+ proto->UninitToxCore();
char dataPath[128];
GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
proto->setString("DataPath", dataPath);
+
+ proto->setByte("DisableUDP", (BYTE)IsDlgButtonChecked(hwnd, IDC_DISABLE_UDP));
+ proto->setByte("DisableIPv6", (BYTE)IsDlgButtonChecked(hwnd, IDC_DISABLE_IPV6));
+
+ proto->InitToxCore();
}
wchar_t groupName[128];
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index d63ea49b7a..5da018a496 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -3,23 +3,8 @@
CToxProto::CToxProto(const char* protoName, const TCHAR* userName) :
PROTO<CToxProto>(protoName, userName)
{
- tox = tox_new(TOX_ENABLE_IPV6_DEFAULT);
-
- LoadToxData();
-
- std::vector<uint8_t> username(TOX_MAX_NAME_LENGTH);
- tox_get_self_name(tox, &username[0]);
- std::string nick(username.begin(), username.end());
- setString("Nick", nick.c_str());
-
- tox_callback_friend_request(tox, OnFriendRequest, this);
- tox_callback_friend_message(tox, OnFriendMessage, this);
- tox_callback_friend_action(tox, OnAction, this);
- tox_callback_name_change(tox, OnFriendNameChange, this);
- tox_callback_status_message(tox, OnStatusMessageChanged, this);
- tox_callback_user_status(tox, OnUserStatusChanged, this);
- tox_callback_read_receipt(tox, OnReadReceipt, this);
- tox_callback_connection_status(tox, OnConnectionStatusChanged, this);
+ InitNetlib();
+ InitToxCore();
CreateProtoService(PS_CREATEACCMGRUI, &CToxProto::OnAccountManagerInit);
@@ -50,9 +35,8 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) :
CToxProto::~CToxProto()
{
- SaveToxData();
-
- tox_kill(tox);
+ UninitToxCore();
+ UninitNetlib();
}
DWORD_PTR __cdecl CToxProto::GetCaps(int type, MCONTACT hContact)
@@ -181,16 +165,11 @@ HANDLE __cdecl CToxProto::SendFile(MCONTACT hContact, const PROTOCHAR* szDescrip
int __cdecl CToxProto::SendMsg(MCONTACT hContact, int flags, const char* msg)
{
- if (!IsOnline() || !hContact || !IsContactOnline(hContact))
- {
- return 0;
- }
-
std::string toxId(getStringA(hContact, TOX_SETTINGS_ID));
std::vector<uint8_t> clientId = HexStringToData(toxId);
uint32_t number = tox_get_friend_number(tox, clientId.data());
-
+
ULONG messageId = InterlockedIncrement(&hMessageProcess);
int result = tox_send_message_withid(tox, number, messageId, (uint8_t*)msg, strlen(msg));
@@ -199,7 +178,7 @@ int __cdecl CToxProto::SendMsg(MCONTACT hContact, int flags, const char* msg)
debugLogA("CToxProto::SendMsg: error sending message %i", result);
return 0;
}
-
+
return messageId;
}
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index 0d185ac143..b19a5b9f74 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -78,6 +78,10 @@ private:
ULONG hMessageProcess;
HANDLE hNetlibUser;
+ // tox
+ void InitToxCore();
+ void UninitToxCore();
+
// instances
static LIST<CToxProto> instanceList;
static int CompareProtos(const CToxProto *p1, const CToxProto *p2);