summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_network.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2016-04-28 16:42:53 +0000
committerAlexander Lantsev <aunsane@gmail.com>2016-04-28 16:42:53 +0000
commit9fa8edc73b6687bbc0f43743b872af83d4d06759 (patch)
tree148f4807922cf6e3d2814df0747494b3cece6f87 /protocols/Tox/src/tox_network.cpp
parentcdd6bf525f77553ed7b30794f24b37dc42f0e434 (diff)
Tox: updating tox nodes from https://nodes.tox.chat/json
git-svn-id: http://svn.miranda-ng.org/main/trunk@16790 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_network.cpp')
-rw-r--r--protocols/Tox/src/tox_network.cpp66
1 files changed, 32 insertions, 34 deletions
diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp
index 65934e533a..1090b75e0c 100644
--- a/protocols/Tox/src/tox_network.cpp
+++ b/protocols/Tox/src/tox_network.cpp
@@ -45,44 +45,14 @@ void CToxProto::BootstrapNodesFromDb(bool isIPv6)
}
}
-void CToxProto::BootstrapNodesFromIni(bool isIPv6)
-{
- if (IsFileExists((TCHAR*)VARST(_T(TOX_INI_PATH))))
- {
- char fileName[MAX_PATH];
- mir_strcpy(fileName, VARS(TOX_INI_PATH));
-
- char *section, sections[MAX_PATH], value[MAX_PATH];
- GetPrivateProfileSectionNamesA(sections, _countof(sections), fileName);
- section = sections;
- while (*section != NULL)
- {
- if (strstr(section, TOX_SETTINGS_NODE_PREFIX) == section)
- {
- GetPrivateProfileStringA(section, "IPv4", NULL, value, _countof(value), fileName);
- ptrA address(mir_strdup(value));
- int port = GetPrivateProfileIntA(section, "Port", 33445, fileName);
- GetPrivateProfileStringA(section, "PubKey", NULL, value, _countof(value), fileName);
- ptrA pubKey(mir_strdup(value));
- BootstrapNode(address, port, pubKey);
- if (isIPv6)
- {
- GetPrivateProfileStringA(section, "IPv6", NULL, value, _countof(value), fileName);
- address = mir_strdup(value);
- BootstrapNode(address, port, pubKey);
- }
- }
- section += mir_strlen(section) + 1;
- }
- }
-}
-
void CToxProto::BootstrapNodesFromJson(bool isIPv6)
{
char *json = NULL;
ptrT path(mir_tstrdup((TCHAR*)VARST(_T(TOX_JSON_PATH))));
- // todo: download from https://nodes.tox.chat/json
+
+ if (!IsFileExists(path))
+ UpdateNodes();
if (IsFileExists(path))
{
@@ -127,10 +97,38 @@ void CToxProto::BootstrapNodes()
logger->Log(__FUNCTION__": bootstraping DHT");
bool isIPv6 = getBool("EnableIPv6", 0);
BootstrapNodesFromDb(isIPv6);
- BootstrapNodesFromIni(isIPv6);
BootstrapNodesFromJson(isIPv6);
}
+void CToxProto::UpdateNodes()
+{
+ ptrT path(mir_tstrdup((TCHAR*)VARST(_T(TOX_JSON_PATH))));
+
+ if (!IsFileExists(path))
+ {
+ HANDLE hProfile = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (hProfile == NULL)
+ {
+ logger->Log(__FUNCTION__": failed to create tox.json");
+ return;
+ }
+ CloseHandle(hProfile);
+ }
+
+ HttpRequest request(REQUEST_GET, "https://nodes.tox.chat/json");
+ NLHR_PTR response(request.Send(hNetlib));
+
+ if (response->resultCode == 200 && response->pData)
+ {
+ FILE *hFile = _tfopen(path, _T("w"));
+ if (hFile)
+ {
+ fwrite(response->pData, sizeof(char), response->dataLength, hFile);
+ fclose(hFile);
+ }
+ }
+}
+
void CToxProto::TryConnect()
{
if (toxThread != NULL)