From 950baa43331a67928e6459b00d4aab0e7356a7e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=92=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Thu, 18 Feb 2016 16:00:08 +0300 Subject: [PATCH] adding bootstrap --- src/tox.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/tox.py b/src/tox.py index d26fecb..7e0b570 100644 --- a/src/tox.py +++ b/src/tox.py @@ -65,7 +65,7 @@ class Tox(object): # creating tox object tox_err = c_int() self.libtoxcore.tox_new.restype = POINTER(c_void_p) - self._tox_pointer = self.libtoxcore.tox_new(self.tox_options, tox_err) + self._tox_pointer = self.libtoxcore.tox_new(self.tox_options, addressof(tox_err)) if tox_err == TOX_ERR_NEW['TOX_ERR_NEW_NULL']: raise ArgumentError('One of the arguments to the function was NULL when it was not expected.') elif tox_err == TOX_ERR_NEW['TOX_ERR_NEW_MALLOC']: @@ -101,6 +101,20 @@ class Tox(object): self.libtoxcore.tox_get_savedata(self._tox_pointer, savedata) return savedata + def bootstrap(self, address, port, public_key): + tox_err_bootstrap = c_int() + result = self.libtoxcore.tox_bootstrap(self._tox_pointer, c_char_p(address), c_uint16(port), + c_char_p(public_key), addressof(tox_err_bootstrap)) + if tox_err_bootstrap == TOX_ERR_BOOTSTRAP['TOX_ERR_BOOTSTRAP_OK']: + return bool(result) + elif tox_err_bootstrap == TOX_ERR_BOOTSTRAP['TOX_ERR_BOOTSTRAP_NULL']: + raise ArgumentError('One of the arguments to the function was NULL when it was not expected.') + elif tox_err_bootstrap == TOX_ERR_BOOTSTRAP['TOX_ERR_BOOTSTRAP_BAD_HOST']: + raise ArgumentError('The address could not be resolved to an IP ' + 'address, or the IP address passed was invalid.') + elif tox_err_bootstrap == TOX_ERR_BOOTSTRAP['TOX_ERR_BOOTSTRAP_BAD_PORT']: + raise ArgumentError('The port passed was invalid. The valid port range is (1, 65535).') + def __del__(self): self.libtoxcore.tox_kill(self._tox_pointer) self.libtoxcore.tox_options_free(self.tox_options)