From 40453965455818d568bf90224b828c3f72b2606d Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Wed, 18 Feb 2015 19:24:48 +0000 Subject: Tox: - code cleaning - removed unneeded dependencies - posible fix for disconnect git-svn-id: http://svn.miranda-ng.org/main/trunk@12183 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/Tox_12.vcxproj | 10 +++++----- protocols/Tox/Tox_12.vcxproj.filters | 2 +- protocols/Tox/src/common.h | 6 +----- protocols/Tox/src/tox_address.h | 8 ++++---- protocols/Tox/src/tox_avatars.cpp | 4 ++-- protocols/Tox/src/tox_core.cpp | 7 +++++++ protocols/Tox/src/tox_network.cpp | 27 +++++++++++++-------------- protocols/Tox/src/tox_options.cpp | 28 ++++++++++++++++++---------- protocols/Tox/src/tox_proto.h | 6 ++++-- protocols/Tox/src/tox_transfer.h | 2 +- 10 files changed, 56 insertions(+), 44 deletions(-) (limited to 'protocols/Tox') diff --git a/protocols/Tox/Tox_12.vcxproj b/protocols/Tox/Tox_12.vcxproj index ac7a37cc8d..a0f0c23c04 100644 --- a/protocols/Tox/Tox_12.vcxproj +++ b/protocols/Tox/Tox_12.vcxproj @@ -97,7 +97,7 @@ $(IntDir)$(TargetName).lib false false - Shlwapi.lib;ws2_32.lib;dnsapi.lib;comctl32.lib;%(AdditionalDependencies) + dnsapi.lib;comctl32.lib;%(AdditionalDependencies) _DEBUG;%(PreprocessorDefinitions) @@ -125,7 +125,7 @@ true $(ProfileDir)..\..\bin12\lib $(IntDir)$(TargetName).lib - Shlwapi.lib;ws2_32.lib;dnsapi.lib;comctl32.lib;%(AdditionalDependencies) + dnsapi.lib;comctl32.lib;%(AdditionalDependencies) false @@ -156,7 +156,7 @@ false $(ProfileDir)..\..\bin12\lib $(IntDir)$(TargetName).lib - Shlwapi.lib;ws2_32.lib;dnsapi.lib;comctl32.lib;%(AdditionalDependencies) + dnsapi.lib;comctl32.lib;%(AdditionalDependencies) NDEBUG;%(PreprocessorDefinitions) @@ -184,7 +184,7 @@ true true false - Shlwapi.lib;ws2_32.lib;dnsapi.lib;comctl32.lib;%(AdditionalDependencies) + dnsapi.lib;comctl32.lib;%(AdditionalDependencies) $(ProfileDir)..\..\bin12\lib $(IntDir)$(TargetName).lib @@ -232,7 +232,7 @@ - + diff --git a/protocols/Tox/Tox_12.vcxproj.filters b/protocols/Tox/Tox_12.vcxproj.filters index ae06a521d6..71e635fa90 100644 --- a/protocols/Tox/Tox_12.vcxproj.filters +++ b/protocols/Tox/Tox_12.vcxproj.filters @@ -122,7 +122,7 @@ Source Files - + Source Files diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h index 4344557ffe..13aadf38aa 100644 --- a/protocols/Tox/src/common.h +++ b/protocols/Tox/src/common.h @@ -1,17 +1,13 @@ #ifndef _COMMON_H_ #define _COMMON_H_ -#include #include #include #include #include -#include #include -#include -#include -//#include +#include #include #include diff --git a/protocols/Tox/src/tox_address.h b/protocols/Tox/src/tox_address.h index a4b152427d..6eada63300 100644 --- a/protocols/Tox/src/tox_address.h +++ b/protocols/Tox/src/tox_address.h @@ -16,7 +16,7 @@ public: { this->ToxHexAddress::ToxHexAddress(bin.data(), bin.size()); } - ToxHexAddress(const uint8_t *bin, int size = TOX_FRIEND_ADDRESS_SIZE) + ToxHexAddress(const uint8_t *bin, size_t size = TOX_FRIEND_ADDRESS_SIZE) { char *hex = (char*)mir_alloc(size * 2 + 1); hexData = bin2hex(bin, size, hex); @@ -46,7 +46,7 @@ private: public: ToxBinAddress(const ToxBinAddress &address) : binData(address.binData) { } ToxBinAddress(const std::vector &bin) : binData(bin) { } - ToxBinAddress(const uint8_t *bin, int size = TOX_FRIEND_ADDRESS_SIZE) : binData(bin, bin + size) { } + ToxBinAddress(const uint8_t *bin, size_t size = TOX_FRIEND_ADDRESS_SIZE) : binData(bin, bin + size) { } ToxBinAddress(const std::string &hex) { this->ToxBinAddress::ToxBinAddress(hex.c_str()); @@ -55,8 +55,8 @@ public: { char *endptr; const char *pos = hex; - int size = mir_strlen(hex) / 2; - for (int i = 0; i < size; i++) + size_t size = mir_strlen(hex) / 2; + for (size_t i = 0; i < size; i++) { char buf[5] = { '0', 'x', pos[0], pos[1], 0 }; binData.push_back((uint8_t)strtol(buf, &endptr, 0)); diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp index 6d52088b22..7ab5d4526d 100644 --- a/protocols/Tox/src/tox_avatars.cpp +++ b/protocols/Tox/src/tox_avatars.cpp @@ -35,7 +35,7 @@ void CToxProto::SetToxAvatar(std::tstring path, bool checkHash) return; }*/ - long length; + size_t length; uint8_t *data; FILE *hFile = _tfopen(path.c_str(), L"rb"); if (!hFile) @@ -55,7 +55,7 @@ void CToxProto::SetToxAvatar(std::tstring path, bool checkHash) } data = (uint8_t*)mir_alloc(length); - long read = fread(data, sizeof(uint8_t), length, hFile); + size_t read = fread(data, sizeof(uint8_t), length, hFile); if (read != length) { fclose(hFile); diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp index f079917040..cff5d56c0d 100644 --- a/protocols/Tox/src/tox_core.cpp +++ b/protocols/Tox/src/tox_core.cpp @@ -1,5 +1,10 @@ #include "common.h" +bool CToxProto::IsToxCoreInited() +{ + return tox != NULL; +} + bool CToxProto::InitToxCore() { debugLogA("CToxProto::InitToxCore: initializing tox core"); @@ -91,6 +96,7 @@ bool CToxProto::InitToxCore() password = NULL; } tox_kill(tox); + tox = NULL; } return isProfileLoaded; @@ -121,4 +127,5 @@ void CToxProto::UninitToxCore() password = NULL; } tox_kill(tox); + tox = NULL; } \ No newline at end of file diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp index 72f090fe76..86afc17607 100644 --- a/protocols/Tox/src/tox_network.cpp +++ b/protocols/Tox/src/tox_network.cpp @@ -5,12 +5,7 @@ bool CToxProto::IsOnline() return isConnected && m_iStatus > ID_STATUS_OFFLINE; } -bool CToxProto::IsOffline() -{ - return !isConnected && m_iStatus == ID_STATUS_OFFLINE; -} - -void CToxProto::BootstrapDht() +void CToxProto::BootstrapNodes() { debugLogA("CToxProto::BootstrapDht: bootstraping DHT"); @@ -21,9 +16,6 @@ void CToxProto::BootstrapDht() tox_bootstrap_from_address( tox, isIPv4 ? "192.254.75.102" : "2607:5600:284::2", 33445, ToxBinAddress("951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F")); - tox_bootstrap_from_address( - tox, "104.219.184.206", 443, - ToxBinAddress("8CD087E31C67568103E8C2A28653337E90E6B8EDA0D765D57C6B5172B4F1F04C")); } else { @@ -91,11 +83,18 @@ void CToxProto::CheckConnection(int &retriesCount) retriesCount = TOX_MAX_DISCONNECT_RETRIES; } } - else if (!(--retriesCount)) + else { - isConnected = false; - debugLogA("CToxProto::CheckConnection: disconnected from DHT"); - SetStatus(ID_STATUS_OFFLINE); + if (--retriesCount == TOX_MAX_DISCONNECT_RETRIES - 1) + { + BootstrapNodes(); + } + else if (!(--retriesCount)) + { + isConnected = false; + debugLogA("CToxProto::CheckConnection: disconnected from DHT"); + SetStatus(ID_STATUS_OFFLINE); + } } } } @@ -124,7 +123,7 @@ void CToxProto::PollingThread(void*) int retriesCount = TOX_MAX_DISCONNECT_RETRIES; isConnected = false; - BootstrapDht(); + BootstrapNodes(); while (!isTerminated) { diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index 77a7e5e806..e99c73dcd5 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -25,16 +25,15 @@ INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l } ptrT group(proto->getTStringA(TOX_SETTINGS_GROUP)); - if (group) - SetDlgItemText(hwnd, IDC_GROUP, group); - else - SetDlgItemText(hwnd, IDC_GROUP, _T("Tox")); + SetDlgItemText(hwnd, IDC_GROUP, group ? group : _T("Tox")); SendDlgItemMessage(hwnd, IDC_GROUP, EM_LIMITTEXT, 64, 0); CheckDlgButton(hwnd, IDC_DISABLE_UDP, proto->getBool("DisableUDP", 0)); CheckDlgButton(hwnd, IDC_DISABLE_IPV6, proto->getBool("DisableIPv6", 0)); - if (proto->IsOffline()) + if (!proto->IsToxCoreInited()) + { EnableWindow(GetDlgItem(hwnd, IDC_IMPORT_PROFILE), TRUE); + } } return TRUE; @@ -90,15 +89,24 @@ INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l if (GetOpenFileName(&ofn)) { - if (proto->IsOffline()) { + if (!proto->IsToxCoreInited()) + { std::tstring defaultProfilePath = GetToxProfilePath(proto->accountName); - if (PathFileExists(defaultProfilePath.c_str())) - if (MessageBox(hwnd, TranslateT("You have existing profile. Do you want remove it with all tox contacts and history and continue import?"), TranslateT("Tox profile import"), MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) == IDNO) - break; - else { + if (CToxProto::IsFileExists(defaultProfilePath.c_str())) + { + if (MessageBox( + hwnd, + TranslateT("You have existing profile. Do you want remove it with all tox contacts and history and continue import?"), + TranslateT("Tox profile import"), + MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) == IDYES) + { while (MCONTACT hContact = db_find_first(proto->m_szModuleName)) + { CallService(MS_DB_CONTACT_DELETE, hContact, 0); + } } + else break; + } if (profilePath && _tcslen(profilePath)) { if (_tcsicmp(profilePath, defaultProfilePath.c_str()) != 0) diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index f7844e1f61..2dfec2ba12 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -83,13 +83,15 @@ private: static INT_PTR CALLBACK ToxProfilePasswordProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); // tox core + bool IsToxCoreInited(); + bool InitToxCore(); void UninitToxCore(); // tox network bool IsOnline(); - bool IsOffline(); - void BootstrapDht(); + + void BootstrapNodes(); void TryConnect(); void CheckConnection(int &retriesCount); void DoTox(); diff --git a/protocols/Tox/src/tox_transfer.h b/protocols/Tox/src/tox_transfer.h index 534565c09f..41c6e1a4c6 100644 --- a/protocols/Tox/src/tox_transfer.h +++ b/protocols/Tox/src/tox_transfer.h @@ -104,7 +104,7 @@ public: return NULL; } - FileTransferParam* GetAt(int64_t index) + FileTransferParam* GetAt(size_t index) { if (index < Count()) { -- cgit v1.2.3