diff options
author | aunsane <aunsane@gmail.com> | 2018-04-13 22:54:05 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-04-13 22:54:27 +0300 |
commit | 430f999f00224a68a967e7122894b469d5ee60bf (patch) | |
tree | b552ff57e5c8a0f1de49208eb511f4edb38f2032 /protocols/Tox/src | |
parent | 81dd07b3ae0c7f31da0c6766b8b325e2601e4195 (diff) |
Tox: added logging from toxcore
- toxcore updated to 0.2.1
- toxcore now bootstraped with random two nodes
- version bump
Diffstat (limited to 'protocols/Tox/src')
-rw-r--r-- | protocols/Tox/src/tox_bootstrap.cpp | 34 | ||||
-rw-r--r-- | protocols/Tox/src/tox_core.cpp | 11 | ||||
-rw-r--r-- | protocols/Tox/src/tox_profile.cpp | 6 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 2 | ||||
-rw-r--r-- | protocols/Tox/src/version.h | 2 |
5 files changed, 41 insertions, 14 deletions
diff --git a/protocols/Tox/src/tox_bootstrap.cpp b/protocols/Tox/src/tox_bootstrap.cpp index 645b85ad90..db4107a776 100644 --- a/protocols/Tox/src/tox_bootstrap.cpp +++ b/protocols/Tox/src/tox_bootstrap.cpp @@ -2,9 +2,6 @@ void CToxProto::BootstrapUdpNode(Tox *tox, const char *address, int port, const char *hexKey) { - if (!m_toxThread) - return; - if (address == nullptr || hexKey == nullptr) return; @@ -16,9 +13,6 @@ void CToxProto::BootstrapUdpNode(Tox *tox, const char *address, int port, const void CToxProto::BootstrapTcpRelay(Tox *tox, const char *address, int port, const char *hexKey) { - if (!m_toxThread) - return; - if (address == nullptr || hexKey == nullptr) return; @@ -63,11 +57,30 @@ void CToxProto::BootstrapNodesFromJson(Tox *tox, bool isIPv6) UpdateNodes(); JSONNode nodes = ParseNodes(); - for (const auto &node : nodes) { + auto nodeCount = nodes.size(); + if (nodeCount == 0) + return; + + static int j = rand() % nodeCount; + + int i = 0; + while (i < 2) { + JSONNode node = nodes[j % nodeCount]; + + bool udpStatus = node.at("status_udp").as_bool(); + bool tcpStatus = node.at("status_tcp").as_bool(); + if (!udpStatus && !tcpStatus) { + nodeCount = j - 1; + j = rand() % nodeCount; + if (j == 0) + return; + continue; + } + JSONNode address = node.at("ipv4"); JSONNode pubKey = node.at("public_key"); - if (node.at("status_udp").as_bool()) { + if (udpStatus) { int port = node.at("port").as_int(); BootstrapUdpNode(tox, address.as_string().c_str(), port, pubKey.as_string().c_str()); if (isIPv6) { @@ -76,7 +89,7 @@ void CToxProto::BootstrapNodesFromJson(Tox *tox, bool isIPv6) } } - if (node.at("status_tcp").as_bool()) { + if (tcpStatus) { JSONNode tcpPorts = node.at("tcp_ports").as_array(); for (size_t k = 0; k < tcpPorts.size(); k++) { int port = tcpPorts[k].as_int(); @@ -87,6 +100,9 @@ void CToxProto::BootstrapNodesFromJson(Tox *tox, bool isIPv6) } } } + + j++; + i++; } } diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp index de977b090f..1132486213 100644 --- a/protocols/Tox/src/tox_core.cpp +++ b/protocols/Tox/src/tox_core.cpp @@ -36,6 +36,9 @@ Tox_Options* CToxProto::GetToxOptions() }
}
+ options->log_callback = CToxProto::OnToxLog;
+ options->log_user_data = this;
+
if (LoadToxProfile(options))
return options;
@@ -93,3 +96,11 @@ void CToxProto::UninitToxCore(Tox *tox) CancelAllTransfers(tox);
SaveToxProfile(tox);
}
+
+void CToxProto::OnToxLog(Tox*, TOX_LOG_LEVEL level, const char *file, uint32_t line, const char *func, const char *message, void *user_data)
+{
+ CToxProto *proto = (CToxProto*)user_data;
+
+ if (level > TOX_LOG_LEVEL_INFO)
+ proto->debugLogA("TOXCORE: %s at %s(...) in %s:%u", message, func, file, line);
+}
\ No newline at end of file diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp index a5ced0c8f9..76f59202d8 100644 --- a/protocols/Tox/src/tox_profile.cpp +++ b/protocols/Tox/src/tox_profile.cpp @@ -111,13 +111,11 @@ void CToxProto::SaveToxProfile(Tox *tox) tox_get_savedata(tox, data);
pass_ptrA password(mir_utf8encodeW(pass_ptrW(getWStringA(TOX_SETTINGS_PASSWORD))));
- if (password && mir_strlen(password))
- {
+ if (password && mir_strlen(password)) {
TOX_ERR_ENCRYPTION coreEncryptError;
size_t encryptedSize = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
uint8_t *encryptedData = (uint8_t*)mir_calloc(encryptedSize);
- if (!tox_pass_encrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), encryptedData, &coreEncryptError))
- {
+ if (!tox_pass_encrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), encryptedData, &coreEncryptError)) {
debugLogA(__FUNCTION__": failed to encrypt tox profile");
mir_free(data);
mir_free(encryptedData);
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 4b97cbad9a..90e6ab8e47 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -91,6 +91,8 @@ private: void InitToxCore(Tox *tox);
void UninitToxCore(Tox *tox);
+ static void OnToxLog(Tox *tox, TOX_LOG_LEVEL level, const char *file, uint32_t line, const char *func, const char *message, void *user_data);
+
// tox bootstrap
void BootstrapUdpNode(Tox *tox, const char *address, int port, const char *pubKey);
void BootstrapTcpRelay(Tox *tox, const char *address, int port, const char *pubKey);
diff --git a/protocols/Tox/src/version.h b/protocols/Tox/src/version.h index 4789f2f861..2ea42089b9 100644 --- a/protocols/Tox/src/version.h +++ b/protocols/Tox/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 3
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>
|