summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_account.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-08-10 14:20:09 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-08-10 14:20:09 +0000
commitb3a63d4e727b8552f8cf2b321cc68d2631ef3179 (patch)
treea533d09af6f41f06a383fb9b703dabc09d7b92d7 /protocols/Tox/src/tox_account.cpp
parent254f7c0601c1972e016e0afb7989b27c9e432239 (diff)
Tox: refactoring
git-svn-id: http://svn.miranda-ng.org/main/trunk@10144 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_account.cpp')
-rw-r--r--protocols/Tox/src/tox_account.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp
new file mode 100644
index 0000000000..9c59965bc7
--- /dev/null
+++ b/protocols/Tox/src/tox_account.cpp
@@ -0,0 +1,63 @@
+#include "common.h"
+#include "tox_bootstrap.h"
+
+void CToxProto::DoBootstrap()
+{
+ static int j = 0;
+ int i = 0;
+ while (i < 2)
+ {
+ struct bootstrap_node *d = &bootstrap_nodes[j % SIZEOF(bootstrap_nodes)];
+ tox_bootstrap_from_address(tox, d->address, TOX_ENABLE_IPV6_DEFAULT, d->port, d->key);
+ i++; j++;
+ }
+}
+
+void CToxProto::DoTox()
+{
+ uint32_t interval = 1000;
+ {
+ //mir_cslock lock(tox_lock);
+
+ tox_do(tox);
+ interval = tox_do_interval(tox);
+ }
+ Sleep(interval);
+}
+
+void CToxProto::PollingThread(void*)
+{
+ debugLogA("CToxProto::PollingThread: entering");
+
+ while (!isTerminated)
+ {
+ DoTox();
+ }
+
+ debugLogA("CToxProto::PollingThread: leaving");
+}
+
+void CToxProto::ConnectionThread(void*)
+{
+ debugLogA("CToxProto::ConnectionThread: entering");
+
+ while (!isTerminated && !isConnected)
+ {
+ DoBootstrap();
+
+ if (tox_isconnected(tox))
+ {
+ isConnected = true;
+ break;
+ }
+
+ DoTox();
+ }
+
+ if (!isTerminated && isConnected)
+ {
+ poolingThread = ForkThreadEx(&CToxProto::PollingThread, 0, NULL);
+ }
+
+ debugLogA("CToxProto::ConnectionThread: leaving");
+} \ No newline at end of file