summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_network.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2016-04-28 13:14:07 +0000
committerAlexander Lantsev <aunsane@gmail.com>2016-04-28 13:14:07 +0000
commit71dc907c4f7bac0cb099a3006e14b88842065e9a (patch)
treec574a893a688e8c4b7603d7c1f197f83582ab204 /protocols/Tox/src/tox_network.cpp
parent57efb887b79a79dca57e940aa1976dbf9b2bde31 (diff)
Tox: loading nodes from json
git-svn-id: http://svn.miranda-ng.org/main/trunk@16788 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_network.cpp')
-rw-r--r--protocols/Tox/src/tox_network.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp
index d3a88056b7..65934e533a 100644
--- a/protocols/Tox/src/tox_network.cpp
+++ b/protocols/Tox/src/tox_network.cpp
@@ -77,12 +77,58 @@ void CToxProto::BootstrapNodesFromIni(bool isIPv6)
}
}
+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))
+ {
+ FILE *hFile = _tfopen(path, L"r");
+ if (hFile != NULL)
+ {
+ _fseeki64(hFile, 0, SEEK_END);
+ size_t size = _ftelli64(hFile);
+ json = (char*)mir_calloc(size);
+ rewind(hFile);
+ fread(json, sizeof(char), size, hFile);
+ fclose(hFile);
+ }
+ }
+
+ if (json)
+ {
+ JSONNode root = JSONNode::parse(json);
+ if (!root.empty())
+ {
+ JSONNode nodes = root.at("nodes").as_array();
+ for (size_t i = 0; i < nodes.size(); i++)
+ {
+ JSONNode node = nodes[i];
+
+ JSONNode address = node.at("ipv4");
+ int port = node.at("port").as_int();
+ JSONNode pubKey = node.at("public_key");
+ BootstrapNode(address.as_string().c_str(), port, pubKey.as_string().c_str());
+ if (isIPv6)
+ {
+ address = node.at("ipv6");
+ BootstrapNode(address.as_string().c_str(), port, pubKey.as_string().c_str());
+ }
+ }
+ }
+ }
+}
+
void CToxProto::BootstrapNodes()
{
logger->Log(__FUNCTION__": bootstraping DHT");
bool isIPv6 = getBool("EnableIPv6", 0);
BootstrapNodesFromDb(isIPv6);
BootstrapNodesFromIni(isIPv6);
+ BootstrapNodesFromJson(isIPv6);
}
void CToxProto::TryConnect()