From 0611ac72c7020b46466309c19622afe0fb3bc122 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Thu, 5 Mar 2015 18:01:07 +0000 Subject: Tox: - removed dns3 servers from code - cv2pdb moved to tools git-svn-id: http://svn.miranda-ng.org/main/trunk@12330 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_address.h | 4 +- protocols/Tox/src/tox_dns.h | 26 ------------ protocols/Tox/src/tox_network.cpp | 26 +++++++----- protocols/Tox/src/tox_proto.h | 5 ++- protocols/Tox/src/tox_search.cpp | 88 +++++++++++++++++++++++---------------- 5 files changed, 72 insertions(+), 77 deletions(-) delete mode 100644 protocols/Tox/src/tox_dns.h (limited to 'protocols/Tox/src') diff --git a/protocols/Tox/src/tox_address.h b/protocols/Tox/src/tox_address.h index 4270e23ee2..f9be08c767 100644 --- a/protocols/Tox/src/tox_address.h +++ b/protocols/Tox/src/tox_address.h @@ -32,7 +32,7 @@ public: } const bool IsEmpty() const { - return hexData.length() == 0; + return hexData.empty(); } const ToxHexAddress GetPubKey() const { @@ -45,7 +45,7 @@ public: } static ToxHexAddress Empty() { - return ToxHexAddress(""); + return ToxHexAddress("", 0); } ToxBinAddress ToBin() const; }; diff --git a/protocols/Tox/src/tox_dns.h b/protocols/Tox/src/tox_dns.h deleted file mode 100644 index 394ea9f61f..0000000000 --- a/protocols/Tox/src/tox_dns.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef _TOX_DNS_H_ -#define _TOX_DNS_H_ - -struct dns_server -{ - char *domain; - uint8_t key[32]; -} dns_servers[] = -{ - { - "toxme.se", - { - 0x5D, 0x72, 0xC5, 0x17, 0xDF, 0x6A, 0xEC, 0x54, 0xF1, 0xE9, 0x77, 0xA6, 0xB6, 0xF2, 0x59, 0x14, - 0xEA, 0x4C, 0xF7, 0x27, 0x7A, 0x85, 0x02, 0x7C, 0xD9, 0xF5, 0x19, 0x6D, 0xF1, 0x7E, 0x0B, 0x13 - } - }, - { - "utox.org", - { - 0xD3, 0x15, 0x4F, 0x65, 0xD2, 0x8A, 0x5B, 0x41, 0xA0, 0x5D, 0x4A, 0xC7, 0xE4, 0xB3, 0x9C, 0x6B, - 0x1C, 0x23, 0x3C, 0xC8, 0x57, 0xFB, 0x36, 0x5C, 0x56, 0xE8, 0x39, 0x27, 0x37, 0x46, 0x2A, 0x12 - } - }, -}; - -#endif //_TOX_DNS_H_ \ No newline at end of file diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp index 109cedbf99..52c66120b9 100644 --- a/protocols/Tox/src/tox_network.cpp +++ b/protocols/Tox/src/tox_network.cpp @@ -5,9 +5,16 @@ bool CToxProto::IsOnline() return isConnected && m_iStatus > ID_STATUS_OFFLINE; } -int CToxProto::BootstrapNodesFromDb(bool isIPv6) +void CToxProto::BootstrapNode(const char *address, int port, const uint8_t *pubKey) +{ + if (!tox_bootstrap_from_address(tox, address, port, pubKey)) + { + debugLogA("CToxProto::BootstrapNode: failed to bootstrap node %s:%d (%s)", address, port, (const char*)ToxHexAddress(pubKey)); + } +} + +void CToxProto::BootstrapNodesFromDb(bool isIPv6) { - int nodesLoaded = 0; char module[MAX_PATH]; mir_snprintf(module, SIZEOF(module), "%s_NODES", m_szModuleName); int nodeCount = db_get_w(NULL, module, TOX_SETTINGS_NODE_COUNT, 0); @@ -21,22 +28,20 @@ int CToxProto::BootstrapNodesFromDb(bool isIPv6) mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, i); int port = db_get_w(NULL, module, setting, 33445); mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, i); - ptrA pubKey(db_get_sa(NULL, module, setting)); - nodesLoaded += tox_bootstrap_from_address(tox, address, port, ToxBinAddress(pubKey)); + ToxBinAddress pubKey(ptrA(db_get_sa(NULL, module, setting))); + BootstrapNode(address, port, pubKey); if (isIPv6) { mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, i); address = db_get_sa(NULL, module, setting); - nodesLoaded += tox_bootstrap_from_address(tox, address, port, ToxBinAddress(pubKey)); + BootstrapNode(address, port, pubKey); } } } - return nodesLoaded; } -int CToxProto::BootstrapNodesFromIni(bool isIPv6) +void CToxProto::BootstrapNodesFromIni(bool isIPv6) { - int nodesLoaded = 0; if (IsFileExists((TCHAR*)VARST(_T(TOX_INI_PATH)))) { char fileName[MAX_PATH]; @@ -54,18 +59,17 @@ int CToxProto::BootstrapNodesFromIni(bool isIPv6) int port = GetPrivateProfileIntA(section, "Port", 33445, fileName); GetPrivateProfileStringA(section, "PubKey", NULL, value, SIZEOF(value), fileName); ToxBinAddress pubKey(value); - nodesLoaded += tox_bootstrap_from_address(tox, address, port, pubKey); + BootstrapNode(address, port, pubKey); if (isIPv6) { GetPrivateProfileStringA(section, "IPv6", NULL, value, SIZEOF(value), fileName); address = mir_strdup(value); - nodesLoaded += tox_bootstrap_from_address(tox, address, port, pubKey); + BootstrapNode(address, port, pubKey); } } section += strlen(section) + 1; } } - return nodesLoaded; } void CToxProto::BootstrapNodes() diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 9a00b20c5a..f6292bdc20 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -101,8 +101,9 @@ private: // tox network bool IsOnline(); - int BootstrapNodesFromDb(bool isIPv6); - int BootstrapNodesFromIni(bool isIPv6); + void BootstrapNode(const char *address, int port, const uint8_t *pubKey); + void BootstrapNodesFromDb(bool isIPv6); + void BootstrapNodesFromIni(bool isIPv6); void BootstrapNodes(); void TryConnect(); void CheckConnection(int &retriesCount); diff --git a/protocols/Tox/src/tox_search.cpp b/protocols/Tox/src/tox_search.cpp index 910b5497a9..49a1b54099 100644 --- a/protocols/Tox/src/tox_search.cpp +++ b/protocols/Tox/src/tox_search.cpp @@ -1,5 +1,4 @@ #include "common.h" -#include "tox_dns.h" ToxHexAddress ResolveToxAddressFromDnsRecordV1(const std::string &dnsRecord) { @@ -47,52 +46,69 @@ void CToxProto::SearchByNameAsync(void *arg) int resolved = 0; - for (size_t i = 0; i < SIZEOF(dns_servers); i++) + if (IsFileExists((TCHAR*)VARST(_T(TOX_INI_PATH)))) { - struct dns_server *server = &dns_servers[i]; - if (domain == NULL || mir_strcmpi(domain, server->domain) == 0) - { - void *dns = tox_dns3_new(server->key); + char fileName[MAX_PATH]; + mir_strcpy(fileName, VARS(TOX_INI_PATH)); - uint32_t requestId = 0; - uint8_t dnsString[MAX_PATH]; - int length = tox_generate_dns3_string(dns, dnsString, sizeof(dnsString), &requestId, (uint8_t*)name, mir_strlen(name)); - if (length != TOX_ERROR) + char *section, sections[MAX_PATH], value[MAX_PATH]; + GetPrivateProfileSectionNamesA(sections, SIZEOF(sections), fileName); + section = sections; + while (*section != NULL) + { + if (strstr(section, "Dns_") == section) { - dnsString[length] = 0; - char dnsQuery[MAX_PATH * 2]; - mir_snprintf(dnsQuery, SIZEOF(dnsQuery), "_%s._tox.%s", dnsString, server->domain); + GetPrivateProfileStringA(section, "Domain", NULL, value, SIZEOF(value), fileName); + ptrA dnsDomain(mir_strdup(value)); + GetPrivateProfileStringA(section, "PubKey", NULL, value, SIZEOF(value), fileName); + ToxBinAddress dnsPubKey(value); - DNS_RECORDA *record = NULL; - DNS_STATUS status = DnsQuery_A(dnsQuery, DNS_TYPE_TEXT, 0, NULL, (PDNS_RECORD*)&record, NULL); - while (status == ERROR_SUCCESS && record) + if (domain == NULL || mir_strcmpi(domain, dnsDomain) == 0) { - DNS_TXT_DATAA *txt = &record->Data.Txt; - if (record->wType == DNS_TYPE_TEXT && txt->dwStringCount) - { - ToxHexAddress address = ResolveToxAddressFromDnsRecordV3(dns, requestId, txt->pStringArray[0]); - if (!address.IsEmpty()) - { - PROTOSEARCHRESULT psr = { sizeof(PROTOSEARCHRESULT) }; - psr.flags = PSR_TCHAR; - psr.id = mir_a2t(address); - psr.nick = mir_utf8decodeT(name); + void *dns = tox_dns3_new((uint8_t*)(const uint8_t*)dnsPubKey); - TCHAR email[MAX_PATH]; - mir_sntprintf(email, SIZEOF(email), _T("%s@%s"), psr.nick, _A2T(server->domain)); - psr.email = mir_tstrdup(email); - - ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr); + uint32_t requestId = 0; + uint8_t dnsString[MAX_PATH]; + int length = tox_generate_dns3_string(dns, dnsString, sizeof(dnsString), &requestId, (uint8_t*)name, mir_strlen(name)); + if (length != TOX_ERROR) + { + dnsString[length] = 0; + char dnsQuery[MAX_PATH * 2]; + mir_snprintf(dnsQuery, SIZEOF(dnsQuery), "_%s._tox.%s", dnsString, dnsDomain); - resolved++; - break; + DNS_RECORDA *record = NULL; + DNS_STATUS status = DnsQuery_A(dnsQuery, DNS_TYPE_TEXT, 0, NULL, (PDNS_RECORD*)&record, NULL); + while (status == ERROR_SUCCESS && record) + { + DNS_TXT_DATAA *txt = &record->Data.Txt; + if (record->wType == DNS_TYPE_TEXT && txt->dwStringCount) + { + ToxHexAddress address = ResolveToxAddressFromDnsRecordV3(dns, requestId, txt->pStringArray[0]); + if (!address.IsEmpty()) + { + PROTOSEARCHRESULT psr = { sizeof(PROTOSEARCHRESULT) }; + psr.flags = PSR_TCHAR; + psr.id = mir_a2t(address); + psr.nick = mir_utf8decodeT(name); + + TCHAR email[MAX_PATH]; + mir_sntprintf(email, SIZEOF(email), _T("%s@%s"), psr.nick, _A2T(dnsDomain)); + psr.email = mir_tstrdup(email); + + ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr); + + resolved++; + break; + } + } + record = record->pNext; } + DnsRecordListFree((PDNS_RECORD*)record, DnsFreeRecordList); } - record = record->pNext; + tox_dns3_kill(dns); } - DnsRecordListFree((PDNS_RECORD*)record, DnsFreeRecordList); } - tox_dns3_kill(dns); + section += strlen(section) + 1; } } -- cgit v1.2.3