diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-02-19 20:12:41 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-02-19 20:12:41 +0000 |
commit | da6afd3553ac4e189071efbffb27cc0c9c951dff (patch) | |
tree | 8c80e5c10d25a0e17c9c57e484657a0a10f40c49 /protocols | |
parent | de728ef47ad30243f2be6a02c77762859ec9b3e3 (diff) |
Tox:
- twiked connection algorithm
- added ability to load nodes from ini automatically
git-svn-id: http://svn.miranda-ng.org/main/trunk@12202 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Tox/docs/tox.ini | 108 | ||||
-rw-r--r-- | protocols/Tox/docs/tox_nodes.ini (renamed from protocols/Tox/docs/autoexec_tox_nodes.ini) | 0 | ||||
-rw-r--r-- | protocols/Tox/src/common.h | 14 | ||||
-rw-r--r-- | protocols/Tox/src/tox_network.cpp | 124 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 2 |
5 files changed, 200 insertions, 48 deletions
diff --git a/protocols/Tox/docs/tox.ini b/protocols/Tox/docs/tox.ini new file mode 100644 index 0000000000..43ff1b23ff --- /dev/null +++ b/protocols/Tox/docs/tox.ini @@ -0,0 +1,108 @@ +[Node_0]
+IPv4=192.254.75.102
+IPv6=2607:5600:284::2
+PubKey=951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F
+Port=33445
+
+[Node_1]
+IPv4=144.76.60.215
+IPv6=2a01:4f8:191:64d6::1
+PubKey=04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F
+Port=33445
+
+[Node_2]
+IPv4=23.226.230.47
+IPv6=2604:180:1::3ded:b280
+PubKey=A09162D68618E742FFBCA1C2C70385E6679604B2D80EA6E84AD0996A1AC8A074
+Port=33445
+
+[Node_3]
+IPv4=178.62.125.224
+IPv6=2a03:b0c0:1:d0::178:6001
+PubKey=10B20C49ACBD968D7C80F2E8438F92EA51F189F4E70CFBBB2C2C8C799E97F03E
+Port=33445
+
+[Node_4]
+IPv4=178.21.112.187
+IPv6=2a02:2308::216:3eff:fe82:eaef
+PubKey=4B2C19E924972CB9B57732FB172F8A8604DE13EEDA2A6234E348983344B23057
+Port=33445
+
+[Node_5]
+IPv4=195.154.119.113
+IPv6=2001:bc8:3698:101::1
+PubKey=E398A69646B8CEACA9F0B84F553726C1C49270558C57DF5F3C368F05A7D71354
+Port=33445
+
+[Node_6]
+IPv4=192.210.149.121
+PubKey=F404ABAA1C99A9D37D61AB54898F56793E1DEF8BD46B1038B9D822E8460FAB67
+Port=33445
+
+[Node_7]
+IPv4=104.219.184.206
+PubKey=8CD087E31C67568103E8C2A28653337E90E6B8EDA0D765D57C6B5172B4F1F04C
+Port=443
+
+[Node_8]
+IPv4=76.191.23.96
+PubKey=93574A3FAB7D612FEA29FD8D67D3DD10DFD07A075A5D62E8AF3DD9F5D0932E11
+Port=33445
+
+[Node_9]
+IPv4=46.38.239.179
+PubKey=F5A1A38EFB6BD3C2C8AF8B10D85F0F89E931704D349F1D0720C3C4059AF2440A
+Port=33445
+
+[Node_10]
+IPv4=178.62.250.138
+IPv6=2a03:b0c0:2:d0::16:1
+PubKey=788236D34978D1D5BD822F0A5BEBD2C53C64CC31CD3149350EE27D4D9A2F9B6B
+Port=33445
+
+[Node_11]
+IPv4=78.225.128.39
+PubKey=7A2306BFBA665E5480AE59B31E116BE9C04DCEFE04D9FE25082316FA34B4DA0C
+Port=33445
+
+[Node_12]
+IPv4=130.133.110.14
+IPv6=2001:6f8:1c3c:babe::14:1
+PubKey=461FA3776EF0FA655F1A05477DF1B3B614F7D6B124F7DB1DD4FE3C08B03B640F
+Port=33445
+
+[Node_13]
+IPv4=104.167.101.29
+PubKey=5918AC3C06955962A75AD7DF4F80A5D7C34F7DB9E1498D2E0495DE35B3FE8A57
+Port=33445
+
+[Node_14]
+IPv4=195.154.109.148
+PubKey=391C96CB67AE893D4782B8E4495EB9D89CF1031F48460C06075AA8CE76D50A21
+Port=33445
+
+[Node_15]
+IPv4=192.3.173.88
+PubKey=3E1FFDEB667BFF549F619EC6737834762124F50A89C8D0DBF1DDF64A2DD6CD1B
+Port=33445
+
+[Node_16]
+IPv4=205.185.116.116
+PubKey=A179B09749AC826FF01F37A9613F6B57118AE014D4196A0E1105A98F93A54702
+Port=33445
+
+[Node_17]
+IPv4=198.98.51.198
+IPv6=2605:6400:1:fed5:22:45af:ec10:f329
+PubKey=1D5A5F2F5D6233058BF0259B09622FB40B482E4FA0931EB8FD3AB8E7BF7DAF6F
+Port=33445
+
+[Node_18]
+IPv4=80.232.246.79
+PubKey=0B8DCEAA7BDDC44BB11173F987CAE3566A2D7057D8DD3CC642BD472B9391002A
+Port=33445
+
+[Node_19]
+IPv4=108.61.165.198
+PubKey=8E7D0B859922EF569298B4D261A8CCB5FEA14FB91ED412A7603A585A25698832
+Port=33445
diff --git a/protocols/Tox/docs/autoexec_tox_nodes.ini b/protocols/Tox/docs/tox_nodes.ini index aaa452bb44..aaa452bb44 100644 --- a/protocols/Tox/docs/autoexec_tox_nodes.ini +++ b/protocols/Tox/docs/tox_nodes.ini diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h index 13aadf38aa..1d75169087 100644 --- a/protocols/Tox/src/common.h +++ b/protocols/Tox/src/common.h @@ -46,18 +46,22 @@ extern HINSTANCE g_hInstance; #define TOX_ERROR -1
+#define TOX_MAX_CONNECT_RETRIES 200
#define TOX_MAX_DISCONNECT_RETRIES 100
+#define TOX_INI_PATH "%miranda_path%\\Plugins\\tox.ini"
+
#define TOX_SETTINGS_ID "ToxID"
#define TOX_SETTINGS_DNS "DnsID"
#define TOX_SETTINGS_GROUP "DefaultGroup"
#define TOX_SETTINGS_AVATAR_HASH "AvatarHash"
-#define TOX_SETTINGS_NODE_IPV4 "Node_%d_IPv4"
-#define TOX_SETTINGS_NODE_IPV6 "Node_%d_IPv6"
-#define TOX_SETTINGS_NODE_PORT "Node_%d_Port"
-#define TOX_SETTINGS_NODE_PKEY "Node_%d_PubKey"
-#define TOX_SETTINGS_NODE_COUNT "NodeCount"
+#define TOX_SETTINGS_NODE_PREFIX "Node_"
+#define TOX_SETTINGS_NODE_IPV4 TOX_SETTINGS_NODE_PREFIX"%d_IPv4"
+#define TOX_SETTINGS_NODE_IPV6 TOX_SETTINGS_NODE_PREFIX"%d_IPv6"
+#define TOX_SETTINGS_NODE_PORT TOX_SETTINGS_NODE_PREFIX"%d_Port"
+#define TOX_SETTINGS_NODE_PKEY TOX_SETTINGS_NODE_PREFIX"%d_PubKey"
+#define TOX_SETTINGS_NODE_COUNT TOX_SETTINGS_NODE_PREFIX"Count"
#define TOX_DB_EVENT_TYPE_ACTION 10001
diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp index 588a41a8fc..dcc7f39153 100644 --- a/protocols/Tox/src/tox_network.cpp +++ b/protocols/Tox/src/tox_network.cpp @@ -5,23 +5,11 @@ bool CToxProto::IsOnline() return isConnected && m_iStatus > ID_STATUS_OFFLINE;
}
-void CToxProto::BootstrapNodes()
+int CToxProto::BootstrapNodesFromDb(bool isIPv6)
{
- debugLogA("CToxProto::BootstrapDht: bootstraping DHT");
-
- bool isIPv6 = !getBool("DisableIPv6", 0);
+ int nodesLoaded = 0;
int nodeCount = db_get_w(NULL, MODULE, TOX_SETTINGS_NODE_COUNT, 0);
- if (!nodeCount)
- {
- tox_bootstrap_from_address(
- tox, "192.254.75.102", 33445,
- ToxBinAddress("951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F"));
- if (isIPv6)
- tox_bootstrap_from_address(
- tox, "2607:5600:284::2", 33445,
- ToxBinAddress("951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F"));
- }
- else
+ if (nodeCount > 0)
{
char setting[MAX_PATH];
for (int i = 0; i < nodeCount; i++)
@@ -32,15 +20,71 @@ void CToxProto::BootstrapNodes() 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));
- tox_bootstrap_from_address(tox, address, port, ToxBinAddress(pubKey));
+ nodesLoaded += tox_bootstrap_from_address(tox, address, port, ToxBinAddress(pubKey));
if (isIPv6)
{
mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, i);
address = db_get_sa(NULL, MODULE, setting);
- tox_bootstrap_from_address(tox, address, port, ToxBinAddress(pubKey));
+ nodesLoaded += tox_bootstrap_from_address(tox, address, port, ToxBinAddress(pubKey));
}
}
}
+ return nodesLoaded;
+}
+
+int CToxProto::BootstrapNodesFromIni(bool isIPv6)
+{
+ int nodesLoaded = 0;
+ 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, SIZEOF(sections), fileName);
+ section = sections;
+ while (*section != NULL)
+ {
+ if (strstr(section, TOX_SETTINGS_NODE_PREFIX) == section)
+ {
+ GetPrivateProfileStringA(section, "IPv4", NULL, value, SIZEOF(value), fileName);
+ ptrA address(mir_strdup(value));
+ 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);
+ if (isIPv6)
+ {
+ GetPrivateProfileStringA(section, "IPv6", NULL, value, SIZEOF(value), fileName);
+ address = mir_strdup(value);
+ nodesLoaded += tox_bootstrap_from_address(tox, address, port, pubKey);
+ }
+ }
+ section += strlen(section) + 1;
+ }
+ }
+ return nodesLoaded;
+}
+
+void CToxProto::BootstrapNodes()
+{
+ debugLogA("CToxProto::BootstrapDht: bootstraping DHT");
+ bool isIPv6 = !getBool("DisableIPv6", 0);
+ int nodesLoaded =
+ BootstrapNodesFromDb(isIPv6) +
+ BootstrapNodesFromIni(isIPv6);
+ if (!nodesLoaded)
+ {
+ tox_bootstrap_from_address(
+ tox, "192.254.75.102", 33445,
+ ToxBinAddress("951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F"));
+ if (isIPv6)
+ {
+ tox_bootstrap_from_address(
+ tox, "2607:5600:284::2", 33445,
+ ToxBinAddress("951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F"));
+ }
+ }
}
void CToxProto::TryConnect()
@@ -57,14 +101,11 @@ void CToxProto::TryConnect() tox_set_user_status(tox, MirandaToToxStatus(m_iStatus));
debugLogA("CToxProto::PollingThread: changing status from %i to %i", ID_STATUS_CONNECTING, m_iDesiredStatus);
}
- else
+ else if (m_iStatus++ > TOX_MAX_CONNECT_RETRIES)
{
- if (m_iStatus++ > MAX_CONNECT_RETRIES)
- {
- SetStatus(ID_STATUS_OFFLINE);
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, LOGINERR_NONETWORK);
- debugLogA("CToxProto::PollingThread: failed to connect to DHT");
- }
+ SetStatus(ID_STATUS_OFFLINE);
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, LOGINERR_NONETWORK);
+ debugLogA("CToxProto::PollingThread: failed to connect to DHT");
}
}
@@ -72,32 +113,29 @@ void CToxProto::CheckConnection(int &retriesCount) {
if (!isConnected)
{
- debugLogA("CToxProto::CheckConnection: lost connection with DHT");
TryConnect();
}
+ else if (tox_isconnected(tox))
+ {
+ if (retriesCount < TOX_MAX_DISCONNECT_RETRIES)
+ {
+ debugLogA("CToxProto::CheckConnection: restored connection with DHT");
+ retriesCount = TOX_MAX_DISCONNECT_RETRIES;
+ }
+ }
else
{
- if (tox_isconnected(tox))
+ if (retriesCount == TOX_MAX_DISCONNECT_RETRIES - 10)
{
- if (retriesCount < TOX_MAX_DISCONNECT_RETRIES)
- {
- debugLogA("CToxProto::CheckConnection: restored connection with DHT");
- retriesCount = TOX_MAX_DISCONNECT_RETRIES;
- }
+ debugLogA("CToxProto::CheckConnection: lost connection with DHT");
+ retriesCount--;
+ BootstrapNodes();
}
- else
+ else if (!(--retriesCount))
{
- if (retriesCount == TOX_MAX_DISCONNECT_RETRIES)
- {
- retriesCount --;
- BootstrapNodes();
- }
- else if (!(--retriesCount))
- {
- isConnected = false;
- debugLogA("CToxProto::CheckConnection: disconnected from DHT");
- SetStatus(ID_STATUS_OFFLINE);
- }
+ isConnected = false;
+ debugLogA("CToxProto::CheckConnection: disconnected from DHT");
+ SetStatus(ID_STATUS_OFFLINE);
}
}
}
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 2dfec2ba12..047969eca2 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -91,6 +91,8 @@ private: // tox network
bool IsOnline();
+ int BootstrapNodesFromDb(bool isIPv6);
+ int BootstrapNodesFromIni(bool isIPv6);
void BootstrapNodes();
void TryConnect();
void CheckConnection(int &retriesCount);
|