/* Generated by Cython 0.29.32 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": [],
        "name": "btdht.dht",
        "sources": [
            "btdht/dht.pyx"
        ]
    },
    "module_name": "btdht.dht"
}
END: Cython Metadata */

#ifndef PY_SSIZE_T_CLEAN
#define PY_SSIZE_T_CLEAN
#endif /* PY_SSIZE_T_CLEAN */
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
    #error Cython requires Python 2.6+ or Python 3.3+.
#else
#define CYTHON_ABI "0_29_32"
#define CYTHON_HEX_VERSION 0x001D20F0
#define CYTHON_FUTURE_DIVISION 0
#include <stddef.h>
#ifndef offsetof
  #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#define __PYX_COMMA ,
#ifndef HAVE_LONG_LONG
  #if PY_VERSION_HEX >= 0x02070000
    #define HAVE_LONG_LONG
  #endif
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
  #define CYTHON_COMPILING_IN_PYPY 1
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_NOGIL 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #if PY_VERSION_HEX < 0x03050000
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #undef CYTHON_AVOID_BORROWED_REFS
  #define CYTHON_AVOID_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC (PYPY_VERSION_HEX >= 0x07030900)
  #endif
#elif defined(PYSTON_VERSION)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 1
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_NOGIL 0
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #undef CYTHON_USE_ASYNC_SLOTS
  #define CYTHON_USE_ASYNC_SLOTS 0
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 0
  #endif
#elif defined(PY_NOGIL)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_NOGIL 1
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #ifndef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT 1
  #endif
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE 1
  #endif
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
  #define CYTHON_COMPILING_IN_NOGIL 0
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYTYPE_LOOKUP
    #define CYTHON_USE_PYTYPE_LOOKUP 0
  #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
    #define CYTHON_USE_PYTYPE_LOOKUP 1
  #endif
  #if PY_MAJOR_VERSION < 3
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYLONG_INTERNALS
    #define CYTHON_USE_PYLONG_INTERNALS 0
  #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
    #define CYTHON_USE_PYLONG_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_PYLIST_INTERNALS
    #define CYTHON_USE_PYLIST_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #if PY_VERSION_HEX < 0x030300F0 || PY_VERSION_HEX >= 0x030B00A2
    #undef CYTHON_USE_UNICODE_WRITER
    #define CYTHON_USE_UNICODE_WRITER 0
  #elif !defined(CYTHON_USE_UNICODE_WRITER)
    #define CYTHON_USE_UNICODE_WRITER 1
  #endif
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #if PY_VERSION_HEX >= 0x030B00A4
    #undef CYTHON_FAST_THREAD_STATE
    #define CYTHON_FAST_THREAD_STATE 0
  #elif !defined(CYTHON_FAST_THREAD_STATE)
    #define CYTHON_FAST_THREAD_STATE 1
  #endif
  #ifndef CYTHON_FAST_PYCALL
    #define CYTHON_FAST_PYCALL (PY_VERSION_HEX < 0x030A0000)
  #endif
  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000)
  #endif
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
  #endif
  #ifndef CYTHON_USE_DICT_VERSIONS
    #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1)
  #endif
  #if PY_VERSION_HEX >= 0x030B00A4
    #undef CYTHON_USE_EXC_INFO_STACK
    #define CYTHON_USE_EXC_INFO_STACK 0
  #elif !defined(CYTHON_USE_EXC_INFO_STACK)
    #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3)
  #endif
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 1
  #endif
#endif
#if !defined(CYTHON_FAST_PYCCALL)
#define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
#endif
#if CYTHON_USE_PYLONG_INTERNALS
  #if PY_MAJOR_VERSION < 3
    #include "longintrepr.h"
  #endif
  #undef SHIFT
  #undef BASE
  #undef MASK
  #ifdef SIZEOF_VOID_P
    enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
  #endif
#endif
#ifndef __has_attribute
  #define __has_attribute(x) 0
#endif
#ifndef __has_cpp_attribute
  #define __has_cpp_attribute(x) 0
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_MAYBE_UNUSED_VAR
#  if defined(__cplusplus)
     template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
#  else
#    define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
#  endif
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
#ifdef _MSC_VER
    #ifndef _MSC_STDINT_H_
        #if _MSC_VER < 1300
           typedef unsigned char     uint8_t;
           typedef unsigned int      uint32_t;
        #else
           typedef unsigned __int8   uint8_t;
           typedef unsigned __int32  uint32_t;
        #endif
    #endif
#else
   #include <stdint.h>
#endif
#ifndef CYTHON_FALLTHROUGH
  #if defined(__cplusplus) && __cplusplus >= 201103L
    #if __has_cpp_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH [[fallthrough]]
    #elif __has_cpp_attribute(clang::fallthrough)
      #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
    #elif __has_cpp_attribute(gnu::fallthrough)
      #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
    #endif
  #endif
  #ifndef CYTHON_FALLTHROUGH
    #if __has_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
    #else
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
  #if defined(__clang__ ) && defined(__apple_build_version__)
    #if __apple_build_version__ < 7000000
      #undef  CYTHON_FALLTHROUGH
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
#endif

#ifndef CYTHON_INLINE
  #if defined(__clang__)
    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  #elif defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif

#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  #define Py_OptimizeFlag 0
#endif
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyClass_Type
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_DefaultClassType PyType_Type
#if PY_VERSION_HEX >= 0x030B00A1
    static CYTHON_INLINE PyCodeObject* __Pyx_PyCode_New(int a, int k, int l, int s, int f,
                                                    PyObject *code, PyObject *c, PyObject* n, PyObject *v,
                                                    PyObject *fv, PyObject *cell, PyObject* fn,
                                                    PyObject *name, int fline, PyObject *lnos) {
        PyObject *kwds=NULL, *argcount=NULL, *posonlyargcount=NULL, *kwonlyargcount=NULL;
        PyObject *nlocals=NULL, *stacksize=NULL, *flags=NULL, *replace=NULL, *call_result=NULL, *empty=NULL;
        const char *fn_cstr=NULL;
        const char *name_cstr=NULL;
        PyCodeObject* co=NULL;
        PyObject *type, *value, *traceback;
        PyErr_Fetch(&type, &value, &traceback);
        if (!(kwds=PyDict_New())) goto end;
        if (!(argcount=PyLong_FromLong(a))) goto end;
        if (PyDict_SetItemString(kwds, "co_argcount", argcount) != 0) goto end;
        if (!(posonlyargcount=PyLong_FromLong(0))) goto end;
        if (PyDict_SetItemString(kwds, "co_posonlyargcount", posonlyargcount) != 0) goto end;
        if (!(kwonlyargcount=PyLong_FromLong(k))) goto end;
        if (PyDict_SetItemString(kwds, "co_kwonlyargcount", kwonlyargcount) != 0) goto end;
        if (!(nlocals=PyLong_FromLong(l))) goto end;
        if (PyDict_SetItemString(kwds, "co_nlocals", nlocals) != 0) goto end;
        if (!(stacksize=PyLong_FromLong(s))) goto end;
        if (PyDict_SetItemString(kwds, "co_stacksize", stacksize) != 0) goto end;
        if (!(flags=PyLong_FromLong(f))) goto end;
        if (PyDict_SetItemString(kwds, "co_flags", flags) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_code", code) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_consts", c) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_names", n) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_varnames", v) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_freevars", fv) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_cellvars", cell) != 0) goto end;
        if (PyDict_SetItemString(kwds, "co_linetable", lnos) != 0) goto end;
        if (!(fn_cstr=PyUnicode_AsUTF8AndSize(fn, NULL))) goto end;
        if (!(name_cstr=PyUnicode_AsUTF8AndSize(name, NULL))) goto end;
        if (!(co = PyCode_NewEmpty(fn_cstr, name_cstr, fline))) goto end;
        if (!(replace = PyObject_GetAttrString((PyObject*)co, "replace"))) goto cleanup_code_too;
        if (!(empty = PyTuple_New(0))) goto cleanup_code_too; // unfortunately __pyx_empty_tuple isn't available here
        if (!(call_result = PyObject_Call(replace, empty, kwds))) goto cleanup_code_too;
        Py_XDECREF((PyObject*)co);
        co = (PyCodeObject*)call_result;
        call_result = NULL;
        if (0) {
            cleanup_code_too:
            Py_XDECREF((PyObject*)co);
            co = NULL;
        }
        end:
        Py_XDECREF(kwds);
        Py_XDECREF(argcount);
        Py_XDECREF(posonlyargcount);
        Py_XDECREF(kwonlyargcount);
        Py_XDECREF(nlocals);
        Py_XDECREF(stacksize);
        Py_XDECREF(replace);
        Py_XDECREF(call_result);
        Py_XDECREF(empty);
        if (type) {
            PyErr_Restore(type, value, traceback);
        }
        return co;
    }
#else
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#endif
  #define __Pyx_DefaultClassType PyType_Type
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
  #define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#ifndef METH_STACKLESS
  #define METH_STACKLESS 0
#endif
#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
  #ifndef METH_FASTCALL
     #define METH_FASTCALL 0x80
  #endif
  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
  typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
                                                          Py_ssize_t nargs, PyObject *kwnames);
#else
  #define __Pyx_PyCFunctionFast _PyCFunctionFast
  #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
#endif
#if CYTHON_FAST_PYCCALL
#define __Pyx_PyFastCFunction_Check(func)\
    ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)))))
#else
#define __Pyx_PyFastCFunction_Check(func) 0
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  #define PyObject_Malloc(s)   PyMem_Malloc(s)
  #define PyObject_Free(p)     PyMem_Free(p)
  #define PyObject_Realloc(p)  PyMem_Realloc(p)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1
  #define PyMem_RawMalloc(n)           PyMem_Malloc(n)
  #define PyMem_RawRealloc(p, n)       PyMem_Realloc(p, n)
  #define PyMem_RawFree(p)             PyMem_Free(p)
#endif
#if CYTHON_COMPILING_IN_PYSTON
  #define __Pyx_PyCode_HasFreeVars(co)  PyCode_HasFreeVars(co)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
#else
  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
#endif
#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#elif PY_VERSION_HEX >= 0x03060000
  #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
#elif PY_VERSION_HEX >= 0x03000000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#else
  #define __Pyx_PyThreadState_Current _PyThreadState_Current
#endif
#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
#include "pythread.h"
#define Py_tss_NEEDS_INIT 0
typedef int Py_tss_t;
static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
  *key = PyThread_create_key();
  return 0;
}
static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
  Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
  *key = Py_tss_NEEDS_INIT;
  return key;
}
static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
  PyObject_Free(key);
}
static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
  return *key != Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
  PyThread_delete_key(*key);
  *key = Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
  return PyThread_set_key_value(*key, value);
}
static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
  return PyThread_get_key_value(*key);
}
#endif
#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
#define __Pyx_PyDict_NewPresized(n)  ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
#else
#define __Pyx_PyDict_NewPresized(n)  PyDict_New()
#endif
#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
#define __Pyx_PyDict_GetItemStr(dict, name)  _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
#else
#define __Pyx_PyDict_GetItemStr(dict, name)  PyDict_GetItem(dict, name)
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #if defined(PyUnicode_IS_READY)
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #else
  #define __Pyx_PyUnicode_READY(op)       (0)
  #endif
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   PyUnicode_MAX_CHAR_VALUE(u)
  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
  #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE)
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length))
  #else
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
  #endif
  #else
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_LENGTH(u))
  #endif
#else
  #define CYTHON_PEP393_ENABLED 0
  #define PyUnicode_1BYTE_KIND  1
  #define PyUnicode_2BYTE_KIND  2
  #define PyUnicode_4BYTE_KIND  4
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  #define PyByteArray_Check(obj)  PyObject_TypeCheck(obj, &PyByteArray_Type)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  #define PyObject_ASCII(o)            PyObject_Repr(o)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#ifndef PyObject_Unicode
  #define PyObject_Unicode             PyObject_Str
#endif
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#if PY_VERSION_HEX >= 0x030900A4
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
#else
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
#endif
#if CYTHON_ASSUME_SAFE_MACROS
  #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
#else
  #define __Pyx_PySequence_SIZE(seq)  PySequence_Size(seq)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define PyNumber_Int                 PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   __Pyx_PyIndex_AsHash_t
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   __Pyx_PyIndex_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#if CYTHON_USE_ASYNC_SLOTS
  #if PY_VERSION_HEX >= 0x030500B1
    #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
    #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  #else
    #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  #endif
#else
  #define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef __Pyx_PyAsyncMethodsStruct
    typedef struct {
        unaryfunc am_await;
        unaryfunc am_aiter;
        unaryfunc am_anext;
    } __Pyx_PyAsyncMethodsStruct;
#endif

#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS)
  #if !defined(_USE_MATH_DEFINES)
    #define _USE_MATH_DEFINES
  #endif
#endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif
#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
#define __Pyx_truncl trunc
#else
#define __Pyx_truncl truncl
#endif

#define __PYX_MARK_ERR_POS(f_index, lineno) \
    { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
#define __PYX_ERR(f_index, lineno, Ln_error) \
    { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }

#ifndef __PYX_EXTERN_C
  #ifdef __cplusplus
    #define __PYX_EXTERN_C extern "C"
  #else
    #define __PYX_EXTERN_C extern
  #endif
#endif

#define __PYX_HAVE__btdht__dht
#define __PYX_HAVE_API__btdht__dht
/* Early includes */
#include <string.h>
#include <stdlib.h>
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
#define CYTHON_WITHOUT_ASSERTIONS
#endif

typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
    (sizeof(type) < sizeof(Py_ssize_t))  ||\
    (sizeof(type) > sizeof(Py_ssize_t) &&\
          likely(v < (type)PY_SSIZE_T_MAX ||\
                 v == (type)PY_SSIZE_T_MAX)  &&\
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
                                v == (type)PY_SSIZE_T_MIN)))  ||\
    (sizeof(type) == sizeof(Py_ssize_t) &&\
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                               v == (type)PY_SSIZE_T_MAX)))  )
static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
    return (size_t) i < (size_t) limit;
}
#if defined (__cplusplus) && __cplusplus >= 201103L
    #include <cstdlib>
    #define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) labs(value)
#elif defined (_MSC_VER)
    #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(value)
#elif defined (__GNUC__)
    #define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
#if PY_MAJOR_VERSION < 3
    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyBytes_AsWritableString(s)     ((char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableSString(s)    ((signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableUString(s)    ((unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsString(s)     ((const char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsSString(s)    ((const signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsUString(s)    ((const unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyObject_AsWritableString(s)    ((char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsSString(s)    ((const signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((const unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
#define __Pyx_PySequence_Tuple(obj)\
    (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*);
#if CYTHON_ASSUME_SAFE_MACROS
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (!ascii_chars_u) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
        Py_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


/* Test for GCC > 2.95 */
#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  #define likely(x)   __builtin_expect(!!(x), 1)
  #define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */
static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }

static PyObject *__pyx_m = NULL;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_cython_runtime = NULL;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static PyObject *__pyx_empty_unicode;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;


static const char *__pyx_f[] = {
  "btdht/dht.pyx",
  "stringsource",
  "btdht/krcp.pxd",
};
/* NoFastGil.proto */
#define __Pyx_PyGILState_Ensure PyGILState_Ensure
#define __Pyx_PyGILState_Release PyGILState_Release
#define __Pyx_FastGIL_Remember()
#define __Pyx_FastGIL_Forget()
#define __Pyx_FastGilFuncInit()

/* ForceInitThreads.proto */
#ifndef __PYX_FORCE_INIT_THREADS
  #define __PYX_FORCE_INIT_THREADS 0
#endif


/*--- Type declarations ---*/
struct __pyx_obj_5btdht_4krcp_BMessage;
struct __pyx_obj_5btdht_3dht_DHT_BASE;
struct __pyx_obj_5btdht_3dht_Node;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_8_genexpr;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge;
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr;
struct __pyx_opt_args_5btdht_3dht_8DHT_BASE__set_transaction_id;

/* "btdht/dht.pyx":997
 * 
 * 
 *     cdef void _set_transaction_id(self, BMessage query, int id_len=6):             # <<<<<<<<<<<<<<
 *         """
 *             Set the transaction id (key t of the dictionnary) on a query
 */
struct __pyx_opt_args_5btdht_3dht_8DHT_BASE__set_transaction_id {
  int __pyx_n;
  int id_len;
};

/* "krcp.pxd":3
 * cdef long _decode_int(char* data, int *i, int max, long long *myint) nogil except -1
 * cdef int _decode_string(char* data, int* i, int max, int* j) nogil except -1
 * cdef class BMessage:             # <<<<<<<<<<<<<<
 *     cdef char* _y
 *     cdef int has_y
 */
struct __pyx_obj_5btdht_4krcp_BMessage {
  PyObject_HEAD
  struct __pyx_vtabstruct_5btdht_4krcp_BMessage *__pyx_vtab;
  char *_y;
  int has_y;
  int y_len;
  char *_t;
  int has_t;
  int t_len;
  char *_q;
  int has_q;
  int q_len;
  char *_v;
  int has_v;
  int v_len;
  int r;
  int a;
  int e;
  int _errno;
  char *_errmsg;
  int errmsg_len;
  char *id;
  int has_id;
  char *target;
  int has_target;
  char *info_hash;
  int has_info_hash;
  int implied_port;
  int has_implied_port;
  int port;
  int has_port;
  char *token;
  int has_token;
  int token_len;
  char *nodes;
  int has_nodes;
  int nodes_len;
  char **values;
  int values_nb;
  int has_values;
  char *encoded;
  int encoded_len;
  int encoded_uptodate;
  int debug;
  PyObject *addr_addr_3;
  PyObject *addr_addr_2;
  int addr_port;
  int failed;
  char *failed_msg;
};


/* "btdht/dht.pyx":53
 * 
 * 
 * cdef class DHT_BASE:             # <<<<<<<<<<<<<<
 *     """
 *     The DHT base class
 */
struct __pyx_obj_5btdht_3dht_DHT_BASE {
  PyObject_HEAD
  struct __pyx_vtabstruct_5btdht_3dht_DHT_BASE *__pyx_vtab;
  char _myid[20];
};


/* "btdht/dht.pyx":1561
 * 
 * 
 * cdef class Node:             # <<<<<<<<<<<<<<
 *     """
 *         A node of the dht in the routing table
 */
struct __pyx_obj_5btdht_3dht_Node {
  PyObject_HEAD
  char _id[20];
  char _ip[4];
  int _port;
  int _last_response;
  int _last_query;
  int _failed;
};


/* "btdht/dht.pyx":493
 * 
 * 
 *     def announce_peer(self, info_hash, port, delay=0, block=True):             # <<<<<<<<<<<<<<
 *         """
 *             Announce that the ``info_hash`` is available on ``port`` to the K closest nodes from
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer {
  PyObject_HEAD
  PyObject *__pyx_v_info_hash;
  PyObject *__pyx_v_port;
  struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self;
};


/* "btdht/dht.pyx":623
 *             return peers
 * 
 *     def _get_peers_closest_loop(self):             # <<<<<<<<<<<<<<
 *         """
 *             Weigthless thread dealing we the :attr:`_get_peer_loop_list` heapq. Its execution
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop {
  PyObject_HEAD
  PyObject *__pyx_v___closest;
  PyObject *__pyx_v__closest;
  PyObject *__pyx_v_callback;
  PyObject *__pyx_v_closest;
  PyObject *__pyx_v_hash;
  PyObject *__pyx_v_limit;
  PyObject *__pyx_v_node;
  PyObject *__pyx_v_nodes;
  PyObject *__pyx_v_on_stop;
  struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self;
  PyObject *__pyx_v_stop;
  PyObject *__pyx_v_tosleep;
  PyObject *__pyx_v_tried_nodes;
  PyObject *__pyx_v_ts;
  PyObject *__pyx_v_typ;
};


/* "btdht/dht.pyx":781
 *                 return self._get_peers(info_hash, compact, errno=errno+1)
 * 
 *     def get_closest_nodes(self, id, compact=False):             # <<<<<<<<<<<<<<
 *         """
 *         return the current K closest nodes from ``id`` present in the routing table (K = 8)
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes {
  PyObject_HEAD
  PyObject *__pyx_v_l;
};


/* "btdht/dht.pyx":805
 *         l = list(self.root.get_closest_nodes(id))
 *         if compact:
 *             return b"".join(n.compact_info() for n in l)             # <<<<<<<<<<<<<<
 *         else:
 *             return list(self.root.get_closest_nodes(id))
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr {
  PyObject_HEAD
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes *__pyx_outer_scope;
  PyObject *__pyx_v_n;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
};


/* "btdht/dht.pyx":1167
 *         return bool(nodes)
 * 
 *     def _routine(self):             # <<<<<<<<<<<<<<
 *         """
 *             Weigthless thread performing some routine (boostraping, building the routing table,
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine {
  PyObject_HEAD
  PyObject *__pyx_v_bads;
  PyObject *__pyx_v_delta;
  PyObject *__pyx_v_goods;
  PyObject *__pyx_v_in_s;
  PyObject *__pyx_v_next_routine;
  PyObject *__pyx_v_nodes;
  PyObject *__pyx_v_now;
  PyObject *__pyx_v_out_s;
  struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self;
};


/* "btdht/dht.pyx":1478
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")
 * 
 *     def _process_loop(self):             # <<<<<<<<<<<<<<
 *         """function lauch by the thread processing messages"""
 *         yield 1
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop {
  PyObject_HEAD
  PyObject *__pyx_v_query;
  PyObject *__pyx_v_response;
  struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self;
};


/* "btdht/dht.pyx":2302
 *             pass
 * 
 *     def _merge_loop(self):             # <<<<<<<<<<<<<<
 *         """Weigthless thread handling the merge of the routing table"""
 *         yield 0
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop {
  PyObject_HEAD
  PyObject *__pyx_v_i;
  PyObject *__pyx_v_next_full_merge;
  PyObject *__pyx_v_next_merge;
  PyObject *__pyx_v_self;
  PyObject *__pyx_v_stack;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "btdht/dht.pyx":2398
 *             self._last_debug_time = time.time()
 * 
 *     def _routine(self):             # <<<<<<<<<<<<<<
 *         """
 *             Weigthless thread perfoming routine on the routing table like performing quering to
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine {
  PyObject_HEAD
  PyObject *__pyx_v_bucket;
  PyObject *__pyx_v_dht;
  PyObject *__pyx_v_dhts;
  Py_ssize_t __pyx_v_dhts_last_elt;
  PyObject *__pyx_v_i;
  PyObject *__pyx_v_id;
  PyObject *__pyx_v_key;
  PyObject *__pyx_v_last_explore_tree;
  PyObject *__pyx_v_node;
  PyObject *__pyx_v_nodes;
  PyObject *__pyx_v_now;
  PyObject *__pyx_v_questionable;
  PyObject *__pyx_v_self;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "btdht/dht.pyx":2449
 *     def empty(self):
 *         """Empty the routing table, deleting all buckets"""
 *         self.trie = datrie.Trie("".join(chr(i) for i in range(256)))             # <<<<<<<<<<<<<<
 *         self.trie[u""]=Bucket()
 * 
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_8_genexpr {
  PyObject_HEAD
  long __pyx_v_i;
  long __pyx_t_0;
};


/* "btdht/dht.pyx":2515
 *                     raise
 * 
 *     def get_closest_nodes(self, id, bad=False, errno=0):             # <<<<<<<<<<<<<<
 *         """
 *             Return the K closest nodes from ``id`` in the routing table
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes {
  PyObject_HEAD
  PyObject *__pyx_v_bad;
  PyObject *__pyx_v_id;
  PyObject *__pyx_v_prefix;
  PyObject *__pyx_v_self;
  PyObject *__pyx_v_suffix;
};


/* "btdht/dht.pyx":2530
 *         try:
 *             id = ID(id)
 *             nodes = set(n for n in self.find(id) if not n.bad)             # <<<<<<<<<<<<<<
 *             try:
 *                 prefix = self.trie.longest_prefix(utils.id_to_longid(id.value))
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr {
  PyObject_HEAD
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *__pyx_outer_scope;
  PyObject *__pyx_v_n;
};


/* "btdht/dht.pyx":2538
 *                 prefix = prefix[:-1]
 *                 for suffix in self.trie.suffixes(prefix):
 *                     nodes = nodes.union(n for n in self.trie[prefix + suffix] if bad or not n.bad)             # <<<<<<<<<<<<<<
 *             nodes = list(nodes)
 *             nodes.sort(key=lambda x:id ^ x.id)
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr {
  PyObject_HEAD
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *__pyx_outer_scope;
  PyObject *__pyx_v_n;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "btdht/dht.pyx":2611
 *         self.need_merge = True
 * 
 *     def _merge(self, stack=None):             # <<<<<<<<<<<<<<
 *         """
 *             Perform a merge of the routing table. If ``stack`` is provided, only a partial merge
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge {
  PyObject_HEAD
  PyObject *__pyx_v_bucket;
  PyObject *__pyx_v_bucket0;
  PyObject *__pyx_v_bucket1;
  int __pyx_v_full_merge;
  PyObject *__pyx_v_genexpr;
  PyObject *__pyx_v_i;
  PyObject *__pyx_v_id;
  PyObject *__pyx_v_j;
  PyObject *__pyx_v_key;
  PyObject *__pyx_v_nodes_before;
  PyObject *__pyx_v_prefix0;
  PyObject *__pyx_v_prefix1;
  PyObject *__pyx_v_self;
  PyObject *__pyx_v_stack;
  PyObject *__pyx_v_started;
  int __pyx_v_to_merge;
};


/* "btdht/dht.pyx":2677
 * 
 *         if full_merge:
 *             self._heigth = max(len(k) for k in self.trie.keys()) + 1             # <<<<<<<<<<<<<<
 *             self.debug(
 *                 1,
 */
struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr {
  PyObject_HEAD
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge *__pyx_outer_scope;
  PyObject *__pyx_v_k;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};



/* "krcp.pxd":3
 * cdef long _decode_int(char* data, int *i, int max, long long *myint) nogil except -1
 * cdef int _decode_string(char* data, int* i, int max, int* j) nogil except -1
 * cdef class BMessage:             # <<<<<<<<<<<<<<
 *     cdef char* _y
 *     cdef int has_y
 */

struct __pyx_vtabstruct_5btdht_4krcp_BMessage {
  int (*set_r)(struct __pyx_obj_5btdht_4krcp_BMessage *, int);
  int (*set_a)(struct __pyx_obj_5btdht_4krcp_BMessage *, int);
  int (*set_e)(struct __pyx_obj_5btdht_4krcp_BMessage *, int);
  int (*set_t)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int);
  void (*del_t)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*set_v)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int);
  void (*del_v)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*set_y)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int);
  void (*del_y)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*set_q)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int);
  void (*del_q)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*set_id)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int);
  void (*del_id)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*set_target)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int);
  void (*del_target)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*set_info_hash)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int);
  void (*del_info_hash)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  void (*del_implied_port)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*set_implied_port)(struct __pyx_obj_5btdht_4krcp_BMessage *, int);
  int (*set_port)(struct __pyx_obj_5btdht_4krcp_BMessage *, int);
  void (*del_port)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*set_token)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int);
  void (*del_token)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*set_nodes)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int);
  int (*del_nodes)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*set_values)(struct __pyx_obj_5btdht_4krcp_BMessage *, char **, int);
  void (*del_values)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*set_errmsg)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int);
  void (*del_errmsg)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*set_errno)(struct __pyx_obj_5btdht_4krcp_BMessage *, int);
  void (*del_encoded)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*_encode_values)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int *, int);
  int (*_encode_secondary_dict)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int *, int);
  int (*_encode_error)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int *, int);
  int (*_encode_main_dict)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int *, int);
  int (*_encode)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*_encode_len)(struct __pyx_obj_5btdht_4krcp_BMessage *);
  int (*_decode_error)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int *, int);
  int (*_decode_dict_elm)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int *, int);
  int (*_decode_values)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int *, int);
  int (*_decode_dict)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int *, int);
  int (*_decode)(struct __pyx_obj_5btdht_4krcp_BMessage *, char *, int *, int);
};
static struct __pyx_vtabstruct_5btdht_4krcp_BMessage *__pyx_vtabptr_5btdht_4krcp_BMessage;


/* "btdht/dht.pyx":53
 * 
 * 
 * cdef class DHT_BASE:             # <<<<<<<<<<<<<<
 *     """
 *     The DHT base class
 */

struct __pyx_vtabstruct_5btdht_3dht_DHT_BASE {
  void (*_set_transaction_id)(struct __pyx_obj_5btdht_3dht_DHT_BASE *, struct __pyx_obj_5btdht_4krcp_BMessage *, struct __pyx_opt_args_5btdht_3dht_8DHT_BASE__set_transaction_id *__pyx_optional_args);
};
static struct __pyx_vtabstruct_5btdht_3dht_DHT_BASE *__pyx_vtabptr_5btdht_3dht_DHT_BASE;

/* --- Runtime support code (head) --- */
/* Refnanny.proto */
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          if (acquire_gil) {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
              PyGILState_Release(__pyx_gilstate_save);\
          } else {\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #define __Pyx_RefNannyFinishContext()\
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif
#define __Pyx_XDECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_XDECREF(tmp);\
    } while (0)
#define __Pyx_DECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_DECREF(tmp);\
    } while (0)
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

/* PyObjectGetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

/* GetBuiltinName.proto */
static PyObject *__Pyx_GetBuiltinName(PyObject *name);

/* RaiseDoubleKeywords.proto */
static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);

/* ParseKeywords.proto */
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
    const char* function_name);

/* RaiseArgTupleInvalid.proto */
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);

/* PyObjectCall.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
#else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif

/* PyThreadStateGet.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign  __pyx_tstate = __Pyx_PyThreadState_Current;
#define __Pyx_PyErr_Occurred()  __pyx_tstate->curexc_type
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#define __Pyx_PyErr_Occurred()  PyErr_Occurred()
#endif

/* PyErrFetchRestore.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
#define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
#else
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#endif
#else
#define __Pyx_PyErr_Clear() PyErr_Clear()
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestoreInState(tstate, type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchInState(tstate, type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
#endif

/* RaiseException.proto */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);

/* PyDictVersioning.proto */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
#define __PYX_DICT_VERSION_INIT  ((PY_UINT64_T) -1)
#define __PYX_GET_DICT_VERSION(dict)  (((PyDictObject*)(dict))->ma_version_tag)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
    (version_var) = __PYX_GET_DICT_VERSION(dict);\
    (cache_var) = (value);
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
        (VAR) = __pyx_dict_cached_value;\
    } else {\
        (VAR) = __pyx_dict_cached_value = (LOOKUP);\
        __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
    }\
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj);
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj);
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version);
#else
#define __PYX_GET_DICT_VERSION(dict)  (0)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP)  (VAR) = (LOOKUP);
#endif

/* GetModuleGlobalName.proto */
#if CYTHON_USE_DICT_VERSIONS
#define __Pyx_GetModuleGlobalName(var, name)  {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\
        (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\
        __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
}
#define __Pyx_GetModuleGlobalNameUncached(var, name)  {\
    PY_UINT64_T __pyx_dict_version;\
    PyObject *__pyx_dict_cached_value;\
    (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
}
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value);
#else
#define __Pyx_GetModuleGlobalName(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
#define __Pyx_GetModuleGlobalNameUncached(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name);
#endif

/* PyCFunctionFastCall.proto */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
#else
#define __Pyx_PyCFunction_FastCall(func, args, nargs)  (assert(0), NULL)
#endif

/* PyFunctionFastCall.proto */
#if CYTHON_FAST_PYCALL
#define __Pyx_PyFunction_FastCall(func, args, nargs)\
    __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs);
#else
#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
#endif
#define __Pyx_BUILD_ASSERT_EXPR(cond)\
    (sizeof(char [1 - 2*!(cond)]) - 1)
#ifndef Py_MEMBER_SIZE
#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
#endif
#if CYTHON_FAST_PYCALL
  static size_t __pyx_pyframe_localsplus_offset = 0;
  #include "frameobject.h"
#if PY_VERSION_HEX >= 0x030b00a6
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
  #define __Pxy_PyFrame_Initialize_Offsets()\
    ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\
     (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
  #define __Pyx_PyFrame_GetLocalsplus(frame)\
    (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
#endif // CYTHON_FAST_PYCALL
#endif

/* PyObjectCall2Args.proto */
static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2);

/* PyObjectCallMethO.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

/* PyObjectCallOneArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

/* PyObjectCallNoArg.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif

/* PyObjectSetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL)
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value);
#else
#define __Pyx_PyObject_DelAttrStr(o,n)   PyObject_DelAttr(o,n)
#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
#endif

/* ListCompAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len)) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        __Pyx_SET_SIZE(list, len + 1);
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
#endif

/* PyObjectLookupSpecial.proto */
#if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name) {
    PyObject *res;
    PyTypeObject *tp = Py_TYPE(obj);
#if PY_MAJOR_VERSION < 3
    if (unlikely(PyInstance_Check(obj)))
        return __Pyx_PyObject_GetAttrStr(obj, attr_name);
#endif
    res = _PyType_Lookup(tp, attr_name);
    if (likely(res)) {
        descrgetfunc f = Py_TYPE(res)->tp_descr_get;
        if (!f) {
            Py_INCREF(res);
        } else {
            res = f(res, obj, (PyObject *)tp);
        }
    } else {
        PyErr_SetObject(PyExc_AttributeError, attr_name);
    }
    return res;
}
#else
#define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n)
#endif

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* GetTopmostException.proto */
#if CYTHON_USE_EXC_INFO_STACK
static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate);
#endif

/* SaveResetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
#else
#define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
#define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
#endif

/* GetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* PyErrExceptionMatches.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
#else
#define __Pyx_PyErr_ExceptionMatches(err)  PyErr_ExceptionMatches(err)
#endif

/* SliceObject.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
        PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
        int has_cstart, int has_cstop, int wraparound);

/* GetItemInt.proto */
#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
               __Pyx_GetItemInt_Generic(o, to_py_func(i))))
#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck);

/* FastTypeChecks.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
#else
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
#endif
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)

/* None.proto */
static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname);

/* FetchCommonType.proto */
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);

/* CythonFunctionShared.proto */
#define __Pyx_CyFunction_USED 1
#define __Pyx_CYFUNCTION_STATICMETHOD  0x01
#define __Pyx_CYFUNCTION_CLASSMETHOD   0x02
#define __Pyx_CYFUNCTION_CCLASS        0x04
#define __Pyx_CyFunction_GetClosure(f)\
    (((__pyx_CyFunctionObject *) (f))->func_closure)
#define __Pyx_CyFunction_GetClassObj(f)\
    (((__pyx_CyFunctionObject *) (f))->func_classobj)
#define __Pyx_CyFunction_Defaults(type, f)\
    ((type *)(((__pyx_CyFunctionObject *) (f))->defaults))
#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\
    ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g)
typedef struct {
    PyCFunctionObject func;
#if PY_VERSION_HEX < 0x030500A0
    PyObject *func_weakreflist;
#endif
    PyObject *func_dict;
    PyObject *func_name;
    PyObject *func_qualname;
    PyObject *func_doc;
    PyObject *func_globals;
    PyObject *func_code;
    PyObject *func_closure;
    PyObject *func_classobj;
    void *defaults;
    int defaults_pyobjects;
    size_t defaults_size;  // used by FusedFunction for copying defaults
    int flags;
    PyObject *defaults_tuple;
    PyObject *defaults_kwdict;
    PyObject *(*defaults_getter)(PyObject *);
    PyObject *func_annotations;
} __pyx_CyFunctionObject;
static PyTypeObject *__pyx_CyFunctionType = 0;
#define __Pyx_CyFunction_Check(obj)  (__Pyx_TypeCheck(obj, __pyx_CyFunctionType))
static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject* op, PyMethodDef *ml,
                                      int flags, PyObject* qualname,
                                      PyObject *self,
                                      PyObject *module, PyObject *globals,
                                      PyObject* code);
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m,
                                                         size_t size,
                                                         int pyobjects);
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m,
                                                            PyObject *tuple);
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m,
                                                             PyObject *dict);
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m,
                                                              PyObject *dict);
static int __pyx_CyFunction_init(void);

/* CythonFunction.proto */
static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml,
                                      int flags, PyObject* qualname,
                                      PyObject *closure,
                                      PyObject *module, PyObject *globals,
                                      PyObject* code);

/* PySequenceContains.proto */
static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) {
    int result = PySequence_Contains(seq, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

/* ObjectGetItem.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key);
#else
#define __Pyx_PyObject_GetItem(obj, key)  PyObject_GetItem(obj, key)
#endif

/* IncludeStringH.proto */
#include <string.h>

/* BytesEquals.proto */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals);

/* UnicodeEquals.proto */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals);

/* StrEquals.proto */
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals
#else
#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
#endif

/* RaiseTooManyValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

/* RaiseNeedMoreValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

/* IterFinish.proto */
static CYTHON_INLINE int __Pyx_IterFinish(void);

/* UnpackItemEndCheck.proto */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);

/* SliceTupleAndList.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
#else
#define __Pyx_PyList_GetSlice(seq, start, stop)   PySequence_GetSlice(seq, start, stop)
#define __Pyx_PyTuple_GetSlice(seq, start, stop)  PySequence_GetSlice(seq, start, stop)
#endif

/* None.proto */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);

/* StringJoin.proto */
#if PY_MAJOR_VERSION < 3
#define __Pyx_PyString_Join __Pyx_PyBytes_Join
#define __Pyx_PyBaseString_Join(s, v) (PyUnicode_CheckExact(s) ? PyUnicode_Join(s, v) : __Pyx_PyBytes_Join(s, v))
#else
#define __Pyx_PyString_Join PyUnicode_Join
#define __Pyx_PyBaseString_Join PyUnicode_Join
#endif
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION < 3
    #define __Pyx_PyBytes_Join _PyString_Join
    #else
    #define __Pyx_PyBytes_Join _PyBytes_Join
    #endif
#else
static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values);
#endif

/* PyIntCompare.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, long inplace);

/* PyIntCompare.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, long intval, long inplace);

/* WriteUnraisableException.proto */
static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback, int nogil);

/* ListAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        __Pyx_SET_SIZE(list, len + 1);
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif

/* PyObjectGetMethod.proto */
static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);

/* PyObjectCallMethod1.proto */
static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);

/* append.proto */
static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x);

/* DictGetItem.proto */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key);
#define __Pyx_PyObject_Dict_GetItem(obj, name)\
    (likely(PyDict_CheckExact(obj)) ?\
     __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name))
#else
#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#define __Pyx_PyObject_Dict_GetItem(obj, name)  PyObject_GetItem(obj, name)
#endif

/* GetAttr.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *);

/* GetAttr3.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *);

/* ArgTypeTest.proto */
#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\
    ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\
        __Pyx__ArgTypeTest(obj, type, name, exact))
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact);

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_FloorDivideObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_FloorDivideObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceFloorDivide(op1, op2) : PyNumber_FloorDivide(op1, op2))
#endif

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_RemainderObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_RemainderObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceRemainder(op1, op2) : PyNumber_Remainder(op1, op2))
#endif

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
#endif

/* PyObjectCallMethod0.proto */
static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name);

/* pop.proto */
static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L);
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L);
#define __Pyx_PyObject_Pop(L) (likely(PyList_CheckExact(L)) ?\
    __Pyx_PyList_Pop(L) : __Pyx__PyObject_Pop(L))
#else
#define __Pyx_PyList_Pop(L)  __Pyx__PyObject_Pop(L)
#define __Pyx_PyObject_Pop(L)  __Pyx__PyObject_Pop(L)
#endif

/* UnpackUnboundCMethod.proto */
typedef struct {
    PyObject *type;
    PyObject **method_name;
    PyCFunction func;
    PyObject *method;
    int flag;
} __Pyx_CachedCFunction;

/* CallUnboundCMethod0.proto */
static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CallUnboundCMethod0(cfunc, self)\
    (likely((cfunc)->func) ?\
        (likely((cfunc)->flag == METH_NOARGS) ?  (*((cfunc)->func))(self, NULL) :\
         (PY_VERSION_HEX >= 0x030600B1 && likely((cfunc)->flag == METH_FASTCALL) ?\
            (PY_VERSION_HEX >= 0x030700A0 ?\
                (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0) :\
                (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL)) :\
          (PY_VERSION_HEX >= 0x030700A0 && (cfunc)->flag == (METH_FASTCALL | METH_KEYWORDS) ?\
            (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL) :\
            (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ?  ((*(PyCFunctionWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, __pyx_empty_tuple, NULL)) :\
               ((cfunc)->flag == METH_VARARGS ?  (*((cfunc)->func))(self, __pyx_empty_tuple) :\
               __Pyx__CallUnboundCMethod0(cfunc, self)))))) :\
        __Pyx__CallUnboundCMethod0(cfunc, self))
#else
#define __Pyx_CallUnboundCMethod0(cfunc, self)  __Pyx__CallUnboundCMethod0(cfunc, self)
#endif

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_XorObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_XorObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceXor(op1, op2) : PyNumber_Xor(op1, op2))
#endif

/* Import.proto */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);

/* ImportFrom.proto */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);

/* HasAttr.proto */
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *);

/* PyObject_GenericGetAttrNoDict.proto */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr
#endif

/* PyObject_GenericGetAttr.proto */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr
#endif

/* SetVTable.proto */
static int __Pyx_SetVtable(PyObject *dict, void *vtable);

/* PyObjectGetAttrStrNoError.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name);

/* SetupReduce.proto */
static int __Pyx_setup_reduce(PyObject* type_obj);

/* TypeImport.proto */
#ifndef __PYX_HAVE_RT_ImportType_proto
#define __PYX_HAVE_RT_ImportType_proto
enum __Pyx_ImportType_CheckSize {
   __Pyx_ImportType_CheckSize_Error = 0,
   __Pyx_ImportType_CheckSize_Warn = 1,
   __Pyx_ImportType_CheckSize_Ignore = 2
};
static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size);
#endif

/* GetVTable.proto */
static void* __Pyx_GetVtable(PyObject *dict);

/* ClassMethod.proto */
#include "descrobject.h"
static CYTHON_UNUSED PyObject* __Pyx_Method_ClassMethod(PyObject *method);

/* GetNameInClass.proto */
#define __Pyx_GetNameInClass(var, nmspace, name)  (var) = __Pyx__GetNameInClass(nmspace, name)
static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name);

/* CalculateMetaclass.proto */
static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases);

/* SetNameInClass.proto */
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
#define __Pyx_SetNameInClass(ns, name, value)\
    (likely(PyDict_CheckExact(ns)) ? _PyDict_SetItem_KnownHash(ns, name, value, ((PyASCIIObject *) name)->hash) : PyObject_SetItem(ns, name, value))
#elif CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_SetNameInClass(ns, name, value)\
    (likely(PyDict_CheckExact(ns)) ? PyDict_SetItem(ns, name, value) : PyObject_SetItem(ns, name, value))
#else
#define __Pyx_SetNameInClass(ns, name, value)  PyObject_SetItem(ns, name, value)
#endif

/* Py3ClassCreate.proto */
static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname,
                                           PyObject *mkw, PyObject *modname, PyObject *doc);
static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict,
                                      PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass);

/* CLineInTraceback.proto */
#ifdef CYTHON_CLINE_IN_TRACEBACK
#define __Pyx_CLineForTraceback(tstate, c_line)  (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
#else
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
#endif

/* CodeObjectCache.proto */
typedef struct {
    PyCodeObject* code_object;
    int code_line;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
    int count;
    int max_count;
    __Pyx_CodeObjectCacheEntry* entries;
};
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static PyCodeObject *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);

/* AddTraceback.proto */
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename);

/* GCCDiagnostics.proto */
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#define __Pyx_HAS_GCC_DIAGNOSTIC
#endif

/* Print.proto */
static int __Pyx_Print(PyObject*, PyObject *, int);
#if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
static PyObject* __pyx_print = 0;
static PyObject* __pyx_print_kwargs = 0;
#endif

/* CIntFromPy.proto */
static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

/* PrintOne.proto */
static int __Pyx_PrintOne(PyObject* stream, PyObject *o);

/* SwapException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSwap(type, value, tb)  __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* CoroutineBase.proto */
typedef PyObject *(*__pyx_coroutine_body_t)(PyObject *, PyThreadState *, PyObject *);
#if CYTHON_USE_EXC_INFO_STACK
#define __Pyx_ExcInfoStruct  _PyErr_StackItem
#else
typedef struct {
    PyObject *exc_type;
    PyObject *exc_value;
    PyObject *exc_traceback;
} __Pyx_ExcInfoStruct;
#endif
typedef struct {
    PyObject_HEAD
    __pyx_coroutine_body_t body;
    PyObject *closure;
    __Pyx_ExcInfoStruct gi_exc_state;
    PyObject *gi_weakreflist;
    PyObject *classobj;
    PyObject *yieldfrom;
    PyObject *gi_name;
    PyObject *gi_qualname;
    PyObject *gi_modulename;
    PyObject *gi_code;
    PyObject *gi_frame;
    int resume_label;
    char is_running;
} __pyx_CoroutineObject;
static __pyx_CoroutineObject *__Pyx__Coroutine_New(
    PyTypeObject *type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
    PyObject *name, PyObject *qualname, PyObject *module_name);
static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit(
            __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
            PyObject *name, PyObject *qualname, PyObject *module_name);
static CYTHON_INLINE void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *self);
static int __Pyx_Coroutine_clear(PyObject *self);
static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value);
static PyObject *__Pyx_Coroutine_Close(PyObject *self);
static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args);
#if CYTHON_USE_EXC_INFO_STACK
#define __Pyx_Coroutine_SwapException(self)
#define __Pyx_Coroutine_ResetAndClearException(self)  __Pyx_Coroutine_ExceptionClear(&(self)->gi_exc_state)
#else
#define __Pyx_Coroutine_SwapException(self) {\
    __Pyx_ExceptionSwap(&(self)->gi_exc_state.exc_type, &(self)->gi_exc_state.exc_value, &(self)->gi_exc_state.exc_traceback);\
    __Pyx_Coroutine_ResetFrameBackpointer(&(self)->gi_exc_state);\
    }
#define __Pyx_Coroutine_ResetAndClearException(self) {\
    __Pyx_ExceptionReset((self)->gi_exc_state.exc_type, (self)->gi_exc_state.exc_value, (self)->gi_exc_state.exc_traceback);\
    (self)->gi_exc_state.exc_type = (self)->gi_exc_state.exc_value = (self)->gi_exc_state.exc_traceback = NULL;\
    }
#endif
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\
    __Pyx_PyGen__FetchStopIterationValue(__pyx_tstate, pvalue)
#else
#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\
    __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, pvalue)
#endif
static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *tstate, PyObject **pvalue);
static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state);

/* PatchModuleWithCoroutine.proto */
static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code);

/* PatchGeneratorABC.proto */
static int __Pyx_patch_abc(void);

/* Generator.proto */
#define __Pyx_Generator_USED
static PyTypeObject *__pyx_GeneratorType = 0;
#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType)
#define __Pyx_Generator_New(body, code, closure, name, qualname, module_name)\
    __Pyx__Coroutine_New(__pyx_GeneratorType, body, code, closure, name, qualname, module_name)
static PyObject *__Pyx_Generator_Next(PyObject *self);
static int __pyx_Generator_init(void);

/* CheckBinaryVersion.proto */
static int __Pyx_check_binary_version(void);

/* InitStrings.proto */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);

static void __pyx_f_5btdht_3dht_8DHT_BASE__set_transaction_id(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, struct __pyx_obj_5btdht_4krcp_BMessage *__pyx_v_query, struct __pyx_opt_args_5btdht_3dht_8DHT_BASE__set_transaction_id *__pyx_optional_args); /* proto*/

/* Module declarations from 'libc.string' */

/* Module declarations from 'libc.stdlib' */

/* Module declarations from 'btdht.krcp' */
static PyTypeObject *__pyx_ptype_5btdht_4krcp_BMessage = 0;

/* Module declarations from 'btdht.dht' */
static PyTypeObject *__pyx_ptype_5btdht_3dht_DHT_BASE = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht_Node = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct__announce_peer = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct_3_genexpr = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct_4__routine = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct_5__process_loop = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct_6__merge_loop = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct_7__routine = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct_8_genexpr = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct_10_genexpr = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct_11_genexpr = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct_12__merge = 0;
static PyTypeObject *__pyx_ptype_5btdht_3dht___pyx_scope_struct_13_genexpr = 0;
static PyObject *__pyx_f_5btdht_3dht___pyx_unpickle_DHT_BASE__set_state(struct __pyx_obj_5btdht_3dht_DHT_BASE *, PyObject *); /*proto*/
static PyObject *__pyx_f_5btdht_3dht___pyx_unpickle_Node__set_state(struct __pyx_obj_5btdht_3dht_Node *, PyObject *); /*proto*/
static int __Pyx_carray_from_py_char(PyObject *, char *, Py_ssize_t); /*proto*/
#define __Pyx_MODULE_NAME "btdht.dht"
extern int __pyx_module_is_main_btdht__dht;
int __pyx_module_is_main_btdht__dht = 0;

/* Implementation of 'btdht.dht' */
static PyObject *__pyx_builtin_ImportError;
static PyObject *__pyx_builtin_property;
static PyObject *__pyx_builtin_object;
static PyObject *__pyx_builtin_RuntimeError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_open;
static PyObject *__pyx_builtin_IOError;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_all;
static PyObject *__pyx_builtin_any;
static PyObject *__pyx_builtin_AttributeError;
static PyObject *__pyx_builtin_KeyError;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_UnboundLocalError;
static PyObject *__pyx_builtin_IndexError;
static PyObject *__pyx_builtin_EnvironmentError;
static PyObject *__pyx_builtin_super;
static PyObject *__pyx_builtin_zip;
static PyObject *__pyx_builtin_chr;
static PyObject *__pyx_builtin_max;
static PyObject *__pyx_builtin_OverflowError;
static PyObject *__pyx_builtin_enumerate;
static const char __pyx_k_0[] = "0";
static const char __pyx_k_1[] = "1";
static const char __pyx_k_b[] = "b";
static const char __pyx_k_e[] = "e";
static const char __pyx_k_i[] = "i";
static const char __pyx_k_j[] = "j";
static const char __pyx_k_l[] = "l";
static const char __pyx_k_n[] = "n";
static const char __pyx_k_q[] = "q";
static const char __pyx_k_r[] = "r";
static const char __pyx_k_s[] = "s";
static const char __pyx_k_t[] = "t";
static const char __pyx_k_y[] = "y";
static const char __pyx_k_01[] = "01";
static const char __pyx_k_ID[] = "ID";
static const char __pyx_k_IN[] = "IN";
static const char __pyx_k__2[] = "";
static const char __pyx_k_b1[] = "b1";
static const char __pyx_k_b2[] = "b2";
static const char __pyx_k_eq[] = "__eq__";
static const char __pyx_k_id[] = "id";
static const char __pyx_k_ip[] = "ip";
static const char __pyx_k_lt[] = "__lt__";
static const char __pyx_k_os[] = "os";
static const char __pyx_k_rb[] = "rb";
static const char __pyx_k_rt[] = "rt";
static const char __pyx_k_wb[] = "wb";
static const char __pyx_k_4sH[] = "!4sH";
static const char __pyx_k_DHT[] = "DHT";
static const char __pyx_k__15[] = "_";
static const char __pyx_k__27[] = "\000\000\000\000";
static const char __pyx_k__28[] = "\000\000";
static const char __pyx_k__30[] = "\000";
static const char __pyx_k__70[] = "\n";
static const char __pyx_k_add[] = "add";
static const char __pyx_k_all[] = "all";
static const char __pyx_k_any[] = "any";
static const char __pyx_k_bad[] = "bad";
static const char __pyx_k_chr[] = "chr";
static const char __pyx_k_dht[] = "dht";
static const char __pyx_k_doc[] = "__doc__";
static const char __pyx_k_end[] = "end";
static const char __pyx_k_get[] = "get";
static const char __pyx_k_key[] = "key";
static const char __pyx_k_lvl[] = "lvl";
static const char __pyx_k_max[] = "max";
static const char __pyx_k_msg[] = "msg";
static const char __pyx_k_new[] = "__new__";
static const char __pyx_k_now[] = "now";
static const char __pyx_k_obj[] = "obj";
static const char __pyx_k_own[] = "own";
static const char __pyx_k_pop[] = "pop";
static const char __pyx_k_put[] = "put";
static const char __pyx_k_r_2[] = "%r";
static const char __pyx_k_r_r[] = "%r:%r";
static const char __pyx_k_six[] = "six";
static const char __pyx_k_sys[] = "sys";
static const char __pyx_k_tmp[] = "tmp";
static const char __pyx_k_typ[] = "typ";
static const char __pyx_k_zip[] = "zip";
static const char __pyx_k_Full[] = "Full";
static const char __pyx_k_Lock[] = "Lock";
static const char __pyx_k_Node[] = "Node";
static const char __pyx_k_Trie[] = "Trie";
static const char __pyx_k_addr[] = "addr";
static const char __pyx_k_args[] = "args";
static const char __pyx_k_bads[] = "bads";
static const char __pyx_k_bind[] = "bind";
static const char __pyx_k_char[] = "char";
static const char __pyx_k_dhts[] = "_dhts";
static const char __pyx_k_dict[] = "__dict__";
static const char __pyx_k_exit[] = "__exit__";
static const char __pyx_k_file[] = "file";
static const char __pyx_k_find[] = "find";
static const char __pyx_k_good[] = "good";
static const char __pyx_k_hash[] = "hash";
static const char __pyx_k_init[] = "init";
static const char __pyx_k_iter[] = "__iter__";
static const char __pyx_k_join[] = "join";
static const char __pyx_k_keys[] = "keys";
static const char __pyx_k_krcp[] = "krcp";
static const char __pyx_k_lock[] = "_lock";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_myid[] = "myid";
static const char __pyx_k_name[] = "__name__";
static const char __pyx_k_nbit[] = "nbit";
static const char __pyx_k_node[] = "node";
static const char __pyx_k_nset[] = "nset";
static const char __pyx_k_open[] = "open";
static const char __pyx_k_pack[] = "pack";
static const char __pyx_k_ping[] = "ping";
static const char __pyx_k_port[] = "port";
static const char __pyx_k_read[] = "read";
static const char __pyx_k_root[] = "root";
static const char __pyx_k_self[] = "self";
static const char __pyx_k_send[] = "send";
static const char __pyx_k_slot[] = "__slot__";
static const char __pyx_k_sock[] = "sock";
static const char __pyx_k_sort[] = "sort";
static const char __pyx_k_stop[] = "stop";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_time[] = "time";
static const char __pyx_k_trie[] = "trie";
static const char __pyx_k_Empty[] = "Empty";
static const char __pyx_k_Queue[] = "Queue";
static const char __pyx_k_block[] = "block";
static const char __pyx_k_class[] = "__class__";
static const char __pyx_k_clean[] = "clean";
static const char __pyx_k_close[] = "close";
static const char __pyx_k_debug[] = "debug";
static const char __pyx_k_delay[] = "delay";
static const char __pyx_k_empty[] = "empty";
static const char __pyx_k_enter[] = "__enter__";
static const char __pyx_k_errno[] = "errno";
static const char __pyx_k_error[] = "error";
static const char __pyx_k_fstop[] = "fstop";
static const char __pyx_k_goods[] = "goods";
static const char __pyx_k_heapq[] = "heapq";
static const char __pyx_k_items[] = "items";
static const char __pyx_k_limit[] = "limit";
static const char __pyx_k_merge[] = "_merge";
static const char __pyx_k_nflip[] = "nflip";
static const char __pyx_k_nodes[] = "nodes";
static const char __pyx_k_one_b[] = "one_b";
static const char __pyx_k_other[] = "other";
static const char __pyx_k_peers[] = "_peers";
static const char __pyx_k_print[] = "print";
static const char __pyx_k_query[] = "query";
static const char __pyx_k_queue[] = "queue";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_sleep[] = "sleep";
static const char __pyx_k_split[] = "split";
static const char __pyx_k_stack[] = "stack";
static const char __pyx_k_start[] = "start";
static const char __pyx_k_stats[] = "stats";
static const char __pyx_k_super[] = "super";
static const char __pyx_k_throw[] = "throw";
static const char __pyx_k_token[] = "token";
static const char __pyx_k_union[] = "union";
static const char __pyx_k_utils[] = "utils";
static const char __pyx_k_value[] = "value";
static const char __pyx_k_write[] = "write";
static const char __pyx_k_20s4sH[] = "!20s4sH";
static const char __pyx_k_BError[] = "BError";
static const char __pyx_k_Bucket[] = "Bucket";
static const char __pyx_k_RT_s_s[] = "RT%s:%s";
static const char __pyx_k_Thread[] = "Thread";
static const char __pyx_k_append[] = "append";
static const char __pyx_k_bucket[] = "bucket";
static const char __pyx_k_daemon[] = "daemon";
static const char __pyx_k_datrie[] = "datrie";
static const char __pyx_k_decode[] = "_decode";
static const char __pyx_k_dhts_2[] = "dhts";
static const char __pyx_k_encode[] = "encode";
static const char __pyx_k_errmsg[] = "errmsg";
static const char __pyx_k_exit_2[] = "exit";
static const char __pyx_k_extend[] = "extend";
static const char __pyx_k_failed[] = "failed";
static const char __pyx_k_hash_2[] = "__hash__";
static const char __pyx_k_heigth[] = "heigth";
static const char __pyx_k_id_end[] = "id_end";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_init_2[] = "__init__";
static const char __pyx_k_module[] = "__module__";
static const char __pyx_k_name_2[] = "name";
static const char __pyx_k_new_id[] = "new_id";
static const char __pyx_k_object[] = "object";
static const char __pyx_k_others[] = "others";
static const char __pyx_k_pickle[] = "pickle";
static const char __pyx_k_prefix[] = "prefix";
static const char __pyx_k_random[] = "random";
static const char __pyx_k_recv_r[] = "recv:%r";
static const char __pyx_k_reduce[] = "__reduce__";
static const char __pyx_k_remove[] = "remove";
static const char __pyx_k_select[] = "select";
static const char __pyx_k_sendto[] = "sendto";
static const char __pyx_k_socket[] = "socket";
static const char __pyx_k_stoped[] = "stoped";
static const char __pyx_k_struct[] = "struct";
static const char __pyx_k_suffix[] = "suffix";
static const char __pyx_k_target[] = "target";
static const char __pyx_k_unpack[] = "unpack";
static const char __pyx_k_update[] = "update";
static const char __pyx_k_values[] = "values";
static const char __pyx_k_zero_b[] = "zero_b";
static const char __pyx_k_zombie[] = "zombie";
static const char __pyx_k_0_0_0_0[] = "0.0.0.0";
static const char __pyx_k_AF_INET[] = "AF_INET";
static const char __pyx_k_IOError[] = "IOError";
static const char __pyx_k_add_dht[] = "add_dht";
static const char __pyx_k_b2a_hex[] = "b2a_hex";
static const char __pyx_k_bind_ip[] = "bind_ip";
static const char __pyx_k_bucket0[] = "bucket0";
static const char __pyx_k_bucket1[] = "bucket1";
static const char __pyx_k_clean_2[] = "_clean";
static const char __pyx_k_closest[] = "closest";
static const char __pyx_k_compact[] = "compact";
static const char __pyx_k_del_dht[] = "del_dht";
static const char __pyx_k_error_r[] = "error %r";
static const char __pyx_k_genexpr[] = "genexpr";
static const char __pyx_k_heappop[] = "heappop";
static const char __pyx_k_maxsize[] = "maxsize";
static const char __pyx_k_merge_2[] = "merge";
static const char __pyx_k_mytoken[] = "mytoken";
static const char __pyx_k_netaddr[] = "netaddr";
static const char __pyx_k_on_stop[] = "on_stop";
static const char __pyx_k_peers_2[] = "peers";
static const char __pyx_k_popitem[] = "popitem";
static const char __pyx_k_prefix0[] = "prefix0";
static const char __pyx_k_prefix1[] = "prefix1";
static const char __pyx_k_prepare[] = "__prepare__";
static const char __pyx_k_randint[] = "randint";
static const char __pyx_k_richcmp[] = "__richcmp__";
static const char __pyx_k_routine[] = "_routine";
static const char __pyx_k_shuffle[] = "shuffle";
static const char __pyx_k_started[] = "started";
static const char __pyx_k_stop_bg[] = "stop_bg";
static const char __pyx_k_threads[] = "threads";
static const char __pyx_k_to_send[] = "to_send";
static const char __pyx_k_urandom[] = "urandom";
static const char __pyx_k_DHT_BASE[] = "DHT_BASE";
static const char __pyx_k_KeyError[] = "KeyError";
static const char __pyx_k_MissingT[] = "MissingT";
static const char __pyx_k_Node_s_s[] = "Node: %s:%s";
static const char __pyx_k_NotFound[] = "NotFound";
static const char __pyx_k_add_peer[] = "_add_peer";
static const char __pyx_k_binascii[] = "binascii";
static const char __pyx_k_callback[] = "callback";
static const char __pyx_k_debuglvl[] = "debuglvl";
static const char __pyx_k_decode_2[] = "decode";
static const char __pyx_k_filename[] = "filename";
static const char __pyx_k_function[] = "function";
static const char __pyx_k_gaierror[] = "gaierror";
static const char __pyx_k_get_node[] = "get_node";
static const char __pyx_k_getstate[] = "__getstate__";
static const char __pyx_k_heappush[] = "heappush";
static const char __pyx_k_heigth_2[] = "_heigth";
static const char __pyx_k_id_start[] = "id_start";
static const char __pyx_k_is_alive[] = "is_alive";
static const char __pyx_k_last_msg[] = "last_msg";
static const char __pyx_k_max_node[] = "max_node";
static const char __pyx_k_max_size[] = "max_size";
static const char __pyx_k_old_node[] = "old_node";
static const char __pyx_k_on_error[] = "on_error";
static const char __pyx_k_property[] = "property";
static const char __pyx_k_pyx_type[] = "__pyx_type";
static const char __pyx_k_qualname[] = "__qualname__";
static const char __pyx_k_recvfrom[] = "recvfrom";
static const char __pyx_k_reduce_2[] = "reduce";
static const char __pyx_k_response[] = "response";
static const char __pyx_k_send_r_r[] = "send:%r %r";
static const char __pyx_k_setstate[] = "__setstate__";
static const char __pyx_k_sroutine[] = "%sroutine";
static const char __pyx_k_stoped_2[] = "_stoped";
static const char __pyx_k_suffixes[] = "suffixes";
static const char __pyx_k_to_bytes[] = "to_bytes";
static const char __pyx_k_to_merge[] = "_to_merge";
static const char __pyx_k_IPNetwork[] = "IPNetwork";
static const char __pyx_k_Scheduler[] = "Scheduler";
static const char __pyx_k_TypeError[] = "TypeError";
static const char __pyx_k_addresses[] = "addresses";
static const char __pyx_k_bind_port[] = "bind_port";
static const char __pyx_k_bootstarp[] = "bootstarp";
static const char __pyx_k_btdht_dht[] = "btdht.dht";
static const char __pyx_k_enumerate[] = "enumerate";
static const char __pyx_k_find_node[] = "find_node";
static const char __pyx_k_functools[] = "functools";
static const char __pyx_k_get_peers[] = "get_peers";
static const char __pyx_k_got_peers[] = "_got_peers";
static const char __pyx_k_id_length[] = "id_length";
static const char __pyx_k_inet_aton[] = "inet_aton";
static const char __pyx_k_inet_ntoa[] = "inet_ntoa";
static const char __pyx_k_info_hash[] = "info_hash";
static const char __pyx_k_iteritems[] = "iteritems";
static const char __pyx_k_metaclass[] = "__metaclass__";
static const char __pyx_k_print_exc[] = "print_exc";
static const char __pyx_k_pyx_state[] = "__pyx_state";
static const char __pyx_k_random_id[] = "random_id";
static const char __pyx_k_reduce_ex[] = "__reduce_ex__";
static const char __pyx_k_scheduler[] = "scheduler";
static const char __pyx_k_socket_in[] = "_socket_in";
static const char __pyx_k_split_ids[] = "_split_ids";
static const char __pyx_k_text_type[] = "text_type";
static const char __pyx_k_threading[] = "threading";
static const char __pyx_k_threads_2[] = "_threads";
static const char __pyx_k_traceback[] = "traceback";
static const char __pyx_k_BucketFull[] = "BucketFull";
static const char __pyx_k_Bucket_add[] = "Bucket.add";
static const char __pyx_k_Bucket_own[] = "Bucket.own";
static const char __pyx_k_FailToStop[] = "FailToStop";
static const char __pyx_k_IPPROTO_IP[] = "IPPROTO_IP";
static const char __pyx_k_IndexError[] = "IndexError";
static const char __pyx_k_SOCK_DGRAM[] = "SOCK_DGRAM";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_add_thread[] = "add_thread";
static const char __pyx_k_clean_long[] = "clean_long";
static const char __pyx_k_del_thread[] = "del_thread";
static const char __pyx_k_exceptions[] = "exceptions";
static const char __pyx_k_full_merge[] = "full_merge";
static const char __pyx_k_get_nowait[] = "get_nowait";
static const char __pyx_k_ignored_ip[] = "ignored_ip";
static const char __pyx_k_ip_in_nets[] = "ip_in_nets";
static const char __pyx_k_last_debug[] = "_last_debug";
static const char __pyx_k_last_query[] = "last_query";
static const char __pyx_k_long_clean[] = "_long_clean";
static const char __pyx_k_merge_loop[] = "_merge_loop";
static const char __pyx_k_need_merge[] = "need_merge";
static const char __pyx_k_next_merge[] = "next_merge";
static const char __pyx_k_put_nowait[] = "put_nowait";
static const char __pyx_k_pyx_result[] = "__pyx_result";
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static const char __pyx_k_recv_r_r_r[] = "recv:%r : (%r, %r)";
static const char __pyx_k_send_r_r_r[] = "send:%r %r %r";
static const char __pyx_k_setsockopt[] = "setsockopt";
static const char __pyx_k_socket_out[] = "_socket_out";
static const char __pyx_k_startswith[] = "startswith";
static const char __pyx_k_to_merge_2[] = "to_merge";
static const char __pyx_k_to_process[] = "_to_process";
static const char __pyx_k_to_refresh[] = "to_refresh";
static const char __pyx_k_Bucket___eq[] = "Bucket.__eq__";
static const char __pyx_k_Bucket___lt[] = "Bucket.__lt__";
static const char __pyx_k_DecodeError[] = "DecodeError";
static const char __pyx_k_ImportError[] = "ImportError";
static const char __pyx_k_OrderedDict[] = "OrderedDict";
static const char __pyx_k_PickleError[] = "PickleError";
static const char __pyx_k_ServerError[] = "ServerError";
static const char __pyx_k_build_table[] = "build_table";
static const char __pyx_k_collections[] = "collections";
static const char __pyx_k_defaultdict[] = "defaultdict";
static const char __pyx_k_get_peers_2[] = "_get_peers";
static const char __pyx_k_getsockname[] = "getsockname";
static const char __pyx_k_ignored_net[] = "ignored_net";
static const char __pyx_k_info_hash_2[] = "_info_hash";
static const char __pyx_k_init_socket[] = "init_socket";
static const char __pyx_k_on__s_query[] = "_on_%s_query";
static const char __pyx_k_release_dht[] = "release_dht";
static const char __pyx_k_root_heigth[] = "_root_heigth";
static const char __pyx_k_scheduler_2[] = "_scheduler";
static const char __pyx_k_setblocking[] = "setblocking";
static const char __pyx_k_to_schedule[] = "to_schedule";
static const char __pyx_k_update_node[] = "_update_node";
static const char __pyx_k_Bootstraping[] = "Bootstraping";
static const char __pyx_k_Bucket_merge[] = "Bucket.merge";
static const char __pyx_k_Bucket_split[] = "Bucket.split";
static const char __pyx_k_GenericError[] = "GenericError";
static const char __pyx_k_NoTokenError[] = "NoTokenError";
static const char __pyx_k_RT_s_routine[] = "RT%s:routine";
static const char __pyx_k_RoutingTable[] = "RoutingTable";
static const char __pyx_k_RuntimeError[] = "RuntimeError";
static const char __pyx_k_Wrong_Bucket[] = "Wrong Bucket";
static const char __pyx_k_compact_info[] = "compact_info";
static const char __pyx_k_id_to_longid[] = "id_to_longid";
static const char __pyx_k_implied_port[] = "implied_port";
static const char __pyx_k_last_changed[] = "last_changed";
static const char __pyx_k_last_msg_rep[] = "last_msg_rep";
static const char __pyx_k_nodes_before[] = "nodes_before";
static const char __pyx_k_process_loop[] = "_process_loop";
static const char __pyx_k_pyx_checksum[] = "__pyx_checksum";
static const char __pyx_k_questionable[] = "questionable";
static const char __pyx_k_register_dht[] = "register_dht";
static const char __pyx_k_socket_stats[] = "_socket_stats";
static const char __pyx_k_stringsource[] = "stringsource";
static const char __pyx_k_thread_alive[] = "thread_alive";
static const char __pyx_k_BucketNotFull[] = "BucketNotFull";
static const char __pyx_k_Bucket___hash[] = "Bucket.__hash__";
static const char __pyx_k_Bucket___init[] = "Bucket.__init__";
static const char __pyx_k_OverflowError[] = "OverflowError";
static const char __pyx_k_PollableQueue[] = "PollableQueue";
static const char __pyx_k_ProtocolError[] = "ProtocolError";
static const char __pyx_k_announce_peer[] = "announce_peer";
static const char __pyx_k_btdht_dht_pyx[] = "btdht/dht.pyx";
static const char __pyx_k_dht__s_status[] = "dht_%s.status";
static const char __pyx_k_dhts_last_elt[] = "dhts_last_elt";
static const char __pyx_k_last_response[] = "last_response";
static const char __pyx_k_obj_of_type_r[] = "obj of type %r";
static const char __pyx_k_on__s_query_2[] = "on_%s_query";
static const char __pyx_k_process_error[] = "_process_error";
static const char __pyx_k_process_query[] = "_process_query";
static const char __pyx_k_reduce_cython[] = "__reduce_cython__";
static const char __pyx_k_routing_table[] = "routing_table";
static const char __pyx_k_sprocess_loop[] = "%sprocess_loop";
static const char __pyx_k_AttributeError[] = "AttributeError";
static const char __pyx_k_IP_PMTUDISC_DO[] = "IP_PMTUDISC_DO";
static const char __pyx_k_longest_prefix[] = "longest_prefix";
static const char __pyx_k_on__s_response[] = "_on_%s_response";
static const char __pyx_k_threads_zombie[] = "_threads_zombie";
static const char __pyx_k_total_ordering[] = "total_ordering";
static const char __pyx_k_Already_started[] = "Already started";
static const char __pyx_k_Bucket_get_node[] = "Bucket.get_node";
static const char __pyx_k_IP_MTU_DISCOVER[] = "IP_MTU_DISCOVER";
static const char __pyx_k_RT_s_merge_loop[] = "RT%s:merge_loop";
static const char __pyx_k_last_debug_time[] = "_last_debug_time";
static const char __pyx_k_next_full_merge[] = "next_full_merge";
static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError";
static const char __pyx_k_release_torrent[] = "release_torrent";
static const char __pyx_k_setstate_cython[] = "__setstate_cython__";
static const char __pyx_k_start_scheduler[] = "start_scheduler";
static const char __pyx_k_Bucket_random_id[] = "Bucket.random_id";
static const char __pyx_k_ERROR_s_s_pour_r[] = "ERROR:%s:%s pour %r";
static const char __pyx_k_EnvironmentError[] = "EnvironmentError";
static const char __pyx_k_RoutingTable_add[] = "RoutingTable.add";
static const char __pyx_k_add_peer_queried[] = "_add_peer_queried";
static const char __pyx_k_get_peers_hash_s[] = "get peers hash %s";
static const char __pyx_k_grenade_genua_fr[] = "grenade.genua.fr";
static const char __pyx_k_on__s_response_2[] = "on_%s_response";
static const char __pyx_k_process_response[] = "_process_response";
static const char __pyx_k_register_torrent[] = "register_torrent";
static const char __pyx_k_transaction_type[] = "transaction_type";
static const char __pyx_k_Bucket_not_Full_r[] = "Bucket not Full %r";
static const char __pyx_k_Bucket_to_refresh[] = "Bucket.to_refresh";
static const char __pyx_k_DHT_BASE__routine[] = "DHT_BASE._routine";
static const char __pyx_k_Hash_s_find_nodes[] = "Hash %s find nodes";
static const char __pyx_k_Hash_s_find_peers[] = "Hash %s find peers";
static const char __pyx_k_Merging_s_buckets[] = "Merging %s buckets";
static const char __pyx_k_Message_malformed[] = "Message malformed";
static const char __pyx_k_Programming_merge[] = "Programming merge";
static const char __pyx_k_RoutingTable_find[] = "RoutingTable.find";
static const char __pyx_k_RoutingTable_stop[] = "RoutingTable.stop";
static const char __pyx_k_UnboundLocalError[] = "UnboundLocalError";
static const char __pyx_k_from_compact_info[] = "from_compact_info";
static const char __pyx_k_get_closest_nodes[] = "get_closest_nodes";
static const char __pyx_k_init_socket_for_s[] = "init socket for %s";
static const char __pyx_k_last_explore_tree[] = "last_explore_tree";
static const char __pyx_k_last_socket_stats[] = "_last_socket_stats";
static const char __pyx_k_pyx_unpickle_Node[] = "__pyx_unpickle_Node";
static const char __pyx_k_r_r_not_in_bucket[] = "%r %r not in bucket";
static const char __pyx_k_ERROR_201_s_pour_r[] = "ERROR:201:%s pour %r";
static const char __pyx_k_ERROR_202_s_pour_r[] = "ERROR:202:%s pour %r";
static const char __pyx_k_ERROR_203_s_pour_r[] = "ERROR:203:%s pour %r";
static const char __pyx_k_ERROR_204_s_pour_r[] = "ERROR:204:%s pour %r";
static const char __pyx_k_Fetching_my_own_id[] = "Fetching my own id";
static const char __pyx_k_MethodUnknownError[] = "MethodUnknownError";
static const char __pyx_k_RoutingTable_debug[] = "RoutingTable.debug";
static const char __pyx_k_RoutingTable_empty[] = "RoutingTable.empty";
static const char __pyx_k_RoutingTable_merge[] = "RoutingTable.merge";
static const char __pyx_k_RoutingTable_split[] = "RoutingTable.split";
static const char __pyx_k_RoutingTable_start[] = "RoutingTable.start";
static const char __pyx_k_RoutingTable_stats[] = "RoutingTable.stats";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_from_compact_infos[] = "from_compact_infos";
static const char __pyx_k_get_closest_hash_s[] = "get closest hash %s";
static const char __pyx_k_get_peer_loop_list[] = "_get_peer_loop_list";
static const char __pyx_k_get_peer_loop_lock[] = "_get_peer_loop_lock";
static const char __pyx_k_process_queue_size[] = "process_queue_size";
static const char __pyx_k_RoutingTable___init[] = "RoutingTable.__init__";
static const char __pyx_k_RoutingTable___iter[] = "RoutingTable.__iter__";
static const char __pyx_k_RoutingTable__merge[] = "RoutingTable._merge";
static const char __pyx_k_RoutingTable_heigth[] = "RoutingTable.heigth";
static const char __pyx_k_RoutingTable_zombie[] = "RoutingTable.zombie";
static const char __pyx_k_get_closest_nodes_r[] = "get_closest_nodes:%r";
static const char __pyx_k_router_utorrent_com[] = "router.utorrent.com";
static const char __pyx_k_start_routing_table[] = "start_routing_table";
static const char __pyx_k_typ_should_not_be_s[] = "typ should not be %s";
static const char __pyx_k_Error_code_s_unknown[] = "Error code %s unknown";
static const char __pyx_k_RoutingTable_stop_bg[] = "RoutingTable.stop_bg";
static const char __pyx_k_TransactionIdUnknown[] = "TransactionIdUnknown";
static const char __pyx_k_longest_prefix_value[] = "longest_prefix_value";
static const char __pyx_k_s_nodes_merged_in_ss[] = "%s nodes merged in %ss";
static const char __pyx_k_IP_start_with_0___r_r[] = "IP start with 0 *_* %r %r";
static const char __pyx_k_RoutingTable__routine[] = "RoutingTable._routine";
static const char __pyx_k_RoutingTable_get_node[] = "RoutingTable.get_node";
static const char __pyx_k_RoutingTable_is_alive[] = "RoutingTable.is_alive";
static const char __pyx_k_get_closest_loop_lock[] = "_get_closest_loop_lock";
static const char __pyx_k_pyx_unpickle_DHT_BASE[] = "__pyx_unpickle_DHT_BASE";
static const char __pyx_k_router_bittorrent_com[] = "router.bittorrent.com";
static const char __pyx_k_to_process_registered[] = "_to_process_registered";
static const char __pyx_k_DHT_BASE__process_loop[] = "DHT_BASE._process_loop";
static const char __pyx_k_dht_transmissionbt_com[] = "dht.transmissionbt.com";
static const char __pyx_k_fail_to_bind_to_port_s[] = "fail to bind to port %s";
static const char __pyx_k_get_peers_closest_loop[] = "_get_peers_closest_loop";
static const char __pyx_k_id_must_be_20_char_long[] = "id must be 20 char long";
static const char __pyx_k_s_not_comparable_with_s[] = "%s not comparable with %s";
static const char __pyx_k_sget_peers_closest_loop[] = "%sget_peers_closest_loop";
static const char __pyx_k_RoutingTable__merge_loop[] = "RoutingTable._merge_loop";
static const char __pyx_k_RoutingTable_release_dht[] = "RoutingTable.release_dht";
static const char __pyx_k_release_torrent_longterm[] = "release_torrent_longterm";
static const char __pyx_k_weigthless_threads_satus[] = "weigthless_threads_satus";
static const char __pyx_k_RoutingTable_register_dht[] = "RoutingTable.register_dht";
static const char __pyx_k_TypeError_r_in__recv_loop[] = "TypeError: %r in _recv_loop";
static const char __pyx_k_register_torrent_longterm[] = "register_torrent_longterm";
static const char __pyx_k_s_gone_away_while_merging[] = "%s gone away while merging";
static const char __pyx_k_trie_changed_while_merging[] = "trie changed while merging";
static const char __pyx_k_One_thread_died_stopping_dht[] = "One thread died, stopping dht";
static const char __pyx_k_RoutingTable_release_torrent[] = "RoutingTable.release_torrent";
static const char __pyx_k_trie_changed_while_splitting[] = "trie changed while splitting";
static const char __pyx_k_Less_than_1000_nodes_no_merge[] = "Less than 1000 nodes, no merge";
static const char __pyx_k_RoutingTable_register_torrent[] = "RoutingTable.register_torrent";
static const char __pyx_k_announce_peer_locals_callback[] = "announce_peer.<locals>.callback";
static const char __pyx_k_obj_without_id_no_node_update[] = "obj without id, no node update";
static const char __pyx_k_Hash_s_no_peers_or_nodes_found[] = "Hash %s no peers or nodes found";
static const char __pyx_k_No_token_to_announce_on_node_s[] = "No token to announce on node %s";
static const char __pyx_k_RoutingTable_get_closest_nodes[] = "RoutingTable.get_closest_nodes";
static const char __pyx_k_Zombie_threads_unable_de_start[] = "Zombie threads, unable de start";
static const char __pyx_k_s_nodes_added_to_routing_table[] = "%s nodes added to routing table";
static const char __pyx_k_A_DHT_class_ready_for_instancia[] = "\n    A DHT class ready for instanciation\n%s";
static const char __pyx_k_A_bucket_of_nodes_in_the_routin[] = "\n        A bucket of nodes in the routing table\n\n        :param bytes id: A prefix identifier from 0 to 169 bits for the bucket\n        :param int id_length: number of signifiant bit in ``id`` (can also be seen as the length\n            between the root and the bucket in the routing table)\n        :param iterable init: some values to store initialy in the bucket\n    ";
static const char __pyx_k_A_routing_table_for_one_or_more[] = "\n        A routing table for one or more :class:`DHT_BASE` instances\n\n        :param utils.Scheduler scheduler: A scheduler instance\n        :param int debuglvl: Level of verbosity, default to ``0``.\n    ";
static const char __pyx_k_Invalid_port_number_on_announce[] = "Invalid port number on announce %s, sould be within 1 and 65535";
static const char __pyx_k_No_msg_response_since_more_than[] = "No msg response since more than 5 minutes on udp port %d";
static const char __pyx_k_UNKNOWN_MSG_r_decoded_as_r_from[] = "UNKNOWN MSG: %r decoded as %r from %r";
static const char __pyx_k_Unable_to_stop_s_threads_giving[] = "Unable to stop %s threads, giving up:\n%r";
static const char __pyx_k_d_nodes_d_goods_d_bads_in_s_out[] = "%d nodes, %d goods, %d bads | in: %s, out: %s en %ss";
static const char __pyx_k_get_peers_closest_loop_locals_o[] = "_get_peers_closest_loop.<locals>.on_stop";
static const char __pyx_k_get_peers_closest_loop_locals_s[] = "_get_peers_closest_loop.<locals>.stop";
static const char __pyx_k_r_i_s_selfid_s_s_r_nodeid_d_r_r[] = "%r i:%s selfid:%s:%s:%r nodeid:%d:%r %r";
static const char __pyx_k_Already_stoped_or_stoping_in_pro[] = "Already stoped or stoping in progress";
static const char __pyx_k_AttributeError_r_in__on_find_nod[] = "AttributeError: %r in _on_find_node_response";
static const char __pyx_k_DHT_BASE__get_peers_closest_loop[] = "DHT_BASE._get_peers_closest_loop";
static const char __pyx_k_DHT_BASE_cannot_be_directly_inst[] = "DHT_BASE cannot be directly instantiated, use DHT instead or any subclass that may have be defined";
static const char __pyx_k_Incompatible_checksums_0x_x_vs_0[] = "Incompatible checksums (0x%x vs (0x4d4fbc6, 0xd7ddd24, 0xf626de7) = (_myid))";
static const char __pyx_k_Invalid_port_number_s_sould_be_w[] = "Invalid port number %s, sould be within 1 and 65535 for %s";
static const char __pyx_k_Message_malformed_s_key_is_missi[] = "Message malformed: %s key is missing";
static const char __pyx_k_No_msg_since_more_than_2_minutes[] = "No msg since more than 2 minutes on udp port %d";
static const char __pyx_k_Port_should_be_whithin_1_and_655[] = "Port should be whithin 1 and 65535, not %s";
static const char __pyx_k_RoutingTable__merge_locals_genex[] = "RoutingTable._merge.<locals>.genexpr";
static const char __pyx_k_RoutingTable_empty_locals_genexp[] = "RoutingTable.empty.<locals>.genexpr";
static const char __pyx_k_RoutingTable_get_closest_nodes_l[] = "RoutingTable.get_closest_nodes.<locals>.genexpr";
static const char __pyx_k_RoutingTable_register_torrent_lo[] = "RoutingTable.register_torrent_longterm";
static const char __pyx_k_RoutingTable_release_torrent_lon[] = "RoutingTable.release_torrent_longterm";
static const char __pyx_k_Unable_to_queue_msg_to_be_proces[] = "Unable to queue msg to be processed, QueueFull";
static const char __pyx_k_Waiting_for_s_threads_to_termina[] = "Waiting for %s threads to terminate";
static const char __pyx_k_compact_node_info_should_be_26_c[] = "compact node info should be 26 chars long";
static const char __pyx_k_get_closest_nodes_locals_genexpr[] = "get_closest_nodes.<locals>.genexpr";
static const char __pyx_k_nodes_length_should_be_a_multipl[] = "nodes length should be a multiple of 26";
static const char __pyx_k_Incompatible_checksums_0x_x_vs_0_2[] = "Incompatible checksums (0x%x vs (0xe3db725, 0x0eaf894, 0xd0728b2) = (_failed, _id, _ip, _last_query, _last_response, _port))";
static const char __pyx_k_RoutingTable_get_closest_nodes_l_2[] = "RoutingTable.get_closest_nodes.<locals>.<lambda>";
static PyObject *__pyx_kp_s_0;
static PyObject *__pyx_kp_u_0;
static PyObject *__pyx_kp_u_01;
static PyObject *__pyx_kp_s_0_0_0_0;
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_u_1;
static PyObject *__pyx_kp_s_20s4sH;
static PyObject *__pyx_kp_s_4sH;
static PyObject *__pyx_n_s_AF_INET;
static PyObject *__pyx_kp_s_A_DHT_class_ready_for_instancia;
static PyObject *__pyx_kp_s_A_bucket_of_nodes_in_the_routin;
static PyObject *__pyx_kp_s_A_routing_table_for_one_or_more;
static PyObject *__pyx_kp_s_Already_started;
static PyObject *__pyx_kp_s_Already_stoped_or_stoping_in_pro;
static PyObject *__pyx_n_s_AttributeError;
static PyObject *__pyx_kp_s_AttributeError_r_in__on_find_nod;
static PyObject *__pyx_n_s_BError;
static PyObject *__pyx_n_s_Bootstraping;
static PyObject *__pyx_n_s_Bucket;
static PyObject *__pyx_n_s_BucketFull;
static PyObject *__pyx_n_s_BucketNotFull;
static PyObject *__pyx_n_s_Bucket___eq;
static PyObject *__pyx_n_s_Bucket___hash;
static PyObject *__pyx_n_s_Bucket___init;
static PyObject *__pyx_n_s_Bucket___lt;
static PyObject *__pyx_n_s_Bucket_add;
static PyObject *__pyx_n_s_Bucket_get_node;
static PyObject *__pyx_n_s_Bucket_merge;
static PyObject *__pyx_kp_s_Bucket_not_Full_r;
static PyObject *__pyx_n_s_Bucket_own;
static PyObject *__pyx_n_s_Bucket_random_id;
static PyObject *__pyx_n_s_Bucket_split;
static PyObject *__pyx_n_s_Bucket_to_refresh;
static PyObject *__pyx_n_s_DHT;
static PyObject *__pyx_n_s_DHT_BASE;
static PyObject *__pyx_n_s_DHT_BASE__get_peers_closest_loop;
static PyObject *__pyx_n_s_DHT_BASE__process_loop;
static PyObject *__pyx_n_s_DHT_BASE__routine;
static PyObject *__pyx_kp_s_DHT_BASE_cannot_be_directly_inst;
static PyObject *__pyx_n_s_DecodeError;
static PyObject *__pyx_kp_s_ERROR_201_s_pour_r;
static PyObject *__pyx_kp_s_ERROR_202_s_pour_r;
static PyObject *__pyx_kp_s_ERROR_203_s_pour_r;
static PyObject *__pyx_kp_s_ERROR_204_s_pour_r;
static PyObject *__pyx_kp_s_ERROR_s_s_pour_r;
static PyObject *__pyx_n_s_Empty;
static PyObject *__pyx_n_s_EnvironmentError;
static PyObject *__pyx_kp_b_Error_code_s_unknown;
static PyObject *__pyx_n_s_FailToStop;
static PyObject *__pyx_kp_s_Fetching_my_own_id;
static PyObject *__pyx_n_s_Full;
static PyObject *__pyx_n_s_GenericError;
static PyObject *__pyx_kp_s_Hash_s_find_nodes;
static PyObject *__pyx_kp_s_Hash_s_find_peers;
static PyObject *__pyx_kp_s_Hash_s_no_peers_or_nodes_found;
static PyObject *__pyx_n_s_ID;
static PyObject *__pyx_n_s_IN;
static PyObject *__pyx_n_s_IOError;
static PyObject *__pyx_n_s_IPNetwork;
static PyObject *__pyx_n_s_IPPROTO_IP;
static PyObject *__pyx_n_s_IP_MTU_DISCOVER;
static PyObject *__pyx_n_s_IP_PMTUDISC_DO;
static PyObject *__pyx_kp_s_IP_start_with_0___r_r;
static PyObject *__pyx_n_s_ImportError;
static PyObject *__pyx_kp_s_Incompatible_checksums_0x_x_vs_0;
static PyObject *__pyx_kp_s_Incompatible_checksums_0x_x_vs_0_2;
static PyObject *__pyx_n_s_IndexError;
static PyObject *__pyx_kp_s_Invalid_port_number_on_announce;
static PyObject *__pyx_kp_s_Invalid_port_number_s_sould_be_w;
static PyObject *__pyx_n_s_KeyError;
static PyObject *__pyx_kp_s_Less_than_1000_nodes_no_merge;
static PyObject *__pyx_n_s_Lock;
static PyObject *__pyx_kp_s_Merging_s_buckets;
static PyObject *__pyx_kp_b_Message_malformed;
static PyObject *__pyx_kp_b_Message_malformed_s_key_is_missi;
static PyObject *__pyx_n_s_MethodUnknownError;
static PyObject *__pyx_n_s_MissingT;
static PyObject *__pyx_n_s_NoTokenError;
static PyObject *__pyx_kp_s_No_msg_response_since_more_than;
static PyObject *__pyx_kp_s_No_msg_since_more_than_2_minutes;
static PyObject *__pyx_kp_s_No_token_to_announce_on_node_s;
static PyObject *__pyx_n_s_Node;
static PyObject *__pyx_kp_s_Node_s_s;
static PyObject *__pyx_n_s_NotFound;
static PyObject *__pyx_kp_s_One_thread_died_stopping_dht;
static PyObject *__pyx_n_s_OrderedDict;
static PyObject *__pyx_n_s_OverflowError;
static PyObject *__pyx_n_s_PickleError;
static PyObject *__pyx_n_s_PollableQueue;
static PyObject *__pyx_kp_s_Port_should_be_whithin_1_and_655;
static PyObject *__pyx_kp_s_Programming_merge;
static PyObject *__pyx_n_s_ProtocolError;
static PyObject *__pyx_n_s_Queue;
static PyObject *__pyx_kp_s_RT_s_merge_loop;
static PyObject *__pyx_kp_s_RT_s_routine;
static PyObject *__pyx_kp_s_RT_s_s;
static PyObject *__pyx_n_s_RoutingTable;
static PyObject *__pyx_n_s_RoutingTable___init;
static PyObject *__pyx_n_s_RoutingTable___iter;
static PyObject *__pyx_n_s_RoutingTable__merge;
static PyObject *__pyx_n_s_RoutingTable__merge_locals_genex;
static PyObject *__pyx_n_s_RoutingTable__merge_loop;
static PyObject *__pyx_n_s_RoutingTable__routine;
static PyObject *__pyx_n_s_RoutingTable_add;
static PyObject *__pyx_n_s_RoutingTable_debug;
static PyObject *__pyx_n_s_RoutingTable_empty;
static PyObject *__pyx_n_s_RoutingTable_empty_locals_genexp;
static PyObject *__pyx_n_s_RoutingTable_find;
static PyObject *__pyx_n_s_RoutingTable_get_closest_nodes;
static PyObject *__pyx_n_s_RoutingTable_get_closest_nodes_l;
static PyObject *__pyx_n_s_RoutingTable_get_closest_nodes_l_2;
static PyObject *__pyx_n_s_RoutingTable_get_node;
static PyObject *__pyx_n_s_RoutingTable_heigth;
static PyObject *__pyx_n_s_RoutingTable_is_alive;
static PyObject *__pyx_n_s_RoutingTable_merge;
static PyObject *__pyx_n_s_RoutingTable_register_dht;
static PyObject *__pyx_n_s_RoutingTable_register_torrent;
static PyObject *__pyx_n_s_RoutingTable_register_torrent_lo;
static PyObject *__pyx_n_s_RoutingTable_release_dht;
static PyObject *__pyx_n_s_RoutingTable_release_torrent;
static PyObject *__pyx_n_s_RoutingTable_release_torrent_lon;
static PyObject *__pyx_n_s_RoutingTable_split;
static PyObject *__pyx_n_s_RoutingTable_start;
static PyObject *__pyx_n_s_RoutingTable_stats;
static PyObject *__pyx_n_s_RoutingTable_stop;
static PyObject *__pyx_n_s_RoutingTable_stop_bg;
static PyObject *__pyx_n_s_RoutingTable_zombie;
static PyObject *__pyx_n_s_RuntimeError;
static PyObject *__pyx_n_s_SOCK_DGRAM;
static PyObject *__pyx_n_s_Scheduler;
static PyObject *__pyx_n_s_ServerError;
static PyObject *__pyx_n_s_Thread;
static PyObject *__pyx_n_s_TransactionIdUnknown;
static PyObject *__pyx_n_s_Trie;
static PyObject *__pyx_n_s_TypeError;
static PyObject *__pyx_kp_s_TypeError_r_in__recv_loop;
static PyObject *__pyx_kp_s_UNKNOWN_MSG_r_decoded_as_r_from;
static PyObject *__pyx_kp_s_Unable_to_queue_msg_to_be_proces;
static PyObject *__pyx_kp_s_Unable_to_stop_s_threads_giving;
static PyObject *__pyx_n_s_UnboundLocalError;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_kp_s_Waiting_for_s_threads_to_termina;
static PyObject *__pyx_kp_s_Wrong_Bucket;
static PyObject *__pyx_kp_s_Zombie_threads_unable_de_start;
static PyObject *__pyx_n_s__15;
static PyObject *__pyx_kp_b__2;
static PyObject *__pyx_kp_s__2;
static PyObject *__pyx_kp_u__2;
static PyObject *__pyx_kp_b__27;
static PyObject *__pyx_kp_b__28;
static PyObject *__pyx_kp_b__30;
static PyObject *__pyx_kp_s__70;
static PyObject *__pyx_n_s_add;
static PyObject *__pyx_n_s_add_dht;
static PyObject *__pyx_n_s_add_peer;
static PyObject *__pyx_n_s_add_peer_queried;
static PyObject *__pyx_n_s_add_thread;
static PyObject *__pyx_n_s_addr;
static PyObject *__pyx_n_s_addresses;
static PyObject *__pyx_n_s_all;
static PyObject *__pyx_n_b_announce_peer;
static PyObject *__pyx_n_s_announce_peer;
static PyObject *__pyx_n_s_announce_peer_locals_callback;
static PyObject *__pyx_n_s_any;
static PyObject *__pyx_n_s_append;
static PyObject *__pyx_n_s_args;
static PyObject *__pyx_n_s_b;
static PyObject *__pyx_n_s_b1;
static PyObject *__pyx_n_s_b2;
static PyObject *__pyx_n_s_b2a_hex;
static PyObject *__pyx_n_s_bad;
static PyObject *__pyx_n_s_bads;
static PyObject *__pyx_n_s_binascii;
static PyObject *__pyx_n_s_bind;
static PyObject *__pyx_n_s_bind_ip;
static PyObject *__pyx_n_s_bind_port;
static PyObject *__pyx_n_s_block;
static PyObject *__pyx_n_s_bootstarp;
static PyObject *__pyx_n_s_btdht_dht;
static PyObject *__pyx_kp_s_btdht_dht_pyx;
static PyObject *__pyx_n_s_bucket;
static PyObject *__pyx_n_s_bucket0;
static PyObject *__pyx_n_s_bucket1;
static PyObject *__pyx_n_s_build_table;
static PyObject *__pyx_n_s_callback;
static PyObject *__pyx_n_s_char;
static PyObject *__pyx_n_s_chr;
static PyObject *__pyx_n_s_class;
static PyObject *__pyx_n_s_clean;
static PyObject *__pyx_n_s_clean_2;
static PyObject *__pyx_n_s_clean_long;
static PyObject *__pyx_n_s_cline_in_traceback;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_n_s_closest;
static PyObject *__pyx_n_s_collections;
static PyObject *__pyx_n_s_compact;
static PyObject *__pyx_n_s_compact_info;
static PyObject *__pyx_kp_s_compact_node_info_should_be_26_c;
static PyObject *__pyx_kp_s_d_nodes_d_goods_d_bads_in_s_out;
static PyObject *__pyx_n_s_daemon;
static PyObject *__pyx_n_s_datrie;
static PyObject *__pyx_n_s_debug;
static PyObject *__pyx_n_s_debuglvl;
static PyObject *__pyx_n_s_decode;
static PyObject *__pyx_n_s_decode_2;
static PyObject *__pyx_n_s_defaultdict;
static PyObject *__pyx_n_s_del_dht;
static PyObject *__pyx_n_s_del_thread;
static PyObject *__pyx_n_s_delay;
static PyObject *__pyx_n_s_dht;
static PyObject *__pyx_kp_s_dht__s_status;
static PyObject *__pyx_kp_s_dht_transmissionbt_com;
static PyObject *__pyx_n_s_dhts;
static PyObject *__pyx_n_s_dhts_2;
static PyObject *__pyx_n_s_dhts_last_elt;
static PyObject *__pyx_n_s_dict;
static PyObject *__pyx_n_s_doc;
static PyObject *__pyx_n_b_e;
static PyObject *__pyx_n_s_e;
static PyObject *__pyx_n_s_empty;
static PyObject *__pyx_n_s_encode;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_n_s_enter;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_n_s_eq;
static PyObject *__pyx_n_s_errmsg;
static PyObject *__pyx_n_s_errno;
static PyObject *__pyx_n_s_error;
static PyObject *__pyx_kp_s_error_r;
static PyObject *__pyx_n_s_exceptions;
static PyObject *__pyx_n_s_exit;
static PyObject *__pyx_n_s_exit_2;
static PyObject *__pyx_n_s_extend;
static PyObject *__pyx_kp_s_fail_to_bind_to_port_s;
static PyObject *__pyx_n_s_failed;
static PyObject *__pyx_n_s_file;
static PyObject *__pyx_n_s_filename;
static PyObject *__pyx_n_s_find;
static PyObject *__pyx_n_b_find_node;
static PyObject *__pyx_n_s_find_node;
static PyObject *__pyx_n_s_from_compact_info;
static PyObject *__pyx_n_s_from_compact_infos;
static PyObject *__pyx_n_s_fstop;
static PyObject *__pyx_n_s_full_merge;
static PyObject *__pyx_n_s_function;
static PyObject *__pyx_n_s_functools;
static PyObject *__pyx_n_s_gaierror;
static PyObject *__pyx_n_s_genexpr;
static PyObject *__pyx_n_s_get;
static PyObject *__pyx_kp_s_get_closest_hash_s;
static PyObject *__pyx_n_s_get_closest_loop_lock;
static PyObject *__pyx_n_s_get_closest_nodes;
static PyObject *__pyx_n_s_get_closest_nodes_locals_genexpr;
static PyObject *__pyx_kp_s_get_closest_nodes_r;
static PyObject *__pyx_n_s_get_node;
static PyObject *__pyx_n_s_get_nowait;
static PyObject *__pyx_n_s_get_peer_loop_list;
static PyObject *__pyx_n_s_get_peer_loop_lock;
static PyObject *__pyx_n_b_get_peers;
static PyObject *__pyx_n_s_get_peers;
static PyObject *__pyx_n_s_get_peers_2;
static PyObject *__pyx_n_s_get_peers_closest_loop;
static PyObject *__pyx_n_s_get_peers_closest_loop_locals_o;
static PyObject *__pyx_n_s_get_peers_closest_loop_locals_s;
static PyObject *__pyx_kp_s_get_peers_hash_s;
static PyObject *__pyx_n_s_getsockname;
static PyObject *__pyx_n_s_getstate;
static PyObject *__pyx_n_s_good;
static PyObject *__pyx_n_s_goods;
static PyObject *__pyx_n_s_got_peers;
static PyObject *__pyx_kp_s_grenade_genua_fr;
static PyObject *__pyx_n_s_hash;
static PyObject *__pyx_n_s_hash_2;
static PyObject *__pyx_n_s_heappop;
static PyObject *__pyx_n_s_heappush;
static PyObject *__pyx_n_s_heapq;
static PyObject *__pyx_n_s_heigth;
static PyObject *__pyx_n_s_heigth_2;
static PyObject *__pyx_n_s_i;
static PyObject *__pyx_n_b_id;
static PyObject *__pyx_n_s_id;
static PyObject *__pyx_n_s_id_end;
static PyObject *__pyx_n_s_id_length;
static PyObject *__pyx_kp_s_id_must_be_20_char_long;
static PyObject *__pyx_n_s_id_start;
static PyObject *__pyx_n_s_id_to_longid;
static PyObject *__pyx_n_s_ignored_ip;
static PyObject *__pyx_n_s_ignored_net;
static PyObject *__pyx_n_b_implied_port;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_inet_aton;
static PyObject *__pyx_n_s_inet_ntoa;
static PyObject *__pyx_n_b_info_hash;
static PyObject *__pyx_n_s_info_hash;
static PyObject *__pyx_n_s_info_hash_2;
static PyObject *__pyx_n_s_init;
static PyObject *__pyx_n_s_init_2;
static PyObject *__pyx_n_s_init_socket;
static PyObject *__pyx_kp_s_init_socket_for_s;
static PyObject *__pyx_n_s_ip;
static PyObject *__pyx_n_s_ip_in_nets;
static PyObject *__pyx_n_s_is_alive;
static PyObject *__pyx_n_s_items;
static PyObject *__pyx_n_s_iter;
static PyObject *__pyx_n_s_iteritems;
static PyObject *__pyx_n_s_j;
static PyObject *__pyx_n_s_join;
static PyObject *__pyx_n_s_key;
static PyObject *__pyx_n_s_keys;
static PyObject *__pyx_n_s_krcp;
static PyObject *__pyx_n_s_l;
static PyObject *__pyx_n_s_last_changed;
static PyObject *__pyx_n_s_last_debug;
static PyObject *__pyx_n_s_last_debug_time;
static PyObject *__pyx_n_s_last_explore_tree;
static PyObject *__pyx_n_s_last_msg;
static PyObject *__pyx_n_s_last_msg_rep;
static PyObject *__pyx_n_s_last_query;
static PyObject *__pyx_n_s_last_response;
static PyObject *__pyx_n_s_last_socket_stats;
static PyObject *__pyx_n_s_limit;
static PyObject *__pyx_n_s_lock;
static PyObject *__pyx_n_s_long_clean;
static PyObject *__pyx_n_s_longest_prefix;
static PyObject *__pyx_n_s_longest_prefix_value;
static PyObject *__pyx_n_s_lt;
static PyObject *__pyx_n_s_lvl;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_max;
static PyObject *__pyx_n_s_max_node;
static PyObject *__pyx_n_s_max_size;
static PyObject *__pyx_n_s_maxsize;
static PyObject *__pyx_n_s_merge;
static PyObject *__pyx_n_s_merge_2;
static PyObject *__pyx_n_s_merge_loop;
static PyObject *__pyx_n_s_metaclass;
static PyObject *__pyx_n_s_module;
static PyObject *__pyx_n_s_msg;
static PyObject *__pyx_n_s_myid;
static PyObject *__pyx_n_s_mytoken;
static PyObject *__pyx_n_s_n;
static PyObject *__pyx_n_s_name;
static PyObject *__pyx_n_s_name_2;
static PyObject *__pyx_n_s_nbit;
static PyObject *__pyx_n_s_need_merge;
static PyObject *__pyx_n_s_netaddr;
static PyObject *__pyx_n_s_new;
static PyObject *__pyx_n_s_new_id;
static PyObject *__pyx_n_s_next_full_merge;
static PyObject *__pyx_n_s_next_merge;
static PyObject *__pyx_n_s_nflip;
static PyObject *__pyx_n_s_node;
static PyObject *__pyx_n_b_nodes;
static PyObject *__pyx_n_s_nodes;
static PyObject *__pyx_n_s_nodes_before;
static PyObject *__pyx_kp_b_nodes_length_should_be_a_multipl;
static PyObject *__pyx_n_s_now;
static PyObject *__pyx_n_s_nset;
static PyObject *__pyx_n_s_obj;
static PyObject *__pyx_kp_s_obj_of_type_r;
static PyObject *__pyx_kp_s_obj_without_id_no_node_update;
static PyObject *__pyx_n_s_object;
static PyObject *__pyx_n_s_old_node;
static PyObject *__pyx_kp_s_on__s_query;
static PyObject *__pyx_kp_s_on__s_query_2;
static PyObject *__pyx_kp_s_on__s_response;
static PyObject *__pyx_kp_s_on__s_response_2;
static PyObject *__pyx_n_s_on_error;
static PyObject *__pyx_n_s_on_stop;
static PyObject *__pyx_n_s_one_b;
static PyObject *__pyx_n_s_open;
static PyObject *__pyx_n_s_os;
static PyObject *__pyx_n_s_other;
static PyObject *__pyx_n_s_others;
static PyObject *__pyx_n_s_own;
static PyObject *__pyx_n_s_pack;
static PyObject *__pyx_n_s_peers;
static PyObject *__pyx_n_s_peers_2;
static PyObject *__pyx_n_s_pickle;
static PyObject *__pyx_n_b_ping;
static PyObject *__pyx_n_s_ping;
static PyObject *__pyx_n_s_pop;
static PyObject *__pyx_n_s_popitem;
static PyObject *__pyx_n_b_port;
static PyObject *__pyx_n_s_port;
static PyObject *__pyx_n_s_prefix;
static PyObject *__pyx_n_s_prefix0;
static PyObject *__pyx_n_s_prefix1;
static PyObject *__pyx_n_s_prepare;
static PyObject *__pyx_n_s_print;
static PyObject *__pyx_n_s_print_exc;
static PyObject *__pyx_n_s_process_error;
static PyObject *__pyx_n_s_process_loop;
static PyObject *__pyx_n_s_process_query;
static PyObject *__pyx_n_s_process_queue_size;
static PyObject *__pyx_n_s_process_response;
static PyObject *__pyx_n_s_property;
static PyObject *__pyx_n_s_put;
static PyObject *__pyx_n_s_put_nowait;
static PyObject *__pyx_n_s_pyx_PickleError;
static PyObject *__pyx_n_s_pyx_checksum;
static PyObject *__pyx_n_s_pyx_result;
static PyObject *__pyx_n_s_pyx_state;
static PyObject *__pyx_n_s_pyx_type;
static PyObject *__pyx_n_s_pyx_unpickle_DHT_BASE;
static PyObject *__pyx_n_s_pyx_unpickle_Node;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_b_q;
static PyObject *__pyx_n_s_q;
static PyObject *__pyx_n_s_qualname;
static PyObject *__pyx_n_s_query;
static PyObject *__pyx_n_s_questionable;
static PyObject *__pyx_n_s_queue;
static PyObject *__pyx_n_b_r;
static PyObject *__pyx_kp_s_r_2;
static PyObject *__pyx_kp_s_r_i_s_selfid_s_s_r_nodeid_d_r_r;
static PyObject *__pyx_kp_s_r_r;
static PyObject *__pyx_kp_s_r_r_not_in_bucket;
static PyObject *__pyx_n_s_randint;
static PyObject *__pyx_n_s_random;
static PyObject *__pyx_n_s_random_id;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_rb;
static PyObject *__pyx_n_s_read;
static PyObject *__pyx_kp_s_recv_r;
static PyObject *__pyx_kp_s_recv_r_r_r;
static PyObject *__pyx_n_s_recvfrom;
static PyObject *__pyx_n_s_reduce;
static PyObject *__pyx_n_s_reduce_2;
static PyObject *__pyx_n_s_reduce_cython;
static PyObject *__pyx_n_s_reduce_ex;
static PyObject *__pyx_n_s_register_dht;
static PyObject *__pyx_n_s_register_torrent;
static PyObject *__pyx_n_s_register_torrent_longterm;
static PyObject *__pyx_n_s_release_dht;
static PyObject *__pyx_n_s_release_torrent;
static PyObject *__pyx_n_s_release_torrent_longterm;
static PyObject *__pyx_n_s_remove;
static PyObject *__pyx_n_s_response;
static PyObject *__pyx_n_s_richcmp;
static PyObject *__pyx_n_s_root;
static PyObject *__pyx_n_s_root_heigth;
static PyObject *__pyx_kp_s_router_bittorrent_com;
static PyObject *__pyx_kp_s_router_utorrent_com;
static PyObject *__pyx_n_s_routine;
static PyObject *__pyx_n_s_routing_table;
static PyObject *__pyx_n_s_rt;
static PyObject *__pyx_n_s_s;
static PyObject *__pyx_kp_s_s_gone_away_while_merging;
static PyObject *__pyx_kp_s_s_nodes_added_to_routing_table;
static PyObject *__pyx_kp_s_s_nodes_merged_in_ss;
static PyObject *__pyx_kp_s_s_not_comparable_with_s;
static PyObject *__pyx_n_s_scheduler;
static PyObject *__pyx_n_s_scheduler_2;
static PyObject *__pyx_n_s_select;
static PyObject *__pyx_n_s_self;
static PyObject *__pyx_n_s_send;
static PyObject *__pyx_kp_s_send_r_r;
static PyObject *__pyx_kp_s_send_r_r_r;
static PyObject *__pyx_n_s_sendto;
static PyObject *__pyx_n_s_setblocking;
static PyObject *__pyx_n_s_setsockopt;
static PyObject *__pyx_n_s_setstate;
static PyObject *__pyx_n_s_setstate_cython;
static PyObject *__pyx_kp_s_sget_peers_closest_loop;
static PyObject *__pyx_n_s_shuffle;
static PyObject *__pyx_n_s_six;
static PyObject *__pyx_n_s_sleep;
static PyObject *__pyx_n_s_slot;
static PyObject *__pyx_n_s_sock;
static PyObject *__pyx_n_s_socket;
static PyObject *__pyx_n_s_socket_in;
static PyObject *__pyx_n_s_socket_out;
static PyObject *__pyx_n_s_socket_stats;
static PyObject *__pyx_n_s_sort;
static PyObject *__pyx_n_s_split;
static PyObject *__pyx_n_s_split_ids;
static PyObject *__pyx_kp_s_sprocess_loop;
static PyObject *__pyx_kp_s_sroutine;
static PyObject *__pyx_n_s_stack;
static PyObject *__pyx_n_s_start;
static PyObject *__pyx_n_s_start_routing_table;
static PyObject *__pyx_n_s_start_scheduler;
static PyObject *__pyx_n_s_started;
static PyObject *__pyx_n_s_startswith;
static PyObject *__pyx_n_s_stats;
static PyObject *__pyx_n_s_stop;
static PyObject *__pyx_n_s_stop_bg;
static PyObject *__pyx_n_s_stoped;
static PyObject *__pyx_n_s_stoped_2;
static PyObject *__pyx_kp_s_stringsource;
static PyObject *__pyx_n_s_struct;
static PyObject *__pyx_n_s_suffix;
static PyObject *__pyx_n_s_suffixes;
static PyObject *__pyx_n_s_super;
static PyObject *__pyx_n_s_sys;
static PyObject *__pyx_n_s_t;
static PyObject *__pyx_n_b_target;
static PyObject *__pyx_n_s_target;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_text_type;
static PyObject *__pyx_n_s_thread_alive;
static PyObject *__pyx_n_s_threading;
static PyObject *__pyx_n_s_threads;
static PyObject *__pyx_n_s_threads_2;
static PyObject *__pyx_n_s_threads_zombie;
static PyObject *__pyx_n_s_throw;
static PyObject *__pyx_n_s_time;
static PyObject *__pyx_n_s_tmp;
static PyObject *__pyx_n_s_to_bytes;
static PyObject *__pyx_n_s_to_merge;
static PyObject *__pyx_n_s_to_merge_2;
static PyObject *__pyx_n_s_to_process;
static PyObject *__pyx_n_s_to_process_registered;
static PyObject *__pyx_n_s_to_refresh;
static PyObject *__pyx_n_s_to_schedule;
static PyObject *__pyx_n_s_to_send;
static PyObject *__pyx_n_b_token;
static PyObject *__pyx_n_s_token;
static PyObject *__pyx_n_s_total_ordering;
static PyObject *__pyx_n_s_traceback;
static PyObject *__pyx_n_s_transaction_type;
static PyObject *__pyx_n_s_trie;
static PyObject *__pyx_kp_s_trie_changed_while_merging;
static PyObject *__pyx_kp_s_trie_changed_while_splitting;
static PyObject *__pyx_n_s_typ;
static PyObject *__pyx_kp_s_typ_should_not_be_s;
static PyObject *__pyx_n_s_union;
static PyObject *__pyx_n_s_unpack;
static PyObject *__pyx_n_s_update;
static PyObject *__pyx_n_s_update_node;
static PyObject *__pyx_n_s_urandom;
static PyObject *__pyx_n_s_utils;
static PyObject *__pyx_n_s_value;
static PyObject *__pyx_n_b_values;
static PyObject *__pyx_n_s_values;
static PyObject *__pyx_n_s_wb;
static PyObject *__pyx_n_s_weigthless_threads_satus;
static PyObject *__pyx_n_s_write;
static PyObject *__pyx_n_s_y;
static PyObject *__pyx_n_s_zero_b;
static PyObject *__pyx_n_s_zip;
static PyObject *__pyx_n_s_zombie;
static int __pyx_pf_5btdht_3dht_8DHT_BASE___init__(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_routing_table, PyObject *__pyx_v_bind_port, PyObject *__pyx_v_bind_ip, PyObject *__pyx_v_id, PyObject *__pyx_v_ignored_ip, PyObject *__pyx_v_debuglvl, PyObject *__pyx_v_prefix, PyObject *__pyx_v_process_queue_size, PyObject *__pyx_v_ignored_net, PyObject *__pyx_v_scheduler); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_2save(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_max_node); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_4load(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_max_node); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_6stop_bg(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_8stop(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_6zombie___get__(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_10start(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_start_routing_table, PyObject *__pyx_v_start_scheduler); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_12is_alive(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_14debug(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_lvl, PyObject *__pyx_v_msg); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_16_socket_stats(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_18init_socket(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_20sleep(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_t, PyObject *__pyx_v_fstop); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_13announce_peer_callback(PyObject *__pyx_self, PyObject *__pyx_v_nodes); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_22announce_peer(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_info_hash, PyObject *__pyx_v_port, PyObject *__pyx_v_delay, PyObject *__pyx_v_block); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_24_add_peer(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_info_hash, PyObject *__pyx_v_ip, PyObject *__pyx_v_port); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_26_add_peer_queried(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_info_hash, PyObject *__pyx_v_ip, PyObject *__pyx_v_port); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_28get_peers(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_hash, PyObject *__pyx_v_delay, PyObject *__pyx_v_block, PyObject *__pyx_v_callback, PyObject *__pyx_v_limit); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_30_get_peers_closest_loop(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_on_stop(PyObject *__pyx_self, PyObject *__pyx_v_hash, PyObject *__pyx_v_typ); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_2stop(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_33_get_peers(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_info_hash, PyObject *__pyx_v_compact, PyObject *__pyx_v_errno); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_17get_closest_nodes_genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_35get_closest_nodes(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_id, PyObject *__pyx_v_compact); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_37bootstarp(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_addresses); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_39_update_node(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_obj); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_41sendto(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_msg, PyObject *__pyx_v_addr); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_43_process_outgoing_message(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_45_process_incoming_message(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_47_get_token(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_ip); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_49_get_valid_token(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_ip); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_51clean(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_53clean_long(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_55_clean(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_57build_table(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_59_routine(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_62register_message(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_msg); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_64on_error(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_error, CYTHON_UNUSED PyObject *__pyx_v_query); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_66on_ping_response(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, CYTHON_UNUSED PyObject *__pyx_v_response); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_68on_find_node_response(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, CYTHON_UNUSED PyObject *__pyx_v_response); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_70on_get_peers_response(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, CYTHON_UNUSED PyObject *__pyx_v_response); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_72on_announce_peer_response(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, CYTHON_UNUSED PyObject *__pyx_v_response); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_74on_ping_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_76on_find_node_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_78on_get_peers_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_80on_announce_peer_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_82_on_ping_response(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, CYTHON_UNUSED PyObject *__pyx_v_response); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_84_on_find_node_response(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, PyObject *__pyx_v_response); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_86_on_get_peers_response(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_query, PyObject *__pyx_v_response); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_88_on_announce_peer_response(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, CYTHON_UNUSED PyObject *__pyx_v_response); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_90_on_ping_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_92_on_find_node_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_94_on_get_peers_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_96_on_announce_peer_query(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_query); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_98_process_error(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_obj, PyObject *__pyx_v_query); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_100_process_response(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_obj, PyObject *__pyx_v_query); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_102_process_query(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_obj); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_104_process_loop(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_107_decode(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_s, PyObject *__pyx_v_addr); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_109__reduce_cython__(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_111__setstate_cython__(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_4port___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self); /* proto */
static int __pyx_pf_5btdht_3dht_4Node_4port_2__set__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, int __pyx_v_i); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_13last_response___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self); /* proto */
static int __pyx_pf_5btdht_3dht_4Node_13last_response_2__set__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, int __pyx_v_i); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_10last_query___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self); /* proto */
static int __pyx_pf_5btdht_3dht_4Node_10last_query_2__set__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, int __pyx_v_i); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_6failed___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self); /* proto */
static int __pyx_pf_5btdht_3dht_4Node_6failed_2__set__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, int __pyx_v_i); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_2id___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_4good___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_3bad___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_2ip___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self); /* proto */
static int __pyx_pf_5btdht_3dht_4Node_2ip_2__set__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, PyObject *__pyx_v_ip); /* proto */
static int __pyx_pf_5btdht_3dht_4Node___init__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, PyObject *__pyx_v_id, PyObject *__pyx_v_ip, int __pyx_v_port, int __pyx_v_last_response, int __pyx_v_last_query, int __pyx_v_failed); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_2__richcmp__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, struct __pyx_obj_5btdht_3dht_Node *__pyx_v_other, int __pyx_v_op); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_4__repr__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_6compact_info(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_8from_compact_infos(CYTHON_UNUSED PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_infos); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_10from_compact_info(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_info); /* proto */
#if PY_MAJOR_VERSION < 3
static int __pyx_pf_5btdht_3dht_4Node_12__cmp__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, struct __pyx_obj_5btdht_3dht_Node *__pyx_v_other); /* proto */
#endif
static Py_hash_t __pyx_pf_5btdht_3dht_4Node_14__hash__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_16ping(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_dht); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_18find_node(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_dht, PyObject *__pyx_v_target); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_20get_peers(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_dht, PyObject *__pyx_v_info_hash); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_22announce_peer(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_dht, PyObject *__pyx_v_info_hash, int __pyx_v_port); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_24__reduce_cython__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_4Node_26__setstate_cython__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_6Bucket_to_refresh(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_6Bucket_2own(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_6Bucket_4__init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id, PyObject *__pyx_v_id_length, PyObject *__pyx_v_init); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_6Bucket_6random_id(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_6Bucket_8get_node(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_6Bucket_10add(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_dht, PyObject *__pyx_v_node); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_6Bucket_12split(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_rt, PyObject *__pyx_v_dht); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_6Bucket_14merge(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_bucket); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_6Bucket_16__hash__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_6Bucket_18__eq__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_6Bucket_20__lt__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_scheduler, PyObject *__pyx_v_debuglvl, PyObject *__pyx_v_prefix); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_2stop_bg(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_4stop(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_6zombie(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_8start(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_10is_alive(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_12register_torrent(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_14release_torrent(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_16_merge_loop(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_19register_torrent_longterm(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_21release_torrent_longterm(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_23register_dht(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_dht); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_25release_dht(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_dht); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_27debug(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_lvl, PyObject *__pyx_v_msg); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_29_routine(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_5empty_genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_32empty(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_34stats(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_36__iter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_38get_node(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_40find(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id, PyObject *__pyx_v_errno); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_17get_closest_nodes_genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_17get_closest_nodes_3genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_lambda_funcdef_lambda4(PyObject *__pyx_self, PyObject *__pyx_v_x); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_42get_closest_nodes(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id, PyObject *__pyx_v_bad, PyObject *__pyx_v_errno); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_44add(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_dht, PyObject *__pyx_v_node); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_46heigth(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_48split(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_dht, PyObject *__pyx_v_bucket); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_50merge(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_6_merge_genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_52_merge(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_stack); /* proto */
static PyObject *__pyx_pf_5btdht_3dht___pyx_unpickle_DHT_BASE(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_pf_5btdht_3dht_2__pyx_unpickle_Node(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_tp_new_5btdht_3dht_DHT_BASE(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht_Node(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct__announce_peer(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_3_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_4__routine(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_5__process_loop(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_6__merge_loop(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_7__routine(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_8_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_10_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_11_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_12__merge(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_13_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static __Pyx_CachedCFunction __pyx_umethod_PyList_Type_pop = {0, &__pyx_n_s_pop, 0, 0, 0};
static PyObject *__pyx_float_0_1;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_3;
static PyObject *__pyx_int_4;
static PyObject *__pyx_int_5;
static PyObject *__pyx_int_8;
static PyObject *__pyx_int_10;
static PyObject *__pyx_int_11;
static PyObject *__pyx_int_13;
static PyObject *__pyx_int_15;
static PyObject *__pyx_int_20;
static PyObject *__pyx_int_24;
static PyObject *__pyx_int_26;
static PyObject *__pyx_int_30;
static PyObject *__pyx_int_60;
static PyObject *__pyx_int_90;
static PyObject *__pyx_int_120;
static PyObject *__pyx_int_160;
static PyObject *__pyx_int_201;
static PyObject *__pyx_int_202;
static PyObject *__pyx_int_203;
static PyObject *__pyx_int_204;
static PyObject *__pyx_int_300;
static PyObject *__pyx_int_500;
static PyObject *__pyx_int_600;
static PyObject *__pyx_int_900;
static PyObject *__pyx_int_1000;
static PyObject *__pyx_int_1800;
static PyObject *__pyx_int_2600;
static PyObject *__pyx_int_4048;
static PyObject *__pyx_int_6880;
static PyObject *__pyx_int_6881;
static PyObject *__pyx_int_10013;
static PyObject *__pyx_int_10035;
static PyObject *__pyx_int_10040;
static PyObject *__pyx_int_65535;
static PyObject *__pyx_int_65536;
static PyObject *__pyx_int_100000;
static PyObject *__pyx_int_15399060;
static PyObject *__pyx_int_81066950;
static PyObject *__pyx_int_218572978;
static PyObject *__pyx_int_226352420;
static PyObject *__pyx_int_238925605;
static PyObject *__pyx_int_258108903;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_int_neg_10;
static PyObject *__pyx_k_;
static PyObject *__pyx_k__18;
static PyObject *__pyx_slice__7;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__4;
static PyObject *__pyx_tuple__5;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_tuple__9;
static PyObject *__pyx_slice__35;
static PyObject *__pyx_slice__72;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__11;
static PyObject *__pyx_tuple__13;
static PyObject *__pyx_tuple__16;
static PyObject *__pyx_tuple__19;
static PyObject *__pyx_tuple__20;
static PyObject *__pyx_tuple__21;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__23;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__25;
static PyObject *__pyx_tuple__26;
static PyObject *__pyx_tuple__29;
static PyObject *__pyx_tuple__31;
static PyObject *__pyx_tuple__32;
static PyObject *__pyx_tuple__36;
static PyObject *__pyx_tuple__38;
static PyObject *__pyx_tuple__39;
static PyObject *__pyx_tuple__40;
static PyObject *__pyx_tuple__41;
static PyObject *__pyx_tuple__42;
static PyObject *__pyx_tuple__43;
static PyObject *__pyx_tuple__44;
static PyObject *__pyx_tuple__45;
static PyObject *__pyx_tuple__46;
static PyObject *__pyx_tuple__48;
static PyObject *__pyx_tuple__49;
static PyObject *__pyx_tuple__51;
static PyObject *__pyx_tuple__53;
static PyObject *__pyx_tuple__54;
static PyObject *__pyx_tuple__56;
static PyObject *__pyx_tuple__58;
static PyObject *__pyx_tuple__60;
static PyObject *__pyx_tuple__62;
static PyObject *__pyx_tuple__64;
static PyObject *__pyx_tuple__66;
static PyObject *__pyx_tuple__68;
static PyObject *__pyx_tuple__71;
static PyObject *__pyx_tuple__73;
static PyObject *__pyx_tuple__74;
static PyObject *__pyx_tuple__76;
static PyObject *__pyx_tuple__77;
static PyObject *__pyx_tuple__79;
static PyObject *__pyx_tuple__81;
static PyObject *__pyx_tuple__83;
static PyObject *__pyx_tuple__85;
static PyObject *__pyx_tuple__87;
static PyObject *__pyx_tuple__89;
static PyObject *__pyx_tuple__91;
static PyObject *__pyx_tuple__92;
static PyObject *__pyx_tuple__94;
static PyObject *__pyx_tuple__96;
static PyObject *__pyx_tuple__98;
static PyObject *__pyx_tuple__100;
static PyObject *__pyx_tuple__102;
static PyObject *__pyx_tuple__103;
static PyObject *__pyx_tuple__105;
static PyObject *__pyx_tuple__107;
static PyObject *__pyx_tuple__109;
static PyObject *__pyx_tuple__111;
static PyObject *__pyx_tuple__113;
static PyObject *__pyx_tuple__114;
static PyObject *__pyx_tuple__116;
static PyObject *__pyx_tuple__117;
static PyObject *__pyx_tuple__119;
static PyObject *__pyx_tuple__121;
static PyObject *__pyx_tuple__123;
static PyObject *__pyx_tuple__125;
static PyObject *__pyx_tuple__126;
static PyObject *__pyx_tuple__127;
static PyObject *__pyx_tuple__129;
static PyObject *__pyx_codeobj__12;
static PyObject *__pyx_codeobj__14;
static PyObject *__pyx_codeobj__17;
static PyObject *__pyx_codeobj__33;
static PyObject *__pyx_codeobj__34;
static PyObject *__pyx_codeobj__37;
static PyObject *__pyx_codeobj__47;
static PyObject *__pyx_codeobj__50;
static PyObject *__pyx_codeobj__52;
static PyObject *__pyx_codeobj__55;
static PyObject *__pyx_codeobj__57;
static PyObject *__pyx_codeobj__59;
static PyObject *__pyx_codeobj__61;
static PyObject *__pyx_codeobj__63;
static PyObject *__pyx_codeobj__65;
static PyObject *__pyx_codeobj__67;
static PyObject *__pyx_codeobj__69;
static PyObject *__pyx_codeobj__75;
static PyObject *__pyx_codeobj__78;
static PyObject *__pyx_codeobj__80;
static PyObject *__pyx_codeobj__82;
static PyObject *__pyx_codeobj__84;
static PyObject *__pyx_codeobj__86;
static PyObject *__pyx_codeobj__88;
static PyObject *__pyx_codeobj__90;
static PyObject *__pyx_codeobj__93;
static PyObject *__pyx_codeobj__95;
static PyObject *__pyx_codeobj__97;
static PyObject *__pyx_codeobj__99;
static PyObject *__pyx_codeobj__101;
static PyObject *__pyx_codeobj__104;
static PyObject *__pyx_codeobj__106;
static PyObject *__pyx_codeobj__108;
static PyObject *__pyx_codeobj__110;
static PyObject *__pyx_codeobj__112;
static PyObject *__pyx_codeobj__115;
static PyObject *__pyx_codeobj__118;
static PyObject *__pyx_codeobj__120;
static PyObject *__pyx_codeobj__122;
static PyObject *__pyx_codeobj__124;
static PyObject *__pyx_codeobj__128;
static PyObject *__pyx_codeobj__130;
/* Late includes */

/* "btdht/dht.pyx":169
 * 
 * 
 *     def __init__(self, routing_table=None, bind_port=None, bind_ip="0.0.0.0",             # <<<<<<<<<<<<<<
 *       id=None, ignored_ip=[], debuglvl=0, prefix="", process_queue_size=500,
 *       ignored_net=None, scheduler=None
 */

/* Python wrapper */
static int __pyx_pw_5btdht_3dht_8DHT_BASE_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5btdht_3dht_8DHT_BASE_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_routing_table = 0;
  PyObject *__pyx_v_bind_port = 0;
  PyObject *__pyx_v_bind_ip = 0;
  PyObject *__pyx_v_id = 0;
  PyObject *__pyx_v_ignored_ip = 0;
  PyObject *__pyx_v_debuglvl = 0;
  PyObject *__pyx_v_prefix = 0;
  PyObject *__pyx_v_process_queue_size = 0;
  PyObject *__pyx_v_ignored_net = 0;
  PyObject *__pyx_v_scheduler = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_routing_table,&__pyx_n_s_bind_port,&__pyx_n_s_bind_ip,&__pyx_n_s_id,&__pyx_n_s_ignored_ip,&__pyx_n_s_debuglvl,&__pyx_n_s_prefix,&__pyx_n_s_process_queue_size,&__pyx_n_s_ignored_net,&__pyx_n_s_scheduler,0};
    PyObject* values[10] = {0,0,0,0,0,0,0,0,0,0};
    values[0] = ((PyObject *)Py_None);
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)__pyx_kp_s_0_0_0_0);

    /* "btdht/dht.pyx":170
 * 
 *     def __init__(self, routing_table=None, bind_port=None, bind_ip="0.0.0.0",
 *       id=None, ignored_ip=[], debuglvl=0, prefix="", process_queue_size=500,             # <<<<<<<<<<<<<<
 *       ignored_net=None, scheduler=None
 *     ):
 */
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k_;
    values[5] = ((PyObject *)__pyx_int_0);
    values[6] = ((PyObject *)__pyx_kp_s__2);
    values[7] = ((PyObject *)__pyx_int_500);

    /* "btdht/dht.pyx":171
 *     def __init__(self, routing_table=None, bind_port=None, bind_ip="0.0.0.0",
 *       id=None, ignored_ip=[], debuglvl=0, prefix="", process_queue_size=500,
 *       ignored_net=None, scheduler=None             # <<<<<<<<<<<<<<
 *     ):
 *         if self.__class__ == DHT_BASE:
 */
    values[8] = ((PyObject *)Py_None);
    values[9] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        CYTHON_FALLTHROUGH;
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_routing_table);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bind_port);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bind_ip);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ignored_ip);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_debuglvl);
          if (value) { values[5] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_prefix);
          if (value) { values[6] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_process_queue_size);
          if (value) { values[7] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  8:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ignored_net);
          if (value) { values[8] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  9:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_scheduler);
          if (value) { values[9] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 169, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        CYTHON_FALLTHROUGH;
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_routing_table = values[0];
    __pyx_v_bind_port = values[1];
    __pyx_v_bind_ip = values[2];
    __pyx_v_id = values[3];
    __pyx_v_ignored_ip = values[4];
    __pyx_v_debuglvl = values[5];
    __pyx_v_prefix = values[6];
    __pyx_v_process_queue_size = values[7];
    __pyx_v_ignored_net = values[8];
    __pyx_v_scheduler = values[9];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 10, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 169, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE___init__(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_routing_table, __pyx_v_bind_port, __pyx_v_bind_ip, __pyx_v_id, __pyx_v_ignored_ip, __pyx_v_debuglvl, __pyx_v_prefix, __pyx_v_process_queue_size, __pyx_v_ignored_net, __pyx_v_scheduler);

  /* "btdht/dht.pyx":169
 * 
 * 
 *     def __init__(self, routing_table=None, bind_port=None, bind_ip="0.0.0.0",             # <<<<<<<<<<<<<<
 *       id=None, ignored_ip=[], debuglvl=0, prefix="", process_queue_size=500,
 *       ignored_net=None, scheduler=None
 */

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5btdht_3dht_8DHT_BASE___init__(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_routing_table, PyObject *__pyx_v_bind_port, PyObject *__pyx_v_bind_ip, PyObject *__pyx_v_id, PyObject *__pyx_v_ignored_ip, PyObject *__pyx_v_debuglvl, PyObject *__pyx_v_prefix, PyObject *__pyx_v_process_queue_size, PyObject *__pyx_v_ignored_net, PyObject *__pyx_v_scheduler) {
  PyObject *__pyx_v_net = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_INCREF(__pyx_v_id);

  /* "btdht/dht.pyx":173
 *       ignored_net=None, scheduler=None
 *     ):
 *         if self.__class__ == DHT_BASE:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(
 *                 "DHT_BASE cannot be directly instantiated, use DHT instead or any subclass that"
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 173, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE), Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 173, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 173, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(__pyx_t_3)) {

    /* "btdht/dht.pyx":174
 *     ):
 *         if self.__class__ == DHT_BASE:
 *             raise RuntimeError(             # <<<<<<<<<<<<<<
 *                 "DHT_BASE cannot be directly instantiated, use DHT instead or any subclass that"
 *                 " may have be defined"
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 174, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 174, __pyx_L1_error)

    /* "btdht/dht.pyx":173
 *       ignored_net=None, scheduler=None
 *     ):
 *         if self.__class__ == DHT_BASE:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(
 *                 "DHT_BASE cannot be directly instantiated, use DHT instead or any subclass that"
 */
  }

  /* "btdht/dht.pyx":179
 *             )
 *         # checking the provided id or picking a random one
 *         if id is not None:             # <<<<<<<<<<<<<<
 *             if len(id) != 20:
 *                 raise ValueError("id must be 20 char long")
 */
  __pyx_t_3 = (__pyx_v_id != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {

    /* "btdht/dht.pyx":180
 *         # checking the provided id or picking a random one
 *         if id is not None:
 *             if len(id) != 20:             # <<<<<<<<<<<<<<
 *                 raise ValueError("id must be 20 char long")
 *             id = ID.to_bytes(id)
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_id); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 180, __pyx_L1_error)
    __pyx_t_4 = ((__pyx_t_5 != 20) != 0);
    if (unlikely(__pyx_t_4)) {

      /* "btdht/dht.pyx":181
 *         if id is not None:
 *             if len(id) != 20:
 *                 raise ValueError("id must be 20 char long")             # <<<<<<<<<<<<<<
 *             id = ID.to_bytes(id)
 *         else:
 */
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 181, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __PYX_ERR(0, 181, __pyx_L1_error)

      /* "btdht/dht.pyx":180
 *         # checking the provided id or picking a random one
 *         if id is not None:
 *             if len(id) != 20:             # <<<<<<<<<<<<<<
 *                 raise ValueError("id must be 20 char long")
 *             id = ID.to_bytes(id)
 */
    }

    /* "btdht/dht.pyx":182
 *             if len(id) != 20:
 *                 raise ValueError("id must be 20 char long")
 *             id = ID.to_bytes(id)             # <<<<<<<<<<<<<<
 *         else:
 *             id = ID().value
 */
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ID); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 182, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_to_bytes); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 182, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_1, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_id);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 182, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF_SET(__pyx_v_id, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "btdht/dht.pyx":179
 *             )
 *         # checking the provided id or picking a random one
 *         if id is not None:             # <<<<<<<<<<<<<<
 *             if len(id) != 20:
 *                 raise ValueError("id must be 20 char long")
 */
    goto __pyx_L4;
  }

  /* "btdht/dht.pyx":184
 *             id = ID.to_bytes(id)
 *         else:
 *             id = ID().value             # <<<<<<<<<<<<<<
 *         self.myid = ID(id)
 * 
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_ID); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 184, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 184, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_value); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 184, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_id, __pyx_t_6);
    __pyx_t_6 = 0;
  }
  __pyx_L4:;

  /* "btdht/dht.pyx":185
 *         else:
 *             id = ID().value
 *         self.myid = ID(id)             # <<<<<<<<<<<<<<
 * 
 *         # initialize the scheduler
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ID); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_id);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_myid, __pyx_t_6) < 0) __PYX_ERR(0, 185, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "btdht/dht.pyx":188
 * 
 *         # initialize the scheduler
 *         self._scheduler = utils.Scheduler() if scheduler is None else scheduler             # <<<<<<<<<<<<<<
 * 
 *         # initialising the routing table
 */
  __pyx_t_4 = (__pyx_v_scheduler == Py_None);
  if ((__pyx_t_4 != 0)) {
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_utils); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 188, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_Scheduler); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 188, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 188, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_6 = __pyx_t_2;
    __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_v_scheduler);
    __pyx_t_6 = __pyx_v_scheduler;
  }
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_scheduler_2, __pyx_t_6) < 0) __PYX_ERR(0, 188, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "btdht/dht.pyx":191
 * 
 *         # initialising the routing table
 *         if routing_table is None:             # <<<<<<<<<<<<<<
 *             self.root = RoutingTable(scheduler=self._scheduler, prefix=prefix)
 *         else:
 */
  __pyx_t_4 = (__pyx_v_routing_table == Py_None);
  __pyx_t_3 = (__pyx_t_4 != 0);
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":192
 *         # initialising the routing table
 *         if routing_table is None:
 *             self.root = RoutingTable(scheduler=self._scheduler, prefix=prefix)             # <<<<<<<<<<<<<<
 *         else:
 *             self.root = routing_table
 */
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_RoutingTable); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 192, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 192, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_scheduler_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 192, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_scheduler, __pyx_t_7) < 0) __PYX_ERR(0, 192, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_prefix, __pyx_v_prefix) < 0) __PYX_ERR(0, 192, __pyx_L1_error)
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 192, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root, __pyx_t_7) < 0) __PYX_ERR(0, 192, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "btdht/dht.pyx":191
 * 
 *         # initialising the routing table
 *         if routing_table is None:             # <<<<<<<<<<<<<<
 *             self.root = RoutingTable(scheduler=self._scheduler, prefix=prefix)
 *         else:
 */
    goto __pyx_L6;
  }

  /* "btdht/dht.pyx":194
 *             self.root = RoutingTable(scheduler=self._scheduler, prefix=prefix)
 *         else:
 *             self.root = routing_table             # <<<<<<<<<<<<<<
 * 
 *         self.bind_port = bind_port
 */
  /*else*/ {
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root, __pyx_v_routing_table) < 0) __PYX_ERR(0, 194, __pyx_L1_error)
  }
  __pyx_L6:;

  /* "btdht/dht.pyx":196
 *             self.root = routing_table
 * 
 *         self.bind_port = bind_port             # <<<<<<<<<<<<<<
 *         self.bind_ip = bind_ip
 * 
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_bind_port, __pyx_v_bind_port) < 0) __PYX_ERR(0, 196, __pyx_L1_error)

  /* "btdht/dht.pyx":197
 * 
 *         self.bind_port = bind_port
 *         self.bind_ip = bind_ip             # <<<<<<<<<<<<<<
 * 
 *         self.ignored_ip = ignored_ip
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_bind_ip, __pyx_v_bind_ip) < 0) __PYX_ERR(0, 197, __pyx_L1_error)

  /* "btdht/dht.pyx":199
 *         self.bind_ip = bind_ip
 * 
 *         self.ignored_ip = ignored_ip             # <<<<<<<<<<<<<<
 *         if ignored_net is not None:
 *             self.ignored_net = [netaddr.IPNetwork(net) for net in ignored_net]
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ignored_ip, __pyx_v_ignored_ip) < 0) __PYX_ERR(0, 199, __pyx_L1_error)

  /* "btdht/dht.pyx":200
 * 
 *         self.ignored_ip = ignored_ip
 *         if ignored_net is not None:             # <<<<<<<<<<<<<<
 *             self.ignored_net = [netaddr.IPNetwork(net) for net in ignored_net]
 *         else:
 */
  __pyx_t_3 = (__pyx_v_ignored_net != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {

    /* "btdht/dht.pyx":201
 *         self.ignored_ip = ignored_ip
 *         if ignored_net is not None:
 *             self.ignored_net = [netaddr.IPNetwork(net) for net in ignored_net]             # <<<<<<<<<<<<<<
 *         else:
 *             self.ignored_net = [netaddr.IPNetwork(net) for net in self.ignored_net]
 */
    __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 201, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (likely(PyList_CheckExact(__pyx_v_ignored_net)) || PyTuple_CheckExact(__pyx_v_ignored_net)) {
      __pyx_t_2 = __pyx_v_ignored_net; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_ignored_net); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 201, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 201, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_8)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 201, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 201, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 201, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 201, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_8(__pyx_t_2);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 201, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_XDECREF_SET(__pyx_v_net, __pyx_t_6);
      __pyx_t_6 = 0;
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_netaddr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 201, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_IPNetwork); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 201, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
        }
      }
      __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_1, __pyx_v_net) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_net);
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 201, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_7, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 201, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ignored_net, __pyx_t_7) < 0) __PYX_ERR(0, 201, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "btdht/dht.pyx":200
 * 
 *         self.ignored_ip = ignored_ip
 *         if ignored_net is not None:             # <<<<<<<<<<<<<<
 *             self.ignored_net = [netaddr.IPNetwork(net) for net in ignored_net]
 *         else:
 */
    goto __pyx_L7;
  }

  /* "btdht/dht.pyx":203
 *             self.ignored_net = [netaddr.IPNetwork(net) for net in ignored_net]
 *         else:
 *             self.ignored_net = [netaddr.IPNetwork(net) for net in self.ignored_net]             # <<<<<<<<<<<<<<
 *         self.debuglvl = debuglvl
 *         self.prefix = prefix
 */
  /*else*/ {
    __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 203, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ignored_net); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 203, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
      __pyx_t_6 = __pyx_t_2; __Pyx_INCREF(__pyx_t_6); __pyx_t_5 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 203, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 203, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (likely(!__pyx_t_8)) {
        if (likely(PyList_CheckExact(__pyx_t_6))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_6)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 203, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_6, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 203, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 203, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_6, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 203, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_8(__pyx_t_6);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 203, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_v_net, __pyx_t_2);
      __pyx_t_2 = 0;
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_netaddr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 203, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_IPNetwork); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 203, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
        }
      }
      __pyx_t_2 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_9, __pyx_v_net) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_net);
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 203, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_7, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 203, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ignored_net, __pyx_t_7) < 0) __PYX_ERR(0, 203, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __pyx_L7:;

  /* "btdht/dht.pyx":204
 *         else:
 *             self.ignored_net = [netaddr.IPNetwork(net) for net in self.ignored_net]
 *         self.debuglvl = debuglvl             # <<<<<<<<<<<<<<
 *         self.prefix = prefix
 * 
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debuglvl, __pyx_v_debuglvl) < 0) __PYX_ERR(0, 204, __pyx_L1_error)

  /* "btdht/dht.pyx":205
 *             self.ignored_net = [netaddr.IPNetwork(net) for net in self.ignored_net]
 *         self.debuglvl = debuglvl
 *         self.prefix = prefix             # <<<<<<<<<<<<<<
 * 
 *         # initialize public attributes
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_prefix, __pyx_v_prefix) < 0) __PYX_ERR(0, 205, __pyx_L1_error)

  /* "btdht/dht.pyx":208
 * 
 *         # initialize public attributes
 *         self.threads = []             # <<<<<<<<<<<<<<
 *         self.transaction_type = {}
 *         self.token = collections.defaultdict(list)
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 208, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads, __pyx_t_7) < 0) __PYX_ERR(0, 208, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":209
 *         # initialize public attributes
 *         self.threads = []
 *         self.transaction_type = {}             # <<<<<<<<<<<<<<
 *         self.token = collections.defaultdict(list)
 *         self.mytoken = {}
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 209, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type, __pyx_t_7) < 0) __PYX_ERR(0, 209, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":210
 *         self.threads = []
 *         self.transaction_type = {}
 *         self.token = collections.defaultdict(list)             # <<<<<<<<<<<<<<
 *         self.mytoken = {}
 *         self.stoped = True
 */
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_collections); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_7 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_6, ((PyObject *)(&PyList_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)(&PyList_Type)));
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_token, __pyx_t_7) < 0) __PYX_ERR(0, 210, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":211
 *         self.transaction_type = {}
 *         self.token = collections.defaultdict(list)
 *         self.mytoken = {}             # <<<<<<<<<<<<<<
 *         self.stoped = True
 *         self.last_msg = 0
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 211, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mytoken, __pyx_t_7) < 0) __PYX_ERR(0, 211, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":212
 *         self.token = collections.defaultdict(list)
 *         self.mytoken = {}
 *         self.stoped = True             # <<<<<<<<<<<<<<
 *         self.last_msg = 0
 *         self.last_msg_rep = 0
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stoped, Py_True) < 0) __PYX_ERR(0, 212, __pyx_L1_error)

  /* "btdht/dht.pyx":213
 *         self.mytoken = {}
 *         self.stoped = True
 *         self.last_msg = 0             # <<<<<<<<<<<<<<
 *         self.last_msg_rep = 0
 * 
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_msg, __pyx_int_0) < 0) __PYX_ERR(0, 213, __pyx_L1_error)

  /* "btdht/dht.pyx":214
 *         self.stoped = True
 *         self.last_msg = 0
 *         self.last_msg_rep = 0             # <<<<<<<<<<<<<<
 * 
 *         # initialize private attributes
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_msg_rep, __pyx_int_0) < 0) __PYX_ERR(0, 214, __pyx_L1_error)

  /* "btdht/dht.pyx":217
 * 
 *         # initialize private attributes
 *         self._peers=collections.defaultdict(collections.OrderedDict)             # <<<<<<<<<<<<<<
 *         self._got_peers=collections.defaultdict(collections.OrderedDict)
 *         self._get_peer_loop_list = []
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 217, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 217, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 217, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_7 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 217, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_peers, __pyx_t_7) < 0) __PYX_ERR(0, 217, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":218
 *         # initialize private attributes
 *         self._peers=collections.defaultdict(collections.OrderedDict)
 *         self._got_peers=collections.defaultdict(collections.OrderedDict)             # <<<<<<<<<<<<<<
 *         self._get_peer_loop_list = []
 *         self._get_peer_loop_lock = {}
 */
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_collections); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 218, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 218, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_collections); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 218, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 218, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_7 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_6, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 218, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers, __pyx_t_7) < 0) __PYX_ERR(0, 218, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":219
 *         self._peers=collections.defaultdict(collections.OrderedDict)
 *         self._got_peers=collections.defaultdict(collections.OrderedDict)
 *         self._get_peer_loop_list = []             # <<<<<<<<<<<<<<
 *         self._get_peer_loop_lock = {}
 *         self._get_closest_loop_lock = {}
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 219, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_peer_loop_list, __pyx_t_7) < 0) __PYX_ERR(0, 219, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":220
 *         self._got_peers=collections.defaultdict(collections.OrderedDict)
 *         self._get_peer_loop_list = []
 *         self._get_peer_loop_lock = {}             # <<<<<<<<<<<<<<
 *         self._get_closest_loop_lock = {}
 *         self._to_process_registered = set()
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 220, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_peer_loop_lock, __pyx_t_7) < 0) __PYX_ERR(0, 220, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":221
 *         self._get_peer_loop_list = []
 *         self._get_peer_loop_lock = {}
 *         self._get_closest_loop_lock = {}             # <<<<<<<<<<<<<<
 *         self._to_process_registered = set()
 *         self._threads = []
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 221, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_closest_loop_lock, __pyx_t_7) < 0) __PYX_ERR(0, 221, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":222
 *         self._get_peer_loop_lock = {}
 *         self._get_closest_loop_lock = {}
 *         self._to_process_registered = set()             # <<<<<<<<<<<<<<
 *         self._threads = []
 *         self._threads_zombie = []
 */
  __pyx_t_7 = PySet_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 222, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_process_registered, __pyx_t_7) < 0) __PYX_ERR(0, 222, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":223
 *         self._get_closest_loop_lock = {}
 *         self._to_process_registered = set()
 *         self._threads = []             # <<<<<<<<<<<<<<
 *         self._threads_zombie = []
 *         self._last_debug = ""
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 223, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2, __pyx_t_7) < 0) __PYX_ERR(0, 223, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":224
 *         self._to_process_registered = set()
 *         self._threads = []
 *         self._threads_zombie = []             # <<<<<<<<<<<<<<
 *         self._last_debug = ""
 *         self._last_debug_time = 0
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_zombie, __pyx_t_7) < 0) __PYX_ERR(0, 224, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":225
 *         self._threads = []
 *         self._threads_zombie = []
 *         self._last_debug = ""             # <<<<<<<<<<<<<<
 *         self._last_debug_time = 0
 *         self._socket_in = 0
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_debug, __pyx_kp_s__2) < 0) __PYX_ERR(0, 225, __pyx_L1_error)

  /* "btdht/dht.pyx":226
 *         self._threads_zombie = []
 *         self._last_debug = ""
 *         self._last_debug_time = 0             # <<<<<<<<<<<<<<
 *         self._socket_in = 0
 *         self._socket_out = 0
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_debug_time, __pyx_int_0) < 0) __PYX_ERR(0, 226, __pyx_L1_error)

  /* "btdht/dht.pyx":227
 *         self._last_debug = ""
 *         self._last_debug_time = 0
 *         self._socket_in = 0             # <<<<<<<<<<<<<<
 *         self._socket_out = 0
 *         self._last_socket_stats = 0
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_in, __pyx_int_0) < 0) __PYX_ERR(0, 227, __pyx_L1_error)

  /* "btdht/dht.pyx":228
 *         self._last_debug_time = 0
 *         self._socket_in = 0
 *         self._socket_out = 0             # <<<<<<<<<<<<<<
 *         self._last_socket_stats = 0
 *         self._long_clean = 0
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_out, __pyx_int_0) < 0) __PYX_ERR(0, 228, __pyx_L1_error)

  /* "btdht/dht.pyx":229
 *         self._socket_in = 0
 *         self._socket_out = 0
 *         self._last_socket_stats = 0             # <<<<<<<<<<<<<<
 *         self._long_clean = 0
 *         self._root_heigth = 0
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_socket_stats, __pyx_int_0) < 0) __PYX_ERR(0, 229, __pyx_L1_error)

  /* "btdht/dht.pyx":230
 *         self._socket_out = 0
 *         self._last_socket_stats = 0
 *         self._long_clean = 0             # <<<<<<<<<<<<<<
 *         self._root_heigth = 0
 *         self._to_process = PollableQueue(maxsize=process_queue_size)
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_long_clean, __pyx_int_0) < 0) __PYX_ERR(0, 230, __pyx_L1_error)

  /* "btdht/dht.pyx":231
 *         self._last_socket_stats = 0
 *         self._long_clean = 0
 *         self._root_heigth = 0             # <<<<<<<<<<<<<<
 *         self._to_process = PollableQueue(maxsize=process_queue_size)
 * 
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root_heigth, __pyx_int_0) < 0) __PYX_ERR(0, 231, __pyx_L1_error)

  /* "btdht/dht.pyx":232
 *         self._long_clean = 0
 *         self._root_heigth = 0
 *         self._to_process = PollableQueue(maxsize=process_queue_size)             # <<<<<<<<<<<<<<
 * 
 *         self.to_schedule = [
 */
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_PollableQueue); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_maxsize, __pyx_v_process_queue_size) < 0) __PYX_ERR(0, 232, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_process, __pyx_t_2) < 0) __PYX_ERR(0, 232, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "btdht/dht.pyx":235
 * 
 *         self.to_schedule = [
 *             ("%sroutine" % self.prefix, self._routine, False),             # <<<<<<<<<<<<<<
 *             ("%sget_peers_closest_loop" % self.prefix, self._get_peers_closest_loop, False),
 *             ("%sprocess_loop" % self.prefix, self._process_loop, True)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_prefix); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyString_FormatSafe(__pyx_kp_s_sroutine, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_routine); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_2);
  __Pyx_INCREF(Py_False);
  __Pyx_GIVEREF(Py_False);
  PyTuple_SET_ITEM(__pyx_t_7, 2, Py_False);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":236
 *         self.to_schedule = [
 *             ("%sroutine" % self.prefix, self._routine, False),
 *             ("%sget_peers_closest_loop" % self.prefix, self._get_peers_closest_loop, False),             # <<<<<<<<<<<<<<
 *             ("%sprocess_loop" % self.prefix, self._process_loop, True)
 *         ]
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_prefix); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 236, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyString_FormatSafe(__pyx_kp_s_sget_peers_closest_loop, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 236, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_peers_closest_loop); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 236, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 236, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_2);
  __Pyx_INCREF(Py_False);
  __Pyx_GIVEREF(Py_False);
  PyTuple_SET_ITEM(__pyx_t_6, 2, Py_False);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":237
 *             ("%sroutine" % self.prefix, self._routine, False),
 *             ("%sget_peers_closest_loop" % self.prefix, self._get_peers_closest_loop, False),
 *             ("%sprocess_loop" % self.prefix, self._process_loop, True)             # <<<<<<<<<<<<<<
 *         ]
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_prefix); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyString_FormatSafe(__pyx_kp_s_sprocess_loop, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_process_loop); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_9, 2, Py_True);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":234
 *         self._to_process = PollableQueue(maxsize=process_queue_size)
 * 
 *         self.to_schedule = [             # <<<<<<<<<<<<<<
 *             ("%sroutine" % self.prefix, self._routine, False),
 *             ("%sget_peers_closest_loop" % self.prefix, self._get_peers_closest_loop, False),
 */
  __pyx_t_2 = PyList_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_7);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_6);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_9);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_t_9);
  __pyx_t_7 = 0;
  __pyx_t_6 = 0;
  __pyx_t_9 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_schedule, __pyx_t_2) < 0) __PYX_ERR(0, 234, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "btdht/dht.pyx":169
 * 
 * 
 *     def __init__(self, routing_table=None, bind_port=None, bind_ip="0.0.0.0",             # <<<<<<<<<<<<<<
 *       id=None, ignored_ip=[], debuglvl=0, prefix="", process_queue_size=500,
 *       ignored_net=None, scheduler=None
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_net);
  __Pyx_XDECREF(__pyx_v_id);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":240
 *         ]
 * 
 *     def save(self, filename=None, max_node=None):             # <<<<<<<<<<<<<<
 *         """save the current list of nodes to ``filename``.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_3save(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_2save[] = "save the current list of nodes to ``filename``.\n\n        :param str filename: An optional filename where to save the current list of nodes.\n            If not provided, the file ``\"dht_`myid`.status`` is used.\n        :param int max_node: An optional integer to limit the number of saved nodes.\n            If not provided, all of the routing table nodes are saved.\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_3save(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_filename = 0;
  PyObject *__pyx_v_max_node = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("save (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename,&__pyx_n_s_max_node,0};
    PyObject* values[2] = {0,0};
    values[0] = ((PyObject *)Py_None);
    values[1] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filename);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_max_node);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "save") < 0)) __PYX_ERR(0, 240, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_filename = values[0];
    __pyx_v_max_node = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("save", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 240, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.save", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_2save(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_filename, __pyx_v_max_node);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_2save(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_max_node) {
  PyObject *__pyx_v_nodes_nb = NULL;
  PyObject *__pyx_v_myid = NULL;
  PyObject *__pyx_v_f = NULL;
  PyObject *__pyx_v_bucket = NULL;
  PyObject *__pyx_v_node = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  Py_ssize_t __pyx_t_11;
  PyObject *(*__pyx_t_12)(PyObject *);
  Py_ssize_t __pyx_t_13;
  PyObject *(*__pyx_t_14)(PyObject *);
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("save", 0);
  __Pyx_INCREF(__pyx_v_filename);

  /* "btdht/dht.pyx":248
 *             If not provided, all of the routing table nodes are saved.
 *         """
 *         nodes_nb = 0             # <<<<<<<<<<<<<<
 *         if filename is None:
 *             myid = binascii.b2a_hex(self.myid.value)
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_v_nodes_nb = __pyx_int_0;

  /* "btdht/dht.pyx":249
 *         """
 *         nodes_nb = 0
 *         if filename is None:             # <<<<<<<<<<<<<<
 *             myid = binascii.b2a_hex(self.myid.value)
 *             filename = "dht_%s.status" % myid
 */
  __pyx_t_1 = (__pyx_v_filename == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "btdht/dht.pyx":250
 *         nodes_nb = 0
 *         if filename is None:
 *             myid = binascii.b2a_hex(self.myid.value)             # <<<<<<<<<<<<<<
 *             filename = "dht_%s.status" % myid
 *         with open(filename, 'wb') as f:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_binascii); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_b2a_hex); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_myid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_value); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 250, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_myid = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":251
 *         if filename is None:
 *             myid = binascii.b2a_hex(self.myid.value)
 *             filename = "dht_%s.status" % myid             # <<<<<<<<<<<<<<
 *         with open(filename, 'wb') as f:
 *             for bucket in self.root.trie.values():
 */
    __pyx_t_3 = __Pyx_PyString_FormatSafe(__pyx_kp_s_dht__s_status, __pyx_v_myid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 251, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF_SET(__pyx_v_filename, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":249
 *         """
 *         nodes_nb = 0
 *         if filename is None:             # <<<<<<<<<<<<<<
 *             myid = binascii.b2a_hex(self.myid.value)
 *             filename = "dht_%s.status" % myid
 */
  }

  /* "btdht/dht.pyx":252
 *             myid = binascii.b2a_hex(self.myid.value)
 *             filename = "dht_%s.status" % myid
 *         with open(filename, 'wb') as f:             # <<<<<<<<<<<<<<
 *             for bucket in self.root.trie.values():
 *                 for node in bucket:
 */
  /*with:*/ {
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_filename);
    __Pyx_GIVEREF(__pyx_v_filename);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_filename);
    __Pyx_INCREF(__pyx_n_s_wb);
    __Pyx_GIVEREF(__pyx_n_s_wb);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_wb);
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_exit); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 252, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_enter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 252, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 252, __pyx_L4_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    /*try:*/ {
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        __Pyx_XGOTREF(__pyx_t_8);
        __Pyx_XGOTREF(__pyx_t_9);
        __Pyx_XGOTREF(__pyx_t_10);
        /*try:*/ {
          __pyx_v_f = __pyx_t_6;
          __pyx_t_6 = 0;

          /* "btdht/dht.pyx":253
 *             filename = "dht_%s.status" % myid
 *         with open(filename, 'wb') as f:
 *             for bucket in self.root.trie.values():             # <<<<<<<<<<<<<<
 *                 for node in bucket:
 *                     if node.good:
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 253, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_trie); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 253, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 253, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_3 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_3)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
            }
          }
          __pyx_t_6 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 253, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
            __pyx_t_5 = __pyx_t_6; __Pyx_INCREF(__pyx_t_5); __pyx_t_11 = 0;
            __pyx_t_12 = NULL;
          } else {
            __pyx_t_11 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 253, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_12 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 253, __pyx_L8_error)
          }
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          for (;;) {
            if (likely(!__pyx_t_12)) {
              if (likely(PyList_CheckExact(__pyx_t_5))) {
                if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_5)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_6 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_11); __Pyx_INCREF(__pyx_t_6); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 253, __pyx_L8_error)
                #else
                __pyx_t_6 = PySequence_ITEM(__pyx_t_5, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 253, __pyx_L8_error)
                __Pyx_GOTREF(__pyx_t_6);
                #endif
              } else {
                if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_11); __Pyx_INCREF(__pyx_t_6); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 253, __pyx_L8_error)
                #else
                __pyx_t_6 = PySequence_ITEM(__pyx_t_5, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 253, __pyx_L8_error)
                __Pyx_GOTREF(__pyx_t_6);
                #endif
              }
            } else {
              __pyx_t_6 = __pyx_t_12(__pyx_t_5);
              if (unlikely(!__pyx_t_6)) {
                PyObject* exc_type = PyErr_Occurred();
                if (exc_type) {
                  if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                  else __PYX_ERR(0, 253, __pyx_L8_error)
                }
                break;
              }
              __Pyx_GOTREF(__pyx_t_6);
            }
            __Pyx_XDECREF_SET(__pyx_v_bucket, __pyx_t_6);
            __pyx_t_6 = 0;

            /* "btdht/dht.pyx":254
 *         with open(filename, 'wb') as f:
 *             for bucket in self.root.trie.values():
 *                 for node in bucket:             # <<<<<<<<<<<<<<
 *                     if node.good:
 *                         f.write(node.compact_info())
 */
            if (likely(PyList_CheckExact(__pyx_v_bucket)) || PyTuple_CheckExact(__pyx_v_bucket)) {
              __pyx_t_6 = __pyx_v_bucket; __Pyx_INCREF(__pyx_t_6); __pyx_t_13 = 0;
              __pyx_t_14 = NULL;
            } else {
              __pyx_t_13 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_v_bucket); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 254, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_6);
              __pyx_t_14 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 254, __pyx_L8_error)
            }
            for (;;) {
              if (likely(!__pyx_t_14)) {
                if (likely(PyList_CheckExact(__pyx_t_6))) {
                  if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_6)) break;
                  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                  __pyx_t_3 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 254, __pyx_L8_error)
                  #else
                  __pyx_t_3 = PySequence_ITEM(__pyx_t_6, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 254, __pyx_L8_error)
                  __Pyx_GOTREF(__pyx_t_3);
                  #endif
                } else {
                  if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
                  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                  __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 254, __pyx_L8_error)
                  #else
                  __pyx_t_3 = PySequence_ITEM(__pyx_t_6, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 254, __pyx_L8_error)
                  __Pyx_GOTREF(__pyx_t_3);
                  #endif
                }
              } else {
                __pyx_t_3 = __pyx_t_14(__pyx_t_6);
                if (unlikely(!__pyx_t_3)) {
                  PyObject* exc_type = PyErr_Occurred();
                  if (exc_type) {
                    if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                    else __PYX_ERR(0, 254, __pyx_L8_error)
                  }
                  break;
                }
                __Pyx_GOTREF(__pyx_t_3);
              }
              __Pyx_XDECREF_SET(__pyx_v_node, __pyx_t_3);
              __pyx_t_3 = 0;

              /* "btdht/dht.pyx":255
 *             for bucket in self.root.trie.values():
 *                 for node in bucket:
 *                     if node.good:             # <<<<<<<<<<<<<<
 *                         f.write(node.compact_info())
 *                         if max_node is not None:
 */
              __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_good); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 255, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_3);
              __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 255, __pyx_L8_error)
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              if (__pyx_t_2) {

                /* "btdht/dht.pyx":256
 *                 for node in bucket:
 *                     if node.good:
 *                         f.write(node.compact_info())             # <<<<<<<<<<<<<<
 *                         if max_node is not None:
 *                             nodes_nb+=1
 */
                __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_f, __pyx_n_s_write); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 256, __pyx_L8_error)
                __Pyx_GOTREF(__pyx_t_4);
                __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_compact_info); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 256, __pyx_L8_error)
                __Pyx_GOTREF(__pyx_t_16);
                __pyx_t_17 = NULL;
                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_16))) {
                  __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_16);
                  if (likely(__pyx_t_17)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
                    __Pyx_INCREF(__pyx_t_17);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_16, function);
                  }
                }
                __pyx_t_15 = (__pyx_t_17) ? __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_17) : __Pyx_PyObject_CallNoArg(__pyx_t_16);
                __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
                if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 256, __pyx_L8_error)
                __Pyx_GOTREF(__pyx_t_15);
                __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
                __pyx_t_16 = NULL;
                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
                  __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_4);
                  if (likely(__pyx_t_16)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
                    __Pyx_INCREF(__pyx_t_16);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_4, function);
                  }
                }
                __pyx_t_3 = (__pyx_t_16) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_16, __pyx_t_15) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_15);
                __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
                __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
                if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 256, __pyx_L8_error)
                __Pyx_GOTREF(__pyx_t_3);
                __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

                /* "btdht/dht.pyx":257
 *                     if node.good:
 *                         f.write(node.compact_info())
 *                         if max_node is not None:             # <<<<<<<<<<<<<<
 *                             nodes_nb+=1
 *                             if nodes_nb >= max_node:
 */
                __pyx_t_2 = (__pyx_v_max_node != Py_None);
                __pyx_t_1 = (__pyx_t_2 != 0);
                if (__pyx_t_1) {

                  /* "btdht/dht.pyx":258
 *                         f.write(node.compact_info())
 *                         if max_node is not None:
 *                             nodes_nb+=1             # <<<<<<<<<<<<<<
 *                             if nodes_nb >= max_node:
 *                                 return
 */
                  __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_nodes_nb, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 258, __pyx_L8_error)
                  __Pyx_GOTREF(__pyx_t_3);
                  __Pyx_DECREF_SET(__pyx_v_nodes_nb, __pyx_t_3);
                  __pyx_t_3 = 0;

                  /* "btdht/dht.pyx":259
 *                         if max_node is not None:
 *                             nodes_nb+=1
 *                             if nodes_nb >= max_node:             # <<<<<<<<<<<<<<
 *                                 return
 * 
 */
                  __pyx_t_3 = PyObject_RichCompare(__pyx_v_nodes_nb, __pyx_v_max_node, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 259, __pyx_L8_error)
                  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 259, __pyx_L8_error)
                  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
                  if (__pyx_t_1) {

                    /* "btdht/dht.pyx":260
 *                             nodes_nb+=1
 *                             if nodes_nb >= max_node:
 *                                 return             # <<<<<<<<<<<<<<
 * 
 *     def load(self, filename=None, max_node=None):
 */
                    __Pyx_XDECREF(__pyx_r);
                    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
                    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
                    goto __pyx_L12_try_return;

                    /* "btdht/dht.pyx":259
 *                         if max_node is not None:
 *                             nodes_nb+=1
 *                             if nodes_nb >= max_node:             # <<<<<<<<<<<<<<
 *                                 return
 * 
 */
                  }

                  /* "btdht/dht.pyx":257
 *                     if node.good:
 *                         f.write(node.compact_info())
 *                         if max_node is not None:             # <<<<<<<<<<<<<<
 *                             nodes_nb+=1
 *                             if nodes_nb >= max_node:
 */
                }

                /* "btdht/dht.pyx":255
 *             for bucket in self.root.trie.values():
 *                 for node in bucket:
 *                     if node.good:             # <<<<<<<<<<<<<<
 *                         f.write(node.compact_info())
 *                         if max_node is not None:
 */
              }

              /* "btdht/dht.pyx":254
 *         with open(filename, 'wb') as f:
 *             for bucket in self.root.trie.values():
 *                 for node in bucket:             # <<<<<<<<<<<<<<
 *                     if node.good:
 *                         f.write(node.compact_info())
 */
            }
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

            /* "btdht/dht.pyx":253
 *             filename = "dht_%s.status" % myid
 *         with open(filename, 'wb') as f:
 *             for bucket in self.root.trie.values():             # <<<<<<<<<<<<<<
 *                 for node in bucket:
 *                     if node.good:
 */
          }
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

          /* "btdht/dht.pyx":252
 *             myid = binascii.b2a_hex(self.myid.value)
 *             filename = "dht_%s.status" % myid
 *         with open(filename, 'wb') as f:             # <<<<<<<<<<<<<<
 *             for bucket in self.root.trie.values():
 *                 for node in bucket:
 */
        }
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L13_try_end;
        __pyx_L8_error:;
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        /*except:*/ {
          __Pyx_AddTraceback("btdht.dht.DHT_BASE.save", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_3) < 0) __PYX_ERR(0, 252, __pyx_L10_except_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_4 = PyTuple_Pack(3, __pyx_t_5, __pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 252, __pyx_L10_except_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 252, __pyx_L10_except_error)
          __Pyx_GOTREF(__pyx_t_18);
          __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_18);
          __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
          if (__pyx_t_1 < 0) __PYX_ERR(0, 252, __pyx_L10_except_error)
          __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
          if (__pyx_t_2) {
            __Pyx_GIVEREF(__pyx_t_5);
            __Pyx_GIVEREF(__pyx_t_6);
            __Pyx_XGIVEREF(__pyx_t_3);
            __Pyx_ErrRestoreWithState(__pyx_t_5, __pyx_t_6, __pyx_t_3);
            __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_3 = 0; 
            __PYX_ERR(0, 252, __pyx_L10_except_error)
          }
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          goto __pyx_L9_exception_handled;
        }
        __pyx_L10_except_error:;
        __Pyx_XGIVEREF(__pyx_t_8);
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        goto __pyx_L1_error;
        __pyx_L12_try_return:;
        __Pyx_XGIVEREF(__pyx_t_8);
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        goto __pyx_L5_return;
        __pyx_L9_exception_handled:;
        __Pyx_XGIVEREF(__pyx_t_8);
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        __pyx_L13_try_end:;
      }
    }
    /*finally:*/ {
      /*normal exit:*/{
        if (__pyx_t_7) {
          __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__5, NULL);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 252, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        }
        goto __pyx_L7;
      }
      __pyx_L5_return: {
        __pyx_t_10 = __pyx_r;
        __pyx_r = 0;
        if (__pyx_t_7) {
          __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__5, NULL);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 252, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __pyx_r = __pyx_t_10;
        __pyx_t_10 = 0;
        goto __pyx_L0;
      }
      __pyx_L7:;
    }
    goto __pyx_L24;
    __pyx_L4_error:;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    goto __pyx_L1_error;
    __pyx_L24:;
  }

  /* "btdht/dht.pyx":240
 *         ]
 * 
 *     def save(self, filename=None, max_node=None):             # <<<<<<<<<<<<<<
 *         """save the current list of nodes to ``filename``.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.save", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_nodes_nb);
  __Pyx_XDECREF(__pyx_v_myid);
  __Pyx_XDECREF(__pyx_v_f);
  __Pyx_XDECREF(__pyx_v_bucket);
  __Pyx_XDECREF(__pyx_v_node);
  __Pyx_XDECREF(__pyx_v_filename);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":262
 *                                 return
 * 
 *     def load(self, filename=None, max_node=None):             # <<<<<<<<<<<<<<
 *         """load a list of nodes from ``filename``.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_5load(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_4load[] = "load a list of nodes from ``filename``.\n\n        :param str filename: An optional filename where to load the list of nodes.\n            If not provided, the file ``\"dht_`myid`.status`` is used.\n        :param int max_node: An optional integer to limit the number of loaded nodes.\n            If not provided, all of the file nodes are loaded.\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_5load(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_filename = 0;
  PyObject *__pyx_v_max_node = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("load (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename,&__pyx_n_s_max_node,0};
    PyObject* values[2] = {0,0};
    values[0] = ((PyObject *)Py_None);
    values[1] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_filename);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_max_node);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "load") < 0)) __PYX_ERR(0, 262, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_filename = values[0];
    __pyx_v_max_node = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("load", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 262, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.load", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_4load(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_filename, __pyx_v_max_node);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_4load(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_max_node) {
  PyObject *__pyx_v_nodes_nb = NULL;
  PyObject *__pyx_v_myid = NULL;
  PyObject *__pyx_v_f = NULL;
  PyObject *__pyx_v_nodes = NULL;
  PyObject *__pyx_v_node = NULL;
  PyObject *__pyx_v_e = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  Py_ssize_t __pyx_t_14;
  PyObject *(*__pyx_t_15)(PyObject *);
  int __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  PyObject *__pyx_t_21 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("load", 0);
  __Pyx_INCREF(__pyx_v_filename);

  /* "btdht/dht.pyx":270
 *             If not provided, all of the file nodes are loaded.
 *         """
 *         nodes_nb = 0             # <<<<<<<<<<<<<<
 *         if filename is None:
 *             myid = binascii.b2a_hex(self.myid.value)
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_v_nodes_nb = __pyx_int_0;

  /* "btdht/dht.pyx":271
 *         """
 *         nodes_nb = 0
 *         if filename is None:             # <<<<<<<<<<<<<<
 *             myid = binascii.b2a_hex(self.myid.value)
 *             filename = "dht_%s.status" % myid
 */
  __pyx_t_1 = (__pyx_v_filename == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "btdht/dht.pyx":272
 *         nodes_nb = 0
 *         if filename is None:
 *             myid = binascii.b2a_hex(self.myid.value)             # <<<<<<<<<<<<<<
 *             filename = "dht_%s.status" % myid
 *         try:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_binascii); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 272, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_b2a_hex); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 272, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_myid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 272, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_value); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 272, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 272, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_myid = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":273
 *         if filename is None:
 *             myid = binascii.b2a_hex(self.myid.value)
 *             filename = "dht_%s.status" % myid             # <<<<<<<<<<<<<<
 *         try:
 *             with open(filename, 'rb') as f:
 */
    __pyx_t_3 = __Pyx_PyString_FormatSafe(__pyx_kp_s_dht__s_status, __pyx_v_myid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 273, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF_SET(__pyx_v_filename, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":271
 *         """
 *         nodes_nb = 0
 *         if filename is None:             # <<<<<<<<<<<<<<
 *             myid = binascii.b2a_hex(self.myid.value)
 *             filename = "dht_%s.status" % myid
 */
  }

  /* "btdht/dht.pyx":274
 *             myid = binascii.b2a_hex(self.myid.value)
 *             filename = "dht_%s.status" % myid
 *         try:             # <<<<<<<<<<<<<<
 *             with open(filename, 'rb') as f:
 *                 nodes = f.read(26*100)
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
    __Pyx_XGOTREF(__pyx_t_7);
    __Pyx_XGOTREF(__pyx_t_8);
    __Pyx_XGOTREF(__pyx_t_9);
    /*try:*/ {

      /* "btdht/dht.pyx":275
 *             filename = "dht_%s.status" % myid
 *         try:
 *             with open(filename, 'rb') as f:             # <<<<<<<<<<<<<<
 *                 nodes = f.read(26*100)
 *                 while nodes:
 */
      /*with:*/ {
        __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 275, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_v_filename);
        __Pyx_GIVEREF(__pyx_v_filename);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_filename);
        __Pyx_INCREF(__pyx_n_s_rb);
        __Pyx_GIVEREF(__pyx_n_s_rb);
        PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_rb);
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 275, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_10 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_exit); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 275, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_enter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 275, __pyx_L10_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_4 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
          }
        }
        __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 275, __pyx_L10_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = __pyx_t_3;
        __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        /*try:*/ {
          {
            __Pyx_PyThreadState_declare
            __Pyx_PyThreadState_assign
            __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
            __Pyx_XGOTREF(__pyx_t_11);
            __Pyx_XGOTREF(__pyx_t_12);
            __Pyx_XGOTREF(__pyx_t_13);
            /*try:*/ {
              __pyx_v_f = __pyx_t_6;
              __pyx_t_6 = 0;

              /* "btdht/dht.pyx":276
 *         try:
 *             with open(filename, 'rb') as f:
 *                 nodes = f.read(26*100)             # <<<<<<<<<<<<<<
 *                 while nodes:
 *                     for node in Node.from_compact_infos(nodes):
 */
              __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_f, __pyx_n_s_read); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 276, __pyx_L14_error)
              __Pyx_GOTREF(__pyx_t_5);
              __pyx_t_3 = NULL;
              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
                __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
                if (likely(__pyx_t_3)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
                  __Pyx_INCREF(__pyx_t_3);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_5, function);
                }
              }
              __pyx_t_6 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_3, __pyx_int_2600) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_int_2600);
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 276, __pyx_L14_error)
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              __pyx_v_nodes = __pyx_t_6;
              __pyx_t_6 = 0;

              /* "btdht/dht.pyx":277
 *             with open(filename, 'rb') as f:
 *                 nodes = f.read(26*100)
 *                 while nodes:             # <<<<<<<<<<<<<<
 *                     for node in Node.from_compact_infos(nodes):
 *                         self.root.add(self, node)
 */
              while (1) {
                __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_nodes); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 277, __pyx_L14_error)
                if (!__pyx_t_2) break;

                /* "btdht/dht.pyx":278
 *                 nodes = f.read(26*100)
 *                 while nodes:
 *                     for node in Node.from_compact_infos(nodes):             # <<<<<<<<<<<<<<
 *                         self.root.add(self, node)
 *                         if max_node is not None:
 */
                __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5btdht_3dht_Node), __pyx_n_s_from_compact_infos); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 278, __pyx_L14_error)
                __Pyx_GOTREF(__pyx_t_5);
                __pyx_t_3 = NULL;
                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
                  __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
                  if (likely(__pyx_t_3)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
                    __Pyx_INCREF(__pyx_t_3);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_5, function);
                  }
                }
                __pyx_t_6 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_3, __pyx_v_nodes) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_nodes);
                __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
                if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 278, __pyx_L14_error)
                __Pyx_GOTREF(__pyx_t_6);
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
                  __pyx_t_5 = __pyx_t_6; __Pyx_INCREF(__pyx_t_5); __pyx_t_14 = 0;
                  __pyx_t_15 = NULL;
                } else {
                  __pyx_t_14 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 278, __pyx_L14_error)
                  __Pyx_GOTREF(__pyx_t_5);
                  __pyx_t_15 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 278, __pyx_L14_error)
                }
                __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
                for (;;) {
                  if (likely(!__pyx_t_15)) {
                    if (likely(PyList_CheckExact(__pyx_t_5))) {
                      if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_5)) break;
                      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                      __pyx_t_6 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_14); __Pyx_INCREF(__pyx_t_6); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 278, __pyx_L14_error)
                      #else
                      __pyx_t_6 = PySequence_ITEM(__pyx_t_5, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 278, __pyx_L14_error)
                      __Pyx_GOTREF(__pyx_t_6);
                      #endif
                    } else {
                      if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
                      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                      __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_14); __Pyx_INCREF(__pyx_t_6); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 278, __pyx_L14_error)
                      #else
                      __pyx_t_6 = PySequence_ITEM(__pyx_t_5, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 278, __pyx_L14_error)
                      __Pyx_GOTREF(__pyx_t_6);
                      #endif
                    }
                  } else {
                    __pyx_t_6 = __pyx_t_15(__pyx_t_5);
                    if (unlikely(!__pyx_t_6)) {
                      PyObject* exc_type = PyErr_Occurred();
                      if (exc_type) {
                        if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                        else __PYX_ERR(0, 278, __pyx_L14_error)
                      }
                      break;
                    }
                    __Pyx_GOTREF(__pyx_t_6);
                  }
                  __Pyx_XDECREF_SET(__pyx_v_node, __pyx_t_6);
                  __pyx_t_6 = 0;

                  /* "btdht/dht.pyx":279
 *                 while nodes:
 *                     for node in Node.from_compact_infos(nodes):
 *                         self.root.add(self, node)             # <<<<<<<<<<<<<<
 *                         if max_node is not None:
 *                             nodes_nb+=1
 */
                  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 279, __pyx_L14_error)
                  __Pyx_GOTREF(__pyx_t_3);
                  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_add); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 279, __pyx_L14_error)
                  __Pyx_GOTREF(__pyx_t_4);
                  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
                  __pyx_t_3 = NULL;
                  __pyx_t_16 = 0;
                  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
                    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
                    if (likely(__pyx_t_3)) {
                      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
                      __Pyx_INCREF(__pyx_t_3);
                      __Pyx_INCREF(function);
                      __Pyx_DECREF_SET(__pyx_t_4, function);
                      __pyx_t_16 = 1;
                    }
                  }
                  #if CYTHON_FAST_PYCALL
                  if (PyFunction_Check(__pyx_t_4)) {
                    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_self), __pyx_v_node};
                    __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 279, __pyx_L14_error)
                    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
                    __Pyx_GOTREF(__pyx_t_6);
                  } else
                  #endif
                  #if CYTHON_FAST_PYCCALL
                  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
                    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_self), __pyx_v_node};
                    __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 279, __pyx_L14_error)
                    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
                    __Pyx_GOTREF(__pyx_t_6);
                  } else
                  #endif
                  {
                    __pyx_t_17 = PyTuple_New(2+__pyx_t_16); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 279, __pyx_L14_error)
                    __Pyx_GOTREF(__pyx_t_17);
                    if (__pyx_t_3) {
                      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_3); __pyx_t_3 = NULL;
                    }
                    __Pyx_INCREF(((PyObject *)__pyx_v_self));
                    __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
                    PyTuple_SET_ITEM(__pyx_t_17, 0+__pyx_t_16, ((PyObject *)__pyx_v_self));
                    __Pyx_INCREF(__pyx_v_node);
                    __Pyx_GIVEREF(__pyx_v_node);
                    PyTuple_SET_ITEM(__pyx_t_17, 1+__pyx_t_16, __pyx_v_node);
                    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_17, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 279, __pyx_L14_error)
                    __Pyx_GOTREF(__pyx_t_6);
                    __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
                  }
                  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

                  /* "btdht/dht.pyx":280
 *                     for node in Node.from_compact_infos(nodes):
 *                         self.root.add(self, node)
 *                         if max_node is not None:             # <<<<<<<<<<<<<<
 *                             nodes_nb+=1
 *                             if nodes_nb >= max_node:
 */
                  __pyx_t_2 = (__pyx_v_max_node != Py_None);
                  __pyx_t_1 = (__pyx_t_2 != 0);
                  if (__pyx_t_1) {

                    /* "btdht/dht.pyx":281
 *                         self.root.add(self, node)
 *                         if max_node is not None:
 *                             nodes_nb+=1             # <<<<<<<<<<<<<<
 *                             if nodes_nb >= max_node:
 *                                 return
 */
                    __pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_v_nodes_nb, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 281, __pyx_L14_error)
                    __Pyx_GOTREF(__pyx_t_6);
                    __Pyx_DECREF_SET(__pyx_v_nodes_nb, __pyx_t_6);
                    __pyx_t_6 = 0;

                    /* "btdht/dht.pyx":282
 *                         if max_node is not None:
 *                             nodes_nb+=1
 *                             if nodes_nb >= max_node:             # <<<<<<<<<<<<<<
 *                                 return
 *                     nodes = f.read(26*100)
 */
                    __pyx_t_6 = PyObject_RichCompare(__pyx_v_nodes_nb, __pyx_v_max_node, Py_GE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 282, __pyx_L14_error)
                    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 282, __pyx_L14_error)
                    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
                    if (__pyx_t_1) {

                      /* "btdht/dht.pyx":283
 *                             nodes_nb+=1
 *                             if nodes_nb >= max_node:
 *                                 return             # <<<<<<<<<<<<<<
 *                     nodes = f.read(26*100)
 *         except IOError as e:
 */
                      __Pyx_XDECREF(__pyx_r);
                      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
                      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                      goto __pyx_L18_try_return;

                      /* "btdht/dht.pyx":282
 *                         if max_node is not None:
 *                             nodes_nb+=1
 *                             if nodes_nb >= max_node:             # <<<<<<<<<<<<<<
 *                                 return
 *                     nodes = f.read(26*100)
 */
                    }

                    /* "btdht/dht.pyx":280
 *                     for node in Node.from_compact_infos(nodes):
 *                         self.root.add(self, node)
 *                         if max_node is not None:             # <<<<<<<<<<<<<<
 *                             nodes_nb+=1
 *                             if nodes_nb >= max_node:
 */
                  }

                  /* "btdht/dht.pyx":278
 *                 nodes = f.read(26*100)
 *                 while nodes:
 *                     for node in Node.from_compact_infos(nodes):             # <<<<<<<<<<<<<<
 *                         self.root.add(self, node)
 *                         if max_node is not None:
 */
                }
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

                /* "btdht/dht.pyx":284
 *                             if nodes_nb >= max_node:
 *                                 return
 *                     nodes = f.read(26*100)             # <<<<<<<<<<<<<<
 *         except IOError as e:
 *             self.debug(0, str(e))
 */
                __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_f, __pyx_n_s_read); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 284, __pyx_L14_error)
                __Pyx_GOTREF(__pyx_t_6);
                __pyx_t_4 = NULL;
                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
                  __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
                  if (likely(__pyx_t_4)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
                    __Pyx_INCREF(__pyx_t_4);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_6, function);
                  }
                }
                __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_4, __pyx_int_2600) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_int_2600);
                __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
                if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 284, __pyx_L14_error)
                __Pyx_GOTREF(__pyx_t_5);
                __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
                __Pyx_DECREF_SET(__pyx_v_nodes, __pyx_t_5);
                __pyx_t_5 = 0;
              }

              /* "btdht/dht.pyx":275
 *             filename = "dht_%s.status" % myid
 *         try:
 *             with open(filename, 'rb') as f:             # <<<<<<<<<<<<<<
 *                 nodes = f.read(26*100)
 *                 while nodes:
 */
            }
            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
            __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            goto __pyx_L19_try_end;
            __pyx_L14_error:;
            __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
            __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            /*except:*/ {
              __Pyx_AddTraceback("btdht.dht.DHT_BASE.load", __pyx_clineno, __pyx_lineno, __pyx_filename);
              if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_4) < 0) __PYX_ERR(0, 275, __pyx_L16_except_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_GOTREF(__pyx_t_4);
              __pyx_t_17 = PyTuple_Pack(3, __pyx_t_5, __pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 275, __pyx_L16_except_error)
              __Pyx_GOTREF(__pyx_t_17);
              __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_17, NULL);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
              if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 275, __pyx_L16_except_error)
              __Pyx_GOTREF(__pyx_t_18);
              __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_18);
              __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
              if (__pyx_t_1 < 0) __PYX_ERR(0, 275, __pyx_L16_except_error)
              __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
              if (__pyx_t_2) {
                __Pyx_GIVEREF(__pyx_t_5);
                __Pyx_GIVEREF(__pyx_t_6);
                __Pyx_XGIVEREF(__pyx_t_4);
                __Pyx_ErrRestoreWithState(__pyx_t_5, __pyx_t_6, __pyx_t_4);
                __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_4 = 0; 
                __PYX_ERR(0, 275, __pyx_L16_except_error)
              }
              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
              goto __pyx_L15_exception_handled;
            }
            __pyx_L16_except_error:;
            __Pyx_XGIVEREF(__pyx_t_11);
            __Pyx_XGIVEREF(__pyx_t_12);
            __Pyx_XGIVEREF(__pyx_t_13);
            __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
            goto __pyx_L4_error;
            __pyx_L18_try_return:;
            __Pyx_XGIVEREF(__pyx_t_11);
            __Pyx_XGIVEREF(__pyx_t_12);
            __Pyx_XGIVEREF(__pyx_t_13);
            __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
            goto __pyx_L11_return;
            __pyx_L15_exception_handled:;
            __Pyx_XGIVEREF(__pyx_t_11);
            __Pyx_XGIVEREF(__pyx_t_12);
            __Pyx_XGIVEREF(__pyx_t_13);
            __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
            __pyx_L19_try_end:;
          }
        }
        /*finally:*/ {
          /*normal exit:*/{
            if (__pyx_t_10) {
              __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__5, NULL);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 275, __pyx_L4_error)
              __Pyx_GOTREF(__pyx_t_13);
              __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
            }
            goto __pyx_L13;
          }
          __pyx_L11_return: {
            __pyx_t_13 = __pyx_r;
            __pyx_r = 0;
            if (__pyx_t_10) {
              __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__5, NULL);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 275, __pyx_L4_error)
              __Pyx_GOTREF(__pyx_t_12);
              __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
            }
            __pyx_r = __pyx_t_13;
            __pyx_t_13 = 0;
            goto __pyx_L8_try_return;
          }
          __pyx_L13:;
        }
        goto __pyx_L29;
        __pyx_L10_error:;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L4_error;
        __pyx_L29:;
      }

      /* "btdht/dht.pyx":274
 *             myid = binascii.b2a_hex(self.myid.value)
 *             filename = "dht_%s.status" % myid
 *         try:             # <<<<<<<<<<<<<<
 *             with open(filename, 'rb') as f:
 *                 nodes = f.read(26*100)
 */
    }
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    goto __pyx_L9_try_end;
    __pyx_L4_error:;
    __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "btdht/dht.pyx":285
 *                                 return
 *                     nodes = f.read(26*100)
 *         except IOError as e:             # <<<<<<<<<<<<<<
 *             self.debug(0, str(e))
 * 
 */
    __pyx_t_16 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_IOError);
    if (__pyx_t_16) {
      __Pyx_AddTraceback("btdht.dht.DHT_BASE.load", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_5) < 0) __PYX_ERR(0, 285, __pyx_L6_except_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __pyx_v_e = __pyx_t_6;

      /* "btdht/dht.pyx":286
 *                     nodes = f.read(26*100)
 *         except IOError as e:
 *             self.debug(0, str(e))             # <<<<<<<<<<<<<<
 * 
 *     def stop_bg(self):
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 286, __pyx_L6_except_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_19 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyString_Type)), __pyx_v_e); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 286, __pyx_L6_except_error)
      __Pyx_GOTREF(__pyx_t_19);
      __pyx_t_20 = NULL;
      __pyx_t_16 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_20)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_20);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_16 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_3)) {
        PyObject *__pyx_temp[3] = {__pyx_t_20, __pyx_int_0, __pyx_t_19};
        __pyx_t_17 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 286, __pyx_L6_except_error)
        __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_GOTREF(__pyx_t_17);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
        PyObject *__pyx_temp[3] = {__pyx_t_20, __pyx_int_0, __pyx_t_19};
        __pyx_t_17 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 286, __pyx_L6_except_error)
        __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_GOTREF(__pyx_t_17);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      } else
      #endif
      {
        __pyx_t_21 = PyTuple_New(2+__pyx_t_16); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 286, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_21);
        if (__pyx_t_20) {
          __Pyx_GIVEREF(__pyx_t_20); PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_20); __pyx_t_20 = NULL;
        }
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_21, 0+__pyx_t_16, __pyx_int_0);
        __Pyx_GIVEREF(__pyx_t_19);
        PyTuple_SET_ITEM(__pyx_t_21, 1+__pyx_t_16, __pyx_t_19);
        __pyx_t_19 = 0;
        __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_21, NULL); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 286, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_17);
        __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L5_exception_handled;
    }
    goto __pyx_L6_except_error;
    __pyx_L6_except_error:;

    /* "btdht/dht.pyx":274
 *             myid = binascii.b2a_hex(self.myid.value)
 *             filename = "dht_%s.status" % myid
 *         try:             # <<<<<<<<<<<<<<
 *             with open(filename, 'rb') as f:
 *                 nodes = f.read(26*100)
 */
    __Pyx_XGIVEREF(__pyx_t_7);
    __Pyx_XGIVEREF(__pyx_t_8);
    __Pyx_XGIVEREF(__pyx_t_9);
    __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
    goto __pyx_L1_error;
    __pyx_L8_try_return:;
    __Pyx_XGIVEREF(__pyx_t_7);
    __Pyx_XGIVEREF(__pyx_t_8);
    __Pyx_XGIVEREF(__pyx_t_9);
    __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
    goto __pyx_L0;
    __pyx_L5_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_7);
    __Pyx_XGIVEREF(__pyx_t_8);
    __Pyx_XGIVEREF(__pyx_t_9);
    __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
    __pyx_L9_try_end:;
  }

  /* "btdht/dht.pyx":262
 *                                 return
 * 
 *     def load(self, filename=None, max_node=None):             # <<<<<<<<<<<<<<
 *         """load a list of nodes from ``filename``.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.load", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_nodes_nb);
  __Pyx_XDECREF(__pyx_v_myid);
  __Pyx_XDECREF(__pyx_v_f);
  __Pyx_XDECREF(__pyx_v_nodes);
  __Pyx_XDECREF(__pyx_v_node);
  __Pyx_XDECREF(__pyx_v_e);
  __Pyx_XDECREF(__pyx_v_filename);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":288
 *             self.debug(0, str(e))
 * 
 *     def stop_bg(self):             # <<<<<<<<<<<<<<
 *         """Lauch the stop process of the dht and return immediately"""
 *         if not self.stoped:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_7stop_bg(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_6stop_bg[] = "Lauch the stop process of the dht and return immediately";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_7stop_bg(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stop_bg (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_6stop_bg(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_6stop_bg(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stop_bg", 0);

  /* "btdht/dht.pyx":290
 *     def stop_bg(self):
 *         """Lauch the stop process of the dht and return immediately"""
 *         if not self.stoped:             # <<<<<<<<<<<<<<
 *             t=Thread(target=self.stop)
 *             t.daemon = True
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stoped); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 290, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 290, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":291
 *         """Lauch the stop process of the dht and return immediately"""
 *         if not self.stoped:
 *             t=Thread(target=self.stop)             # <<<<<<<<<<<<<<
 *             t.daemon = True
 *             t.start()
 */
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_Thread); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 291, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 291, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stop); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 291, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_target, __pyx_t_5) < 0) __PYX_ERR(0, 291, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 291, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_t = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "btdht/dht.pyx":292
 *         if not self.stoped:
 *             t=Thread(target=self.stop)
 *             t.daemon = True             # <<<<<<<<<<<<<<
 *             t.start()
 * 
 */
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_t, __pyx_n_s_daemon, Py_True) < 0) __PYX_ERR(0, 292, __pyx_L1_error)

    /* "btdht/dht.pyx":293
 *             t=Thread(target=self.stop)
 *             t.daemon = True
 *             t.start()             # <<<<<<<<<<<<<<
 * 
 *     def stop(self):
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_start); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 293, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 293, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "btdht/dht.pyx":290
 *     def stop_bg(self):
 *         """Lauch the stop process of the dht and return immediately"""
 *         if not self.stoped:             # <<<<<<<<<<<<<<
 *             t=Thread(target=self.stop)
 *             t.daemon = True
 */
  }

  /* "btdht/dht.pyx":288
 *             self.debug(0, str(e))
 * 
 *     def stop_bg(self):             # <<<<<<<<<<<<<<
 *         """Lauch the stop process of the dht and return immediately"""
 *         if not self.stoped:
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.stop_bg", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":295
 *             t.start()
 * 
 *     def stop(self):             # <<<<<<<<<<<<<<
 *         """
 *             Stop the dht:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_9stop(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_8stop[] = "\n            Stop the dht:\n\n              * Set the attribute :attr:`stoped` to ``True`` and wait for threads to terminate\n              * Close the dht socket\n\n            :raises FailToStop: if there is still some alive threads after 30 secondes, with the\n                list of still alive threads as parameter.\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_9stop(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stop (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_8stop(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_8stop(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  long __pyx_v_i;
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  long __pyx_t_9;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stop", 0);

  /* "btdht/dht.pyx":305
 *                 list of still alive threads as parameter.
 *         """
 *         if self.stoped:             # <<<<<<<<<<<<<<
 *             self.debug(0, "Already stoped or stoping in progress")
 *             return
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stoped); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 305, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 305, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "btdht/dht.pyx":306
 *         """
 *         if self.stoped:
 *             self.debug(0, "Already stoped or stoping in progress")             # <<<<<<<<<<<<<<
 *             return
 *         self._scheduler.del_dht(self)
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 306, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 306, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":307
 *         if self.stoped:
 *             self.debug(0, "Already stoped or stoping in progress")
 *             return             # <<<<<<<<<<<<<<
 *         self._scheduler.del_dht(self)
 *         self.root.release_dht(self)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "btdht/dht.pyx":305
 *                 list of still alive threads as parameter.
 *         """
 *         if self.stoped:             # <<<<<<<<<<<<<<
 *             self.debug(0, "Already stoped or stoping in progress")
 *             return
 */
  }

  /* "btdht/dht.pyx":308
 *             self.debug(0, "Already stoped or stoping in progress")
 *             return
 *         self._scheduler.del_dht(self)             # <<<<<<<<<<<<<<
 *         self.root.release_dht(self)
 *         self.stoped = True
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_scheduler_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_del_dht); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 308, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, ((PyObject *)__pyx_v_self)) : __Pyx_PyObject_CallOneArg(__pyx_t_4, ((PyObject *)__pyx_v_self));
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 308, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "btdht/dht.pyx":309
 *             return
 *         self._scheduler.del_dht(self)
 *         self.root.release_dht(self)             # <<<<<<<<<<<<<<
 *         self.stoped = True
 *         self._threads = [t for t in self._threads[:] if t.is_alive()]
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 309, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_release_dht); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 309, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_4, ((PyObject *)__pyx_v_self)) : __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)__pyx_v_self));
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 309, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "btdht/dht.pyx":310
 *         self._scheduler.del_dht(self)
 *         self.root.release_dht(self)
 *         self.stoped = True             # <<<<<<<<<<<<<<
 *         self._threads = [t for t in self._threads[:] if t.is_alive()]
 *         #self.debug(0, "Trying to terminate thread for 1 minutes")
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stoped, Py_True) < 0) __PYX_ERR(0, 310, __pyx_L1_error)

  /* "btdht/dht.pyx":311
 *         self.root.release_dht(self)
 *         self.stoped = True
 *         self._threads = [t for t in self._threads[:] if t.is_alive()]             # <<<<<<<<<<<<<<
 *         #self.debug(0, "Trying to terminate thread for 1 minutes")
 *         for i in range(0, 30):
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_t_1, 0, 0, NULL, NULL, &__pyx_slice__7, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_1 = __pyx_t_4; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 311, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 311, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 311, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 311, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 311, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 311, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 311, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_is_alive); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 311, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_4 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 311, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 311, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_2) {
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_v_t))) __PYX_ERR(0, 311, __pyx_L1_error)
    }
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2, __pyx_t_3) < 0) __PYX_ERR(0, 311, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "btdht/dht.pyx":313
 *         self._threads = [t for t in self._threads[:] if t.is_alive()]
 *         #self.debug(0, "Trying to terminate thread for 1 minutes")
 *         for i in range(0, 30):             # <<<<<<<<<<<<<<
 *             if self._threads:
 *                 if i > 5:
 */
  for (__pyx_t_9 = 0; __pyx_t_9 < 30; __pyx_t_9+=1) {
    __pyx_v_i = __pyx_t_9;

    /* "btdht/dht.pyx":314
 *         #self.debug(0, "Trying to terminate thread for 1 minutes")
 *         for i in range(0, 30):
 *             if self._threads:             # <<<<<<<<<<<<<<
 *                 if i > 5:
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 314, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_2) {

      /* "btdht/dht.pyx":315
 *         for i in range(0, 30):
 *             if self._threads:
 *                 if i > 5:             # <<<<<<<<<<<<<<
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))
 *                 time.sleep(1)
 */
      __pyx_t_2 = ((__pyx_v_i > 5) != 0);
      if (__pyx_t_2) {

        /* "btdht/dht.pyx":316
 *             if self._threads:
 *                 if i > 5:
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))             # <<<<<<<<<<<<<<
 *                 time.sleep(1)
 *                 self._threads = [t for t in self._threads[:] if t.is_alive()]
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 316, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 316, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_5 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 316, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 316, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_Waiting_for_s_threads_to_termina, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 316, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = NULL;
        __pyx_t_10 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_1, function);
            __pyx_t_10 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_1)) {
          PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_int_0, __pyx_t_7};
          __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 316, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
          PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_int_0, __pyx_t_7};
          __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 316, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        } else
        #endif
        {
          __pyx_t_8 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 316, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          if (__pyx_t_4) {
            __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_4); __pyx_t_4 = NULL;
          }
          __Pyx_INCREF(__pyx_int_0);
          __Pyx_GIVEREF(__pyx_int_0);
          PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_10, __pyx_int_0);
          __Pyx_GIVEREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_10, __pyx_t_7);
          __pyx_t_7 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 316, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "btdht/dht.pyx":315
 *         for i in range(0, 30):
 *             if self._threads:
 *                 if i > 5:             # <<<<<<<<<<<<<<
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))
 *                 time.sleep(1)
 */
      }

      /* "btdht/dht.pyx":317
 *                 if i > 5:
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))
 *                 time.sleep(1)             # <<<<<<<<<<<<<<
 *                 self._threads = [t for t in self._threads[:] if t.is_alive()]
 *             else:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_sleep); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 317, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_1, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_int_1);
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 317, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "btdht/dht.pyx":318
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))
 *                 time.sleep(1)
 *                 self._threads = [t for t in self._threads[:] if t.is_alive()]             # <<<<<<<<<<<<<<
 *             else:
 *                 break
 */
      __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 318, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 318, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_t_8, 0, 0, NULL, NULL, &__pyx_slice__7, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 318, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
        __pyx_t_8 = __pyx_t_1; __Pyx_INCREF(__pyx_t_8); __pyx_t_5 = 0;
        __pyx_t_6 = NULL;
      } else {
        __pyx_t_5 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 318, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_6 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 318, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      for (;;) {
        if (likely(!__pyx_t_6)) {
          if (likely(PyList_CheckExact(__pyx_t_8))) {
            if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_8)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_1 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 318, __pyx_L1_error)
            #else
            __pyx_t_1 = PySequence_ITEM(__pyx_t_8, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 318, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            #endif
          } else {
            if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 318, __pyx_L1_error)
            #else
            __pyx_t_1 = PySequence_ITEM(__pyx_t_8, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 318, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            #endif
          }
        } else {
          __pyx_t_1 = __pyx_t_6(__pyx_t_8);
          if (unlikely(!__pyx_t_1)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 318, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_1);
        }
        __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_is_alive); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 318, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_4 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
          }
        }
        __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 318, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 318, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (__pyx_t_2) {
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_v_t))) __PYX_ERR(0, 318, __pyx_L1_error)
        }
      }
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2, __pyx_t_3) < 0) __PYX_ERR(0, 318, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "btdht/dht.pyx":314
 *         #self.debug(0, "Trying to terminate thread for 1 minutes")
 *         for i in range(0, 30):
 *             if self._threads:             # <<<<<<<<<<<<<<
 *                 if i > 5:
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))
 */
      goto __pyx_L9;
    }

    /* "btdht/dht.pyx":320
 *                 self._threads = [t for t in self._threads[:] if t.is_alive()]
 *             else:
 *                 break             # <<<<<<<<<<<<<<
 *         if self._threads:
 *             self.debug(
 */
    /*else*/ {
      goto __pyx_L8_break;
    }
    __pyx_L9:;
  }
  __pyx_L8_break:;

  /* "btdht/dht.pyx":321
 *             else:
 *                 break
 *         if self._threads:             # <<<<<<<<<<<<<<
 *             self.debug(
 *                 0,
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 321, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 321, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_2) {

    /* "btdht/dht.pyx":322
 *                 break
 *         if self._threads:
 *             self.debug(             # <<<<<<<<<<<<<<
 *                 0,
 *                 "Unable to stop %s threads, giving up:\n%r" % (len(self._threads), self._threads)
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 322, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);

    /* "btdht/dht.pyx":324
 *             self.debug(
 *                 0,
 *                 "Unable to stop %s threads, giving up:\n%r" % (len(self._threads), self._threads)             # <<<<<<<<<<<<<<
 *             )
 *             self._threads_zombie.extend(self._threads)
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 324, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_7);
    __pyx_t_1 = 0;
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_Unable_to_stop_s_threads_giving, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_int_0, __pyx_t_7};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 322, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_int_0, __pyx_t_7};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 322, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    {
      __pyx_t_1 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 322, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (__pyx_t_4) {
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); __pyx_t_4 = NULL;
      }
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_10, __pyx_int_0);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_10, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 322, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":326
 *                 "Unable to stop %s threads, giving up:\n%r" % (len(self._threads), self._threads)
 *             )
 *             self._threads_zombie.extend(self._threads)             # <<<<<<<<<<<<<<
 *             self._threads = []
 * 
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_zombie); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_extend); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 326, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":327
 *             )
 *             self._threads_zombie.extend(self._threads)
 *             self._threads = []             # <<<<<<<<<<<<<<
 * 
 *         if self.sock:
 */
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 327, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2, __pyx_t_3) < 0) __PYX_ERR(0, 327, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":321
 *             else:
 *                 break
 *         if self._threads:             # <<<<<<<<<<<<<<
 *             self.debug(
 *                 0,
 */
  }

  /* "btdht/dht.pyx":329
 *             self._threads = []
 * 
 *         if self.sock:             # <<<<<<<<<<<<<<
 *             try:self.sock.close()
 *             except: pass
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sock); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 329, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 329, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_2) {

    /* "btdht/dht.pyx":330
 * 
 *         if self.sock:
 *             try:self.sock.close()             # <<<<<<<<<<<<<<
 *             except: pass
 * 
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
      __Pyx_XGOTREF(__pyx_t_11);
      __Pyx_XGOTREF(__pyx_t_12);
      __Pyx_XGOTREF(__pyx_t_13);
      /*try:*/ {
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sock); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 330, __pyx_L16_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_close); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 330, __pyx_L16_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_1)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
          }
        }
        __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_8);
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 330, __pyx_L16_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      }
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      goto __pyx_L21_try_end;
      __pyx_L16_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "btdht/dht.pyx":331
 *         if self.sock:
 *             try:self.sock.close()
 *             except: pass             # <<<<<<<<<<<<<<
 * 
 *         if self._threads_zombie:
 */
      /*except:*/ {
        __Pyx_ErrRestore(0,0,0);
        goto __pyx_L17_exception_handled;
      }
      __pyx_L17_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_11);
      __Pyx_XGIVEREF(__pyx_t_12);
      __Pyx_XGIVEREF(__pyx_t_13);
      __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
      __pyx_L21_try_end:;
    }

    /* "btdht/dht.pyx":329
 *             self._threads = []
 * 
 *         if self.sock:             # <<<<<<<<<<<<<<
 *             try:self.sock.close()
 *             except: pass
 */
  }

  /* "btdht/dht.pyx":333
 *             except: pass
 * 
 *         if self._threads_zombie:             # <<<<<<<<<<<<<<
 *             raise FailToStop(self._threads_zombie)
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_zombie); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 333, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 333, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(__pyx_t_2)) {

    /* "btdht/dht.pyx":334
 * 
 *         if self._threads_zombie:
 *             raise FailToStop(self._threads_zombie)             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_FailToStop); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_zombie); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_1);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 334, __pyx_L1_error)

    /* "btdht/dht.pyx":333
 *             except: pass
 * 
 *         if self._threads_zombie:             # <<<<<<<<<<<<<<
 *             raise FailToStop(self._threads_zombie)
 * 
 */
  }

  /* "btdht/dht.pyx":295
 *             t.start()
 * 
 *     def stop(self):             # <<<<<<<<<<<<<<
 *         """
 *             Stop the dht:
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.stop", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":337
 * 
 *     @property
 *     def zombie(self):             # <<<<<<<<<<<<<<
 *         """``True`` if dht is stopped but one thread or more remains alive, ``False`` otherwise"""
 *         return bool(self.stoped and [t for t in self._threads if t.is_alive()])
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_6zombie_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_6zombie_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_6zombie___get__(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_6zombie___get__(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "btdht/dht.pyx":339
 *     def zombie(self):
 *         """``True`` if dht is stopped but one thread or more remains alive, ``False`` otherwise"""
 *         return bool(self.stoped and [t for t in self._threads if t.is_alive()])             # <<<<<<<<<<<<<<
 * 
 *     def start(self, start_routing_table=True, start_scheduler=True):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stoped); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 339, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L3_bool_binop_done;
  }
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 339, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_5 = __pyx_t_4; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 339, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 339, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_5))) {
        if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 339, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 339, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 339, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 339, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_7(__pyx_t_5);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 339, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_is_alive); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 339, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    __pyx_t_4 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_8);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 339, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 339, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_3) {
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_v_t))) __PYX_ERR(0, 339, __pyx_L1_error)
    }
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_3 = (PyList_GET_SIZE(__pyx_t_2) != 0);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = __pyx_t_3;
  __pyx_L3_bool_binop_done:;
  __pyx_t_2 = __Pyx_PyBool_FromLong((!(!__pyx_t_1))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 339, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":337
 * 
 *     @property
 *     def zombie(self):             # <<<<<<<<<<<<<<
 *         """``True`` if dht is stopped but one thread or more remains alive, ``False`` otherwise"""
 *         return bool(self.stoped and [t for t in self._threads if t.is_alive()])
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.zombie.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":341
 *         return bool(self.stoped and [t for t in self._threads if t.is_alive()])
 * 
 *     def start(self, start_routing_table=True, start_scheduler=True):             # <<<<<<<<<<<<<<
 *         """
 *             Start the dht:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_11start(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_10start[] = "\n            Start the dht:\n                * initialize some attributes\n                * initialize the dht socket (see :meth:init_socket)\n                * register this instance of the dht in the routing table\n                  (see :meth:`RoutingTable.register_dht`)\n                * register this instance of the dht in the scheduler\n                * start the routing table if needed and ``start_routing_table` is ``True``\n                * start the scheduler if needed and ``start_scheduler`` is ``True``\n\n            :param bool start_routing_table: If ``True`` (the default) also start the routing table\n                if needed\n            :param bool start_scheduler: If ``True``(the default) alsp start the scheduler\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_11start(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_start_routing_table = 0;
  PyObject *__pyx_v_start_scheduler = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("start (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_start_routing_table,&__pyx_n_s_start_scheduler,0};
    PyObject* values[2] = {0,0};
    values[0] = ((PyObject *)Py_True);
    values[1] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start_routing_table);
          if (value) { values[0] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_start_scheduler);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "start") < 0)) __PYX_ERR(0, 341, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_start_routing_table = values[0];
    __pyx_v_start_scheduler = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("start", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 341, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.start", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_10start(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_start_routing_table, __pyx_v_start_scheduler);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_10start(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_start_routing_table, PyObject *__pyx_v_start_scheduler) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("start", 0);

  /* "btdht/dht.pyx":356
 *             :param bool start_scheduler: If ``True``(the default) alsp start the scheduler
 *         """
 *         if not self.stoped:             # <<<<<<<<<<<<<<
 *             self.debug(0, "Already started")
 *             return
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stoped); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 356, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 356, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":357
 *         """
 *         if not self.stoped:
 *             self.debug(0, "Already started")             # <<<<<<<<<<<<<<
 *             return
 *         if self.zombie:
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 357, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 357, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "btdht/dht.pyx":358
 *         if not self.stoped:
 *             self.debug(0, "Already started")
 *             return             # <<<<<<<<<<<<<<
 *         if self.zombie:
 *             self.debug(0, "Zombie threads, unable de start")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "btdht/dht.pyx":356
 *             :param bool start_scheduler: If ``True``(the default) alsp start the scheduler
 *         """
 *         if not self.stoped:             # <<<<<<<<<<<<<<
 *             self.debug(0, "Already started")
 *             return
 */
  }

  /* "btdht/dht.pyx":359
 *             self.debug(0, "Already started")
 *             return
 *         if self.zombie:             # <<<<<<<<<<<<<<
 *             self.debug(0, "Zombie threads, unable de start")
 *             return self._threads_zombie
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_zombie); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 359, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 359, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":360
 *             return
 *         if self.zombie:
 *             self.debug(0, "Zombie threads, unable de start")             # <<<<<<<<<<<<<<
 *             return self._threads_zombie
 * 
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 360, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 360, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":361
 *         if self.zombie:
 *             self.debug(0, "Zombie threads, unable de start")
 *             return self._threads_zombie             # <<<<<<<<<<<<<<
 * 
 *         self.stoped = False
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_zombie); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "btdht/dht.pyx":359
 *             self.debug(0, "Already started")
 *             return
 *         if self.zombie:             # <<<<<<<<<<<<<<
 *             self.debug(0, "Zombie threads, unable de start")
 *             return self._threads_zombie
 */
  }

  /* "btdht/dht.pyx":363
 *             return self._threads_zombie
 * 
 *         self.stoped = False             # <<<<<<<<<<<<<<
 *         self._root_heigth = 0
 *         self._socket_in = 0
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stoped, Py_False) < 0) __PYX_ERR(0, 363, __pyx_L1_error)

  /* "btdht/dht.pyx":364
 * 
 *         self.stoped = False
 *         self._root_heigth = 0             # <<<<<<<<<<<<<<
 *         self._socket_in = 0
 *         self._socket_out = 0
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root_heigth, __pyx_int_0) < 0) __PYX_ERR(0, 364, __pyx_L1_error)

  /* "btdht/dht.pyx":365
 *         self.stoped = False
 *         self._root_heigth = 0
 *         self._socket_in = 0             # <<<<<<<<<<<<<<
 *         self._socket_out = 0
 *         self._last_socket_stats = time.time()
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_in, __pyx_int_0) < 0) __PYX_ERR(0, 365, __pyx_L1_error)

  /* "btdht/dht.pyx":366
 *         self._root_heigth = 0
 *         self._socket_in = 0
 *         self._socket_out = 0             # <<<<<<<<<<<<<<
 *         self._last_socket_stats = time.time()
 *         self.last_msg = time.time()
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_out, __pyx_int_0) < 0) __PYX_ERR(0, 366, __pyx_L1_error)

  /* "btdht/dht.pyx":367
 *         self._socket_in = 0
 *         self._socket_out = 0
 *         self._last_socket_stats = time.time()             # <<<<<<<<<<<<<<
 *         self.last_msg = time.time()
 *         self.last_msg_rep = time.time()
 */
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_socket_stats, __pyx_t_1) < 0) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":368
 *         self._socket_out = 0
 *         self._last_socket_stats = time.time()
 *         self.last_msg = time.time()             # <<<<<<<<<<<<<<
 *         self.last_msg_rep = time.time()
 *         self._long_clean = time.time()
 */
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 368, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 368, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 368, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_msg, __pyx_t_1) < 0) __PYX_ERR(0, 368, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":369
 *         self._last_socket_stats = time.time()
 *         self.last_msg = time.time()
 *         self.last_msg_rep = time.time()             # <<<<<<<<<<<<<<
 *         self._long_clean = time.time()
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 369, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 369, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 369, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_msg_rep, __pyx_t_1) < 0) __PYX_ERR(0, 369, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":370
 *         self.last_msg = time.time()
 *         self.last_msg_rep = time.time()
 *         self._long_clean = time.time()             # <<<<<<<<<<<<<<
 * 
 *         self.init_socket()
 */
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 370, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 370, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 370, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_long_clean, __pyx_t_1) < 0) __PYX_ERR(0, 370, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":372
 *         self._long_clean = time.time()
 * 
 *         self.init_socket()             # <<<<<<<<<<<<<<
 * 
 *         self.root.register_dht(self)
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_init_socket); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 372, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 372, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":374
 *         self.init_socket()
 * 
 *         self.root.register_dht(self)             # <<<<<<<<<<<<<<
 *         self._scheduler.add_dht(self)
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 374, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_register_dht); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 374, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, ((PyObject *)__pyx_v_self)) : __Pyx_PyObject_CallOneArg(__pyx_t_5, ((PyObject *)__pyx_v_self));
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 374, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":375
 * 
 *         self.root.register_dht(self)
 *         self._scheduler.add_dht(self)             # <<<<<<<<<<<<<<
 * 
 *         if start_routing_table and self.root.stoped:
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_scheduler_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 375, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_add_dht); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 375, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, ((PyObject *)__pyx_v_self)) : __Pyx_PyObject_CallOneArg(__pyx_t_4, ((PyObject *)__pyx_v_self));
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 375, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":377
 *         self._scheduler.add_dht(self)
 * 
 *         if start_routing_table and self.root.stoped:             # <<<<<<<<<<<<<<
 *             self.root.start()
 *         if start_scheduler and self._scheduler._stoped:
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_start_routing_table); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 377, __pyx_L1_error)
  if (__pyx_t_2) {
  } else {
    __pyx_t_3 = __pyx_t_2;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 377, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_stoped); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 377, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 377, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_3 = __pyx_t_2;
  __pyx_L6_bool_binop_done:;
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":378
 * 
 *         if start_routing_table and self.root.stoped:
 *             self.root.start()             # <<<<<<<<<<<<<<
 *         if start_scheduler and self._scheduler._stoped:
 *             self._scheduler.start()
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_start); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_4 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "btdht/dht.pyx":377
 *         self._scheduler.add_dht(self)
 * 
 *         if start_routing_table and self.root.stoped:             # <<<<<<<<<<<<<<
 *             self.root.start()
 *         if start_scheduler and self._scheduler._stoped:
 */
  }

  /* "btdht/dht.pyx":379
 *         if start_routing_table and self.root.stoped:
 *             self.root.start()
 *         if start_scheduler and self._scheduler._stoped:             # <<<<<<<<<<<<<<
 *             self._scheduler.start()
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_start_scheduler); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 379, __pyx_L1_error)
  if (__pyx_t_2) {
  } else {
    __pyx_t_3 = __pyx_t_2;
    goto __pyx_L9_bool_binop_done;
  }
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_scheduler_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 379, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_stoped_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 379, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 379, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_3 = __pyx_t_2;
  __pyx_L9_bool_binop_done:;
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":380
 *             self.root.start()
 *         if start_scheduler and self._scheduler._stoped:
 *             self._scheduler.start()             # <<<<<<<<<<<<<<
 * 
 *     def is_alive(self):
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_scheduler_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 380, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 380, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_5 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 380, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "btdht/dht.pyx":379
 *         if start_routing_table and self.root.stoped:
 *             self.root.start()
 *         if start_scheduler and self._scheduler._stoped:             # <<<<<<<<<<<<<<
 *             self._scheduler.start()
 * 
 */
  }

  /* "btdht/dht.pyx":341
 *         return bool(self.stoped and [t for t in self._threads if t.is_alive()])
 * 
 *     def start(self, start_routing_table=True, start_scheduler=True):             # <<<<<<<<<<<<<<
 *         """
 *             Start the dht:
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.start", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":382
 *             self._scheduler.start()
 * 
 *     def is_alive(self):             # <<<<<<<<<<<<<<
 *         """Test if all threads of the dht are alive, stop the dht if one of the thread is dead
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_13is_alive(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_12is_alive[] = "Test if all threads of the dht are alive, stop the dht if one of the thread is dead\n\n        :return: ``True`` if all dht threads are alive, ``False`` otherwise and stop all remaining\n            threads.\n        :rtype: bool\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_13is_alive(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_alive (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_12is_alive(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_12is_alive(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  PyObject *__pyx_v_weigthless_threads_satus = NULL;
  PyObject *__pyx_v_s = NULL;
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("is_alive", 0);

  /* "btdht/dht.pyx":389
 *         :rtype: bool
 *         """
 *         weigthless_threads_satus = [             # <<<<<<<<<<<<<<
 *             self._scheduler.thread_alive(s[0]) for s in self.to_schedule
 *         ]
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 389, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "btdht/dht.pyx":390
 *         """
 *         weigthless_threads_satus = [
 *             self._scheduler.thread_alive(s[0]) for s in self.to_schedule             # <<<<<<<<<<<<<<
 *         ]
 *         if (
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_schedule); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 390, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 390, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 390, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 390, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 390, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 390, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 390, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_5(__pyx_t_3);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 390, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XDECREF_SET(__pyx_v_s, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_scheduler_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 390, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_thread_alive); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 390, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_s, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 390, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_2 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 390, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 389, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_weigthless_threads_satus = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":393
 *         ]
 *         if (
 *             self.threads is not None and             # <<<<<<<<<<<<<<
 *             all([t.is_alive() for t in self.threads])
 *             and all(weigthless_threads_satus)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_10 = (__pyx_t_1 != Py_None);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_11 = (__pyx_t_10 != 0);
  if (__pyx_t_11) {
  } else {
    __pyx_t_9 = __pyx_t_11;
    goto __pyx_L6_bool_binop_done;
  }

  /* "btdht/dht.pyx":394
 *         if (
 *             self.threads is not None and
 *             all([t.is_alive() for t in self.threads])             # <<<<<<<<<<<<<<
 *             and all(weigthless_threads_satus)
 *         ):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 394, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 394, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 394, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 394, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 394, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 394, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 394, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 394, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_5(__pyx_t_2);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 394, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_is_alive); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 394, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 394, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 394, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_all, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 394, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 394, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_11) {
  } else {
    __pyx_t_9 = __pyx_t_11;
    goto __pyx_L6_bool_binop_done;
  }

  /* "btdht/dht.pyx":395
 *             self.threads is not None and
 *             all([t.is_alive() for t in self.threads])
 *             and all(weigthless_threads_satus)             # <<<<<<<<<<<<<<
 *         ):
 *             return True
 */
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_all, __pyx_v_weigthless_threads_satus); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 395, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 395, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_9 = __pyx_t_11;
  __pyx_L6_bool_binop_done:;

  /* "btdht/dht.pyx":392
 *             self._scheduler.thread_alive(s[0]) for s in self.to_schedule
 *         ]
 *         if (             # <<<<<<<<<<<<<<
 *             self.threads is not None and
 *             all([t.is_alive() for t in self.threads])
 */
  if (__pyx_t_9) {

    /* "btdht/dht.pyx":397
 *             and all(weigthless_threads_satus)
 *         ):
 *             return True             # <<<<<<<<<<<<<<
 *         elif not self._threads and self.stoped and not any(weigthless_threads_satus):
 *             return False
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_True);
    __pyx_r = Py_True;
    goto __pyx_L0;

    /* "btdht/dht.pyx":392
 *             self._scheduler.thread_alive(s[0]) for s in self.to_schedule
 *         ]
 *         if (             # <<<<<<<<<<<<<<
 *             self.threads is not None and
 *             all([t.is_alive() for t in self.threads])
 */
  }

  /* "btdht/dht.pyx":398
 *         ):
 *             return True
 *         elif not self._threads and self.stoped and not any(weigthless_threads_satus):             # <<<<<<<<<<<<<<
 *             return False
 *         else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 398, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 398, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_10 = ((!__pyx_t_11) != 0);
  if (__pyx_t_10) {
  } else {
    __pyx_t_9 = __pyx_t_10;
    goto __pyx_L11_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stoped); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 398, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 398, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_10) {
  } else {
    __pyx_t_9 = __pyx_t_10;
    goto __pyx_L11_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_any, __pyx_v_weigthless_threads_satus); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 398, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 398, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_11 = ((!__pyx_t_10) != 0);
  __pyx_t_9 = __pyx_t_11;
  __pyx_L11_bool_binop_done:;
  if (__pyx_t_9) {

    /* "btdht/dht.pyx":399
 *             return True
 *         elif not self._threads and self.stoped and not any(weigthless_threads_satus):
 *             return False             # <<<<<<<<<<<<<<
 *         else:
 *             self.debug(0, "One thread died, stopping dht")
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_False);
    __pyx_r = Py_False;
    goto __pyx_L0;

    /* "btdht/dht.pyx":398
 *         ):
 *             return True
 *         elif not self._threads and self.stoped and not any(weigthless_threads_satus):             # <<<<<<<<<<<<<<
 *             return False
 *         else:
 */
  }

  /* "btdht/dht.pyx":401
 *             return False
 *         else:
 *             self.debug(0, "One thread died, stopping dht")             # <<<<<<<<<<<<<<
 *             self.stop_bg()
 *             return False
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 401, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 401, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":402
 *         else:
 *             self.debug(0, "One thread died, stopping dht")
 *             self.stop_bg()             # <<<<<<<<<<<<<<
 *             return False
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stop_bg); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 402, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 402, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":403
 *             self.debug(0, "One thread died, stopping dht")
 *             self.stop_bg()
 *             return False             # <<<<<<<<<<<<<<
 * 
 *     def debug(self, lvl, msg):
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_False);
    __pyx_r = Py_False;
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":382
 *             self._scheduler.start()
 * 
 *     def is_alive(self):             # <<<<<<<<<<<<<<
 *         """Test if all threads of the dht are alive, stop the dht if one of the thread is dead
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.is_alive", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_weigthless_threads_satus);
  __Pyx_XDECREF(__pyx_v_s);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":405
 *             return False
 * 
 *     def debug(self, lvl, msg):             # <<<<<<<<<<<<<<
 *         """
 *         Print ``msg`` prefixed with :attr:`prefix` if ``lvl`` <= :attr:`debuglvl`
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_15debug(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_14debug[] = "\n        Print ``msg`` prefixed with :attr:`prefix` if ``lvl`` <= :attr:`debuglvl`\n\n        :param int lvl: The debug level of the message to print\n        :param str msg: The debug message to print\n\n        Note:\n            duplicate messages are removed\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_15debug(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_lvl = 0;
  PyObject *__pyx_v_msg = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("debug (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_lvl,&__pyx_n_s_msg,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_lvl)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_msg)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("debug", 1, 2, 2, 1); __PYX_ERR(0, 405, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "debug") < 0)) __PYX_ERR(0, 405, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_lvl = values[0];
    __pyx_v_msg = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("debug", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 405, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.debug", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_14debug(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_lvl, __pyx_v_msg);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_14debug(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_lvl, PyObject *__pyx_v_msg) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("debug", 0);

  /* "btdht/dht.pyx":416
 *         """
 *         if (
 *             lvl <= self.debuglvl and             # <<<<<<<<<<<<<<
 *             (self._last_debug != msg or (time.time() - self._last_debug_time) > 5)
 *         ):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debuglvl); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_lvl, __pyx_t_2, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 416, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 416, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {
  } else {
    __pyx_t_1 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }

  /* "btdht/dht.pyx":417
 *         if (
 *             lvl <= self.debuglvl and
 *             (self._last_debug != msg or (time.time() - self._last_debug_time) > 5)             # <<<<<<<<<<<<<<
 *         ):
 *             print(self.prefix + msg)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_debug); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 417, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_v_msg, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 417, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 417, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_4) {
  } else {
    __pyx_t_1 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 417, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 417, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 417, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_debug_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 417, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyNumber_Subtract(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 417, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_int_5, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 417, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 417, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_1 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;

  /* "btdht/dht.pyx":415
 *             duplicate messages are removed
 *         """
 *         if (             # <<<<<<<<<<<<<<
 *             lvl <= self.debuglvl and
 *             (self._last_debug != msg or (time.time() - self._last_debug_time) > 5)
 */
  if (__pyx_t_1) {

    /* "btdht/dht.pyx":419
 *             (self._last_debug != msg or (time.time() - self._last_debug_time) > 5)
 *         ):
 *             print(self.prefix + msg)             # <<<<<<<<<<<<<<
 *             self._last_debug = msg
 *             self._last_debug_time = time.time()
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_prefix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 419, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyNumber_Add(__pyx_t_5, __pyx_v_msg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 419, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__Pyx_PrintOne(0, __pyx_t_3) < 0) __PYX_ERR(0, 419, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":420
 *         ):
 *             print(self.prefix + msg)
 *             self._last_debug = msg             # <<<<<<<<<<<<<<
 *             self._last_debug_time = time.time()
 * 
 */
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_debug, __pyx_v_msg) < 0) __PYX_ERR(0, 420, __pyx_L1_error)

    /* "btdht/dht.pyx":421
 *             print(self.prefix + msg)
 *             self._last_debug = msg
 *             self._last_debug_time = time.time()             # <<<<<<<<<<<<<<
 * 
 *     def _socket_stats(self):
 */
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 421, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 421, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 421, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_debug_time, __pyx_t_3) < 0) __PYX_ERR(0, 421, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":415
 *             duplicate messages are removed
 *         """
 *         if (             # <<<<<<<<<<<<<<
 *             lvl <= self.debuglvl and
 *             (self._last_debug != msg or (time.time() - self._last_debug_time) > 5)
 */
  }

  /* "btdht/dht.pyx":405
 *             return False
 * 
 *     def debug(self, lvl, msg):             # <<<<<<<<<<<<<<
 *         """
 *         Print ``msg`` prefixed with :attr:`prefix` if ``lvl`` <= :attr:`debuglvl`
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.debug", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":423
 *             self._last_debug_time = time.time()
 * 
 *     def _socket_stats(self):             # <<<<<<<<<<<<<<
 *         """
 *         Display some statistic on send/received messages
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_17_socket_stats(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_16_socket_stats[] = "\n        Display some statistic on send/received messages\n\n        :return: A tuple (number of received messages, number of sended messages, periode of time)\n        :rtype: tuple\n\n        Note:\n            The counter are reset to 0 on each call\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_17_socket_stats(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_socket_stats (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_16_socket_stats(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_16_socket_stats(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  PyObject *__pyx_v_now = NULL;
  PyObject *__pyx_v_in_s = NULL;
  PyObject *__pyx_v_out_s = NULL;
  PyObject *__pyx_v_delta = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_socket_stats", 0);

  /* "btdht/dht.pyx":433
 *             The counter are reset to 0 on each call
 *         """
 *         now = time.time()             # <<<<<<<<<<<<<<
 *         in_s = self._socket_in
 *         self._socket_in = 0
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 433, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 433, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 433, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_now = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":434
 *         """
 *         now = time.time()
 *         in_s = self._socket_in             # <<<<<<<<<<<<<<
 *         self._socket_in = 0
 *         out_s = self._socket_out
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_in); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 434, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_in_s = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":435
 *         now = time.time()
 *         in_s = self._socket_in
 *         self._socket_in = 0             # <<<<<<<<<<<<<<
 *         out_s = self._socket_out
 *         self._socket_out = 0
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_in, __pyx_int_0) < 0) __PYX_ERR(0, 435, __pyx_L1_error)

  /* "btdht/dht.pyx":436
 *         in_s = self._socket_in
 *         self._socket_in = 0
 *         out_s = self._socket_out             # <<<<<<<<<<<<<<
 *         self._socket_out = 0
 *         delta = now - self._last_socket_stats
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_out); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 436, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_out_s = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":437
 *         self._socket_in = 0
 *         out_s = self._socket_out
 *         self._socket_out = 0             # <<<<<<<<<<<<<<
 *         delta = now - self._last_socket_stats
 *         self._last_socket_stats = now
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_out, __pyx_int_0) < 0) __PYX_ERR(0, 437, __pyx_L1_error)

  /* "btdht/dht.pyx":438
 *         out_s = self._socket_out
 *         self._socket_out = 0
 *         delta = now - self._last_socket_stats             # <<<<<<<<<<<<<<
 *         self._last_socket_stats = now
 *         return (in_s, out_s, delta)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_socket_stats); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 438, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyNumber_Subtract(__pyx_v_now, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 438, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_delta = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "btdht/dht.pyx":439
 *         self._socket_out = 0
 *         delta = now - self._last_socket_stats
 *         self._last_socket_stats = now             # <<<<<<<<<<<<<<
 *         return (in_s, out_s, delta)
 * 
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_socket_stats, __pyx_v_now) < 0) __PYX_ERR(0, 439, __pyx_L1_error)

  /* "btdht/dht.pyx":440
 *         delta = now - self._last_socket_stats
 *         self._last_socket_stats = now
 *         return (in_s, out_s, delta)             # <<<<<<<<<<<<<<
 * 
 *     def init_socket(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 440, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_in_s);
  __Pyx_GIVEREF(__pyx_v_in_s);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_in_s);
  __Pyx_INCREF(__pyx_v_out_s);
  __Pyx_GIVEREF(__pyx_v_out_s);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_out_s);
  __Pyx_INCREF(__pyx_v_delta);
  __Pyx_GIVEREF(__pyx_v_delta);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_delta);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":423
 *             self._last_debug_time = time.time()
 * 
 *     def _socket_stats(self):             # <<<<<<<<<<<<<<
 *         """
 *         Display some statistic on send/received messages
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._socket_stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_now);
  __Pyx_XDECREF(__pyx_v_in_s);
  __Pyx_XDECREF(__pyx_v_out_s);
  __Pyx_XDECREF(__pyx_v_delta);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":442
 *         return (in_s, out_s, delta)
 * 
 *     def init_socket(self):             # <<<<<<<<<<<<<<
 *         """Initialize the UDP socket of the DHT"""
 *         self.debug(0, "init socket for %s" % binascii.b2a_hex(self.myid.value))
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_19init_socket(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_18init_socket[] = "Initialize the UDP socket of the DHT";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_19init_socket(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("init_socket (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_18init_socket(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_18init_socket(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("init_socket", 0);

  /* "btdht/dht.pyx":444
 *     def init_socket(self):
 *         """Initialize the UDP socket of the DHT"""
 *         self.debug(0, "init socket for %s" % binascii.b2a_hex(self.myid.value))             # <<<<<<<<<<<<<<
 *         if self.sock:
 *              try:self.sock.close()
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 444, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_binascii); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 444, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_b2a_hex); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 444, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_myid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 444, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_value); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 444, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 444, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyString_FormatSafe(__pyx_kp_s_init_socket_for_s, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 444, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  __pyx_t_7 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_7 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_0, __pyx_t_5};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 444, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_0, __pyx_t_5};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 444, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  {
    __pyx_t_6 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 444, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_7, __pyx_int_0);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_7, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 444, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":445
 *         """Initialize the UDP socket of the DHT"""
 *         self.debug(0, "init socket for %s" % binascii.b2a_hex(self.myid.value))
 *         if self.sock:             # <<<<<<<<<<<<<<
 *              try:self.sock.close()
 *              except: pass
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sock); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 445, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 445, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_8) {

    /* "btdht/dht.pyx":446
 *         self.debug(0, "init socket for %s" % binascii.b2a_hex(self.myid.value))
 *         if self.sock:
 *              try:self.sock.close()             # <<<<<<<<<<<<<<
 *              except: pass
 *         # initialize the sending queue
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      __Pyx_XGOTREF(__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_10);
      __Pyx_XGOTREF(__pyx_t_11);
      /*try:*/ {
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sock); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 446, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_close); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 446, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_2)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
          }
        }
        __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 446, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      goto __pyx_L9_try_end;
      __pyx_L4_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "btdht/dht.pyx":447
 *         if self.sock:
 *              try:self.sock.close()
 *              except: pass             # <<<<<<<<<<<<<<
 *         # initialize the sending queue
 *         self.to_send = PollableQueue()
 */
      /*except:*/ {
        __Pyx_ErrRestore(0,0,0);
        goto __pyx_L5_exception_handled;
      }
      __pyx_L5_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_XGIVEREF(__pyx_t_11);
      __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      __pyx_L9_try_end:;
    }

    /* "btdht/dht.pyx":445
 *         """Initialize the UDP socket of the DHT"""
 *         self.debug(0, "init socket for %s" % binascii.b2a_hex(self.myid.value))
 *         if self.sock:             # <<<<<<<<<<<<<<
 *              try:self.sock.close()
 *              except: pass
 */
  }

  /* "btdht/dht.pyx":449
 *              except: pass
 *         # initialize the sending queue
 *         self.to_send = PollableQueue()             # <<<<<<<<<<<<<<
 *         self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 *         #self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 */
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_PollableQueue); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_send, __pyx_t_1) < 0) __PYX_ERR(0, 449, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":450
 *         # initialize the sending queue
 *         self.to_send = PollableQueue()
 *         self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)             # <<<<<<<<<<<<<<
 *         #self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 *         if IN is not None:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_socket); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 450, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_socket); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 450, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_socket); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 450, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_AF_INET); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 450, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_socket); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 450, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_SOCK_DGRAM); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 450, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = NULL;
  __pyx_t_7 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_7 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_t_3};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 450, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_5, __pyx_t_3};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 450, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  {
    __pyx_t_4 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 450, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_7, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_7, __pyx_t_3);
    __pyx_t_5 = 0;
    __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 450, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sock, __pyx_t_1) < 0) __PYX_ERR(0, 450, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":452
 *         self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 *         #self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 *         if IN is not None:             # <<<<<<<<<<<<<<
 *             try:
 *                 self.sock.setsockopt(socket.IPPROTO_IP, IN.IP_MTU_DISCOVER, IN.IP_PMTUDISC_DO)
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_IN); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 452, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = (__pyx_t_1 != Py_None);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_12 = (__pyx_t_8 != 0);
  if (__pyx_t_12) {

    /* "btdht/dht.pyx":453
 *         #self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 *         if IN is not None:
 *             try:             # <<<<<<<<<<<<<<
 *                 self.sock.setsockopt(socket.IPPROTO_IP, IN.IP_MTU_DISCOVER, IN.IP_PMTUDISC_DO)
 *             except AttributeError:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_11);
      __Pyx_XGOTREF(__pyx_t_10);
      __Pyx_XGOTREF(__pyx_t_9);
      /*try:*/ {

        /* "btdht/dht.pyx":454
 *         if IN is not None:
 *             try:
 *                 self.sock.setsockopt(socket.IPPROTO_IP, IN.IP_MTU_DISCOVER, IN.IP_PMTUDISC_DO)             # <<<<<<<<<<<<<<
 *             except AttributeError:
 *                 pass
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sock); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 454, __pyx_L11_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_setsockopt); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 454, __pyx_L11_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_socket); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 454, __pyx_L11_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_IPPROTO_IP); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 454, __pyx_L11_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_IN); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 454, __pyx_L11_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_IP_MTU_DISCOVER); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 454, __pyx_L11_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_IN); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 454, __pyx_L11_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_IP_PMTUDISC_DO); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 454, __pyx_L11_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = NULL;
        __pyx_t_7 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
          if (likely(__pyx_t_2)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_4, function);
            __pyx_t_7 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_t_3, __pyx_t_5, __pyx_t_6};
          __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 454, __pyx_L11_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_t_3, __pyx_t_5, __pyx_t_6};
          __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 3+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 454, __pyx_L11_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        {
          __pyx_t_13 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 454, __pyx_L11_error)
          __Pyx_GOTREF(__pyx_t_13);
          if (__pyx_t_2) {
            __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_2); __pyx_t_2 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_7, __pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_5);
          PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_7, __pyx_t_5);
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_13, 2+__pyx_t_7, __pyx_t_6);
          __pyx_t_3 = 0;
          __pyx_t_5 = 0;
          __pyx_t_6 = 0;
          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 454, __pyx_L11_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        }
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "btdht/dht.pyx":453
 *         #self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 *         if IN is not None:
 *             try:             # <<<<<<<<<<<<<<
 *                 self.sock.setsockopt(socket.IPPROTO_IP, IN.IP_MTU_DISCOVER, IN.IP_PMTUDISC_DO)
 *             except AttributeError:
 */
      }
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      goto __pyx_L16_try_end;
      __pyx_L11_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "btdht/dht.pyx":455
 *             try:
 *                 self.sock.setsockopt(socket.IPPROTO_IP, IN.IP_MTU_DISCOVER, IN.IP_PMTUDISC_DO)
 *             except AttributeError:             # <<<<<<<<<<<<<<
 *                 pass
 *         self.sock.setblocking(0)
 */
      __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
      if (__pyx_t_7) {
        __Pyx_ErrRestore(0,0,0);
        goto __pyx_L12_exception_handled;
      }
      goto __pyx_L13_except_error;
      __pyx_L13_except_error:;

      /* "btdht/dht.pyx":453
 *         #self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 *         if IN is not None:
 *             try:             # <<<<<<<<<<<<<<
 *                 self.sock.setsockopt(socket.IPPROTO_IP, IN.IP_MTU_DISCOVER, IN.IP_PMTUDISC_DO)
 *             except AttributeError:
 */
      __Pyx_XGIVEREF(__pyx_t_11);
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_10, __pyx_t_9);
      goto __pyx_L1_error;
      __pyx_L12_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_11);
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_10, __pyx_t_9);
      __pyx_L16_try_end:;
    }

    /* "btdht/dht.pyx":452
 *         self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 *         #self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 *         if IN is not None:             # <<<<<<<<<<<<<<
 *             try:
 *                 self.sock.setsockopt(socket.IPPROTO_IP, IN.IP_MTU_DISCOVER, IN.IP_PMTUDISC_DO)
 */
  }

  /* "btdht/dht.pyx":457
 *             except AttributeError:
 *                 pass
 *         self.sock.setblocking(0)             # <<<<<<<<<<<<<<
 *         if self.bind_port:
 *             try:
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sock); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_setblocking); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_13);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_13, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_4, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_int_0);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":458
 *                 pass
 *         self.sock.setblocking(0)
 *         if self.bind_port:             # <<<<<<<<<<<<<<
 *             try:
 *                 self.sock.bind((self.bind_ip, self.bind_port))
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_bind_port); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 458, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_12) {

    /* "btdht/dht.pyx":459
 *         self.sock.setblocking(0)
 *         if self.bind_port:
 *             try:             # <<<<<<<<<<<<<<
 *                 self.sock.bind((self.bind_ip, self.bind_port))
 *             except socket.error:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      __Pyx_XGOTREF(__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_10);
      __Pyx_XGOTREF(__pyx_t_11);
      /*try:*/ {

        /* "btdht/dht.pyx":460
 *         if self.bind_port:
 *             try:
 *                 self.sock.bind((self.bind_ip, self.bind_port))             # <<<<<<<<<<<<<<
 *             except socket.error:
 *                 self.debug(-10, "fail to bind to port %s" % self.bind_port)
 */
        __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sock); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 460, __pyx_L18_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_bind); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 460, __pyx_L18_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_bind_ip); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 460, __pyx_L18_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_bind_port); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 460, __pyx_L18_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 460, __pyx_L18_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_13);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_13);
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6);
        __pyx_t_13 = 0;
        __pyx_t_6 = 0;
        __pyx_t_6 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
          if (likely(__pyx_t_6)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_4, function);
          }
        }
        __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5);
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 460, __pyx_L18_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "btdht/dht.pyx":459
 *         self.sock.setblocking(0)
 *         if self.bind_port:
 *             try:             # <<<<<<<<<<<<<<
 *                 self.sock.bind((self.bind_ip, self.bind_port))
 *             except socket.error:
 */
      }
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      goto __pyx_L23_try_end;
      __pyx_L18_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "btdht/dht.pyx":461
 *             try:
 *                 self.sock.bind((self.bind_ip, self.bind_port))
 *             except socket.error:             # <<<<<<<<<<<<<<
 *                 self.debug(-10, "fail to bind to port %s" % self.bind_port)
 *                 raise
 */
      __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_4, &__pyx_t_5);
      __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_socket); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 461, __pyx_L20_except_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_error); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 461, __pyx_L20_except_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_7 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_13);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_ErrRestore(__pyx_t_1, __pyx_t_4, __pyx_t_5);
      __pyx_t_1 = 0; __pyx_t_4 = 0; __pyx_t_5 = 0;
      if (__pyx_t_7) {
        __Pyx_AddTraceback("btdht.dht.DHT_BASE.init_socket", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_4, &__pyx_t_1) < 0) __PYX_ERR(0, 461, __pyx_L20_except_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GOTREF(__pyx_t_1);

        /* "btdht/dht.pyx":462
 *                 self.sock.bind((self.bind_ip, self.bind_port))
 *             except socket.error:
 *                 self.debug(-10, "fail to bind to port %s" % self.bind_port)             # <<<<<<<<<<<<<<
 *                 raise
 *         else:
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 462, __pyx_L20_except_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_bind_port); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 462, __pyx_L20_except_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_2 = __Pyx_PyString_FormatSafe(__pyx_kp_s_fail_to_bind_to_port_s, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 462, __pyx_L20_except_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = NULL;
        __pyx_t_7 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
            __pyx_t_7 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_neg_10, __pyx_t_2};
          __pyx_t_13 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 462, __pyx_L20_except_error)
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_neg_10, __pyx_t_2};
          __pyx_t_13 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 462, __pyx_L20_except_error)
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        } else
        #endif
        {
          __pyx_t_14 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 462, __pyx_L20_except_error)
          __Pyx_GOTREF(__pyx_t_14);
          if (__pyx_t_3) {
            __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); __pyx_t_3 = NULL;
          }
          __Pyx_INCREF(__pyx_int_neg_10);
          __Pyx_GIVEREF(__pyx_int_neg_10);
          PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_7, __pyx_int_neg_10);
          __Pyx_GIVEREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_7, __pyx_t_2);
          __pyx_t_2 = 0;
          __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_14, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 462, __pyx_L20_except_error)
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        }
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

        /* "btdht/dht.pyx":463
 *             except socket.error:
 *                 self.debug(-10, "fail to bind to port %s" % self.bind_port)
 *                 raise             # <<<<<<<<<<<<<<
 *         else:
 *             self.sock.bind((self.bind_ip, 0))
 */
        __Pyx_GIVEREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_4);
        __Pyx_XGIVEREF(__pyx_t_1);
        __Pyx_ErrRestoreWithState(__pyx_t_5, __pyx_t_4, __pyx_t_1);
        __pyx_t_5 = 0; __pyx_t_4 = 0; __pyx_t_1 = 0; 
        __PYX_ERR(0, 463, __pyx_L20_except_error)
      }
      goto __pyx_L20_except_error;
      __pyx_L20_except_error:;

      /* "btdht/dht.pyx":459
 *         self.sock.setblocking(0)
 *         if self.bind_port:
 *             try:             # <<<<<<<<<<<<<<
 *                 self.sock.bind((self.bind_ip, self.bind_port))
 *             except socket.error:
 */
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_XGIVEREF(__pyx_t_11);
      __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      goto __pyx_L1_error;
      __pyx_L23_try_end:;
    }

    /* "btdht/dht.pyx":458
 *                 pass
 *         self.sock.setblocking(0)
 *         if self.bind_port:             # <<<<<<<<<<<<<<
 *             try:
 *                 self.sock.bind((self.bind_ip, self.bind_port))
 */
    goto __pyx_L17;
  }

  /* "btdht/dht.pyx":465
 *                 raise
 *         else:
 *             self.sock.bind((self.bind_ip, 0))             # <<<<<<<<<<<<<<
 *             # set :attr:`bind_port` to the port choosen by the system
 *             self.bind_port = self.sock.getsockname()[1]
 */
  /*else*/ {
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sock); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_bind); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_bind_ip); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_13 = PyTuple_New(2); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_4);
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_int_0);
    __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_t_13) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_13);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":467
 *             self.sock.bind((self.bind_ip, 0))
 *             # set :attr:`bind_port` to the port choosen by the system
 *             self.bind_port = self.sock.getsockname()[1]             # <<<<<<<<<<<<<<
 * 
 *     def sleep(self, t, fstop=None):
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sock); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 467, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_getsockname); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 467, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_13);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_13, function);
      }
    }
    __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_13);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 467, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_13 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 467, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_bind_port, __pyx_t_13) < 0) __PYX_ERR(0, 467, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  }
  __pyx_L17:;

  /* "btdht/dht.pyx":442
 *         return (in_s, out_s, delta)
 * 
 *     def init_socket(self):             # <<<<<<<<<<<<<<
 *         """Initialize the UDP socket of the DHT"""
 *         self.debug(0, "init socket for %s" % binascii.b2a_hex(self.myid.value))
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.init_socket", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":469
 *             self.bind_port = self.sock.getsockname()[1]
 * 
 *     def sleep(self, t, fstop=None):             # <<<<<<<<<<<<<<
 *         """
 *             Sleep for t seconds. If the dht is requested to be stop, run ``fstop()`` and exit
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_21sleep(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_20sleep[] = "\n            Sleep for t seconds. If the dht is requested to be stop, run ``fstop()`` and exit\n\n            :param float t: A time to sleep, in seconds\n            :param fstop: A callable with no arguments, called before exiting\n\n            Note:\n                Dont use it in the main thread otherwise it can exit before child threads.\n                Only use it in child threads\n\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_21sleep(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_t = 0;
  PyObject *__pyx_v_fstop = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sleep (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_t,&__pyx_n_s_fstop,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_t)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_fstop);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sleep") < 0)) __PYX_ERR(0, 469, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_t = values[0];
    __pyx_v_fstop = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("sleep", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 469, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.sleep", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_20sleep(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_t, __pyx_v_fstop);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_20sleep(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_t, PyObject *__pyx_v_fstop) {
  PyObject *__pyx_v_t_int = NULL;
  PyObject *__pyx_v_t_dec = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sleep", 0);

  /* "btdht/dht.pyx":481
 * 
 *         """
 *         if t>0:             # <<<<<<<<<<<<<<
 *             t_int = int(t)
 *             t_dec = t - t_int
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_t, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 481, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 481, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "btdht/dht.pyx":482
 *         """
 *         if t>0:
 *             t_int = int(t)             # <<<<<<<<<<<<<<
 *             t_dec = t - t_int
 *             for i in range(0, t_int):
 */
    __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_v_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 482, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_t_int = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "btdht/dht.pyx":483
 *         if t>0:
 *             t_int = int(t)
 *             t_dec = t - t_int             # <<<<<<<<<<<<<<
 *             for i in range(0, t_int):
 *                 time.sleep(1)
 */
    __pyx_t_1 = PyNumber_Subtract(__pyx_v_t, __pyx_v_t_int); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 483, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_t_dec = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "btdht/dht.pyx":484
 *             t_int = int(t)
 *             t_dec = t - t_int
 *             for i in range(0, t_int):             # <<<<<<<<<<<<<<
 *                 time.sleep(1)
 *                 if self.stoped:
 */
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 484, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_0);
    __Pyx_INCREF(__pyx_v_t_int);
    __Pyx_GIVEREF(__pyx_v_t_int);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_t_int);
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 484, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
      __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 484, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 484, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 484, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 484, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 484, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 484, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        }
      } else {
        __pyx_t_3 = __pyx_t_5(__pyx_t_1);
        if (unlikely(!__pyx_t_3)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 484, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "btdht/dht.pyx":485
 *             t_dec = t - t_int
 *             for i in range(0, t_int):
 *                 time.sleep(1)             # <<<<<<<<<<<<<<
 *                 if self.stoped:
 *                     if fstop:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 485, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_sleep); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 485, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
        }
      }
      __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_int_1);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 485, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "btdht/dht.pyx":486
 *             for i in range(0, t_int):
 *                 time.sleep(1)
 *                 if self.stoped:             # <<<<<<<<<<<<<<
 *                     if fstop:
 *                         fstop()
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stoped); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 486, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 486, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_2) {

        /* "btdht/dht.pyx":487
 *                 time.sleep(1)
 *                 if self.stoped:
 *                     if fstop:             # <<<<<<<<<<<<<<
 *                         fstop()
 *                     sys.exit(0)
 */
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_fstop); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 487, __pyx_L1_error)
        if (__pyx_t_2) {

          /* "btdht/dht.pyx":488
 *                 if self.stoped:
 *                     if fstop:
 *                         fstop()             # <<<<<<<<<<<<<<
 *                     sys.exit(0)
 *             time.sleep(t_dec)
 */
          __Pyx_INCREF(__pyx_v_fstop);
          __pyx_t_7 = __pyx_v_fstop; __pyx_t_6 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
            __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
            if (likely(__pyx_t_6)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
              __Pyx_INCREF(__pyx_t_6);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_7, function);
            }
          }
          __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 488, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "btdht/dht.pyx":487
 *                 time.sleep(1)
 *                 if self.stoped:
 *                     if fstop:             # <<<<<<<<<<<<<<
 *                         fstop()
 *                     sys.exit(0)
 */
        }

        /* "btdht/dht.pyx":489
 *                     if fstop:
 *                         fstop()
 *                     sys.exit(0)             # <<<<<<<<<<<<<<
 *             time.sleep(t_dec)
 * 
 */
        __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_sys); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 489, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_exit_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 489, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
          }
        }
        __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_7, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_int_0);
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 489, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "btdht/dht.pyx":486
 *             for i in range(0, t_int):
 *                 time.sleep(1)
 *                 if self.stoped:             # <<<<<<<<<<<<<<
 *                     if fstop:
 *                         fstop()
 */
      }

      /* "btdht/dht.pyx":484
 *             t_int = int(t)
 *             t_dec = t - t_int
 *             for i in range(0, t_int):             # <<<<<<<<<<<<<<
 *                 time.sleep(1)
 *                 if self.stoped:
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":490
 *                         fstop()
 *                     sys.exit(0)
 *             time.sleep(t_dec)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_sleep); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_v_t_dec) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_t_dec);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":481
 * 
 *         """
 *         if t>0:             # <<<<<<<<<<<<<<
 *             t_int = int(t)
 *             t_dec = t - t_int
 */
  }

  /* "btdht/dht.pyx":469
 *             self.bind_port = self.sock.getsockname()[1]
 * 
 *     def sleep(self, t, fstop=None):             # <<<<<<<<<<<<<<
 *         """
 *             Sleep for t seconds. If the dht is requested to be stop, run ``fstop()`` and exit
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.sleep", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_t_int);
  __Pyx_XDECREF(__pyx_v_t_dec);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":493
 * 
 * 
 *     def announce_peer(self, info_hash, port, delay=0, block=True):             # <<<<<<<<<<<<<<
 *         """
 *             Announce that the ``info_hash`` is available on ``port`` to the K closest nodes from
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_23announce_peer(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_22announce_peer[] = "\n            Announce that the ``info_hash`` is available on ``port`` to the K closest nodes from\n            ``info_hash`` found in the whole dht.\n\n            :param bytes info_hash: A 160 bits (20 Bytes) long identifier to announce\n            :param int port: The tcp port of with ``info_hash`` if available\n            :param int delay: An optional delay in second to wait before starting to look for the K\n                closest nodes into the dht. The default is ``0``.\n            :param bool block: If ``True`` (the default) wait until the announce in done to the K\n                closest nodes. Otherwise, return immediately.\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_23announce_peer(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_info_hash = 0;
  PyObject *__pyx_v_port = 0;
  PyObject *__pyx_v_delay = 0;
  PyObject *__pyx_v_block = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("announce_peer (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_info_hash,&__pyx_n_s_port,&__pyx_n_s_delay,&__pyx_n_s_block,0};
    PyObject* values[4] = {0,0,0,0};
    values[2] = ((PyObject *)__pyx_int_0);
    values[3] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_info_hash)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_port)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("announce_peer", 0, 2, 4, 1); __PYX_ERR(0, 493, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_delay);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_block);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "announce_peer") < 0)) __PYX_ERR(0, 493, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_info_hash = values[0];
    __pyx_v_port = values[1];
    __pyx_v_delay = values[2];
    __pyx_v_block = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("announce_peer", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 493, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.announce_peer", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_22announce_peer(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_info_hash, __pyx_v_port, __pyx_v_delay, __pyx_v_block);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":505
 *                 closest nodes. Otherwise, return immediately.
 *         """
 *         def callback(nodes):             # <<<<<<<<<<<<<<
 *             for node in nodes:
 *                 try:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_13announce_peer_1callback(PyObject *__pyx_self, PyObject *__pyx_v_nodes); /*proto*/
static PyMethodDef __pyx_mdef_5btdht_3dht_8DHT_BASE_13announce_peer_1callback = {"callback", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_13announce_peer_1callback, METH_O, 0};
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_13announce_peer_1callback(PyObject *__pyx_self, PyObject *__pyx_v_nodes) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("callback (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_13announce_peer_callback(__pyx_self, ((PyObject *)__pyx_v_nodes));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_13announce_peer_callback(PyObject *__pyx_self, PyObject *__pyx_v_nodes) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *__pyx_cur_scope;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *__pyx_outer_scope;
  PyObject *__pyx_v_node = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *(*__pyx_t_3)(PyObject *);
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("callback", 0);
  __pyx_outer_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *) __Pyx_CyFunction_GetClosure(__pyx_self);
  __pyx_cur_scope = __pyx_outer_scope;

  /* "btdht/dht.pyx":506
 *         """
 *         def callback(nodes):
 *             for node in nodes:             # <<<<<<<<<<<<<<
 *                 try:
 *                     node.announce_peer(self, info_hash, port)
 */
  if (likely(PyList_CheckExact(__pyx_v_nodes)) || PyTuple_CheckExact(__pyx_v_nodes)) {
    __pyx_t_1 = __pyx_v_nodes; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_nodes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 506, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 506, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 506, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 506, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 506, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 506, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 506, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_node, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "btdht/dht.pyx":507
 *         def callback(nodes):
 *             for node in nodes:
 *                 try:             # <<<<<<<<<<<<<<
 *                     node.announce_peer(self, info_hash, port)
 *                 except NoTokenError:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_6);
      __Pyx_XGOTREF(__pyx_t_7);
      /*try:*/ {

        /* "btdht/dht.pyx":508
 *             for node in nodes:
 *                 try:
 *                     node.announce_peer(self, info_hash, port)             # <<<<<<<<<<<<<<
 *                 except NoTokenError:
 *                     node.get_peers(self, info_hash)
 */
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_announce_peer); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 508, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_8);
        if (unlikely(!__pyx_cur_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 508, __pyx_L5_error) }
        if (unlikely(!__pyx_cur_scope->__pyx_v_info_hash)) { __Pyx_RaiseClosureNameError("info_hash"); __PYX_ERR(0, 508, __pyx_L5_error) }
        if (unlikely(!__pyx_cur_scope->__pyx_v_port)) { __Pyx_RaiseClosureNameError("port"); __PYX_ERR(0, 508, __pyx_L5_error) }
        __pyx_t_9 = NULL;
        __pyx_t_10 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_9)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
            __pyx_t_10 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_8)) {
          PyObject *__pyx_temp[4] = {__pyx_t_9, ((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_info_hash, __pyx_cur_scope->__pyx_v_port};
          __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 508, __pyx_L5_error)
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_GOTREF(__pyx_t_4);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
          PyObject *__pyx_temp[4] = {__pyx_t_9, ((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_info_hash, __pyx_cur_scope->__pyx_v_port};
          __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 3+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 508, __pyx_L5_error)
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_GOTREF(__pyx_t_4);
        } else
        #endif
        {
          __pyx_t_11 = PyTuple_New(3+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 508, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_11);
          if (__pyx_t_9) {
            __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL;
          }
          __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_self));
          __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_self));
          PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, ((PyObject *)__pyx_cur_scope->__pyx_v_self));
          __Pyx_INCREF(__pyx_cur_scope->__pyx_v_info_hash);
          __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_info_hash);
          PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_cur_scope->__pyx_v_info_hash);
          __Pyx_INCREF(__pyx_cur_scope->__pyx_v_port);
          __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_port);
          PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_10, __pyx_cur_scope->__pyx_v_port);
          __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 508, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        }
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "btdht/dht.pyx":507
 *         def callback(nodes):
 *             for node in nodes:
 *                 try:             # <<<<<<<<<<<<<<
 *                     node.announce_peer(self, info_hash, port)
 *                 except NoTokenError:
 */
      }
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L12_try_end;
      __pyx_L5_error:;
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "btdht/dht.pyx":509
 *                 try:
 *                     node.announce_peer(self, info_hash, port)
 *                 except NoTokenError:             # <<<<<<<<<<<<<<
 *                     node.get_peers(self, info_hash)
 *                     self.debug(1, "No token to announce on node %s" % node)
 */
      __Pyx_ErrFetch(&__pyx_t_4, &__pyx_t_8, &__pyx_t_11);
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_NoTokenError); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 509, __pyx_L7_except_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_10 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_4, __pyx_t_9);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_ErrRestore(__pyx_t_4, __pyx_t_8, __pyx_t_11);
      __pyx_t_4 = 0; __pyx_t_8 = 0; __pyx_t_11 = 0;
      if (__pyx_t_10) {
        __Pyx_AddTraceback("btdht.dht.DHT_BASE.announce_peer.callback", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_11, &__pyx_t_8, &__pyx_t_4) < 0) __PYX_ERR(0, 509, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GOTREF(__pyx_t_4);

        /* "btdht/dht.pyx":510
 *                     node.announce_peer(self, info_hash, port)
 *                 except NoTokenError:
 *                     node.get_peers(self, info_hash)             # <<<<<<<<<<<<<<
 *                     self.debug(1, "No token to announce on node %s" % node)
 *         if block:
 */
        __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_get_peers); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 510, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_12);
        if (unlikely(!__pyx_cur_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 510, __pyx_L7_except_error) }
        if (unlikely(!__pyx_cur_scope->__pyx_v_info_hash)) { __Pyx_RaiseClosureNameError("info_hash"); __PYX_ERR(0, 510, __pyx_L7_except_error) }
        __pyx_t_13 = NULL;
        __pyx_t_10 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12);
          if (likely(__pyx_t_13)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_12, function);
            __pyx_t_10 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_12)) {
          PyObject *__pyx_temp[3] = {__pyx_t_13, ((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_info_hash};
          __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 510, __pyx_L7_except_error)
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_GOTREF(__pyx_t_9);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) {
          PyObject *__pyx_temp[3] = {__pyx_t_13, ((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_info_hash};
          __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 510, __pyx_L7_except_error)
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_GOTREF(__pyx_t_9);
        } else
        #endif
        {
          __pyx_t_14 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 510, __pyx_L7_except_error)
          __Pyx_GOTREF(__pyx_t_14);
          if (__pyx_t_13) {
            __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_13); __pyx_t_13 = NULL;
          }
          __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_self));
          __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_self));
          PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_10, ((PyObject *)__pyx_cur_scope->__pyx_v_self));
          __Pyx_INCREF(__pyx_cur_scope->__pyx_v_info_hash);
          __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_info_hash);
          PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_10, __pyx_cur_scope->__pyx_v_info_hash);
          __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_14, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 510, __pyx_L7_except_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        }
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "btdht/dht.pyx":511
 *                 except NoTokenError:
 *                     node.get_peers(self, info_hash)
 *                     self.debug(1, "No token to announce on node %s" % node)             # <<<<<<<<<<<<<<
 *         if block:
 *             while info_hash in self._get_closest_loop_lock and not self.stoped:
 */
        if (unlikely(!__pyx_cur_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 511, __pyx_L7_except_error) }
        __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 511, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_14 = __Pyx_PyString_FormatSafe(__pyx_kp_s_No_token_to_announce_on_node_s, __pyx_v_node); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 511, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_13 = NULL;
        __pyx_t_10 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12);
          if (likely(__pyx_t_13)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_12, function);
            __pyx_t_10 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_12)) {
          PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_int_1, __pyx_t_14};
          __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 511, __pyx_L7_except_error)
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) {
          PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_int_1, __pyx_t_14};
          __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 511, __pyx_L7_except_error)
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        } else
        #endif
        {
          __pyx_t_15 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 511, __pyx_L7_except_error)
          __Pyx_GOTREF(__pyx_t_15);
          if (__pyx_t_13) {
            __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_13); __pyx_t_13 = NULL;
          }
          __Pyx_INCREF(__pyx_int_1);
          __Pyx_GIVEREF(__pyx_int_1);
          PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_10, __pyx_int_1);
          __Pyx_GIVEREF(__pyx_t_14);
          PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_10, __pyx_t_14);
          __pyx_t_14 = 0;
          __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_15, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 511, __pyx_L7_except_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        }
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        goto __pyx_L6_exception_handled;
      }
      goto __pyx_L7_except_error;
      __pyx_L7_except_error:;

      /* "btdht/dht.pyx":507
 *         def callback(nodes):
 *             for node in nodes:
 *                 try:             # <<<<<<<<<<<<<<
 *                     node.announce_peer(self, info_hash, port)
 *                 except NoTokenError:
 */
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      goto __pyx_L1_error;
      __pyx_L6_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      __pyx_L12_try_end:;
    }

    /* "btdht/dht.pyx":506
 *         """
 *         def callback(nodes):
 *             for node in nodes:             # <<<<<<<<<<<<<<
 *                 try:
 *                     node.announce_peer(self, info_hash, port)
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":505
 *                 closest nodes. Otherwise, return immediately.
 *         """
 *         def callback(nodes):             # <<<<<<<<<<<<<<
 *             for node in nodes:
 *                 try:
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.announce_peer.callback", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_node);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":493
 * 
 * 
 *     def announce_peer(self, info_hash, port, delay=0, block=True):             # <<<<<<<<<<<<<<
 *         """
 *             Announce that the ``info_hash`` is available on ``port`` to the K closest nodes from
 */

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_22announce_peer(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_info_hash, PyObject *__pyx_v_port, PyObject *__pyx_v_delay, PyObject *__pyx_v_block) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *__pyx_cur_scope;
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_tried_nodes = NULL;
  PyObject *__pyx_v_ts = NULL;
  PyObject *__pyx_v_closest = NULL;
  PyObject *__pyx_v_typ = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("announce_peer", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct__announce_peer(__pyx_ptype_5btdht_3dht___pyx_scope_struct__announce_peer, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 493, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
  __pyx_cur_scope->__pyx_v_info_hash = __pyx_v_info_hash;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_info_hash);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_info_hash);
  __pyx_cur_scope->__pyx_v_port = __pyx_v_port;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_port);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_port);

  /* "btdht/dht.pyx":505
 *                 closest nodes. Otherwise, return immediately.
 *         """
 *         def callback(nodes):             # <<<<<<<<<<<<<<
 *             for node in nodes:
 *                 try:
 */
  __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_8DHT_BASE_13announce_peer_1callback, 0, __pyx_n_s_announce_peer_locals_callback, ((PyObject*)__pyx_cur_scope), __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__12)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_callback = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":512
 *                     node.get_peers(self, info_hash)
 *                     self.debug(1, "No token to announce on node %s" % node)
 *         if block:             # <<<<<<<<<<<<<<
 *             while info_hash in self._get_closest_loop_lock and not self.stoped:
 *                 self.sleep(0.1)
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_block); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 512, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "btdht/dht.pyx":513
 *                     self.debug(1, "No token to announce on node %s" % node)
 *         if block:
 *             while info_hash in self._get_closest_loop_lock and not self.stoped:             # <<<<<<<<<<<<<<
 *                 self.sleep(0.1)
 *         if not info_hash in self._get_closest_loop_lock:
 */
    while (1) {
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_closest_loop_lock); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 513, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_cur_scope->__pyx_v_info_hash, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 513, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_4 = (__pyx_t_3 != 0);
      if (__pyx_t_4) {
      } else {
        __pyx_t_2 = __pyx_t_4;
        goto __pyx_L6_bool_binop_done;
      }
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_stoped); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 513, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 513, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_3 = ((!__pyx_t_4) != 0);
      __pyx_t_2 = __pyx_t_3;
      __pyx_L6_bool_binop_done:;
      if (!__pyx_t_2) break;

      /* "btdht/dht.pyx":514
 *         if block:
 *             while info_hash in self._get_closest_loop_lock and not self.stoped:
 *                 self.sleep(0.1)             # <<<<<<<<<<<<<<
 *         if not info_hash in self._get_closest_loop_lock:
 *             self._get_closest_loop_lock[info_hash]=time.time()
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_sleep); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 514, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_float_0_1) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_float_0_1);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 514, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }

    /* "btdht/dht.pyx":512
 *                     node.get_peers(self, info_hash)
 *                     self.debug(1, "No token to announce on node %s" % node)
 *         if block:             # <<<<<<<<<<<<<<
 *             while info_hash in self._get_closest_loop_lock and not self.stoped:
 *                 self.sleep(0.1)
 */
  }

  /* "btdht/dht.pyx":515
 *             while info_hash in self._get_closest_loop_lock and not self.stoped:
 *                 self.sleep(0.1)
 *         if not info_hash in self._get_closest_loop_lock:             # <<<<<<<<<<<<<<
 *             self._get_closest_loop_lock[info_hash]=time.time()
 *             self.debug(2, "get closest hash %s" % binascii.b2a_hex(info_hash))
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_closest_loop_lock); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 515, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_cur_scope->__pyx_v_info_hash, __pyx_t_1, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 515, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":516
 *                 self.sleep(0.1)
 *         if not info_hash in self._get_closest_loop_lock:
 *             self._get_closest_loop_lock[info_hash]=time.time()             # <<<<<<<<<<<<<<
 *             self.debug(2, "get closest hash %s" % binascii.b2a_hex(info_hash))
 *             self.root.register_torrent(info_hash)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 516, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 516, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 516, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_closest_loop_lock); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 516, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (unlikely(PyObject_SetItem(__pyx_t_6, __pyx_cur_scope->__pyx_v_info_hash, __pyx_t_1) < 0)) __PYX_ERR(0, 516, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":517
 *         if not info_hash in self._get_closest_loop_lock:
 *             self._get_closest_loop_lock[info_hash]=time.time()
 *             self.debug(2, "get closest hash %s" % binascii.b2a_hex(info_hash))             # <<<<<<<<<<<<<<
 *             self.root.register_torrent(info_hash)
 *             tried_nodes = set()
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 517, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_binascii); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 517, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_b2a_hex); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 517, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    __pyx_t_5 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_cur_scope->__pyx_v_info_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_cur_scope->__pyx_v_info_hash);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 517, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyString_FormatSafe(__pyx_kp_s_get_closest_hash_s, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 517, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    __pyx_t_9 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
        __pyx_t_9 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_2, __pyx_t_8};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 517, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_2, __pyx_t_8};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 517, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else
    #endif
    {
      __pyx_t_7 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 517, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_INCREF(__pyx_int_2);
      __Pyx_GIVEREF(__pyx_int_2);
      PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_int_2);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 517, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":518
 *             self._get_closest_loop_lock[info_hash]=time.time()
 *             self.debug(2, "get closest hash %s" % binascii.b2a_hex(info_hash))
 *             self.root.register_torrent(info_hash)             # <<<<<<<<<<<<<<
 *             tried_nodes = set()
 *             ts = time.time() + delay
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 518, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_register_torrent); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 518, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_cur_scope->__pyx_v_info_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_cur_scope->__pyx_v_info_hash);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 518, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":519
 *             self.debug(2, "get closest hash %s" % binascii.b2a_hex(info_hash))
 *             self.root.register_torrent(info_hash)
 *             tried_nodes = set()             # <<<<<<<<<<<<<<
 *             ts = time.time() + delay
 *             closest = self.get_closest_nodes(info_hash)
 */
    __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 519, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_tried_nodes = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "btdht/dht.pyx":520
 *             self.root.register_torrent(info_hash)
 *             tried_nodes = set()
 *             ts = time.time() + delay             # <<<<<<<<<<<<<<
 *             closest = self.get_closest_nodes(info_hash)
 *             typ = "closest"
 */
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_time); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 520, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 520, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 520, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyNumber_Add(__pyx_t_1, __pyx_v_delay); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 520, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_ts = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "btdht/dht.pyx":521
 *             tried_nodes = set()
 *             ts = time.time() + delay
 *             closest = self.get_closest_nodes(info_hash)             # <<<<<<<<<<<<<<
 *             typ = "closest"
 *             heapq.heappush(
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_closest_nodes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 521, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_7, __pyx_cur_scope->__pyx_v_info_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_cur_scope->__pyx_v_info_hash);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 521, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_closest = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "btdht/dht.pyx":522
 *             ts = time.time() + delay
 *             closest = self.get_closest_nodes(info_hash)
 *             typ = "closest"             # <<<<<<<<<<<<<<
 *             heapq.heappush(
 *                 self._get_peer_loop_list,
 */
    __Pyx_INCREF(__pyx_n_s_closest);
    __pyx_v_typ = __pyx_n_s_closest;

    /* "btdht/dht.pyx":523
 *             closest = self.get_closest_nodes(info_hash)
 *             typ = "closest"
 *             heapq.heappush(             # <<<<<<<<<<<<<<
 *                 self._get_peer_loop_list,
 *                 (ts, info_hash, tried_nodes, closest, typ, callback, None)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_heapq); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 523, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_heappush); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 523, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":524
 *             typ = "closest"
 *             heapq.heappush(
 *                 self._get_peer_loop_list,             # <<<<<<<<<<<<<<
 *                 (ts, info_hash, tried_nodes, closest, typ, callback, None)
 *             )
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_peer_loop_list); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 524, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "btdht/dht.pyx":525
 *             heapq.heappush(
 *                 self._get_peer_loop_list,
 *                 (ts, info_hash, tried_nodes, closest, typ, callback, None)             # <<<<<<<<<<<<<<
 *             )
 *             if block:
 */
    __pyx_t_8 = PyTuple_New(7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 525, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_INCREF(__pyx_v_ts);
    __Pyx_GIVEREF(__pyx_v_ts);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_ts);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_info_hash);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_info_hash);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_cur_scope->__pyx_v_info_hash);
    __Pyx_INCREF(__pyx_v_tried_nodes);
    __Pyx_GIVEREF(__pyx_v_tried_nodes);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_v_tried_nodes);
    __Pyx_INCREF(__pyx_v_closest);
    __Pyx_GIVEREF(__pyx_v_closest);
    PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_v_closest);
    __Pyx_INCREF(__pyx_v_typ);
    __Pyx_GIVEREF(__pyx_v_typ);
    PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_v_typ);
    __Pyx_INCREF(__pyx_v_callback);
    __Pyx_GIVEREF(__pyx_v_callback);
    PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_v_callback);
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    PyTuple_SET_ITEM(__pyx_t_8, 6, Py_None);
    __pyx_t_5 = NULL;
    __pyx_t_9 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
        __pyx_t_9 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_7)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_t_8};
      __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 523, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_t_8};
      __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 523, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else
    #endif
    {
      __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 523, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_8);
      __pyx_t_1 = 0;
      __pyx_t_8 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_10, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 523, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "btdht/dht.pyx":527
 *                 (ts, info_hash, tried_nodes, closest, typ, callback, None)
 *             )
 *             if block:             # <<<<<<<<<<<<<<
 *                 while info_hash in self._get_closest_loop_lock and not self.stoped:
 *                     self.sleep(0.1)
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_block); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 527, __pyx_L1_error)
    if (__pyx_t_3) {

      /* "btdht/dht.pyx":528
 *             )
 *             if block:
 *                 while info_hash in self._get_closest_loop_lock and not self.stoped:             # <<<<<<<<<<<<<<
 *                     self.sleep(0.1)
 * 
 */
      while (1) {
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_closest_loop_lock); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 528, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_cur_scope->__pyx_v_info_hash, __pyx_t_6, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 528, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_4 = (__pyx_t_2 != 0);
        if (__pyx_t_4) {
        } else {
          __pyx_t_3 = __pyx_t_4;
          goto __pyx_L12_bool_binop_done;
        }
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_stoped); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 528, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 528, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_2 = ((!__pyx_t_4) != 0);
        __pyx_t_3 = __pyx_t_2;
        __pyx_L12_bool_binop_done:;
        if (!__pyx_t_3) break;

        /* "btdht/dht.pyx":529
 *             if block:
 *                 while info_hash in self._get_closest_loop_lock and not self.stoped:
 *                     self.sleep(0.1)             # <<<<<<<<<<<<<<
 * 
 *     def _add_peer(self, info_hash, ip, port):
 */
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_sleep); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 529, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_10 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_10)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_10);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
          }
        }
        __pyx_t_6 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_10, __pyx_float_0_1) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_float_0_1);
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 529, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }

      /* "btdht/dht.pyx":527
 *                 (ts, info_hash, tried_nodes, closest, typ, callback, None)
 *             )
 *             if block:             # <<<<<<<<<<<<<<
 *                 while info_hash in self._get_closest_loop_lock and not self.stoped:
 *                     self.sleep(0.1)
 */
    }

    /* "btdht/dht.pyx":515
 *             while info_hash in self._get_closest_loop_lock and not self.stoped:
 *                 self.sleep(0.1)
 *         if not info_hash in self._get_closest_loop_lock:             # <<<<<<<<<<<<<<
 *             self._get_closest_loop_lock[info_hash]=time.time()
 *             self.debug(2, "get closest hash %s" % binascii.b2a_hex(info_hash))
 */
  }

  /* "btdht/dht.pyx":493
 * 
 * 
 *     def announce_peer(self, info_hash, port, delay=0, block=True):             # <<<<<<<<<<<<<<
 *         """
 *             Announce that the ``info_hash`` is available on ``port`` to the K closest nodes from
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.announce_peer", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_callback);
  __Pyx_XDECREF(__pyx_v_tried_nodes);
  __Pyx_XDECREF(__pyx_v_ts);
  __Pyx_XDECREF(__pyx_v_closest);
  __Pyx_XDECREF(__pyx_v_typ);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":531
 *                     self.sleep(0.1)
 * 
 *     def _add_peer(self, info_hash, ip, port):             # <<<<<<<<<<<<<<
 *         """
 *             Store a peer after a announce_peer query
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_25_add_peer(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_24_add_peer[] = "\n            Store a peer after a announce_peer query\n\n            :param bytes info_hash: A 160 bits (20 Bytes) long identifier the peer is offering\n            :param str ip: The ip address of the peer in dotted notation (``\"1.2.3.4\"``)\n            :param int port: The tcp port of the peer\n\n            Note:\n                The peer address is store 30 minutes\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_25_add_peer(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_info_hash = 0;
  PyObject *__pyx_v_ip = 0;
  PyObject *__pyx_v_port = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_add_peer (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_info_hash,&__pyx_n_s_ip,&__pyx_n_s_port,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_info_hash)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ip)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_add_peer", 1, 3, 3, 1); __PYX_ERR(0, 531, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_port)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_add_peer", 1, 3, 3, 2); __PYX_ERR(0, 531, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_add_peer") < 0)) __PYX_ERR(0, 531, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_info_hash = values[0];
    __pyx_v_ip = values[1];
    __pyx_v_port = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_add_peer", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 531, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._add_peer", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_24_add_peer(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_info_hash, __pyx_v_ip, __pyx_v_port);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_24_add_peer(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_info_hash, PyObject *__pyx_v_ip, PyObject *__pyx_v_port) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  Py_ssize_t __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_add_peer", 0);

  /* "btdht/dht.pyx":542
 *                 The peer address is store 30 minutes
 *         """
 *         if ip not in self.ignored_ip and not utils.ip_in_nets(ip, self.ignored_net):             # <<<<<<<<<<<<<<
 *             self._peers[info_hash][(ip,port)]=time.time()
 *             # we only keep at most 100 peers per hash
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ignored_ip); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 542, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_v_ip, __pyx_t_2, Py_NE)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 542, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_1 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_utils); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 542, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_ip_in_nets); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 542, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ignored_net); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 542, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = NULL;
  __pyx_t_8 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
      __pyx_t_8 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_6)) {
    PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_ip, __pyx_t_5};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 542, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
    PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_ip, __pyx_t_5};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 542, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  {
    __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 542, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    if (__pyx_t_7) {
      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
    }
    __Pyx_INCREF(__pyx_v_ip);
    __Pyx_GIVEREF(__pyx_v_ip);
    PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_v_ip);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 542, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 542, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = ((!__pyx_t_4) != 0);
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "btdht/dht.pyx":543
 *         """
 *         if ip not in self.ignored_ip and not utils.ip_in_nets(ip, self.ignored_net):
 *             self._peers[info_hash][(ip,port)]=time.time()             # <<<<<<<<<<<<<<
 *             # we only keep at most 100 peers per hash
 *             if len(self._peers[info_hash]) > 100:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 543, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 543, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_9);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 543, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_peers); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 543, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_9, __pyx_v_info_hash); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 543, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 543, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(__pyx_v_ip);
    __Pyx_GIVEREF(__pyx_v_ip);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_ip);
    __Pyx_INCREF(__pyx_v_port);
    __Pyx_GIVEREF(__pyx_v_port);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_port);
    if (unlikely(PyObject_SetItem(__pyx_t_6, __pyx_t_9, __pyx_t_2) < 0)) __PYX_ERR(0, 543, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "btdht/dht.pyx":545
 *             self._peers[info_hash][(ip,port)]=time.time()
 *             # we only keep at most 100 peers per hash
 *             if len(self._peers[info_hash]) > 100:             # <<<<<<<<<<<<<<
 *                 self._peers[info_hash].popitem(False)
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_peers); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 545, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_info_hash); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 545, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_10 = PyObject_Length(__pyx_t_9); if (unlikely(__pyx_t_10 == ((Py_ssize_t)-1))) __PYX_ERR(0, 545, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_1 = ((__pyx_t_10 > 0x64) != 0);
    if (__pyx_t_1) {

      /* "btdht/dht.pyx":546
 *             # we only keep at most 100 peers per hash
 *             if len(self._peers[info_hash]) > 100:
 *                 self._peers[info_hash].popitem(False)             # <<<<<<<<<<<<<<
 * 
 *     def _add_peer_queried(self, info_hash, ip, port):
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_peers); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 546, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_info_hash); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 546, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_popitem); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 546, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      __pyx_t_9 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_6, Py_False) : __Pyx_PyObject_CallOneArg(__pyx_t_2, Py_False);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 546, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "btdht/dht.pyx":545
 *             self._peers[info_hash][(ip,port)]=time.time()
 *             # we only keep at most 100 peers per hash
 *             if len(self._peers[info_hash]) > 100:             # <<<<<<<<<<<<<<
 *                 self._peers[info_hash].popitem(False)
 * 
 */
    }

    /* "btdht/dht.pyx":542
 *                 The peer address is store 30 minutes
 *         """
 *         if ip not in self.ignored_ip and not utils.ip_in_nets(ip, self.ignored_net):             # <<<<<<<<<<<<<<
 *             self._peers[info_hash][(ip,port)]=time.time()
 *             # we only keep at most 100 peers per hash
 */
  }

  /* "btdht/dht.pyx":531
 *                     self.sleep(0.1)
 * 
 *     def _add_peer(self, info_hash, ip, port):             # <<<<<<<<<<<<<<
 *         """
 *             Store a peer after a announce_peer query
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._add_peer", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":548
 *                 self._peers[info_hash].popitem(False)
 * 
 *     def _add_peer_queried(self, info_hash, ip, port):             # <<<<<<<<<<<<<<
 *         """
 *             Store a peer after a get_peer response
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_27_add_peer_queried(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_26_add_peer_queried[] = "\n            Store a peer after a get_peer response\n\n            :param bytes info_hash: A 160 bits (20 Bytes) long identifier the peer is offering\n            :param str ip: The ip address of the peer in dotted notation (``\"1.2.3.4\"``)\n            :param int port: The tcp port of the peer\n\n            Note:\n                The peer address is store 15 minutes\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_27_add_peer_queried(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_info_hash = 0;
  PyObject *__pyx_v_ip = 0;
  PyObject *__pyx_v_port = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_add_peer_queried (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_info_hash,&__pyx_n_s_ip,&__pyx_n_s_port,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_info_hash)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ip)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_add_peer_queried", 1, 3, 3, 1); __PYX_ERR(0, 548, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_port)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_add_peer_queried", 1, 3, 3, 2); __PYX_ERR(0, 548, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_add_peer_queried") < 0)) __PYX_ERR(0, 548, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_info_hash = values[0];
    __pyx_v_ip = values[1];
    __pyx_v_port = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_add_peer_queried", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 548, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._add_peer_queried", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_26_add_peer_queried(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_info_hash, __pyx_v_ip, __pyx_v_port);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_26_add_peer_queried(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_info_hash, PyObject *__pyx_v_ip, PyObject *__pyx_v_port) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  Py_ssize_t __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_add_peer_queried", 0);

  /* "btdht/dht.pyx":560
 *         """
 *         if (
 *             port > 0 and             # <<<<<<<<<<<<<<
 *             ip not in self.ignored_ip and
 *             not utils.ip_in_nets(ip, self.ignored_net)
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_port, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 560, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }

  /* "btdht/dht.pyx":561
 *         if (
 *             port > 0 and
 *             ip not in self.ignored_ip and             # <<<<<<<<<<<<<<
 *             not utils.ip_in_nets(ip, self.ignored_net)
 *         ):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ignored_ip); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_v_ip, __pyx_t_2, Py_NE)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 561, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_1 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }

  /* "btdht/dht.pyx":562
 *             port > 0 and
 *             ip not in self.ignored_ip and
 *             not utils.ip_in_nets(ip, self.ignored_net)             # <<<<<<<<<<<<<<
 *         ):
 *             self._got_peers[info_hash][(ip,port)]=time.time()
 */
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_utils); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 562, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_ip_in_nets); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 562, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ignored_net); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 562, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_7 = NULL;
  __pyx_t_8 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
      __pyx_t_8 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_6)) {
    PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_ip, __pyx_t_5};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 562, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
    PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_ip, __pyx_t_5};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 562, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  {
    __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 562, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    if (__pyx_t_7) {
      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
    }
    __Pyx_INCREF(__pyx_v_ip);
    __Pyx_GIVEREF(__pyx_v_ip);
    PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_v_ip);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 562, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 562, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = ((!__pyx_t_4) != 0);
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;

  /* "btdht/dht.pyx":559
 *                 The peer address is store 15 minutes
 *         """
 *         if (             # <<<<<<<<<<<<<<
 *             port > 0 and
 *             ip not in self.ignored_ip and
 */
  if (__pyx_t_1) {

    /* "btdht/dht.pyx":564
 *             not utils.ip_in_nets(ip, self.ignored_net)
 *         ):
 *             self._got_peers[info_hash][(ip,port)]=time.time()             # <<<<<<<<<<<<<<
 *             # we only keep at most 1000 peers per hash
 *             if len(self._got_peers[info_hash]) > 1000:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_9);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_9, __pyx_v_info_hash); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(__pyx_v_ip);
    __Pyx_GIVEREF(__pyx_v_ip);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_ip);
    __Pyx_INCREF(__pyx_v_port);
    __Pyx_GIVEREF(__pyx_v_port);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_port);
    if (unlikely(PyObject_SetItem(__pyx_t_6, __pyx_t_9, __pyx_t_2) < 0)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "btdht/dht.pyx":566
 *             self._got_peers[info_hash][(ip,port)]=time.time()
 *             # we only keep at most 1000 peers per hash
 *             if len(self._got_peers[info_hash]) > 1000:             # <<<<<<<<<<<<<<
 *                 self._got_peers[info_hash].popitem(False)
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 566, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_info_hash); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 566, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_10 = PyObject_Length(__pyx_t_9); if (unlikely(__pyx_t_10 == ((Py_ssize_t)-1))) __PYX_ERR(0, 566, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_1 = ((__pyx_t_10 > 0x3E8) != 0);
    if (__pyx_t_1) {

      /* "btdht/dht.pyx":567
 *             # we only keep at most 1000 peers per hash
 *             if len(self._got_peers[info_hash]) > 1000:
 *                 self._got_peers[info_hash].popitem(False)             # <<<<<<<<<<<<<<
 * 
 *     def get_peers(self, hash, delay=0, block=True, callback=None, limit=10):
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_info_hash); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 567, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_popitem); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      __pyx_t_9 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_6, Py_False) : __Pyx_PyObject_CallOneArg(__pyx_t_2, Py_False);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 567, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "btdht/dht.pyx":566
 *             self._got_peers[info_hash][(ip,port)]=time.time()
 *             # we only keep at most 1000 peers per hash
 *             if len(self._got_peers[info_hash]) > 1000:             # <<<<<<<<<<<<<<
 *                 self._got_peers[info_hash].popitem(False)
 * 
 */
    }

    /* "btdht/dht.pyx":559
 *                 The peer address is store 15 minutes
 *         """
 *         if (             # <<<<<<<<<<<<<<
 *             port > 0 and
 *             ip not in self.ignored_ip and
 */
  }

  /* "btdht/dht.pyx":548
 *                 self._peers[info_hash].popitem(False)
 * 
 *     def _add_peer_queried(self, info_hash, ip, port):             # <<<<<<<<<<<<<<
 *         """
 *             Store a peer after a get_peer response
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._add_peer_queried", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":569
 *                 self._got_peers[info_hash].popitem(False)
 * 
 *     def get_peers(self, hash, delay=0, block=True, callback=None, limit=10):             # <<<<<<<<<<<<<<
 *         """
 *             Return a list of at most 1000 (ip, port) downloading ``hash`` or pass-it to ``callback``
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_29get_peers(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_28get_peers[] = "\n            Return a list of at most 1000 (ip, port) downloading ``hash`` or pass-it to ``callback``\n\n            :param bytes hash: A 160bits (20 Bytes) long identifier to look for peers\n            :param float delay: A delay in second to wait before starting to look for the K closest\n                nodes into the dht. The default is ``0``\n            :param bool block: If ``True`` (the default) block until we get at least one peer,\n                otherwise, return immediately (with or without peers).\n            :param callback: An optional callable taking as argument a list of peers (ip, port).\n                Called once we found most of the peers store in the DHT.\n            :param int limit: The maximum number of peer to look for before stoping the search.\n                The default is 10, the max is 1000.\n            :return: A list of peers (ip, port) with the ip in dotted notation (``\"1.2.3.4\"``)\n            :rtype: list\n\n            Note:\n                if ``block`` is False, the returned list will be most likely empty on the first call\n                subsequent call will return peers found so far.\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_29get_peers(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_hash = 0;
  PyObject *__pyx_v_delay = 0;
  PyObject *__pyx_v_block = 0;
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_limit = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_peers (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_hash,&__pyx_n_s_delay,&__pyx_n_s_block,&__pyx_n_s_callback,&__pyx_n_s_limit,0};
    PyObject* values[5] = {0,0,0,0,0};
    values[1] = ((PyObject *)__pyx_int_0);
    values[2] = ((PyObject *)Py_True);
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)__pyx_int_10);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_hash)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_delay);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_block);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_callback);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_limit);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_peers") < 0)) __PYX_ERR(0, 569, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_hash = values[0];
    __pyx_v_delay = values[1];
    __pyx_v_block = values[2];
    __pyx_v_callback = values[3];
    __pyx_v_limit = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_peers", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 569, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.get_peers", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_28get_peers(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_hash, __pyx_v_delay, __pyx_v_block, __pyx_v_callback, __pyx_v_limit);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_28get_peers(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_hash, PyObject *__pyx_v_delay, PyObject *__pyx_v_block, PyObject *__pyx_v_callback, PyObject *__pyx_v_limit) {
  PyObject *__pyx_v_peers = NULL;
  PyObject *__pyx_v_tried_nodes = NULL;
  PyObject *__pyx_v_ts = NULL;
  PyObject *__pyx_v_closest = NULL;
  PyObject *__pyx_v_typ = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_peers", 0);

  /* "btdht/dht.pyx":589
 *                 subsequent call will return peers found so far.
 *         """
 *         peers = None             # <<<<<<<<<<<<<<
 *         if hash in self._got_peers and self._got_peers[hash] and len(self._got_peers[hash])>=limit:
 *             peers = self._get_peers(hash, compact=False)
 */
  __Pyx_INCREF(Py_None);
  __pyx_v_peers = Py_None;

  /* "btdht/dht.pyx":590
 *         """
 *         peers = None
 *         if hash in self._got_peers and self._got_peers[hash] and len(self._got_peers[hash])>=limit:             # <<<<<<<<<<<<<<
 *             peers = self._get_peers(hash, compact=False)
 *             if callback:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_v_hash, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_1 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_hash); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_4) {
  } else {
    __pyx_t_1 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_5, __pyx_v_hash); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_v_limit, Py_GE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 590, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_1 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "btdht/dht.pyx":591
 *         peers = None
 *         if hash in self._got_peers and self._got_peers[hash] and len(self._got_peers[hash])>=limit:
 *             peers = self._get_peers(hash, compact=False)             # <<<<<<<<<<<<<<
 *             if callback:
 *                 callback(peers)
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_peers_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 591, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 591, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_hash);
    __Pyx_GIVEREF(__pyx_v_hash);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_hash);
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 591, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_compact, Py_False) < 0) __PYX_ERR(0, 591, __pyx_L1_error)
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 591, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF_SET(__pyx_v_peers, __pyx_t_8);
    __pyx_t_8 = 0;

    /* "btdht/dht.pyx":592
 *         if hash in self._got_peers and self._got_peers[hash] and len(self._got_peers[hash])>=limit:
 *             peers = self._get_peers(hash, compact=False)
 *             if callback:             # <<<<<<<<<<<<<<
 *                 callback(peers)
 *             return peers
 */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 592, __pyx_L1_error)
    if (__pyx_t_1) {

      /* "btdht/dht.pyx":593
 *             peers = self._get_peers(hash, compact=False)
 *             if callback:
 *                 callback(peers)             # <<<<<<<<<<<<<<
 *             return peers
 *         elif hash in self._get_peer_loop_lock:
 */
      __Pyx_INCREF(__pyx_v_callback);
      __pyx_t_7 = __pyx_v_callback; __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
        }
      }
      __pyx_t_8 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, __pyx_v_peers) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_peers);
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 593, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "btdht/dht.pyx":592
 *         if hash in self._got_peers and self._got_peers[hash] and len(self._got_peers[hash])>=limit:
 *             peers = self._get_peers(hash, compact=False)
 *             if callback:             # <<<<<<<<<<<<<<
 *                 callback(peers)
 *             return peers
 */
    }

    /* "btdht/dht.pyx":594
 *             if callback:
 *                 callback(peers)
 *             return peers             # <<<<<<<<<<<<<<
 *         elif hash in self._get_peer_loop_lock:
 *             if block:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_peers);
    __pyx_r = __pyx_v_peers;
    goto __pyx_L0;

    /* "btdht/dht.pyx":590
 *         """
 *         peers = None
 *         if hash in self._got_peers and self._got_peers[hash] and len(self._got_peers[hash])>=limit:             # <<<<<<<<<<<<<<
 *             peers = self._get_peers(hash, compact=False)
 *             if callback:
 */
  }

  /* "btdht/dht.pyx":595
 *                 callback(peers)
 *             return peers
 *         elif hash in self._get_peer_loop_lock:             # <<<<<<<<<<<<<<
 *             if block:
 *                 while hash in self._get_peer_loop_lock and not self.stoped:
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_peer_loop_lock); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 595, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_hash, __pyx_t_8, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 595, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_4 = (__pyx_t_1 != 0);
  if (__pyx_t_4) {

    /* "btdht/dht.pyx":596
 *             return peers
 *         elif hash in self._get_peer_loop_lock:
 *             if block:             # <<<<<<<<<<<<<<
 *                 while hash in self._get_peer_loop_lock and not self.stoped:
 *                     peers = self._get_peers(hash, compact=False)
 */
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_block); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 596, __pyx_L1_error)
    if (__pyx_t_4) {

      /* "btdht/dht.pyx":597
 *         elif hash in self._get_peer_loop_lock:
 *             if block:
 *                 while hash in self._get_peer_loop_lock and not self.stoped:             # <<<<<<<<<<<<<<
 *                     peers = self._get_peers(hash, compact=False)
 *                     if peers:
 */
      while (1) {
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_peer_loop_lock); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 597, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_hash, __pyx_t_8, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 597, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_3 = (__pyx_t_1 != 0);
        if (__pyx_t_3) {
        } else {
          __pyx_t_4 = __pyx_t_3;
          goto __pyx_L11_bool_binop_done;
        }
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stoped); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 597, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 597, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_1 = ((!__pyx_t_3) != 0);
        __pyx_t_4 = __pyx_t_1;
        __pyx_L11_bool_binop_done:;
        if (!__pyx_t_4) break;

        /* "btdht/dht.pyx":598
 *             if block:
 *                 while hash in self._get_peer_loop_lock and not self.stoped:
 *                     peers = self._get_peers(hash, compact=False)             # <<<<<<<<<<<<<<
 *                     if peers:
 *                         break
 */
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_peers_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_v_hash);
        __Pyx_GIVEREF(__pyx_v_hash);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_hash);
        __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_compact, Py_False) < 0) __PYX_ERR(0, 598, __pyx_L1_error)
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 598, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF_SET(__pyx_v_peers, __pyx_t_5);
        __pyx_t_5 = 0;

        /* "btdht/dht.pyx":599
 *                 while hash in self._get_peer_loop_lock and not self.stoped:
 *                     peers = self._get_peers(hash, compact=False)
 *                     if peers:             # <<<<<<<<<<<<<<
 *                         break
 *                     self.sleep(0.1)
 */
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_peers); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 599, __pyx_L1_error)
        if (__pyx_t_4) {

          /* "btdht/dht.pyx":600
 *                     peers = self._get_peers(hash, compact=False)
 *                     if peers:
 *                         break             # <<<<<<<<<<<<<<
 *                     self.sleep(0.1)
 *             return peers
 */
          goto __pyx_L10_break;

          /* "btdht/dht.pyx":599
 *                 while hash in self._get_peer_loop_lock and not self.stoped:
 *                     peers = self._get_peers(hash, compact=False)
 *                     if peers:             # <<<<<<<<<<<<<<
 *                         break
 *                     self.sleep(0.1)
 */
        }

        /* "btdht/dht.pyx":601
 *                     if peers:
 *                         break
 *                     self.sleep(0.1)             # <<<<<<<<<<<<<<
 *             return peers
 *         else:
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sleep); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 601, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
          }
        }
        __pyx_t_5 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_7, __pyx_float_0_1) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_float_0_1);
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 601, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __pyx_L10_break:;

      /* "btdht/dht.pyx":596
 *             return peers
 *         elif hash in self._get_peer_loop_lock:
 *             if block:             # <<<<<<<<<<<<<<
 *                 while hash in self._get_peer_loop_lock and not self.stoped:
 *                     peers = self._get_peers(hash, compact=False)
 */
    }

    /* "btdht/dht.pyx":602
 *                         break
 *                     self.sleep(0.1)
 *             return peers             # <<<<<<<<<<<<<<
 *         else:
 *             self._get_peer_loop_lock[hash]=time.time()
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_peers);
    __pyx_r = __pyx_v_peers;
    goto __pyx_L0;

    /* "btdht/dht.pyx":595
 *                 callback(peers)
 *             return peers
 *         elif hash in self._get_peer_loop_lock:             # <<<<<<<<<<<<<<
 *             if block:
 *                 while hash in self._get_peer_loop_lock and not self.stoped:
 */
  }

  /* "btdht/dht.pyx":604
 *             return peers
 *         else:
 *             self._get_peer_loop_lock[hash]=time.time()             # <<<<<<<<<<<<<<
 *             self.debug(2, "get peers hash %s" % binascii.b2a_hex(hash))
 *             self.root.register_torrent(hash)
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_5 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_peer_loop_lock); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (unlikely(PyObject_SetItem(__pyx_t_7, __pyx_v_hash, __pyx_t_5) < 0)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "btdht/dht.pyx":605
 *         else:
 *             self._get_peer_loop_lock[hash]=time.time()
 *             self.debug(2, "get peers hash %s" % binascii.b2a_hex(hash))             # <<<<<<<<<<<<<<
 *             self.root.register_torrent(hash)
 *             tried_nodes = set()
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 605, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_binascii); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 605, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_b2a_hex); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 605, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_2 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_v_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_hash);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 605, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyString_FormatSafe(__pyx_kp_s_get_peers_hash_s, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 605, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_7)) {
      PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_int_2, __pyx_t_9};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 605, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
      PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_int_2, __pyx_t_9};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 605, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else
    #endif
    {
      __pyx_t_8 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 605, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (__pyx_t_2) {
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); __pyx_t_2 = NULL;
      }
      __Pyx_INCREF(__pyx_int_2);
      __Pyx_GIVEREF(__pyx_int_2);
      PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_10, __pyx_int_2);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_10, __pyx_t_9);
      __pyx_t_9 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 605, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "btdht/dht.pyx":606
 *             self._get_peer_loop_lock[hash]=time.time()
 *             self.debug(2, "get peers hash %s" % binascii.b2a_hex(hash))
 *             self.root.register_torrent(hash)             # <<<<<<<<<<<<<<
 *             tried_nodes = set()
 *             ts = time.time() + delay
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 606, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_register_torrent); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 606, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    __pyx_t_5 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_7, __pyx_v_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_hash);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 606, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "btdht/dht.pyx":607
 *             self.debug(2, "get peers hash %s" % binascii.b2a_hex(hash))
 *             self.root.register_torrent(hash)
 *             tried_nodes = set()             # <<<<<<<<<<<<<<
 *             ts = time.time() + delay
 *             closest = self.get_closest_nodes(hash)
 */
    __pyx_t_5 = PySet_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 607, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_v_tried_nodes = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "btdht/dht.pyx":608
 *             self.root.register_torrent(hash)
 *             tried_nodes = set()
 *             ts = time.time() + delay             # <<<<<<<<<<<<<<
 *             closest = self.get_closest_nodes(hash)
 *             typ = "peers"
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 608, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 608, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 608, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyNumber_Add(__pyx_t_5, __pyx_v_delay); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 608, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_ts = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "btdht/dht.pyx":609
 *             tried_nodes = set()
 *             ts = time.time() + delay
 *             closest = self.get_closest_nodes(hash)             # <<<<<<<<<<<<<<
 *             typ = "peers"
 *             heapq.heappush(
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_closest_nodes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 609, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, __pyx_v_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_hash);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 609, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_closest = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "btdht/dht.pyx":610
 *             ts = time.time() + delay
 *             closest = self.get_closest_nodes(hash)
 *             typ = "peers"             # <<<<<<<<<<<<<<
 *             heapq.heappush(
 *                 self._get_peer_loop_list,
 */
    __Pyx_INCREF(__pyx_n_s_peers_2);
    __pyx_v_typ = __pyx_n_s_peers_2;

    /* "btdht/dht.pyx":611
 *             closest = self.get_closest_nodes(hash)
 *             typ = "peers"
 *             heapq.heappush(             # <<<<<<<<<<<<<<
 *                 self._get_peer_loop_list,
 *                 (ts, hash, tried_nodes, closest, typ, callback, limit)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_heapq); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 611, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_heappush); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 611, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "btdht/dht.pyx":612
 *             typ = "peers"
 *             heapq.heappush(
 *                 self._get_peer_loop_list,             # <<<<<<<<<<<<<<
 *                 (ts, hash, tried_nodes, closest, typ, callback, limit)
 *             )
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_peer_loop_list); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 612, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);

    /* "btdht/dht.pyx":613
 *             heapq.heappush(
 *                 self._get_peer_loop_list,
 *                 (ts, hash, tried_nodes, closest, typ, callback, limit)             # <<<<<<<<<<<<<<
 *             )
 *             if block:
 */
    __pyx_t_9 = PyTuple_New(7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 613, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(__pyx_v_ts);
    __Pyx_GIVEREF(__pyx_v_ts);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_ts);
    __Pyx_INCREF(__pyx_v_hash);
    __Pyx_GIVEREF(__pyx_v_hash);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_hash);
    __Pyx_INCREF(__pyx_v_tried_nodes);
    __Pyx_GIVEREF(__pyx_v_tried_nodes);
    PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_v_tried_nodes);
    __Pyx_INCREF(__pyx_v_closest);
    __Pyx_GIVEREF(__pyx_v_closest);
    PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_v_closest);
    __Pyx_INCREF(__pyx_v_typ);
    __Pyx_GIVEREF(__pyx_v_typ);
    PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_v_typ);
    __Pyx_INCREF(__pyx_v_callback);
    __Pyx_GIVEREF(__pyx_v_callback);
    PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_v_callback);
    __Pyx_INCREF(__pyx_v_limit);
    __Pyx_GIVEREF(__pyx_v_limit);
    PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_v_limit);
    __pyx_t_2 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_5, __pyx_t_9};
      __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 611, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_5, __pyx_t_9};
      __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 611, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else
    #endif
    {
      __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 611, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      if (__pyx_t_2) {
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_2); __pyx_t_2 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_9);
      __pyx_t_5 = 0;
      __pyx_t_9 = 0;
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 611, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "btdht/dht.pyx":615
 *                 (ts, hash, tried_nodes, closest, typ, callback, limit)
 *             )
 *             if block:             # <<<<<<<<<<<<<<
 *                 while hash in self._get_peer_loop_lock and not self.stoped:
 *                     peers = self._get_peers(hash, compact=False)
 */
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_block); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 615, __pyx_L1_error)
    if (__pyx_t_4) {

      /* "btdht/dht.pyx":616
 *             )
 *             if block:
 *                 while hash in self._get_peer_loop_lock and not self.stoped:             # <<<<<<<<<<<<<<
 *                     peers = self._get_peers(hash, compact=False)
 *                     if peers:
 */
      while (1) {
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_peer_loop_lock); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 616, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_hash, __pyx_t_7, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 616, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_3 = (__pyx_t_1 != 0);
        if (__pyx_t_3) {
        } else {
          __pyx_t_4 = __pyx_t_3;
          goto __pyx_L17_bool_binop_done;
        }
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stoped); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 616, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 616, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_1 = ((!__pyx_t_3) != 0);
        __pyx_t_4 = __pyx_t_1;
        __pyx_L17_bool_binop_done:;
        if (!__pyx_t_4) break;

        /* "btdht/dht.pyx":617
 *             if block:
 *                 while hash in self._get_peer_loop_lock and not self.stoped:
 *                     peers = self._get_peers(hash, compact=False)             # <<<<<<<<<<<<<<
 *                     if peers:
 *                         break
 */
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_peers_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 617, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 617, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_v_hash);
        __Pyx_GIVEREF(__pyx_v_hash);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_hash);
        __pyx_t_11 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 617, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_compact, Py_False) < 0) __PYX_ERR(0, 617, __pyx_L1_error)
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, __pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 617, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_DECREF_SET(__pyx_v_peers, __pyx_t_9);
        __pyx_t_9 = 0;

        /* "btdht/dht.pyx":618
 *                 while hash in self._get_peer_loop_lock and not self.stoped:
 *                     peers = self._get_peers(hash, compact=False)
 *                     if peers:             # <<<<<<<<<<<<<<
 *                         break
 *                     self.sleep(0.1)
 */
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_peers); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 618, __pyx_L1_error)
        if (__pyx_t_4) {

          /* "btdht/dht.pyx":619
 *                     peers = self._get_peers(hash, compact=False)
 *                     if peers:
 *                         break             # <<<<<<<<<<<<<<
 *                     self.sleep(0.1)
 *             return peers
 */
          goto __pyx_L16_break;

          /* "btdht/dht.pyx":618
 *                 while hash in self._get_peer_loop_lock and not self.stoped:
 *                     peers = self._get_peers(hash, compact=False)
 *                     if peers:             # <<<<<<<<<<<<<<
 *                         break
 *                     self.sleep(0.1)
 */
        }

        /* "btdht/dht.pyx":620
 *                     if peers:
 *                         break
 *                     self.sleep(0.1)             # <<<<<<<<<<<<<<
 *             return peers
 * 
 */
        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sleep); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 620, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_8 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_11);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_11, function);
          }
        }
        __pyx_t_9 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_8, __pyx_float_0_1) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_float_0_1);
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 620, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __pyx_L16_break:;

      /* "btdht/dht.pyx":615
 *                 (ts, hash, tried_nodes, closest, typ, callback, limit)
 *             )
 *             if block:             # <<<<<<<<<<<<<<
 *                 while hash in self._get_peer_loop_lock and not self.stoped:
 *                     peers = self._get_peers(hash, compact=False)
 */
    }

    /* "btdht/dht.pyx":621
 *                         break
 *                     self.sleep(0.1)
 *             return peers             # <<<<<<<<<<<<<<
 * 
 *     def _get_peers_closest_loop(self):
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_peers);
    __pyx_r = __pyx_v_peers;
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":569
 *                 self._got_peers[info_hash].popitem(False)
 * 
 *     def get_peers(self, hash, delay=0, block=True, callback=None, limit=10):             # <<<<<<<<<<<<<<
 *         """
 *             Return a list of at most 1000 (ip, port) downloading ``hash`` or pass-it to ``callback``
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.get_peers", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_peers);
  __Pyx_XDECREF(__pyx_v_tried_nodes);
  __Pyx_XDECREF(__pyx_v_ts);
  __Pyx_XDECREF(__pyx_v_closest);
  __Pyx_XDECREF(__pyx_v_typ);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_5btdht_3dht_8DHT_BASE_32generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "btdht/dht.pyx":623
 *             return peers
 * 
 *     def _get_peers_closest_loop(self):             # <<<<<<<<<<<<<<
 *         """
 *             Weigthless thread dealing we the :attr:`_get_peer_loop_list` heapq. Its execution
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_31_get_peers_closest_loop(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_30_get_peers_closest_loop[] = "\n            Weigthless thread dealing we the :attr:`_get_peer_loop_list` heapq. Its execution\n            is handled by :attr:`_scheduler` of type :class:`utils.Scheduler`\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_31_get_peers_closest_loop(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_get_peers_closest_loop (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_30_get_peers_closest_loop(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_30_get_peers_closest_loop(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_get_peers_closest_loop", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop(__pyx_ptype_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 623, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5btdht_3dht_8DHT_BASE_32generator, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_get_peers_closest_loop, __pyx_n_s_DHT_BASE__get_peers_closest_loop, __pyx_n_s_btdht_dht); if (unlikely(!gen)) __PYX_ERR(0, 623, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._get_peers_closest_loop", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":629
 *         """
 *         yield 0
 *         def on_stop(hash, typ):             # <<<<<<<<<<<<<<
 *             self.root.release_torrent(hash)
 *             if typ == "peers":
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_1on_stop(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_1on_stop = {"on_stop", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_1on_stop, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_1on_stop(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_hash = 0;
  PyObject *__pyx_v_typ = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_stop (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_hash,&__pyx_n_s_typ,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_hash)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_typ)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("on_stop", 1, 2, 2, 1); __PYX_ERR(0, 629, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "on_stop") < 0)) __PYX_ERR(0, 629, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_hash = values[0];
    __pyx_v_typ = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("on_stop", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 629, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._get_peers_closest_loop.on_stop", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_on_stop(__pyx_self, __pyx_v_hash, __pyx_v_typ);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_on_stop(PyObject *__pyx_self, PyObject *__pyx_v_hash, PyObject *__pyx_v_typ) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *__pyx_cur_scope;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *__pyx_outer_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("on_stop", 0);
  __pyx_outer_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *) __Pyx_CyFunction_GetClosure(__pyx_self);
  __pyx_cur_scope = __pyx_outer_scope;

  /* "btdht/dht.pyx":630
 *         yield 0
 *         def on_stop(hash, typ):
 *             self.root.release_torrent(hash)             # <<<<<<<<<<<<<<
 *             if typ == "peers":
 *                 try: del self._get_peer_loop_lock[hash]
 */
  if (unlikely(!__pyx_cur_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 630, __pyx_L1_error) }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 630, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_release_torrent); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 630, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_hash);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 630, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":631
 *         def on_stop(hash, typ):
 *             self.root.release_torrent(hash)
 *             if typ == "peers":             # <<<<<<<<<<<<<<
 *                 try: del self._get_peer_loop_lock[hash]
 *                 except KeyError: pass
 */
  __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_typ, __pyx_n_s_peers_2, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 631, __pyx_L1_error)
  if (__pyx_t_4) {

    /* "btdht/dht.pyx":632
 *             self.root.release_torrent(hash)
 *             if typ == "peers":
 *                 try: del self._get_peer_loop_lock[hash]             # <<<<<<<<<<<<<<
 *                 except KeyError: pass
 *             elif typ == "closest":
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_6);
      __Pyx_XGOTREF(__pyx_t_7);
      /*try:*/ {
        if (unlikely(!__pyx_cur_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 632, __pyx_L4_error) }
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_peer_loop_lock); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 632, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(PyObject_DelItem(__pyx_t_1, __pyx_v_hash) < 0)) __PYX_ERR(0, 632, __pyx_L4_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L9_try_end;
      __pyx_L4_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "btdht/dht.pyx":633
 *             if typ == "peers":
 *                 try: del self._get_peer_loop_lock[hash]
 *                 except KeyError: pass             # <<<<<<<<<<<<<<
 *             elif typ == "closest":
 *                 try: del self._get_closest_loop_lock[hash]
 */
      __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
      if (__pyx_t_8) {
        __Pyx_ErrRestore(0,0,0);
        goto __pyx_L5_exception_handled;
      }
      goto __pyx_L6_except_error;
      __pyx_L6_except_error:;

      /* "btdht/dht.pyx":632
 *             self.root.release_torrent(hash)
 *             if typ == "peers":
 *                 try: del self._get_peer_loop_lock[hash]             # <<<<<<<<<<<<<<
 *                 except KeyError: pass
 *             elif typ == "closest":
 */
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      goto __pyx_L1_error;
      __pyx_L5_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      __pyx_L9_try_end:;
    }

    /* "btdht/dht.pyx":631
 *         def on_stop(hash, typ):
 *             self.root.release_torrent(hash)
 *             if typ == "peers":             # <<<<<<<<<<<<<<
 *                 try: del self._get_peer_loop_lock[hash]
 *                 except KeyError: pass
 */
    goto __pyx_L3;
  }

  /* "btdht/dht.pyx":634
 *                 try: del self._get_peer_loop_lock[hash]
 *                 except KeyError: pass
 *             elif typ == "closest":             # <<<<<<<<<<<<<<
 *                 try: del self._get_closest_loop_lock[hash]
 *                 except KeyError: pass
 */
  __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_typ, __pyx_n_s_closest, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 634, __pyx_L1_error)
  if (__pyx_t_4) {

    /* "btdht/dht.pyx":635
 *                 except KeyError: pass
 *             elif typ == "closest":
 *                 try: del self._get_closest_loop_lock[hash]             # <<<<<<<<<<<<<<
 *                 except KeyError: pass
 * 
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_6, &__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_6);
      __Pyx_XGOTREF(__pyx_t_5);
      /*try:*/ {
        if (unlikely(!__pyx_cur_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 635, __pyx_L10_error) }
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_closest_loop_lock); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 635, __pyx_L10_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(PyObject_DelItem(__pyx_t_1, __pyx_v_hash) < 0)) __PYX_ERR(0, 635, __pyx_L10_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L15_try_end;
      __pyx_L10_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "btdht/dht.pyx":636
 *             elif typ == "closest":
 *                 try: del self._get_closest_loop_lock[hash]
 *                 except KeyError: pass             # <<<<<<<<<<<<<<
 * 
 *         def stop():
 */
      __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
      if (__pyx_t_8) {
        __Pyx_ErrRestore(0,0,0);
        goto __pyx_L11_exception_handled;
      }
      goto __pyx_L12_except_error;
      __pyx_L12_except_error:;

      /* "btdht/dht.pyx":635
 *                 except KeyError: pass
 *             elif typ == "closest":
 *                 try: del self._get_closest_loop_lock[hash]             # <<<<<<<<<<<<<<
 *                 except KeyError: pass
 * 
 */
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_6, __pyx_t_5);
      goto __pyx_L1_error;
      __pyx_L11_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_6, __pyx_t_5);
      __pyx_L15_try_end:;
    }

    /* "btdht/dht.pyx":634
 *                 try: del self._get_peer_loop_lock[hash]
 *                 except KeyError: pass
 *             elif typ == "closest":             # <<<<<<<<<<<<<<
 *                 try: del self._get_closest_loop_lock[hash]
 *                 except KeyError: pass
 */
  }
  __pyx_L3:;

  /* "btdht/dht.pyx":629
 *         """
 *         yield 0
 *         def on_stop(hash, typ):             # <<<<<<<<<<<<<<
 *             self.root.release_torrent(hash)
 *             if typ == "peers":
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._get_peers_closest_loop.on_stop", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":638
 *                 except KeyError: pass
 * 
 *         def stop():             # <<<<<<<<<<<<<<
 *             while self._get_peer_loop_list:
 *                 (_, hash, _, _, typ, _, _) = heapq.heappop(self._get_peer_loop_list)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_3stop(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyMethodDef __pyx_mdef_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_3stop = {"stop", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_3stop, METH_NOARGS, 0};
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_3stop(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stop (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_2stop(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_2stop(PyObject *__pyx_self) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *__pyx_cur_scope;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *__pyx_outer_scope;
  CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
  PyObject *__pyx_v_hash = NULL;
  PyObject *__pyx_v_typ = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *(*__pyx_t_11)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stop", 0);
  __pyx_outer_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *) __Pyx_CyFunction_GetClosure(__pyx_self);
  __pyx_cur_scope = __pyx_outer_scope;

  /* "btdht/dht.pyx":639
 * 
 *         def stop():
 *             while self._get_peer_loop_list:             # <<<<<<<<<<<<<<
 *                 (_, hash, _, _, typ, _, _) = heapq.heappop(self._get_peer_loop_list)
 *                 on_stop(hash, typ)
 */
  while (1) {
    if (unlikely(!__pyx_cur_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 639, __pyx_L1_error) }
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_peer_loop_list); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 639, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!__pyx_t_2) break;

    /* "btdht/dht.pyx":640
 *         def stop():
 *             while self._get_peer_loop_list:
 *                 (_, hash, _, _, typ, _, _) = heapq.heappop(self._get_peer_loop_list)             # <<<<<<<<<<<<<<
 *                 on_stop(hash, typ)
 * 
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_heapq); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 640, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_heappop); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 640, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_cur_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 640, __pyx_L1_error) }
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_peer_loop_list); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 640, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 640, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
      PyObject* sequence = __pyx_t_1;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 7)) {
        if (size > 7) __Pyx_RaiseTooManyValuesError(7);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 640, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 2); 
        __pyx_t_6 = PyTuple_GET_ITEM(sequence, 3); 
        __pyx_t_7 = PyTuple_GET_ITEM(sequence, 4); 
        __pyx_t_8 = PyTuple_GET_ITEM(sequence, 5); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 6); 
      } else {
        __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_5 = PyList_GET_ITEM(sequence, 2); 
        __pyx_t_6 = PyList_GET_ITEM(sequence, 3); 
        __pyx_t_7 = PyList_GET_ITEM(sequence, 4); 
        __pyx_t_8 = PyList_GET_ITEM(sequence, 5); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 6); 
      }
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_9);
      #else
      {
        Py_ssize_t i;
        PyObject** temps[7] = {&__pyx_t_4,&__pyx_t_3,&__pyx_t_5,&__pyx_t_6,&__pyx_t_7,&__pyx_t_8,&__pyx_t_9};
        for (i=0; i < 7; i++) {
          PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 640, __pyx_L1_error)
          __Pyx_GOTREF(item);
          *(temps[i]) = item;
        }
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      Py_ssize_t index = -1;
      PyObject** temps[7] = {&__pyx_t_4,&__pyx_t_3,&__pyx_t_5,&__pyx_t_6,&__pyx_t_7,&__pyx_t_8,&__pyx_t_9};
      __pyx_t_10 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 640, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
      for (index=0; index < 7; index++) {
        PyObject* item = __pyx_t_11(__pyx_t_10); if (unlikely(!item)) goto __pyx_L5_unpacking_failed;
        __Pyx_GOTREF(item);
        *(temps[index]) = item;
      }
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 7) < 0) __PYX_ERR(0, 640, __pyx_L1_error)
      __pyx_t_11 = NULL;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      goto __pyx_L6_unpacking_done;
      __pyx_L5_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_11 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 640, __pyx_L1_error)
      __pyx_L6_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_4);
    __pyx_t_4 = 0;
    __Pyx_XDECREF_SET(__pyx_v_hash, __pyx_t_3);
    __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v__, __pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v__, __pyx_t_6);
    __pyx_t_6 = 0;
    __Pyx_XDECREF_SET(__pyx_v_typ, __pyx_t_7);
    __pyx_t_7 = 0;
    __Pyx_DECREF_SET(__pyx_v__, __pyx_t_8);
    __pyx_t_8 = 0;
    __Pyx_DECREF_SET(__pyx_v__, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "btdht/dht.pyx":641
 *             while self._get_peer_loop_list:
 *                 (_, hash, _, _, typ, _, _) = heapq.heappop(self._get_peer_loop_list)
 *                 on_stop(hash, typ)             # <<<<<<<<<<<<<<
 * 
 *         while True:
 */
    if (unlikely(!__pyx_cur_scope->__pyx_v_on_stop)) { __Pyx_RaiseClosureNameError("on_stop"); __PYX_ERR(0, 641, __pyx_L1_error) }
    __pyx_t_1 = __pyx_pf_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_on_stop(__pyx_cur_scope->__pyx_v_on_stop, __pyx_v_hash, __pyx_v_typ); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 641, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "btdht/dht.pyx":638
 *                 except KeyError: pass
 * 
 *         def stop():             # <<<<<<<<<<<<<<
 *             while self._get_peer_loop_list:
 *                 (_, hash, _, _, typ, _, _) = heapq.heappop(self._get_peer_loop_list)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._get_peers_closest_loop.stop", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v__);
  __Pyx_XDECREF(__pyx_v_hash);
  __Pyx_XDECREF(__pyx_v_typ);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":623
 *             return peers
 * 
 *     def _get_peers_closest_loop(self):             # <<<<<<<<<<<<<<
 *         """
 *             Weigthless thread dealing we the :attr:`_get_peer_loop_list` heapq. Its execution
 */

static PyObject *__pyx_gb_5btdht_3dht_8DHT_BASE_32generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *__pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *(*__pyx_t_11)(PyObject *);
  int __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  PyObject *(*__pyx_t_14)(PyObject *);
  int __pyx_t_15;
  int __pyx_t_16;
  long __pyx_t_17;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_get_peers_closest_loop", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L4_resume_from_yield;
    case 2: goto __pyx_L38_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 623, __pyx_L1_error)

  /* "btdht/dht.pyx":628
 *             is handled by :attr:`_scheduler` of type :class:`utils.Scheduler`
 *         """
 *         yield 0             # <<<<<<<<<<<<<<
 *         def on_stop(hash, typ):
 *             self.root.release_torrent(hash)
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_r = __pyx_int_0;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  /* return from generator, yielding value */
  __pyx_generator->resume_label = 1;
  return __pyx_r;
  __pyx_L4_resume_from_yield:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 628, __pyx_L1_error)

  /* "btdht/dht.pyx":629
 *         """
 *         yield 0
 *         def on_stop(hash, typ):             # <<<<<<<<<<<<<<
 *             self.root.release_torrent(hash)
 *             if typ == "peers":
 */
  __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_1on_stop, 0, __pyx_n_s_get_peers_closest_loop_locals_o, ((PyObject*)__pyx_cur_scope), __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__14)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 629, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_on_stop = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":638
 *                 except KeyError: pass
 * 
 *         def stop():             # <<<<<<<<<<<<<<
 *             while self._get_peer_loop_list:
 *                 (_, hash, _, _, typ, _, _) = heapq.heappop(self._get_peer_loop_list)
 */
  __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_3stop, 0, __pyx_n_s_get_peers_closest_loop_locals_s, ((PyObject*)__pyx_cur_scope), __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__17)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_stop = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":643
 *                 on_stop(hash, typ)
 * 
 *         while True:             # <<<<<<<<<<<<<<
 *             tosleep = 1
 *             while self._get_peer_loop_list:
 */
  while (1) {

    /* "btdht/dht.pyx":644
 * 
 *         while True:
 *             tosleep = 1             # <<<<<<<<<<<<<<
 *             while self._get_peer_loop_list:
 *                 if self.stoped:
 */
    __Pyx_INCREF(__pyx_int_1);
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_tosleep);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_tosleep, __pyx_int_1);
    __Pyx_GIVEREF(__pyx_int_1);

    /* "btdht/dht.pyx":645
 *         while True:
 *             tosleep = 1
 *             while self._get_peer_loop_list:             # <<<<<<<<<<<<<<
 *                 if self.stoped:
 *                     stop()
 */
    while (1) {
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_peer_loop_list); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 645, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 645, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (!__pyx_t_2) break;

      /* "btdht/dht.pyx":646
 *             tosleep = 1
 *             while self._get_peer_loop_list:
 *                 if self.stoped:             # <<<<<<<<<<<<<<
 *                     stop()
 *                     return
 */
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_stoped); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 646, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 646, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_2) {

        /* "btdht/dht.pyx":647
 *             while self._get_peer_loop_list:
 *                 if self.stoped:
 *                     stop()             # <<<<<<<<<<<<<<
 *                     return
 *                 # fetch next hash to process
 */
        __pyx_t_1 = __pyx_pf_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_2stop(__pyx_cur_scope->__pyx_v_stop); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 647, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "btdht/dht.pyx":648
 *                 if self.stoped:
 *                     stop()
 *                     return             # <<<<<<<<<<<<<<
 *                 # fetch next hash to process
 *                 (
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = NULL;
        goto __pyx_L0;

        /* "btdht/dht.pyx":646
 *             tosleep = 1
 *             while self._get_peer_loop_list:
 *                 if self.stoped:             # <<<<<<<<<<<<<<
 *                     stop()
 *                     return
 */
      }

      /* "btdht/dht.pyx":652
 *                 (
 *                     ts, hash, tried_nodes, closest, typ, callback, limit
 *                 ) = heapq.heappop(self._get_peer_loop_list)             # <<<<<<<<<<<<<<
 *                 if typ not in ["peers", "closest"]:
 *                     raise ValueError("typ should not be %s" % typ)
 */
      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_heapq); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 652, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_heappop); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 652, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_peer_loop_list); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 652, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3);
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 652, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
        PyObject* sequence = __pyx_t_1;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 7)) {
          if (size > 7) __Pyx_RaiseTooManyValuesError(7);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 651, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
          __pyx_t_5 = PyTuple_GET_ITEM(sequence, 2); 
          __pyx_t_6 = PyTuple_GET_ITEM(sequence, 3); 
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 4); 
          __pyx_t_8 = PyTuple_GET_ITEM(sequence, 5); 
          __pyx_t_9 = PyTuple_GET_ITEM(sequence, 6); 
        } else {
          __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
          __pyx_t_5 = PyList_GET_ITEM(sequence, 2); 
          __pyx_t_6 = PyList_GET_ITEM(sequence, 3); 
          __pyx_t_7 = PyList_GET_ITEM(sequence, 4); 
          __pyx_t_8 = PyList_GET_ITEM(sequence, 5); 
          __pyx_t_9 = PyList_GET_ITEM(sequence, 6); 
        }
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_9);
        #else
        {
          Py_ssize_t i;
          PyObject** temps[7] = {&__pyx_t_4,&__pyx_t_3,&__pyx_t_5,&__pyx_t_6,&__pyx_t_7,&__pyx_t_8,&__pyx_t_9};
          for (i=0; i < 7; i++) {
            PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 651, __pyx_L1_error)
            __Pyx_GOTREF(item);
            *(temps[i]) = item;
          }
        }
        #endif
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else {
        Py_ssize_t index = -1;
        PyObject** temps[7] = {&__pyx_t_4,&__pyx_t_3,&__pyx_t_5,&__pyx_t_6,&__pyx_t_7,&__pyx_t_8,&__pyx_t_9};
        __pyx_t_10 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 651, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
        for (index=0; index < 7; index++) {
          PyObject* item = __pyx_t_11(__pyx_t_10); if (unlikely(!item)) goto __pyx_L10_unpacking_failed;
          __Pyx_GOTREF(item);
          *(temps[index]) = item;
        }
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 7) < 0) __PYX_ERR(0, 651, __pyx_L1_error)
        __pyx_t_11 = NULL;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L11_unpacking_done;
        __pyx_L10_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_11 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 651, __pyx_L1_error)
        __pyx_L11_unpacking_done:;
      }

      /* "btdht/dht.pyx":651
 *                 # fetch next hash to process
 *                 (
 *                     ts, hash, tried_nodes, closest, typ, callback, limit             # <<<<<<<<<<<<<<
 *                 ) = heapq.heappop(self._get_peer_loop_list)
 *                 if typ not in ["peers", "closest"]:
 */
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_ts);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_ts, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __pyx_t_4 = 0;
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_hash);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_hash, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_tried_nodes);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_tried_nodes, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_5 = 0;
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_closest);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_closest, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __pyx_t_6 = 0;
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_typ);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_typ, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_callback);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_callback, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      __pyx_t_8 = 0;
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_limit);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_limit, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_9);
      __pyx_t_9 = 0;

      /* "btdht/dht.pyx":653
 *                     ts, hash, tried_nodes, closest, typ, callback, limit
 *                 ) = heapq.heappop(self._get_peer_loop_list)
 *                 if typ not in ["peers", "closest"]:             # <<<<<<<<<<<<<<
 *                     raise ValueError("typ should not be %s" % typ)
 *                 # if process time is in the past process it
 */
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_typ);
      __pyx_t_1 = __pyx_cur_scope->__pyx_v_typ;
      __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_peers_2, Py_NE)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 653, __pyx_L1_error)
      if (__pyx_t_12) {
      } else {
        __pyx_t_2 = __pyx_t_12;
        goto __pyx_L13_bool_binop_done;
      }
      __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_closest, Py_NE)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 653, __pyx_L1_error)
      __pyx_t_2 = __pyx_t_12;
      __pyx_L13_bool_binop_done:;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_12 = (__pyx_t_2 != 0);
      if (unlikely(__pyx_t_12)) {

        /* "btdht/dht.pyx":654
 *                 ) = heapq.heappop(self._get_peer_loop_list)
 *                 if typ not in ["peers", "closest"]:
 *                     raise ValueError("typ should not be %s" % typ)             # <<<<<<<<<<<<<<
 *                 # if process time is in the past process it
 *                 if ts <= time.time():
 */
        __pyx_t_1 = __Pyx_PyString_FormatSafe(__pyx_kp_s_typ_should_not_be_s, __pyx_cur_scope->__pyx_v_typ); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 654, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 654, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_Raise(__pyx_t_9, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __PYX_ERR(0, 654, __pyx_L1_error)

        /* "btdht/dht.pyx":653
 *                     ts, hash, tried_nodes, closest, typ, callback, limit
 *                 ) = heapq.heappop(self._get_peer_loop_list)
 *                 if typ not in ["peers", "closest"]:             # <<<<<<<<<<<<<<
 *                     raise ValueError("typ should not be %s" % typ)
 *                 # if process time is in the past process it
 */
      }

      /* "btdht/dht.pyx":656
 *                     raise ValueError("typ should not be %s" % typ)
 *                 # if process time is in the past process it
 *                 if ts <= time.time():             # <<<<<<<<<<<<<<
 *                     # get hash k closest node that have not been tried
 *                     _closest = self.get_closest_nodes(hash)
 */
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 656, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 656, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      __pyx_t_9 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_8);
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 656, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_ts, __pyx_t_9, Py_LE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 656, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 656, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_12) {

        /* "btdht/dht.pyx":658
 *                 if ts <= time.time():
 *                     # get hash k closest node that have not been tried
 *                     _closest = self.get_closest_nodes(hash)             # <<<<<<<<<<<<<<
 *                     __closest = [node for node in _closest if node not in tried_nodes]
 * 
 */
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_closest_nodes); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 658, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_1 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_9);
          if (likely(__pyx_t_1)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_9, function);
          }
        }
        __pyx_t_8 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_1, __pyx_cur_scope->__pyx_v_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_cur_scope->__pyx_v_hash);
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 658, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_GIVEREF(__pyx_t_8);
        __pyx_cur_scope->__pyx_v__closest = __pyx_t_8;
        __pyx_t_8 = 0;

        /* "btdht/dht.pyx":659
 *                     # get hash k closest node that have not been tried
 *                     _closest = self.get_closest_nodes(hash)
 *                     __closest = [node for node in _closest if node not in tried_nodes]             # <<<<<<<<<<<<<<
 * 
 *                     if __closest:
 */
        __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 659, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v__closest)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v__closest)) {
          __pyx_t_9 = __pyx_cur_scope->__pyx_v__closest; __Pyx_INCREF(__pyx_t_9); __pyx_t_13 = 0;
          __pyx_t_14 = NULL;
        } else {
          __pyx_t_13 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_cur_scope->__pyx_v__closest); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 659, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_14 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 659, __pyx_L1_error)
        }
        for (;;) {
          if (likely(!__pyx_t_14)) {
            if (likely(PyList_CheckExact(__pyx_t_9))) {
              if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_9)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 659, __pyx_L1_error)
              #else
              __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 659, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              #endif
            } else {
              if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 659, __pyx_L1_error)
              #else
              __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 659, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              #endif
            }
          } else {
            __pyx_t_1 = __pyx_t_14(__pyx_t_9);
            if (unlikely(!__pyx_t_1)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 659, __pyx_L1_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_1);
          }
          __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_node);
          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_node, __pyx_t_1);
          __Pyx_GIVEREF(__pyx_t_1);
          __pyx_t_1 = 0;
          __pyx_t_12 = (__Pyx_PySequence_ContainsTF(__pyx_cur_scope->__pyx_v_node, __pyx_cur_scope->__pyx_v_tried_nodes, Py_NE)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 659, __pyx_L1_error)
          __pyx_t_2 = (__pyx_t_12 != 0);
          if (__pyx_t_2) {
            if (unlikely(__Pyx_ListComp_Append(__pyx_t_8, (PyObject*)__pyx_cur_scope->__pyx_v_node))) __PYX_ERR(0, 659, __pyx_L1_error)
          }
        }
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_GIVEREF(__pyx_t_8);
        __pyx_cur_scope->__pyx_v___closest = ((PyObject*)__pyx_t_8);
        __pyx_t_8 = 0;

        /* "btdht/dht.pyx":661
 *                     __closest = [node for node in _closest if node not in tried_nodes]
 * 
 *                     if __closest:             # <<<<<<<<<<<<<<
 *                         # alpha = 3 from the kademlia paper
 *                         nodes = __closest[0:3]
 */
        __pyx_t_2 = (PyList_GET_SIZE(__pyx_cur_scope->__pyx_v___closest) != 0);
        if (__pyx_t_2) {

          /* "btdht/dht.pyx":663
 *                     if __closest:
 *                         # alpha = 3 from the kademlia paper
 *                         nodes = __closest[0:3]             # <<<<<<<<<<<<<<
 *                         # send a get peer to the 3 closest nodes
 *                         for node in nodes:
 */
          __pyx_t_8 = __Pyx_PyList_GetSlice(__pyx_cur_scope->__pyx_v___closest, 0, 3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 663, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_nodes);
          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_nodes, ((PyObject*)__pyx_t_8));
          __Pyx_GIVEREF(__pyx_t_8);
          __pyx_t_8 = 0;

          /* "btdht/dht.pyx":665
 *                         nodes = __closest[0:3]
 *                         # send a get peer to the 3 closest nodes
 *                         for node in nodes:             # <<<<<<<<<<<<<<
 *                             node.get_peers(self, hash)
 *                             tried_nodes.add(node)
 */
          __pyx_t_8 = __pyx_cur_scope->__pyx_v_nodes; __Pyx_INCREF(__pyx_t_8); __pyx_t_13 = 0;
          for (;;) {
            if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_8)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_9 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_13); __Pyx_INCREF(__pyx_t_9); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 665, __pyx_L1_error)
            #else
            __pyx_t_9 = PySequence_ITEM(__pyx_t_8, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 665, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            #endif
            __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_node);
            __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_node, __pyx_t_9);
            __Pyx_GIVEREF(__pyx_t_9);
            __pyx_t_9 = 0;

            /* "btdht/dht.pyx":666
 *                         # send a get peer to the 3 closest nodes
 *                         for node in nodes:
 *                             node.get_peers(self, hash)             # <<<<<<<<<<<<<<
 *                             tried_nodes.add(node)
 *                         ts = time.time() + 2
 */
            __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s_get_peers); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 666, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_7 = NULL;
            __pyx_t_15 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
              __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
              if (likely(__pyx_t_7)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
                __Pyx_INCREF(__pyx_t_7);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_1, function);
                __pyx_t_15 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[3] = {__pyx_t_7, ((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_hash};
              __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 666, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_GOTREF(__pyx_t_9);
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[3] = {__pyx_t_7, ((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_hash};
              __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 666, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_GOTREF(__pyx_t_9);
            } else
            #endif
            {
              __pyx_t_6 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 666, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              if (__pyx_t_7) {
                __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = NULL;
              }
              __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_self));
              __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_self));
              PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_15, ((PyObject *)__pyx_cur_scope->__pyx_v_self));
              __Pyx_INCREF(__pyx_cur_scope->__pyx_v_hash);
              __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_hash);
              PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_15, __pyx_cur_scope->__pyx_v_hash);
              __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 666, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            }
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

            /* "btdht/dht.pyx":667
 *                         for node in nodes:
 *                             node.get_peers(self, hash)
 *                             tried_nodes.add(node)             # <<<<<<<<<<<<<<
 *                         ts = time.time() + 2
 *                         # we search peers and we found as least limit of them
 */
            __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_tried_nodes, __pyx_n_s_add); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 667, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_6 = NULL;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
              __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1);
              if (likely(__pyx_t_6)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
                __Pyx_INCREF(__pyx_t_6);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_1, function);
              }
            }
            __pyx_t_9 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_6, __pyx_cur_scope->__pyx_v_node) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_cur_scope->__pyx_v_node);
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 667, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

            /* "btdht/dht.pyx":665
 *                         nodes = __closest[0:3]
 *                         # send a get peer to the 3 closest nodes
 *                         for node in nodes:             # <<<<<<<<<<<<<<
 *                             node.get_peers(self, hash)
 *                             tried_nodes.add(node)
 */
          }
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

          /* "btdht/dht.pyx":668
 *                             node.get_peers(self, hash)
 *                             tried_nodes.add(node)
 *                         ts = time.time() + 2             # <<<<<<<<<<<<<<
 *                         # we search peers and we found as least limit of them
 *                         if (
 */
          __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_time); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 668, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 668, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
            if (likely(__pyx_t_9)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
              __Pyx_INCREF(__pyx_t_9);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_1, function);
            }
          }
          __pyx_t_8 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 668, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_8, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 668, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ts);
          __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_ts, __pyx_t_1);
          __Pyx_GIVEREF(__pyx_t_1);
          __pyx_t_1 = 0;

          /* "btdht/dht.pyx":671
 *                         # we search peers and we found as least limit of them
 *                         if (
 *                             typ == "peers" and             # <<<<<<<<<<<<<<
 *                             limit and
 *                             hash in self._got_peers and
 */
          __pyx_t_12 = (__Pyx_PyString_Equals(__pyx_cur_scope->__pyx_v_typ, __pyx_n_s_peers_2, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 671, __pyx_L1_error)
          if (__pyx_t_12) {
          } else {
            __pyx_t_2 = __pyx_t_12;
            goto __pyx_L23_bool_binop_done;
          }

          /* "btdht/dht.pyx":672
 *                         if (
 *                             typ == "peers" and
 *                             limit and             # <<<<<<<<<<<<<<
 *                             hash in self._got_peers and
 *                             self._got_peers[hash] and
 */
          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_limit); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 672, __pyx_L1_error)
          if (__pyx_t_12) {
          } else {
            __pyx_t_2 = __pyx_t_12;
            goto __pyx_L23_bool_binop_done;
          }

          /* "btdht/dht.pyx":673
 *                             typ == "peers" and
 *                             limit and
 *                             hash in self._got_peers and             # <<<<<<<<<<<<<<
 *                             self._got_peers[hash] and
 *                             len(self._got_peers[hash])>=limit
 */
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 673, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_12 = (__Pyx_PySequence_ContainsTF(__pyx_cur_scope->__pyx_v_hash, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 673, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_16 = (__pyx_t_12 != 0);
          if (__pyx_t_16) {
          } else {
            __pyx_t_2 = __pyx_t_16;
            goto __pyx_L23_bool_binop_done;
          }

          /* "btdht/dht.pyx":674
 *                             limit and
 *                             hash in self._got_peers and
 *                             self._got_peers[hash] and             # <<<<<<<<<<<<<<
 *                             len(self._got_peers[hash])>=limit
 *                         ):
 */
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 674, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_cur_scope->__pyx_v_hash); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 674, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 674, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (__pyx_t_16) {
          } else {
            __pyx_t_2 = __pyx_t_16;
            goto __pyx_L23_bool_binop_done;
          }

          /* "btdht/dht.pyx":675
 *                             hash in self._got_peers and
 *                             self._got_peers[hash] and
 *                             len(self._got_peers[hash])>=limit             # <<<<<<<<<<<<<<
 *                         ):
 *                             self.debug(2, "Hash %s find peers" % binascii.b2a_hex(hash))
 */
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 675, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_t_8, __pyx_cur_scope->__pyx_v_hash); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 675, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_13 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 675, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 675, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_8 = PyObject_RichCompare(__pyx_t_1, __pyx_cur_scope->__pyx_v_limit, Py_GE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 675, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 675, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_2 = __pyx_t_16;
          __pyx_L23_bool_binop_done:;

          /* "btdht/dht.pyx":670
 *                         ts = time.time() + 2
 *                         # we search peers and we found as least limit of them
 *                         if (             # <<<<<<<<<<<<<<
 *                             typ == "peers" and
 *                             limit and
 */
          if (__pyx_t_2) {

            /* "btdht/dht.pyx":677
 *                             len(self._got_peers[hash])>=limit
 *                         ):
 *                             self.debug(2, "Hash %s find peers" % binascii.b2a_hex(hash))             # <<<<<<<<<<<<<<
 *                             if callback:
 *                                 callback(self._get_peers(hash, compact=False))
 */
            __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 677, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_binascii); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 677, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_b2a_hex); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 677, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __pyx_t_6 = NULL;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
              __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
              if (likely(__pyx_t_6)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
                __Pyx_INCREF(__pyx_t_6);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_7, function);
              }
            }
            __pyx_t_9 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_cur_scope->__pyx_v_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_cur_scope->__pyx_v_hash);
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 677, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __pyx_t_7 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Hash_s_find_peers, __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 677, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __pyx_t_9 = NULL;
            __pyx_t_15 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
              __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
              if (likely(__pyx_t_9)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
                __Pyx_INCREF(__pyx_t_9);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_1, function);
                __pyx_t_15 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_int_2, __pyx_t_7};
              __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 677, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_int_2, __pyx_t_7};
              __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 677, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            } else
            #endif
            {
              __pyx_t_6 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 677, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              if (__pyx_t_9) {
                __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_9); __pyx_t_9 = NULL;
              }
              __Pyx_INCREF(__pyx_int_2);
              __Pyx_GIVEREF(__pyx_int_2);
              PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_15, __pyx_int_2);
              __Pyx_GIVEREF(__pyx_t_7);
              PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_15, __pyx_t_7);
              __pyx_t_7 = 0;
              __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 677, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            }
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

            /* "btdht/dht.pyx":678
 *                         ):
 *                             self.debug(2, "Hash %s find peers" % binascii.b2a_hex(hash))
 *                             if callback:             # <<<<<<<<<<<<<<
 *                                 callback(self._get_peers(hash, compact=False))
 *                             on_stop(hash, typ)
 */
            __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_callback); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 678, __pyx_L1_error)
            if (__pyx_t_2) {

              /* "btdht/dht.pyx":679
 *                             self.debug(2, "Hash %s find peers" % binascii.b2a_hex(hash))
 *                             if callback:
 *                                 callback(self._get_peers(hash, compact=False))             # <<<<<<<<<<<<<<
 *                             on_stop(hash, typ)
 *                         # we search closest node and we don't find any closest
 */
              __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_peers_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 679, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 679, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_INCREF(__pyx_cur_scope->__pyx_v_hash);
              __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_hash);
              PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_cur_scope->__pyx_v_hash);
              __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 679, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_7);
              if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_compact, Py_False) < 0) __PYX_ERR(0, 679, __pyx_L1_error)
              __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 679, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_INCREF(__pyx_cur_scope->__pyx_v_callback);
              __pyx_t_7 = __pyx_cur_scope->__pyx_v_callback; __pyx_t_6 = NULL;
              if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
                __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
                if (likely(__pyx_t_6)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
                  __Pyx_INCREF(__pyx_t_6);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_7, function);
                }
              }
              __pyx_t_8 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_9);
              __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
              if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 679, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

              /* "btdht/dht.pyx":678
 *                         ):
 *                             self.debug(2, "Hash %s find peers" % binascii.b2a_hex(hash))
 *                             if callback:             # <<<<<<<<<<<<<<
 *                                 callback(self._get_peers(hash, compact=False))
 *                             on_stop(hash, typ)
 */
            }

            /* "btdht/dht.pyx":680
 *                             if callback:
 *                                 callback(self._get_peers(hash, compact=False))
 *                             on_stop(hash, typ)             # <<<<<<<<<<<<<<
 *                         # we search closest node and we don't find any closest
 *                         elif (typ == "closest" and closest == _closest):
 */
            __pyx_t_8 = __pyx_pf_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_on_stop(__pyx_cur_scope->__pyx_v_on_stop, __pyx_cur_scope->__pyx_v_hash, __pyx_cur_scope->__pyx_v_typ); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 680, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

            /* "btdht/dht.pyx":670
 *                         ts = time.time() + 2
 *                         # we search peers and we found as least limit of them
 *                         if (             # <<<<<<<<<<<<<<
 *                             typ == "peers" and
 *                             limit and
 */
            goto __pyx_L22;
          }

          /* "btdht/dht.pyx":682
 *                             on_stop(hash, typ)
 *                         # we search closest node and we don't find any closest
 *                         elif (typ == "closest" and closest == _closest):             # <<<<<<<<<<<<<<
 *                             self.debug(2, "Hash %s find nodes" % binascii.b2a_hex(hash))
 *                             if callback:
 */
          __pyx_t_16 = (__Pyx_PyString_Equals(__pyx_cur_scope->__pyx_v_typ, __pyx_n_s_closest, Py_EQ)); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 682, __pyx_L1_error)
          if (__pyx_t_16) {
          } else {
            __pyx_t_2 = __pyx_t_16;
            goto __pyx_L29_bool_binop_done;
          }
          __pyx_t_8 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_closest, __pyx_cur_scope->__pyx_v__closest, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 682, __pyx_L1_error)
          __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 682, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_2 = __pyx_t_16;
          __pyx_L29_bool_binop_done:;
          if (__pyx_t_2) {

            /* "btdht/dht.pyx":683
 *                         # we search closest node and we don't find any closest
 *                         elif (typ == "closest" and closest == _closest):
 *                             self.debug(2, "Hash %s find nodes" % binascii.b2a_hex(hash))             # <<<<<<<<<<<<<<
 *                             if callback:
 *                                 callback(_closest)
 */
            __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 683, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_binascii); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 683, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_b2a_hex); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 683, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __pyx_t_6 = NULL;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
              __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1);
              if (likely(__pyx_t_6)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
                __Pyx_INCREF(__pyx_t_6);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_1, function);
              }
            }
            __pyx_t_9 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_6, __pyx_cur_scope->__pyx_v_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_cur_scope->__pyx_v_hash);
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 683, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __pyx_t_1 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Hash_s_find_nodes, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 683, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __pyx_t_9 = NULL;
            __pyx_t_15 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
              __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7);
              if (likely(__pyx_t_9)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
                __Pyx_INCREF(__pyx_t_9);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_7, function);
                __pyx_t_15 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_7)) {
              PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_int_2, __pyx_t_1};
              __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 683, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
              PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_int_2, __pyx_t_1};
              __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 683, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            } else
            #endif
            {
              __pyx_t_6 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 683, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              if (__pyx_t_9) {
                __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_9); __pyx_t_9 = NULL;
              }
              __Pyx_INCREF(__pyx_int_2);
              __Pyx_GIVEREF(__pyx_int_2);
              PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_15, __pyx_int_2);
              __Pyx_GIVEREF(__pyx_t_1);
              PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_15, __pyx_t_1);
              __pyx_t_1 = 0;
              __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_6, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 683, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            }
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

            /* "btdht/dht.pyx":684
 *                         elif (typ == "closest" and closest == _closest):
 *                             self.debug(2, "Hash %s find nodes" % binascii.b2a_hex(hash))
 *                             if callback:             # <<<<<<<<<<<<<<
 *                                 callback(_closest)
 *                             on_stop(hash, typ)
 */
            __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_callback); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 684, __pyx_L1_error)
            if (__pyx_t_2) {

              /* "btdht/dht.pyx":685
 *                             self.debug(2, "Hash %s find nodes" % binascii.b2a_hex(hash))
 *                             if callback:
 *                                 callback(_closest)             # <<<<<<<<<<<<<<
 *                             on_stop(hash, typ)
 *                         # Else had it the the heap to be processed later
 */
              __Pyx_INCREF(__pyx_cur_scope->__pyx_v_callback);
              __pyx_t_7 = __pyx_cur_scope->__pyx_v_callback; __pyx_t_6 = NULL;
              if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
                __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
                if (likely(__pyx_t_6)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
                  __Pyx_INCREF(__pyx_t_6);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_7, function);
                }
              }
              __pyx_t_8 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_cur_scope->__pyx_v__closest) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_cur_scope->__pyx_v__closest);
              __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
              if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 685, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

              /* "btdht/dht.pyx":684
 *                         elif (typ == "closest" and closest == _closest):
 *                             self.debug(2, "Hash %s find nodes" % binascii.b2a_hex(hash))
 *                             if callback:             # <<<<<<<<<<<<<<
 *                                 callback(_closest)
 *                             on_stop(hash, typ)
 */
            }

            /* "btdht/dht.pyx":686
 *                             if callback:
 *                                 callback(_closest)
 *                             on_stop(hash, typ)             # <<<<<<<<<<<<<<
 *                         # Else had it the the heap to be processed later
 *                         else:
 */
            __pyx_t_8 = __pyx_pf_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_on_stop(__pyx_cur_scope->__pyx_v_on_stop, __pyx_cur_scope->__pyx_v_hash, __pyx_cur_scope->__pyx_v_typ); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 686, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

            /* "btdht/dht.pyx":682
 *                             on_stop(hash, typ)
 *                         # we search closest node and we don't find any closest
 *                         elif (typ == "closest" and closest == _closest):             # <<<<<<<<<<<<<<
 *                             self.debug(2, "Hash %s find nodes" % binascii.b2a_hex(hash))
 *                             if callback:
 */
            goto __pyx_L22;
          }

          /* "btdht/dht.pyx":689
 *                         # Else had it the the heap to be processed later
 *                         else:
 *                             heapq.heappush(             # <<<<<<<<<<<<<<
 *                                 self._get_peer_loop_list,
 *                                 (ts, hash, tried_nodes, _closest, typ, callback, limit)
 */
          /*else*/ {
            __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_heapq); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 689, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_7);
            __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_heappush); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 689, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

            /* "btdht/dht.pyx":690
 *                         else:
 *                             heapq.heappush(
 *                                 self._get_peer_loop_list,             # <<<<<<<<<<<<<<
 *                                 (ts, hash, tried_nodes, _closest, typ, callback, limit)
 *                             )
 */
            __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_peer_loop_list); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 690, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_7);

            /* "btdht/dht.pyx":691
 *                             heapq.heappush(
 *                                 self._get_peer_loop_list,
 *                                 (ts, hash, tried_nodes, _closest, typ, callback, limit)             # <<<<<<<<<<<<<<
 *                             )
 *                         del node
 */
            __pyx_t_1 = PyTuple_New(7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 691, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_INCREF(__pyx_cur_scope->__pyx_v_ts);
            __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_ts);
            PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_cur_scope->__pyx_v_ts);
            __Pyx_INCREF(__pyx_cur_scope->__pyx_v_hash);
            __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_hash);
            PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_cur_scope->__pyx_v_hash);
            __Pyx_INCREF(__pyx_cur_scope->__pyx_v_tried_nodes);
            __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_tried_nodes);
            PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_cur_scope->__pyx_v_tried_nodes);
            __Pyx_INCREF(__pyx_cur_scope->__pyx_v__closest);
            __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v__closest);
            PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_cur_scope->__pyx_v__closest);
            __Pyx_INCREF(__pyx_cur_scope->__pyx_v_typ);
            __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_typ);
            PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_cur_scope->__pyx_v_typ);
            __Pyx_INCREF(__pyx_cur_scope->__pyx_v_callback);
            __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_callback);
            PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_cur_scope->__pyx_v_callback);
            __Pyx_INCREF(__pyx_cur_scope->__pyx_v_limit);
            __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_limit);
            PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_cur_scope->__pyx_v_limit);
            __pyx_t_9 = NULL;
            __pyx_t_15 = 0;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
              __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
              if (likely(__pyx_t_9)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
                __Pyx_INCREF(__pyx_t_9);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_6, function);
                __pyx_t_15 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_6)) {
              PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_1};
              __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 689, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
              PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_1};
              __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 689, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            } else
            #endif
            {
              __pyx_t_5 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 689, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_5);
              if (__pyx_t_9) {
                __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_9); __pyx_t_9 = NULL;
              }
              __Pyx_GIVEREF(__pyx_t_7);
              PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_15, __pyx_t_7);
              __Pyx_GIVEREF(__pyx_t_1);
              PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_15, __pyx_t_1);
              __pyx_t_7 = 0;
              __pyx_t_1 = 0;
              __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 689, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            }
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          }
          __pyx_L22:;

          /* "btdht/dht.pyx":693
 *                                 (ts, hash, tried_nodes, _closest, typ, callback, limit)
 *                             )
 *                         del node             # <<<<<<<<<<<<<<
 *                         del ts
 *                     else:
 */
          if (unlikely(!__pyx_cur_scope->__pyx_v_node)) { __Pyx_RaiseUnboundLocalError("node"); __PYX_ERR(0, 693, __pyx_L1_error) }
          __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_node);
          __Pyx_DECREF(__pyx_cur_scope->__pyx_v_node);
          __pyx_cur_scope->__pyx_v_node = NULL;

          /* "btdht/dht.pyx":694
 *                             )
 *                         del node
 *                         del ts             # <<<<<<<<<<<<<<
 *                     else:
 *                         # we search peers, and we found some
 */
          __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_ts);
          __Pyx_DECREF(__pyx_cur_scope->__pyx_v_ts);
          __pyx_cur_scope->__pyx_v_ts = NULL;

          /* "btdht/dht.pyx":661
 *                     __closest = [node for node in _closest if node not in tried_nodes]
 * 
 *                     if __closest:             # <<<<<<<<<<<<<<
 *                         # alpha = 3 from the kademlia paper
 *                         nodes = __closest[0:3]
 */
          goto __pyx_L19;
        }

        /* "btdht/dht.pyx":697
 *                     else:
 *                         # we search peers, and we found some
 *                         if (typ == "peers" and hash in self._got_peers and self._got_peers[hash]):             # <<<<<<<<<<<<<<
 *                             self.debug(2, "Hash %s find peers" % binascii.b2a_hex(hash))
 *                             if callback:
 */
        /*else*/ {
          __pyx_t_16 = (__Pyx_PyString_Equals(__pyx_cur_scope->__pyx_v_typ, __pyx_n_s_peers_2, Py_EQ)); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 697, __pyx_L1_error)
          if (__pyx_t_16) {
          } else {
            __pyx_t_2 = __pyx_t_16;
            goto __pyx_L33_bool_binop_done;
          }
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 697, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_16 = (__Pyx_PySequence_ContainsTF(__pyx_cur_scope->__pyx_v_hash, __pyx_t_8, Py_EQ)); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 697, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_12 = (__pyx_t_16 != 0);
          if (__pyx_t_12) {
          } else {
            __pyx_t_2 = __pyx_t_12;
            goto __pyx_L33_bool_binop_done;
          }
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 697, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_8, __pyx_cur_scope->__pyx_v_hash); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 697, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 697, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_2 = __pyx_t_12;
          __pyx_L33_bool_binop_done:;
          if (__pyx_t_2) {

            /* "btdht/dht.pyx":698
 *                         # we search peers, and we found some
 *                         if (typ == "peers" and hash in self._got_peers and self._got_peers[hash]):
 *                             self.debug(2, "Hash %s find peers" % binascii.b2a_hex(hash))             # <<<<<<<<<<<<<<
 *                             if callback:
 *                                 callback(self._get_peers(hash, compact=False))
 */
            __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 698, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_binascii); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 698, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_b2a_hex); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 698, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __pyx_t_1 = NULL;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
              __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
              if (likely(__pyx_t_1)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
                __Pyx_INCREF(__pyx_t_1);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_7, function);
              }
            }
            __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_cur_scope->__pyx_v_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_cur_scope->__pyx_v_hash);
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 698, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __pyx_t_7 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Hash_s_find_peers, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 698, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __pyx_t_5 = NULL;
            __pyx_t_15 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
              __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
              if (likely(__pyx_t_5)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
                __Pyx_INCREF(__pyx_t_5);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_8, function);
                __pyx_t_15 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_8)) {
              PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_2, __pyx_t_7};
              __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 698, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
              PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_2, __pyx_t_7};
              __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 698, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            } else
            #endif
            {
              __pyx_t_1 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 698, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              if (__pyx_t_5) {
                __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); __pyx_t_5 = NULL;
              }
              __Pyx_INCREF(__pyx_int_2);
              __Pyx_GIVEREF(__pyx_int_2);
              PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_15, __pyx_int_2);
              __Pyx_GIVEREF(__pyx_t_7);
              PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_15, __pyx_t_7);
              __pyx_t_7 = 0;
              __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 698, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            }
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

            /* "btdht/dht.pyx":699
 *                         if (typ == "peers" and hash in self._got_peers and self._got_peers[hash]):
 *                             self.debug(2, "Hash %s find peers" % binascii.b2a_hex(hash))
 *                             if callback:             # <<<<<<<<<<<<<<
 *                                 callback(self._get_peers(hash, compact=False))
 *                             on_stop(hash, typ)
 */
            __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_callback); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 699, __pyx_L1_error)
            if (__pyx_t_2) {

              /* "btdht/dht.pyx":700
 *                             self.debug(2, "Hash %s find peers" % binascii.b2a_hex(hash))
 *                             if callback:
 *                                 callback(self._get_peers(hash, compact=False))             # <<<<<<<<<<<<<<
 *                             on_stop(hash, typ)
 *                         # we did not found peers nor closest node althougth we ask every close nodes
 */
              __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_peers_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 700, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_8);
              __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 700, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_INCREF(__pyx_cur_scope->__pyx_v_hash);
              __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_hash);
              PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_cur_scope->__pyx_v_hash);
              __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 700, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_7);
              if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_compact, Py_False) < 0) __PYX_ERR(0, 700, __pyx_L1_error)
              __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 700, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_INCREF(__pyx_cur_scope->__pyx_v_callback);
              __pyx_t_7 = __pyx_cur_scope->__pyx_v_callback; __pyx_t_1 = NULL;
              if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
                __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
                if (likely(__pyx_t_1)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
                  __Pyx_INCREF(__pyx_t_1);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_7, function);
                }
              }
              __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_5);
              __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 700, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

              /* "btdht/dht.pyx":699
 *                         if (typ == "peers" and hash in self._got_peers and self._got_peers[hash]):
 *                             self.debug(2, "Hash %s find peers" % binascii.b2a_hex(hash))
 *                             if callback:             # <<<<<<<<<<<<<<
 *                                 callback(self._get_peers(hash, compact=False))
 *                             on_stop(hash, typ)
 */
            }

            /* "btdht/dht.pyx":701
 *                             if callback:
 *                                 callback(self._get_peers(hash, compact=False))
 *                             on_stop(hash, typ)             # <<<<<<<<<<<<<<
 *                         # we did not found peers nor closest node althougth we ask every close nodes
 *                         # we know of
 */
            __pyx_t_6 = __pyx_pf_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_on_stop(__pyx_cur_scope->__pyx_v_on_stop, __pyx_cur_scope->__pyx_v_hash, __pyx_cur_scope->__pyx_v_typ); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 701, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

            /* "btdht/dht.pyx":697
 *                     else:
 *                         # we search peers, and we found some
 *                         if (typ == "peers" and hash in self._got_peers and self._got_peers[hash]):             # <<<<<<<<<<<<<<
 *                             self.debug(2, "Hash %s find peers" % binascii.b2a_hex(hash))
 *                             if callback:
 */
            goto __pyx_L32;
          }

          /* "btdht/dht.pyx":705
 *                         # we know of
 *                         else:
 *                             self.debug(             # <<<<<<<<<<<<<<
 *                                 2,
 *                                 "Hash %s no peers or nodes found" % binascii.b2a_hex(hash)
 */
          /*else*/ {
            __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 705, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_7);

            /* "btdht/dht.pyx":707
 *                             self.debug(
 *                                 2,
 *                                 "Hash %s no peers or nodes found" % binascii.b2a_hex(hash)             # <<<<<<<<<<<<<<
 *                             )
 *                             if callback:
 */
            __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_binascii); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 707, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_b2a_hex); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 707, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __pyx_t_1 = NULL;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
              __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8);
              if (likely(__pyx_t_1)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
                __Pyx_INCREF(__pyx_t_1);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_8, function);
              }
            }
            __pyx_t_5 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_1, __pyx_cur_scope->__pyx_v_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_cur_scope->__pyx_v_hash);
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 707, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            __pyx_t_8 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Hash_s_no_peers_or_nodes_found, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 707, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __pyx_t_5 = NULL;
            __pyx_t_15 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
              __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7);
              if (likely(__pyx_t_5)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
                __Pyx_INCREF(__pyx_t_5);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_7, function);
                __pyx_t_15 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_7)) {
              PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_2, __pyx_t_8};
              __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 705, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
              PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_2, __pyx_t_8};
              __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 705, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            } else
            #endif
            {
              __pyx_t_1 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 705, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              if (__pyx_t_5) {
                __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); __pyx_t_5 = NULL;
              }
              __Pyx_INCREF(__pyx_int_2);
              __Pyx_GIVEREF(__pyx_int_2);
              PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_15, __pyx_int_2);
              __Pyx_GIVEREF(__pyx_t_8);
              PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_15, __pyx_t_8);
              __pyx_t_8 = 0;
              __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 705, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            }
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

            /* "btdht/dht.pyx":709
 *                                 "Hash %s no peers or nodes found" % binascii.b2a_hex(hash)
 *                             )
 *                             if callback:             # <<<<<<<<<<<<<<
 *                                 callback([])
 *                             on_stop(hash, typ)
 */
            __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_callback); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 709, __pyx_L1_error)
            if (__pyx_t_2) {

              /* "btdht/dht.pyx":710
 *                             )
 *                             if callback:
 *                                 callback([])             # <<<<<<<<<<<<<<
 *                             on_stop(hash, typ)
 *                     del _closest
 */
              __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 710, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_7);
              __Pyx_INCREF(__pyx_cur_scope->__pyx_v_callback);
              __pyx_t_1 = __pyx_cur_scope->__pyx_v_callback; __pyx_t_8 = NULL;
              if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
                __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
                if (likely(__pyx_t_8)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
                  __Pyx_INCREF(__pyx_t_8);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_1, function);
                }
              }
              __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_7);
              __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
              if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 710, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

              /* "btdht/dht.pyx":709
 *                                 "Hash %s no peers or nodes found" % binascii.b2a_hex(hash)
 *                             )
 *                             if callback:             # <<<<<<<<<<<<<<
 *                                 callback([])
 *                             on_stop(hash, typ)
 */
            }

            /* "btdht/dht.pyx":711
 *                             if callback:
 *                                 callback([])
 *                             on_stop(hash, typ)             # <<<<<<<<<<<<<<
 *                     del _closest
 *                     del __closest
 */
            __pyx_t_6 = __pyx_pf_5btdht_3dht_8DHT_BASE_23_get_peers_closest_loop_on_stop(__pyx_cur_scope->__pyx_v_on_stop, __pyx_cur_scope->__pyx_v_hash, __pyx_cur_scope->__pyx_v_typ); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 711, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          }
          __pyx_L32:;
        }
        __pyx_L19:;

        /* "btdht/dht.pyx":712
 *                                 callback([])
 *                             on_stop(hash, typ)
 *                     del _closest             # <<<<<<<<<<<<<<
 *                     del __closest
 *                 else:
 */
        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v__closest);
        __Pyx_DECREF(__pyx_cur_scope->__pyx_v__closest);
        __pyx_cur_scope->__pyx_v__closest = NULL;

        /* "btdht/dht.pyx":713
 *                             on_stop(hash, typ)
 *                     del _closest
 *                     del __closest             # <<<<<<<<<<<<<<
 *                 else:
 *                     # if fetch time in the future, sleep until that date
 */
        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v___closest);
        __Pyx_DECREF(__pyx_cur_scope->__pyx_v___closest);
        __pyx_cur_scope->__pyx_v___closest = NULL;

        /* "btdht/dht.pyx":656
 *                     raise ValueError("typ should not be %s" % typ)
 *                 # if process time is in the past process it
 *                 if ts <= time.time():             # <<<<<<<<<<<<<<
 *                     # get hash k closest node that have not been tried
 *                     _closest = self.get_closest_nodes(hash)
 */
        goto __pyx_L15;
      }

      /* "btdht/dht.pyx":716
 *                 else:
 *                     # if fetch time in the future, sleep until that date
 *                     tosleep = max(1, ts - time.time())             # <<<<<<<<<<<<<<
 *                     heapq.heappush(
 *                         self._get_peer_loop_list,
 */
      /*else*/ {
        __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 716, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 716, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_1)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
          }
        }
        __pyx_t_6 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 716, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = PyNumber_Subtract(__pyx_cur_scope->__pyx_v_ts, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 716, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_17 = 1;
        __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_t_17); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 716, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_8 = PyObject_RichCompare(__pyx_t_7, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 716, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 716, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (__pyx_t_2) {
          __Pyx_INCREF(__pyx_t_7);
          __pyx_t_6 = __pyx_t_7;
        } else {
          __pyx_t_8 = __Pyx_PyInt_From_long(__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 716, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_6 = __pyx_t_8;
          __pyx_t_8 = 0;
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = __pyx_t_6;
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_tosleep);
        __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_tosleep, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_7);
        __pyx_t_7 = 0;

        /* "btdht/dht.pyx":717
 *                     # if fetch time in the future, sleep until that date
 *                     tosleep = max(1, ts - time.time())
 *                     heapq.heappush(             # <<<<<<<<<<<<<<
 *                         self._get_peer_loop_list,
 *                         (ts, hash, tried_nodes, closest, typ, callback, limit)
 */
        __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_heapq); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 717, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_heappush); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 717, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "btdht/dht.pyx":718
 *                     tosleep = max(1, ts - time.time())
 *                     heapq.heappush(
 *                         self._get_peer_loop_list,             # <<<<<<<<<<<<<<
 *                         (ts, hash, tried_nodes, closest, typ, callback, limit)
 *                     )
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_get_peer_loop_list); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 718, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);

        /* "btdht/dht.pyx":719
 *                     heapq.heappush(
 *                         self._get_peer_loop_list,
 *                         (ts, hash, tried_nodes, closest, typ, callback, limit)             # <<<<<<<<<<<<<<
 *                     )
 *                     break
 */
        __pyx_t_1 = PyTuple_New(7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 719, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_cur_scope->__pyx_v_ts);
        __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_ts);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_cur_scope->__pyx_v_ts);
        __Pyx_INCREF(__pyx_cur_scope->__pyx_v_hash);
        __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_hash);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_cur_scope->__pyx_v_hash);
        __Pyx_INCREF(__pyx_cur_scope->__pyx_v_tried_nodes);
        __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_tried_nodes);
        PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_cur_scope->__pyx_v_tried_nodes);
        __Pyx_INCREF(__pyx_cur_scope->__pyx_v_closest);
        __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_closest);
        PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_cur_scope->__pyx_v_closest);
        __Pyx_INCREF(__pyx_cur_scope->__pyx_v_typ);
        __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_typ);
        PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_cur_scope->__pyx_v_typ);
        __Pyx_INCREF(__pyx_cur_scope->__pyx_v_callback);
        __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_callback);
        PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_cur_scope->__pyx_v_callback);
        __Pyx_INCREF(__pyx_cur_scope->__pyx_v_limit);
        __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_limit);
        PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_cur_scope->__pyx_v_limit);
        __pyx_t_5 = NULL;
        __pyx_t_15 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
            __pyx_t_15 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_8)) {
          PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_6, __pyx_t_1};
          __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 717, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
          PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_6, __pyx_t_1};
          __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 717, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        } else
        #endif
        {
          __pyx_t_9 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 717, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          if (__pyx_t_5) {
            __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_5); __pyx_t_5 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_15, __pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_15, __pyx_t_1);
          __pyx_t_6 = 0;
          __pyx_t_1 = 0;
          __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_9, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 717, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "btdht/dht.pyx":721
 *                         (ts, hash, tried_nodes, closest, typ, callback, limit)
 *                     )
 *                     break             # <<<<<<<<<<<<<<
 *                 del tried_nodes
 *                 del closest
 */
        goto __pyx_L8_break;
      }
      __pyx_L15:;

      /* "btdht/dht.pyx":722
 *                     )
 *                     break
 *                 del tried_nodes             # <<<<<<<<<<<<<<
 *                 del closest
 *             yield (time.time() + tosleep)
 */
      __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_tried_nodes);
      __Pyx_DECREF(__pyx_cur_scope->__pyx_v_tried_nodes);
      __pyx_cur_scope->__pyx_v_tried_nodes = NULL;

      /* "btdht/dht.pyx":723
 *                     break
 *                 del tried_nodes
 *                 del closest             # <<<<<<<<<<<<<<
 *             yield (time.time() + tosleep)
 * 
 */
      __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_closest);
      __Pyx_DECREF(__pyx_cur_scope->__pyx_v_closest);
      __pyx_cur_scope->__pyx_v_closest = NULL;
    }
    __pyx_L8_break:;

    /* "btdht/dht.pyx":724
 *                 del tried_nodes
 *                 del closest
 *             yield (time.time() + tosleep)             # <<<<<<<<<<<<<<
 * 
 *     def _get_peers(self, info_hash, compact=True, errno=0):
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 724, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 724, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_9);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 724, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyNumber_Add(__pyx_t_7, __pyx_cur_scope->__pyx_v_tosleep); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 724, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_r = __pyx_t_9;
    __pyx_t_9 = 0;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 2;
    return __pyx_r;
    __pyx_L38_resume_from_yield:;
    if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 724, __pyx_L1_error)
  }
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* "btdht/dht.pyx":623
 *             return peers
 * 
 *     def _get_peers_closest_loop(self):             # <<<<<<<<<<<<<<
 *         """
 *             Weigthless thread dealing we the :attr:`_get_peer_loop_list` heapq. Its execution
 */

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("_get_peers_closest_loop", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":726
 *             yield (time.time() + tosleep)
 * 
 *     def _get_peers(self, info_hash, compact=True, errno=0):             # <<<<<<<<<<<<<<
 *         """
 *             Return peers store locally by remote announce_peer queries
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_34_get_peers(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_33_get_peers[] = "\n            Return peers store locally by remote announce_peer queries\n\n            :param bytes info_hash: A 160 bits (20 Bytes) long identifier for which we want to get\n                peers\n            :param bool compact: If ``True`` the peers addresses are returned in compact format\n                Otherwise, the peers addresses are tuple (ip, port) with ip in dotted notation\n                (``\"1.2.3.4\"``) and port an integer. The default is ``True``.\n            :return: A list of peers addresses\n            :rtype: list\n            :raises KeyError: if no peers for ``info_hash`` are store locally\n\n            Note:\n                If not peer are found for ``info_hash``, the function will retry for 2s before\n                raising a KeyError exception.\n\n                Contact information in for peers is encoded as a 6-byte string.\n                Also known as \"Compact IP-address/port info\" the 4-byte IP address\n                is in network byte order with the 2 byte port in network byte order\n                concatenated onto the end.\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_34_get_peers(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_info_hash = 0;
  PyObject *__pyx_v_compact = 0;
  PyObject *__pyx_v_errno = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_get_peers (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_info_hash,&__pyx_n_s_compact,&__pyx_n_s_errno,0};
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)Py_True);
    values[2] = ((PyObject *)__pyx_int_0);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_info_hash)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_compact);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_errno);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_get_peers") < 0)) __PYX_ERR(0, 726, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_info_hash = values[0];
    __pyx_v_compact = values[1];
    __pyx_v_errno = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_get_peers", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 726, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._get_peers", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_33_get_peers(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_info_hash, __pyx_v_compact, __pyx_v_errno);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_33_get_peers(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_info_hash, PyObject *__pyx_v_compact, PyObject *__pyx_v_errno) {
  PyObject *__pyx_v_peers = NULL;
  PyObject *__pyx_v_ip = NULL;
  PyObject *__pyx_v_port = NULL;
  PyObject *__pyx_v_t = NULL;
  CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  Py_ssize_t __pyx_t_12;
  PyObject *(*__pyx_t_13)(PyObject *);
  PyObject *__pyx_t_14 = NULL;
  PyObject *(*__pyx_t_15)(PyObject *);
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_t_18;
  int __pyx_t_19;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_get_peers", 0);

  /* "btdht/dht.pyx":748
 *                 concatenated onto the end.
 *         """
 *         if not info_hash in self._peers and compact:             # <<<<<<<<<<<<<<
 *             return None
 *         elif not info_hash in self._got_peers and not compact:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_peers); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 748, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_v_info_hash, __pyx_t_2, Py_NE)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 748, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_1 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_compact); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 748, __pyx_L1_error)
  __pyx_t_1 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "btdht/dht.pyx":749
 *         """
 *         if not info_hash in self._peers and compact:
 *             return None             # <<<<<<<<<<<<<<
 *         elif not info_hash in self._got_peers and not compact:
 *             return None
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "btdht/dht.pyx":748
 *                 concatenated onto the end.
 *         """
 *         if not info_hash in self._peers and compact:             # <<<<<<<<<<<<<<
 *             return None
 *         elif not info_hash in self._got_peers and not compact:
 */
  }

  /* "btdht/dht.pyx":750
 *         if not info_hash in self._peers and compact:
 *             return None
 *         elif not info_hash in self._got_peers and not compact:             # <<<<<<<<<<<<<<
 *             return None
 *         else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 750, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_v_info_hash, __pyx_t_2, Py_NE)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 750, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = (__pyx_t_4 != 0);
  if (__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_compact); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 750, __pyx_L1_error)
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  __pyx_t_1 = __pyx_t_4;
  __pyx_L6_bool_binop_done:;
  if (__pyx_t_1) {

    /* "btdht/dht.pyx":751
 *             return None
 *         elif not info_hash in self._got_peers and not compact:
 *             return None             # <<<<<<<<<<<<<<
 *         else:
 *             try:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "btdht/dht.pyx":750
 *         if not info_hash in self._peers and compact:
 *             return None
 *         elif not info_hash in self._got_peers and not compact:             # <<<<<<<<<<<<<<
 *             return None
 *         else:
 */
  }

  /* "btdht/dht.pyx":753
 *             return None
 *         else:
 *             try:             # <<<<<<<<<<<<<<
 *                 # In compact mode (to send over udp) return max 70 peers to avoid udp fragmentation
 *                 if compact:
 */
  /*else*/ {
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_6);
      __Pyx_XGOTREF(__pyx_t_7);
      /*try:*/ {

        /* "btdht/dht.pyx":755
 *             try:
 *                 # In compact mode (to send over udp) return max 70 peers to avoid udp fragmentation
 *                 if compact:             # <<<<<<<<<<<<<<
 *                     peers = [
 *                         (-t,ip,port) for ((ip, port), t) in six.iteritems(self._peers[info_hash])
 */
        __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_compact); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 755, __pyx_L8_error)
        if (__pyx_t_1) {

          /* "btdht/dht.pyx":756
 *                 # In compact mode (to send over udp) return max 70 peers to avoid udp fragmentation
 *                 if compact:
 *                     peers = [             # <<<<<<<<<<<<<<
 *                         (-t,ip,port) for ((ip, port), t) in six.iteritems(self._peers[info_hash])
 *                     ]
 */
          __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 756, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_2);

          /* "btdht/dht.pyx":757
 *                 if compact:
 *                     peers = [
 *                         (-t,ip,port) for ((ip, port), t) in six.iteritems(self._peers[info_hash])             # <<<<<<<<<<<<<<
 *                     ]
 *                     # putting the more recent annonces in first
 */
          __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_six); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 757, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_iteritems); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 757, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_peers); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 757, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_t_9, __pyx_v_info_hash); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 757, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
            __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_10);
            if (likely(__pyx_t_9)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
              __Pyx_INCREF(__pyx_t_9);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_10, function);
            }
          }
          __pyx_t_8 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_9, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_11);
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 757, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) {
            __pyx_t_10 = __pyx_t_8; __Pyx_INCREF(__pyx_t_10); __pyx_t_12 = 0;
            __pyx_t_13 = NULL;
          } else {
            __pyx_t_12 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 757, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_10);
            __pyx_t_13 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 757, __pyx_L8_error)
          }
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          for (;;) {
            if (likely(!__pyx_t_13)) {
              if (likely(PyList_CheckExact(__pyx_t_10))) {
                if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_10)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_8 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_12); __Pyx_INCREF(__pyx_t_8); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 757, __pyx_L8_error)
                #else
                __pyx_t_8 = PySequence_ITEM(__pyx_t_10, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 757, __pyx_L8_error)
                __Pyx_GOTREF(__pyx_t_8);
                #endif
              } else {
                if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_10)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_12); __Pyx_INCREF(__pyx_t_8); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 757, __pyx_L8_error)
                #else
                __pyx_t_8 = PySequence_ITEM(__pyx_t_10, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 757, __pyx_L8_error)
                __Pyx_GOTREF(__pyx_t_8);
                #endif
              }
            } else {
              __pyx_t_8 = __pyx_t_13(__pyx_t_10);
              if (unlikely(!__pyx_t_8)) {
                PyObject* exc_type = PyErr_Occurred();
                if (exc_type) {
                  if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                  else __PYX_ERR(0, 757, __pyx_L8_error)
                }
                break;
              }
              __Pyx_GOTREF(__pyx_t_8);
            }
            if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
              PyObject* sequence = __pyx_t_8;
              Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
              if (unlikely(size != 2)) {
                if (size > 2) __Pyx_RaiseTooManyValuesError(2);
                else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
                __PYX_ERR(0, 757, __pyx_L8_error)
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              if (likely(PyTuple_CheckExact(sequence))) {
                __pyx_t_11 = PyTuple_GET_ITEM(sequence, 0); 
                __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
              } else {
                __pyx_t_11 = PyList_GET_ITEM(sequence, 0); 
                __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
              }
              __Pyx_INCREF(__pyx_t_11);
              __Pyx_INCREF(__pyx_t_9);
              #else
              __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 757, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_11);
              __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 757, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_9);
              #endif
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            } else {
              Py_ssize_t index = -1;
              __pyx_t_14 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 757, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_14);
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
              __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext;
              index = 0; __pyx_t_11 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_11)) goto __pyx_L17_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_11);
              index = 1; __pyx_t_9 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_9)) goto __pyx_L17_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_9);
              if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) __PYX_ERR(0, 757, __pyx_L8_error)
              __pyx_t_15 = NULL;
              __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
              goto __pyx_L18_unpacking_done;
              __pyx_L17_unpacking_failed:;
              __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
              __pyx_t_15 = NULL;
              if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
              __PYX_ERR(0, 757, __pyx_L8_error)
              __pyx_L18_unpacking_done:;
            }
            if ((likely(PyTuple_CheckExact(__pyx_t_11))) || (PyList_CheckExact(__pyx_t_11))) {
              PyObject* sequence = __pyx_t_11;
              Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
              if (unlikely(size != 2)) {
                if (size > 2) __Pyx_RaiseTooManyValuesError(2);
                else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
                __PYX_ERR(0, 757, __pyx_L8_error)
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              if (likely(PyTuple_CheckExact(sequence))) {
                __pyx_t_14 = PyTuple_GET_ITEM(sequence, 0); 
                __pyx_t_16 = PyTuple_GET_ITEM(sequence, 1); 
              } else {
                __pyx_t_14 = PyList_GET_ITEM(sequence, 0); 
                __pyx_t_16 = PyList_GET_ITEM(sequence, 1); 
              }
              __Pyx_INCREF(__pyx_t_14);
              __Pyx_INCREF(__pyx_t_16);
              #else
              __pyx_t_14 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 757, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_14);
              __pyx_t_16 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 757, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_16);
              #endif
              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            } else {
              Py_ssize_t index = -1;
              __pyx_t_17 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 757, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_17);
              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
              __pyx_t_15 = Py_TYPE(__pyx_t_17)->tp_iternext;
              index = 0; __pyx_t_14 = __pyx_t_15(__pyx_t_17); if (unlikely(!__pyx_t_14)) goto __pyx_L19_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_14);
              index = 1; __pyx_t_16 = __pyx_t_15(__pyx_t_17); if (unlikely(!__pyx_t_16)) goto __pyx_L19_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_16);
              if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_17), 2) < 0) __PYX_ERR(0, 757, __pyx_L8_error)
              __pyx_t_15 = NULL;
              __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
              goto __pyx_L20_unpacking_done;
              __pyx_L19_unpacking_failed:;
              __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
              __pyx_t_15 = NULL;
              if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
              __PYX_ERR(0, 757, __pyx_L8_error)
              __pyx_L20_unpacking_done:;
            }
            __Pyx_XDECREF_SET(__pyx_v_ip, __pyx_t_14);
            __pyx_t_14 = 0;
            __Pyx_XDECREF_SET(__pyx_v_port, __pyx_t_16);
            __pyx_t_16 = 0;
            __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_9);
            __pyx_t_9 = 0;
            __pyx_t_8 = PyNumber_Negative(__pyx_v_t); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 757, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_8);
            __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 757, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_GIVEREF(__pyx_t_8);
            PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
            __Pyx_INCREF(__pyx_v_ip);
            __Pyx_GIVEREF(__pyx_v_ip);
            PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_ip);
            __Pyx_INCREF(__pyx_v_port);
            __Pyx_GIVEREF(__pyx_v_port);
            PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_v_port);
            __pyx_t_8 = 0;
            if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_9))) __PYX_ERR(0, 756, __pyx_L8_error)
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          }
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_v_peers = ((PyObject*)__pyx_t_2);
          __pyx_t_2 = 0;

          /* "btdht/dht.pyx":760
 *                     ]
 *                     # putting the more recent annonces in first
 *                     peers.sort()             # <<<<<<<<<<<<<<
 *                     return [
 *                         struct.pack("!4sH", socket.inet_aton(ip), port)
 */
          __pyx_t_18 = PyList_Sort(__pyx_v_peers); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 760, __pyx_L8_error)

          /* "btdht/dht.pyx":761
 *                     # putting the more recent annonces in first
 *                     peers.sort()
 *                     return [             # <<<<<<<<<<<<<<
 *                         struct.pack("!4sH", socket.inet_aton(ip), port)
 *                         for (_, ip, port)
 */
          __Pyx_XDECREF(__pyx_r);
          __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 761, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_2);

          /* "btdht/dht.pyx":764
 *                         struct.pack("!4sH", socket.inet_aton(ip), port)
 *                         for (_, ip, port)
 *                         in peers[0:70]             # <<<<<<<<<<<<<<
 *                     ]
 *                 else:
 */
          __pyx_t_10 = __Pyx_PyList_GetSlice(__pyx_v_peers, 0, 70); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 764, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_9 = __pyx_t_10; __Pyx_INCREF(__pyx_t_9); __pyx_t_12 = 0;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          for (;;) {
            if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_9)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_10 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_12); __Pyx_INCREF(__pyx_t_10); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 764, __pyx_L8_error)
            #else
            __pyx_t_10 = PySequence_ITEM(__pyx_t_9, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 764, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_10);
            #endif
            if ((likely(PyTuple_CheckExact(__pyx_t_10))) || (PyList_CheckExact(__pyx_t_10))) {
              PyObject* sequence = __pyx_t_10;
              Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
              if (unlikely(size != 3)) {
                if (size > 3) __Pyx_RaiseTooManyValuesError(3);
                else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
                __PYX_ERR(0, 763, __pyx_L8_error)
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              if (likely(PyTuple_CheckExact(sequence))) {
                __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
                __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); 
                __pyx_t_16 = PyTuple_GET_ITEM(sequence, 2); 
              } else {
                __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
                __pyx_t_11 = PyList_GET_ITEM(sequence, 1); 
                __pyx_t_16 = PyList_GET_ITEM(sequence, 2); 
              }
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(__pyx_t_11);
              __Pyx_INCREF(__pyx_t_16);
              #else
              __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 763, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_8);
              __pyx_t_11 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 763, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_11);
              __pyx_t_16 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 763, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_16);
              #endif
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            } else {
              Py_ssize_t index = -1;
              __pyx_t_14 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 763, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_14);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext;
              index = 0; __pyx_t_8 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_8)) goto __pyx_L23_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_8);
              index = 1; __pyx_t_11 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_11)) goto __pyx_L23_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_11);
              index = 2; __pyx_t_16 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_16)) goto __pyx_L23_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_16);
              if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 3) < 0) __PYX_ERR(0, 763, __pyx_L8_error)
              __pyx_t_15 = NULL;
              __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
              goto __pyx_L24_unpacking_done;
              __pyx_L23_unpacking_failed:;
              __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
              __pyx_t_15 = NULL;
              if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
              __PYX_ERR(0, 763, __pyx_L8_error)
              __pyx_L24_unpacking_done:;
            }

            /* "btdht/dht.pyx":763
 *                     return [
 *                         struct.pack("!4sH", socket.inet_aton(ip), port)
 *                         for (_, ip, port)             # <<<<<<<<<<<<<<
 *                         in peers[0:70]
 *                     ]
 */
            __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_8);
            __pyx_t_8 = 0;
            __Pyx_XDECREF_SET(__pyx_v_ip, __pyx_t_11);
            __pyx_t_11 = 0;
            __Pyx_XDECREF_SET(__pyx_v_port, __pyx_t_16);
            __pyx_t_16 = 0;

            /* "btdht/dht.pyx":762
 *                     peers.sort()
 *                     return [
 *                         struct.pack("!4sH", socket.inet_aton(ip), port)             # <<<<<<<<<<<<<<
 *                         for (_, ip, port)
 *                         in peers[0:70]
 */
            __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_struct); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 762, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_16);
            __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_pack); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 762, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
            __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_socket); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 762, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_8);
            __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_inet_aton); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 762, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_14);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            __pyx_t_8 = NULL;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) {
              __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_14);
              if (likely(__pyx_t_8)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
                __Pyx_INCREF(__pyx_t_8);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_14, function);
              }
            }
            __pyx_t_16 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_8, __pyx_v_ip) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_ip);
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 762, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_16);
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
            __pyx_t_14 = NULL;
            __pyx_t_19 = 0;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
              __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_11);
              if (likely(__pyx_t_14)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
                __Pyx_INCREF(__pyx_t_14);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_11, function);
                __pyx_t_19 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_11)) {
              PyObject *__pyx_temp[4] = {__pyx_t_14, __pyx_kp_s_4sH, __pyx_t_16, __pyx_v_port};
              __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 762, __pyx_L8_error)
              __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
              PyObject *__pyx_temp[4] = {__pyx_t_14, __pyx_kp_s_4sH, __pyx_t_16, __pyx_v_port};
              __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_19, 3+__pyx_t_19); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 762, __pyx_L8_error)
              __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
            } else
            #endif
            {
              __pyx_t_8 = PyTuple_New(3+__pyx_t_19); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 762, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_8);
              if (__pyx_t_14) {
                __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_14); __pyx_t_14 = NULL;
              }
              __Pyx_INCREF(__pyx_kp_s_4sH);
              __Pyx_GIVEREF(__pyx_kp_s_4sH);
              PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_19, __pyx_kp_s_4sH);
              __Pyx_GIVEREF(__pyx_t_16);
              PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_19, __pyx_t_16);
              __Pyx_INCREF(__pyx_v_port);
              __Pyx_GIVEREF(__pyx_v_port);
              PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_19, __pyx_v_port);
              __pyx_t_16 = 0;
              __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_8, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 762, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            }
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_10))) __PYX_ERR(0, 761, __pyx_L8_error)
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

            /* "btdht/dht.pyx":763
 *                     return [
 *                         struct.pack("!4sH", socket.inet_aton(ip), port)
 *                         for (_, ip, port)             # <<<<<<<<<<<<<<
 *                         in peers[0:70]
 *                     ]
 */
          }
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_r = __pyx_t_2;
          __pyx_t_2 = 0;
          goto __pyx_L12_try_return;

          /* "btdht/dht.pyx":755
 *             try:
 *                 # In compact mode (to send over udp) return max 70 peers to avoid udp fragmentation
 *                 if compact:             # <<<<<<<<<<<<<<
 *                     peers = [
 *                         (-t,ip,port) for ((ip, port), t) in six.iteritems(self._peers[info_hash])
 */
        }

        /* "btdht/dht.pyx":767
 *                     ]
 *                 else:
 *                     peers = [             # <<<<<<<<<<<<<<
 *                         (-t,ip,port)
 *                         for ((ip, port), t)
 */
        /*else*/ {
          __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 767, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_2);

          /* "btdht/dht.pyx":770
 *                         (-t,ip,port)
 *                         for ((ip, port), t)
 *                         in six.iteritems(self._got_peers[info_hash])             # <<<<<<<<<<<<<<
 *                     ]
 *                     # putting the more recent annonces in first
 */
          __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_six); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 770, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_iteritems); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 770, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 770, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_10, __pyx_v_info_hash); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 770, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_10 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
            __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_11);
            if (likely(__pyx_t_10)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
              __Pyx_INCREF(__pyx_t_10);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_11, function);
            }
          }
          __pyx_t_9 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_10, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_8);
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 770, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          if (likely(PyList_CheckExact(__pyx_t_9)) || PyTuple_CheckExact(__pyx_t_9)) {
            __pyx_t_11 = __pyx_t_9; __Pyx_INCREF(__pyx_t_11); __pyx_t_12 = 0;
            __pyx_t_13 = NULL;
          } else {
            __pyx_t_12 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 770, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_11);
            __pyx_t_13 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 770, __pyx_L8_error)
          }
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          for (;;) {
            if (likely(!__pyx_t_13)) {
              if (likely(PyList_CheckExact(__pyx_t_11))) {
                if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_11)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_9 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_9); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 770, __pyx_L8_error)
                #else
                __pyx_t_9 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 770, __pyx_L8_error)
                __Pyx_GOTREF(__pyx_t_9);
                #endif
              } else {
                if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_11)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_9); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 770, __pyx_L8_error)
                #else
                __pyx_t_9 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 770, __pyx_L8_error)
                __Pyx_GOTREF(__pyx_t_9);
                #endif
              }
            } else {
              __pyx_t_9 = __pyx_t_13(__pyx_t_11);
              if (unlikely(!__pyx_t_9)) {
                PyObject* exc_type = PyErr_Occurred();
                if (exc_type) {
                  if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                  else __PYX_ERR(0, 770, __pyx_L8_error)
                }
                break;
              }
              __Pyx_GOTREF(__pyx_t_9);
            }
            if ((likely(PyTuple_CheckExact(__pyx_t_9))) || (PyList_CheckExact(__pyx_t_9))) {
              PyObject* sequence = __pyx_t_9;
              Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
              if (unlikely(size != 2)) {
                if (size > 2) __Pyx_RaiseTooManyValuesError(2);
                else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
                __PYX_ERR(0, 769, __pyx_L8_error)
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              if (likely(PyTuple_CheckExact(sequence))) {
                __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
                __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
              } else {
                __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
                __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
              }
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(__pyx_t_10);
              #else
              __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 769, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_8);
              __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 769, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_10);
              #endif
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            } else {
              Py_ssize_t index = -1;
              __pyx_t_16 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 769, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_16);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
              __pyx_t_15 = Py_TYPE(__pyx_t_16)->tp_iternext;
              index = 0; __pyx_t_8 = __pyx_t_15(__pyx_t_16); if (unlikely(!__pyx_t_8)) goto __pyx_L27_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_8);
              index = 1; __pyx_t_10 = __pyx_t_15(__pyx_t_16); if (unlikely(!__pyx_t_10)) goto __pyx_L27_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_10);
              if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_16), 2) < 0) __PYX_ERR(0, 769, __pyx_L8_error)
              __pyx_t_15 = NULL;
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
              goto __pyx_L28_unpacking_done;
              __pyx_L27_unpacking_failed:;
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
              __pyx_t_15 = NULL;
              if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
              __PYX_ERR(0, 769, __pyx_L8_error)
              __pyx_L28_unpacking_done:;
            }

            /* "btdht/dht.pyx":769
 *                     peers = [
 *                         (-t,ip,port)
 *                         for ((ip, port), t)             # <<<<<<<<<<<<<<
 *                         in six.iteritems(self._got_peers[info_hash])
 *                     ]
 */
            if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
              PyObject* sequence = __pyx_t_8;
              Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
              if (unlikely(size != 2)) {
                if (size > 2) __Pyx_RaiseTooManyValuesError(2);
                else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
                __PYX_ERR(0, 769, __pyx_L8_error)
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              if (likely(PyTuple_CheckExact(sequence))) {
                __pyx_t_16 = PyTuple_GET_ITEM(sequence, 0); 
                __pyx_t_14 = PyTuple_GET_ITEM(sequence, 1); 
              } else {
                __pyx_t_16 = PyList_GET_ITEM(sequence, 0); 
                __pyx_t_14 = PyList_GET_ITEM(sequence, 1); 
              }
              __Pyx_INCREF(__pyx_t_16);
              __Pyx_INCREF(__pyx_t_14);
              #else
              __pyx_t_16 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 769, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_16);
              __pyx_t_14 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 769, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_14);
              #endif
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            } else {
              Py_ssize_t index = -1;
              __pyx_t_17 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 769, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_17);
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
              __pyx_t_15 = Py_TYPE(__pyx_t_17)->tp_iternext;
              index = 0; __pyx_t_16 = __pyx_t_15(__pyx_t_17); if (unlikely(!__pyx_t_16)) goto __pyx_L29_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_16);
              index = 1; __pyx_t_14 = __pyx_t_15(__pyx_t_17); if (unlikely(!__pyx_t_14)) goto __pyx_L29_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_14);
              if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_17), 2) < 0) __PYX_ERR(0, 769, __pyx_L8_error)
              __pyx_t_15 = NULL;
              __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
              goto __pyx_L30_unpacking_done;
              __pyx_L29_unpacking_failed:;
              __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
              __pyx_t_15 = NULL;
              if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
              __PYX_ERR(0, 769, __pyx_L8_error)
              __pyx_L30_unpacking_done:;
            }
            __Pyx_XDECREF_SET(__pyx_v_ip, __pyx_t_16);
            __pyx_t_16 = 0;
            __Pyx_XDECREF_SET(__pyx_v_port, __pyx_t_14);
            __pyx_t_14 = 0;
            __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_10);
            __pyx_t_10 = 0;

            /* "btdht/dht.pyx":768
 *                 else:
 *                     peers = [
 *                         (-t,ip,port)             # <<<<<<<<<<<<<<
 *                         for ((ip, port), t)
 *                         in six.iteritems(self._got_peers[info_hash])
 */
            __pyx_t_9 = PyNumber_Negative(__pyx_v_t); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 768, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 768, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_GIVEREF(__pyx_t_9);
            PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9);
            __Pyx_INCREF(__pyx_v_ip);
            __Pyx_GIVEREF(__pyx_v_ip);
            PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_ip);
            __Pyx_INCREF(__pyx_v_port);
            __Pyx_GIVEREF(__pyx_v_port);
            PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_v_port);
            __pyx_t_9 = 0;
            if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_10))) __PYX_ERR(0, 767, __pyx_L8_error)
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

            /* "btdht/dht.pyx":769
 *                     peers = [
 *                         (-t,ip,port)
 *                         for ((ip, port), t)             # <<<<<<<<<<<<<<
 *                         in six.iteritems(self._got_peers[info_hash])
 *                     ]
 */
          }
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __pyx_v_peers = ((PyObject*)__pyx_t_2);
          __pyx_t_2 = 0;

          /* "btdht/dht.pyx":773
 *                     ]
 *                     # putting the more recent annonces in first
 *                     peers.sort()             # <<<<<<<<<<<<<<
 *                     return [(ip, port) for (_, ip, port) in peers]
 *             except KeyError:
 */
          __pyx_t_18 = PyList_Sort(__pyx_v_peers); if (unlikely(__pyx_t_18 == ((int)-1))) __PYX_ERR(0, 773, __pyx_L8_error)

          /* "btdht/dht.pyx":774
 *                     # putting the more recent annonces in first
 *                     peers.sort()
 *                     return [(ip, port) for (_, ip, port) in peers]             # <<<<<<<<<<<<<<
 *             except KeyError:
 *                 if errno > 20:
 */
          __Pyx_XDECREF(__pyx_r);
          __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 774, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_11 = __pyx_v_peers; __Pyx_INCREF(__pyx_t_11); __pyx_t_12 = 0;
          for (;;) {
            if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_11)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_10 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_12); __Pyx_INCREF(__pyx_t_10); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 774, __pyx_L8_error)
            #else
            __pyx_t_10 = PySequence_ITEM(__pyx_t_11, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 774, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_10);
            #endif
            if ((likely(PyTuple_CheckExact(__pyx_t_10))) || (PyList_CheckExact(__pyx_t_10))) {
              PyObject* sequence = __pyx_t_10;
              Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
              if (unlikely(size != 3)) {
                if (size > 3) __Pyx_RaiseTooManyValuesError(3);
                else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
                __PYX_ERR(0, 774, __pyx_L8_error)
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              if (likely(PyTuple_CheckExact(sequence))) {
                __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); 
                __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); 
                __pyx_t_14 = PyTuple_GET_ITEM(sequence, 2); 
              } else {
                __pyx_t_9 = PyList_GET_ITEM(sequence, 0); 
                __pyx_t_8 = PyList_GET_ITEM(sequence, 1); 
                __pyx_t_14 = PyList_GET_ITEM(sequence, 2); 
              }
              __Pyx_INCREF(__pyx_t_9);
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(__pyx_t_14);
              #else
              __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 774, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_9);
              __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 774, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_8);
              __pyx_t_14 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 774, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_14);
              #endif
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            } else {
              Py_ssize_t index = -1;
              __pyx_t_16 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 774, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_16);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              __pyx_t_15 = Py_TYPE(__pyx_t_16)->tp_iternext;
              index = 0; __pyx_t_9 = __pyx_t_15(__pyx_t_16); if (unlikely(!__pyx_t_9)) goto __pyx_L33_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_9);
              index = 1; __pyx_t_8 = __pyx_t_15(__pyx_t_16); if (unlikely(!__pyx_t_8)) goto __pyx_L33_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_8);
              index = 2; __pyx_t_14 = __pyx_t_15(__pyx_t_16); if (unlikely(!__pyx_t_14)) goto __pyx_L33_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_14);
              if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_16), 3) < 0) __PYX_ERR(0, 774, __pyx_L8_error)
              __pyx_t_15 = NULL;
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
              goto __pyx_L34_unpacking_done;
              __pyx_L33_unpacking_failed:;
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
              __pyx_t_15 = NULL;
              if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
              __PYX_ERR(0, 774, __pyx_L8_error)
              __pyx_L34_unpacking_done:;
            }
            __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_9);
            __pyx_t_9 = 0;
            __Pyx_XDECREF_SET(__pyx_v_ip, __pyx_t_8);
            __pyx_t_8 = 0;
            __Pyx_XDECREF_SET(__pyx_v_port, __pyx_t_14);
            __pyx_t_14 = 0;
            __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 774, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_INCREF(__pyx_v_ip);
            __Pyx_GIVEREF(__pyx_v_ip);
            PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_ip);
            __Pyx_INCREF(__pyx_v_port);
            __Pyx_GIVEREF(__pyx_v_port);
            PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_port);
            if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_10))) __PYX_ERR(0, 774, __pyx_L8_error)
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          }
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __pyx_r = __pyx_t_2;
          __pyx_t_2 = 0;
          goto __pyx_L12_try_return;
        }

        /* "btdht/dht.pyx":753
 *             return None
 *         else:
 *             try:             # <<<<<<<<<<<<<<
 *                 # In compact mode (to send over udp) return max 70 peers to avoid udp fragmentation
 *                 if compact:
 */
      }
      __pyx_L8_error:;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "btdht/dht.pyx":775
 *                     peers.sort()
 *                     return [(ip, port) for (_, ip, port) in peers]
 *             except KeyError:             # <<<<<<<<<<<<<<
 *                 if errno > 20:
 *                     raise
 */
      __pyx_t_19 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
      if (__pyx_t_19) {
        __Pyx_AddTraceback("btdht.dht.DHT_BASE._get_peers", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_11, &__pyx_t_10) < 0) __PYX_ERR(0, 775, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GOTREF(__pyx_t_10);

        /* "btdht/dht.pyx":776
 *                     return [(ip, port) for (_, ip, port) in peers]
 *             except KeyError:
 *                 if errno > 20:             # <<<<<<<<<<<<<<
 *                     raise
 *                 time.sleep(0.1)
 */
        __pyx_t_14 = PyObject_RichCompare(__pyx_v_errno, __pyx_int_20, Py_GT); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 776, __pyx_L10_except_error)
        __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 776, __pyx_L10_except_error)
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        if (unlikely(__pyx_t_1)) {

          /* "btdht/dht.pyx":777
 *             except KeyError:
 *                 if errno > 20:
 *                     raise             # <<<<<<<<<<<<<<
 *                 time.sleep(0.1)
 *                 return self._get_peers(info_hash, compact, errno=errno+1)
 */
          __Pyx_GIVEREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_11);
          __Pyx_XGIVEREF(__pyx_t_10);
          __Pyx_ErrRestoreWithState(__pyx_t_2, __pyx_t_11, __pyx_t_10);
          __pyx_t_2 = 0; __pyx_t_11 = 0; __pyx_t_10 = 0; 
          __PYX_ERR(0, 777, __pyx_L10_except_error)

          /* "btdht/dht.pyx":776
 *                     return [(ip, port) for (_, ip, port) in peers]
 *             except KeyError:
 *                 if errno > 20:             # <<<<<<<<<<<<<<
 *                     raise
 *                 time.sleep(0.1)
 */
        }

        /* "btdht/dht.pyx":778
 *                 if errno > 20:
 *                     raise
 *                 time.sleep(0.1)             # <<<<<<<<<<<<<<
 *                 return self._get_peers(info_hash, compact, errno=errno+1)
 * 
 */
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 778, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_sleep); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 778, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_8 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_9, function);
          }
        }
        __pyx_t_14 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_float_0_1) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_float_0_1);
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 778, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

        /* "btdht/dht.pyx":779
 *                     raise
 *                 time.sleep(0.1)
 *                 return self._get_peers(info_hash, compact, errno=errno+1)             # <<<<<<<<<<<<<<
 * 
 *     def get_closest_nodes(self, id, compact=False):
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_14 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_peers_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 779, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 779, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_INCREF(__pyx_v_info_hash);
        __Pyx_GIVEREF(__pyx_v_info_hash);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_info_hash);
        __Pyx_INCREF(__pyx_v_compact);
        __Pyx_GIVEREF(__pyx_v_compact);
        PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_compact);
        __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 779, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_16 = __Pyx_PyInt_AddObjC(__pyx_v_errno, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 779, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_16);
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_errno, __pyx_t_16) < 0) __PYX_ERR(0, 779, __pyx_L10_except_error)
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_9, __pyx_t_8); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 779, __pyx_L10_except_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_r = __pyx_t_16;
        __pyx_t_16 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        goto __pyx_L11_except_return;
      }
      goto __pyx_L10_except_error;
      __pyx_L10_except_error:;

      /* "btdht/dht.pyx":753
 *             return None
 *         else:
 *             try:             # <<<<<<<<<<<<<<
 *                 # In compact mode (to send over udp) return max 70 peers to avoid udp fragmentation
 *                 if compact:
 */
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      goto __pyx_L1_error;
      __pyx_L12_try_return:;
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      goto __pyx_L0;
      __pyx_L11_except_return:;
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      goto __pyx_L0;
    }
  }

  /* "btdht/dht.pyx":726
 *             yield (time.time() + tosleep)
 * 
 *     def _get_peers(self, info_hash, compact=True, errno=0):             # <<<<<<<<<<<<<<
 *         """
 *             Return peers store locally by remote announce_peer queries
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._get_peers", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_peers);
  __Pyx_XDECREF(__pyx_v_ip);
  __Pyx_XDECREF(__pyx_v_port);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v__);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":781
 *                 return self._get_peers(info_hash, compact, errno=errno+1)
 * 
 *     def get_closest_nodes(self, id, compact=False):             # <<<<<<<<<<<<<<
 *         """
 *         return the current K closest nodes from ``id`` present in the routing table (K = 8)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_36get_closest_nodes(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_35get_closest_nodes[] = "\n        return the current K closest nodes from ``id`` present in the routing table (K = 8)\n\n        :param bytes id:  A 160bits (20 Bytes) long identifier for which we want the closest nodes\n            in the routing table.\n        :param bool compact: If ``True`` the nodes infos are returned in compact format.\n            Otherwise, intances of :class:`Node` are returned. The default is ``False``.\n        :return: A list of :class:`Node` if ``compact`` is ``False``, a :class:`bytes` of size\n            multiple of 26 if ``compact`` is ``True``.\n        :rtype: :class:`list` if ``compact`` is ``False``, a :class:`bytes` otherwise.\n\n        Note:\n            Contact information for peers is encoded as a 6-byte string.\n            Also known as \"Compact IP-address/port info\" the 4-byte IP address\n            is in network byte order with the 2 byte port in network byte order\n            concatenated onto the end.\n\n            Contact information for nodes is encoded as a 26-byte string.\n            Also known as \"Compact node info\" the 20-byte Node ID in network byte\n            order and the compact IP-address/port info concatenated to the end.\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_36get_closest_nodes(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_id = 0;
  PyObject *__pyx_v_compact = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_closest_nodes (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_id,&__pyx_n_s_compact,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_False);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_compact);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_closest_nodes") < 0)) __PYX_ERR(0, 781, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_id = values[0];
    __pyx_v_compact = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_closest_nodes", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 781, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.get_closest_nodes", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_35get_closest_nodes(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_id, __pyx_v_compact);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_5btdht_3dht_8DHT_BASE_17get_closest_nodes_2generator6(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "btdht/dht.pyx":805
 *         l = list(self.root.get_closest_nodes(id))
 *         if compact:
 *             return b"".join(n.compact_info() for n in l)             # <<<<<<<<<<<<<<
 *         else:
 *             return list(self.root.get_closest_nodes(id))
 */

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_17get_closest_nodes_genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct_3_genexpr(__pyx_ptype_5btdht_3dht___pyx_scope_struct_3_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 805, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes *) __pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5btdht_3dht_8DHT_BASE_17get_closest_nodes_2generator6, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_get_closest_nodes_locals_genexpr, __pyx_n_s_btdht_dht); if (unlikely(!gen)) __PYX_ERR(0, 805, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.get_closest_nodes.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5btdht_3dht_8DHT_BASE_17get_closest_nodes_2generator6(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("genexpr", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L6_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 805, __pyx_L1_error)
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_l)) { __Pyx_RaiseClosureNameError("l"); __PYX_ERR(0, 805, __pyx_L1_error) }
  if (unlikely(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_l == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 805, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_l; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 805, __pyx_L1_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_n);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_n, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_n, __pyx_n_s_compact_info); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L6_resume_from_yield:;
    __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
    __pyx_cur_scope->__pyx_t_0 = 0;
    __Pyx_XGOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
    if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 805, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":781
 *                 return self._get_peers(info_hash, compact, errno=errno+1)
 * 
 *     def get_closest_nodes(self, id, compact=False):             # <<<<<<<<<<<<<<
 *         """
 *         return the current K closest nodes from ``id`` present in the routing table (K = 8)
 */

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_35get_closest_nodes(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_id, PyObject *__pyx_v_compact) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes *__pyx_cur_scope;
  PyObject *__pyx_gb_5btdht_3dht_8DHT_BASE_17get_closest_nodes_2generator6 = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_closest_nodes", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes(__pyx_ptype_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 781, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }

  /* "btdht/dht.pyx":803
 *             order and the compact IP-address/port info concatenated to the end.
 *         """
 *         l = list(self.root.get_closest_nodes(id))             # <<<<<<<<<<<<<<
 *         if compact:
 *             return b"".join(n.compact_info() for n in l)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 803, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get_closest_nodes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 803, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_id);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 803, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 803, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_cur_scope->__pyx_v_l = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "btdht/dht.pyx":804
 *         """
 *         l = list(self.root.get_closest_nodes(id))
 *         if compact:             # <<<<<<<<<<<<<<
 *             return b"".join(n.compact_info() for n in l)
 *         else:
 */
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_compact); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 804, __pyx_L1_error)
  if (__pyx_t_4) {

    /* "btdht/dht.pyx":805
 *         l = list(self.root.get_closest_nodes(id))
 *         if compact:
 *             return b"".join(n.compact_info() for n in l)             # <<<<<<<<<<<<<<
 *         else:
 *             return list(self.root.get_closest_nodes(id))
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __pyx_pf_5btdht_3dht_8DHT_BASE_17get_closest_nodes_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyBytes_Join(__pyx_kp_b__2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "btdht/dht.pyx":804
 *         """
 *         l = list(self.root.get_closest_nodes(id))
 *         if compact:             # <<<<<<<<<<<<<<
 *             return b"".join(n.compact_info() for n in l)
 *         else:
 */
  }

  /* "btdht/dht.pyx":807
 *             return b"".join(n.compact_info() for n in l)
 *         else:
 *             return list(self.root.get_closest_nodes(id))             # <<<<<<<<<<<<<<
 * 
 *     def bootstarp(
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 807, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get_closest_nodes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 807, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_id);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 807, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 807, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":781
 *                 return self._get_peers(info_hash, compact, errno=errno+1)
 * 
 *     def get_closest_nodes(self, id, compact=False):             # <<<<<<<<<<<<<<
 *         """
 *         return the current K closest nodes from ``id`` present in the routing table (K = 8)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.get_closest_nodes", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_gb_5btdht_3dht_8DHT_BASE_17get_closest_nodes_2generator6);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":809
 *             return list(self.root.get_closest_nodes(id))
 * 
 *     def bootstarp(             # <<<<<<<<<<<<<<
 *         self,
 *         addresses=[
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_38bootstarp(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_37bootstarp[] = "\n            Boostrap the DHT to some wellknown nodes\n\n            :param list addresses: A list of couple (node addresse, node ip). The default the list\n                of the following nodes\n                    * router.utorrent.com:6881\n                    * router.bittorrent.com:6881\n                    * dht.transmissionbt.com:6881\n                    * grenade.genua.fr:6880\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_38bootstarp(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_addresses = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("bootstarp (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_addresses,0};
    PyObject* values[1] = {0};
    values[0] = __pyx_k__18;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_addresses);
          if (value) { values[0] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "bootstarp") < 0)) __PYX_ERR(0, 809, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_addresses = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("bootstarp", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 809, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.bootstarp", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_37bootstarp(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_addresses);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_37bootstarp(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_addresses) {
  PyObject *__pyx_v_addr = NULL;
  struct __pyx_obj_5btdht_4krcp_BMessage *__pyx_v_msg = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *(*__pyx_t_4)(PyObject *);
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("bootstarp", 0);

  /* "btdht/dht.pyx":828
 *                     * grenade.genua.fr:6880
 *         """
 *         self.debug(0,"Bootstraping")             # <<<<<<<<<<<<<<
 *         for addr in addresses:
 *             msg = BMessage()
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 828, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 828, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "btdht/dht.pyx":829
 *         """
 *         self.debug(0,"Bootstraping")
 *         for addr in addresses:             # <<<<<<<<<<<<<<
 *             msg = BMessage()
 *             msg.y = b'q'
 */
  if (likely(PyList_CheckExact(__pyx_v_addresses)) || PyTuple_CheckExact(__pyx_v_addresses)) {
    __pyx_t_2 = __pyx_v_addresses; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_addresses); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 829, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 829, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_4)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 829, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 829, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 829, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 829, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_4(__pyx_t_2);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 829, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_addr, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "btdht/dht.pyx":830
 *         self.debug(0,"Bootstraping")
 *         for addr in addresses:
 *             msg = BMessage()             # <<<<<<<<<<<<<<
 *             msg.y = b'q'
 *             msg.q = b"find_node"
 */
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_5btdht_4krcp_BMessage)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_msg, ((struct __pyx_obj_5btdht_4krcp_BMessage *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "btdht/dht.pyx":831
 *         for addr in addresses:
 *             msg = BMessage()
 *             msg.y = b'q'             # <<<<<<<<<<<<<<
 *             msg.q = b"find_node"
 *             self._set_transaction_id(msg)
 */
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_y, __pyx_n_b_q) < 0) __PYX_ERR(0, 831, __pyx_L1_error)

    /* "btdht/dht.pyx":832
 *             msg = BMessage()
 *             msg.y = b'q'
 *             msg.q = b"find_node"             # <<<<<<<<<<<<<<
 *             self._set_transaction_id(msg)
 *             msg.set_a(True)
 */
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_q, __pyx_n_b_find_node) < 0) __PYX_ERR(0, 832, __pyx_L1_error)

    /* "btdht/dht.pyx":833
 *             msg.y = b'q'
 *             msg.q = b"find_node"
 *             self._set_transaction_id(msg)             # <<<<<<<<<<<<<<
 *             msg.set_a(True)
 *             msg[b"id"] = self.myid.value
 */
    ((struct __pyx_vtabstruct_5btdht_3dht_DHT_BASE *)__pyx_v_self->__pyx_vtab)->_set_transaction_id(__pyx_v_self, __pyx_v_msg, NULL);

    /* "btdht/dht.pyx":834
 *             msg.q = b"find_node"
 *             self._set_transaction_id(msg)
 *             msg.set_a(True)             # <<<<<<<<<<<<<<
 *             msg[b"id"] = self.myid.value
 *             msg[b"target"] = self.myid.value
 */
    (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_a(__pyx_v_msg, 1));

    /* "btdht/dht.pyx":835
 *             self._set_transaction_id(msg)
 *             msg.set_a(True)
 *             msg[b"id"] = self.myid.value             # <<<<<<<<<<<<<<
 *             msg[b"target"] = self.myid.value
 *             self.sendto(msg.encode(), addr)
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_myid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 835, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_value); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 835, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_msg), __pyx_n_b_id, __pyx_t_5) < 0)) __PYX_ERR(0, 835, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "btdht/dht.pyx":836
 *             msg.set_a(True)
 *             msg[b"id"] = self.myid.value
 *             msg[b"target"] = self.myid.value             # <<<<<<<<<<<<<<
 *             self.sendto(msg.encode(), addr)
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_myid); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 836, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 836, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(PyObject_SetItem(((PyObject *)__pyx_v_msg), __pyx_n_b_target, __pyx_t_1) < 0)) __PYX_ERR(0, 836, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":837
 *             msg[b"id"] = self.myid.value
 *             msg[b"target"] = self.myid.value
 *             self.sendto(msg.encode(), addr)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sendto); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 837, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_encode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 837, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 837, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = NULL;
    __pyx_t_9 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
        __pyx_t_9 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_addr};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 837, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_addr};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 837, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    {
      __pyx_t_8 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 837, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (__pyx_t_7) {
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_9, __pyx_t_6);
      __Pyx_INCREF(__pyx_v_addr);
      __Pyx_GIVEREF(__pyx_v_addr);
      PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_9, __pyx_v_addr);
      __pyx_t_6 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 837, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":829
 *         """
 *         self.debug(0,"Bootstraping")
 *         for addr in addresses:             # <<<<<<<<<<<<<<
 *             msg = BMessage()
 *             msg.y = b'q'
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "btdht/dht.pyx":809
 *             return list(self.root.get_closest_nodes(id))
 * 
 *     def bootstarp(             # <<<<<<<<<<<<<<
 *         self,
 *         addresses=[
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.bootstarp", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_addr);
  __Pyx_XDECREF((PyObject *)__pyx_v_msg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":841
 * 
 * 
 *     def _update_node(self, obj):             # <<<<<<<<<<<<<<
 *         """
 *             Update a node the in routing table on msg receival, especially its
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_40_update_node(PyObject *__pyx_v_self, PyObject *__pyx_v_obj); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_39_update_node[] = "\n            Update a node the in routing table on msg receival, especially its\n            :attr:`Node.last_query` :attr:`Node.last_response` and :attr:`Node.failed` attributes\n\n            :param brcp.BMessage obj: A reived message\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_40_update_node(PyObject *__pyx_v_self, PyObject *__pyx_v_obj) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_update_node (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_39_update_node(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v_obj));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_39_update_node(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_obj) {
  PyObject *__pyx_v_id = NULL;
  PyObject *__pyx_v_node = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_update_node", 0);

  /* "btdht/dht.pyx":848
 *             :param brcp.BMessage obj: A reived message
 *         """
 *         if obj.y == b"q" or obj.y == b"r":             # <<<<<<<<<<<<<<
 *             id = obj.get(b"id")
 *             if id:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 848, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = (__Pyx_PyBytes_Equals(__pyx_t_2, __pyx_n_b_q, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 848, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = (__Pyx_PyBytes_Equals(__pyx_t_2, __pyx_n_b_r, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "btdht/dht.pyx":849
 *         """
 *         if obj.y == b"q" or obj.y == b"r":
 *             id = obj.get(b"id")             # <<<<<<<<<<<<<<
 *             if id:
 *                 try:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_get); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 849, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_n_b_id) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_n_b_id);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 849, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_id = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "btdht/dht.pyx":850
 *         if obj.y == b"q" or obj.y == b"r":
 *             id = obj.get(b"id")
 *             if id:             # <<<<<<<<<<<<<<
 *                 try:
 *                     node = self.root.get_node(id)
 */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_id); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 850, __pyx_L1_error)
    if (__pyx_t_1) {

      /* "btdht/dht.pyx":851
 *             id = obj.get(b"id")
 *             if id:
 *                 try:             # <<<<<<<<<<<<<<
 *                     node = self.root.get_node(id)
 *                     node.ip = obj.addr[0]
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
        __Pyx_XGOTREF(__pyx_t_6);
        __Pyx_XGOTREF(__pyx_t_7);
        __Pyx_XGOTREF(__pyx_t_8);
        /*try:*/ {

          /* "btdht/dht.pyx":852
 *             if id:
 *                 try:
 *                     node = self.root.get_node(id)             # <<<<<<<<<<<<<<
 *                     node.ip = obj.addr[0]
 *                     node.port = obj.addr[1]
 */
          __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 852, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_get_node); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 852, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_4 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_4)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_4);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
            }
          }
          __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_id);
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 852, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_v_node = __pyx_t_2;
          __pyx_t_2 = 0;

          /* "btdht/dht.pyx":853
 *                 try:
 *                     node = self.root.get_node(id)
 *                     node.ip = obj.addr[0]             # <<<<<<<<<<<<<<
 *                     node.port = obj.addr[1]
 *                 except NotFound:
 */
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_addr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 853, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 853, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (__Pyx_PyObject_SetAttrStr(__pyx_v_node, __pyx_n_s_ip, __pyx_t_5) < 0) __PYX_ERR(0, 853, __pyx_L7_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

          /* "btdht/dht.pyx":854
 *                     node = self.root.get_node(id)
 *                     node.ip = obj.addr[0]
 *                     node.port = obj.addr[1]             # <<<<<<<<<<<<<<
 *                 except NotFound:
 *                     node = Node(id=id, ip=obj.addr[0], port=obj.addr[1])
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_addr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 854, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_5, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 854, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (__Pyx_PyObject_SetAttrStr(__pyx_v_node, __pyx_n_s_port, __pyx_t_2) < 0) __PYX_ERR(0, 854, __pyx_L7_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "btdht/dht.pyx":851
 *             id = obj.get(b"id")
 *             if id:
 *                 try:             # <<<<<<<<<<<<<<
 *                     node = self.root.get_node(id)
 *                     node.ip = obj.addr[0]
 */
        }
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        goto __pyx_L12_try_end;
        __pyx_L7_error:;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "btdht/dht.pyx":855
 *                     node.ip = obj.addr[0]
 *                     node.port = obj.addr[1]
 *                 except NotFound:             # <<<<<<<<<<<<<<
 *                     node = Node(id=id, ip=obj.addr[0], port=obj.addr[1])
 *                     self.root.add(self, node)
 */
        __Pyx_ErrFetch(&__pyx_t_2, &__pyx_t_5, &__pyx_t_4);
        __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_NotFound); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 855, __pyx_L9_except_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_10 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_2, __pyx_t_9);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_ErrRestore(__pyx_t_2, __pyx_t_5, __pyx_t_4);
        __pyx_t_2 = 0; __pyx_t_5 = 0; __pyx_t_4 = 0;
        if (__pyx_t_10) {
          __Pyx_AddTraceback("btdht.dht.DHT_BASE._update_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_5, &__pyx_t_2) < 0) __PYX_ERR(0, 855, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_GOTREF(__pyx_t_2);

          /* "btdht/dht.pyx":856
 *                     node.port = obj.addr[1]
 *                 except NotFound:
 *                     node = Node(id=id, ip=obj.addr[0], port=obj.addr[1])             # <<<<<<<<<<<<<<
 *                     self.root.add(self, node)
 *                 if obj.y == b"q":
 */
          __pyx_t_9 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 856, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_9);
          if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_id, __pyx_v_id) < 0) __PYX_ERR(0, 856, __pyx_L9_except_error)
          __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_addr); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 856, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_12 = __Pyx_GetItemInt(__pyx_t_11, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 856, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_ip, __pyx_t_12) < 0) __PYX_ERR(0, 856, __pyx_L9_except_error)
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_addr); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 856, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_12);
          __pyx_t_11 = __Pyx_GetItemInt(__pyx_t_12, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 856, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_port, __pyx_t_11) < 0) __PYX_ERR(0, 856, __pyx_L9_except_error)
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __pyx_t_11 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5btdht_3dht_Node), __pyx_empty_tuple, __pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 856, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_XDECREF_SET(__pyx_v_node, __pyx_t_11);
          __pyx_t_11 = 0;

          /* "btdht/dht.pyx":857
 *                 except NotFound:
 *                     node = Node(id=id, ip=obj.addr[0], port=obj.addr[1])
 *                     self.root.add(self, node)             # <<<<<<<<<<<<<<
 *                 if obj.y == b"q":
 *                     node.last_query = int(time.time())
 */
          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 857, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_add); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 857, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = NULL;
          __pyx_t_10 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
            __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_12);
            if (likely(__pyx_t_9)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
              __Pyx_INCREF(__pyx_t_9);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_12, function);
              __pyx_t_10 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_12)) {
            PyObject *__pyx_temp[3] = {__pyx_t_9, ((PyObject *)__pyx_v_self), __pyx_v_node};
            __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 857, __pyx_L9_except_error)
            __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_GOTREF(__pyx_t_11);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) {
            PyObject *__pyx_temp[3] = {__pyx_t_9, ((PyObject *)__pyx_v_self), __pyx_v_node};
            __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 857, __pyx_L9_except_error)
            __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_GOTREF(__pyx_t_11);
          } else
          #endif
          {
            __pyx_t_13 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 857, __pyx_L9_except_error)
            __Pyx_GOTREF(__pyx_t_13);
            if (__pyx_t_9) {
              __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_9); __pyx_t_9 = NULL;
            }
            __Pyx_INCREF(((PyObject *)__pyx_v_self));
            __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
            PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_10, ((PyObject *)__pyx_v_self));
            __Pyx_INCREF(__pyx_v_node);
            __Pyx_GIVEREF(__pyx_v_node);
            PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_10, __pyx_v_node);
            __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_13, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 857, __pyx_L9_except_error)
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          }
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          goto __pyx_L8_exception_handled;
        }
        goto __pyx_L9_except_error;
        __pyx_L9_except_error:;

        /* "btdht/dht.pyx":851
 *             id = obj.get(b"id")
 *             if id:
 *                 try:             # <<<<<<<<<<<<<<
 *                     node = self.root.get_node(id)
 *                     node.ip = obj.addr[0]
 */
        __Pyx_XGIVEREF(__pyx_t_6);
        __Pyx_XGIVEREF(__pyx_t_7);
        __Pyx_XGIVEREF(__pyx_t_8);
        __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
        goto __pyx_L1_error;
        __pyx_L8_exception_handled:;
        __Pyx_XGIVEREF(__pyx_t_6);
        __Pyx_XGIVEREF(__pyx_t_7);
        __Pyx_XGIVEREF(__pyx_t_8);
        __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
        __pyx_L12_try_end:;
      }

      /* "btdht/dht.pyx":858
 *                     node = Node(id=id, ip=obj.addr[0], port=obj.addr[1])
 *                     self.root.add(self, node)
 *                 if obj.y == b"q":             # <<<<<<<<<<<<<<
 *                     node.last_query = int(time.time())
 *                 elif obj.y == b"r":
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 858, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = (__Pyx_PyBytes_Equals(__pyx_t_2, __pyx_n_b_q, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 858, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_1) {

        /* "btdht/dht.pyx":859
 *                     self.root.add(self, node)
 *                 if obj.y == b"q":
 *                     node.last_query = int(time.time())             # <<<<<<<<<<<<<<
 *                 elif obj.y == b"r":
 *                     node.last_response = int(time.time())
 */
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 859, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 859, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_4, function);
          }
        }
        __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 859, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 859, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_node, __pyx_n_s_last_query, __pyx_t_4) < 0) __PYX_ERR(0, 859, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "btdht/dht.pyx":858
 *                     node = Node(id=id, ip=obj.addr[0], port=obj.addr[1])
 *                     self.root.add(self, node)
 *                 if obj.y == b"q":             # <<<<<<<<<<<<<<
 *                     node.last_query = int(time.time())
 *                 elif obj.y == b"r":
 */
        goto __pyx_L15;
      }

      /* "btdht/dht.pyx":860
 *                 if obj.y == b"q":
 *                     node.last_query = int(time.time())
 *                 elif obj.y == b"r":             # <<<<<<<<<<<<<<
 *                     node.last_response = int(time.time())
 *                     node.failed = 0
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_y); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 860, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = (__Pyx_PyBytes_Equals(__pyx_t_4, __pyx_n_b_r, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 860, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_1) {

        /* "btdht/dht.pyx":861
 *                     node.last_query = int(time.time())
 *                 elif obj.y == b"r":
 *                     node.last_response = int(time.time())             # <<<<<<<<<<<<<<
 *                     node.failed = 0
 *             else:
 */
        __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 861, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 861, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_2)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
          }
        }
        __pyx_t_4 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 861, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = __Pyx_PyNumber_Int(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 861, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_node, __pyx_n_s_last_response, __pyx_t_5) < 0) __PYX_ERR(0, 861, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "btdht/dht.pyx":862
 *                 elif obj.y == b"r":
 *                     node.last_response = int(time.time())
 *                     node.failed = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 self.debug(1, "obj without id, no node update")
 */
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_node, __pyx_n_s_failed, __pyx_int_0) < 0) __PYX_ERR(0, 862, __pyx_L1_error)

        /* "btdht/dht.pyx":860
 *                 if obj.y == b"q":
 *                     node.last_query = int(time.time())
 *                 elif obj.y == b"r":             # <<<<<<<<<<<<<<
 *                     node.last_response = int(time.time())
 *                     node.failed = 0
 */
      }
      __pyx_L15:;

      /* "btdht/dht.pyx":850
 *         if obj.y == b"q" or obj.y == b"r":
 *             id = obj.get(b"id")
 *             if id:             # <<<<<<<<<<<<<<
 *                 try:
 *                     node = self.root.get_node(id)
 */
      goto __pyx_L6;
    }

    /* "btdht/dht.pyx":864
 *                     node.failed = 0
 *             else:
 *                 self.debug(1, "obj without id, no node update")             # <<<<<<<<<<<<<<
 *         else:
 *             self.debug(2, "obj of type %r" % obj.y)
 */
    /*else*/ {
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 864, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 864, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __pyx_L6:;

    /* "btdht/dht.pyx":848
 *             :param brcp.BMessage obj: A reived message
 *         """
 *         if obj.y == b"q" or obj.y == b"r":             # <<<<<<<<<<<<<<
 *             id = obj.get(b"id")
 *             if id:
 */
    goto __pyx_L3;
  }

  /* "btdht/dht.pyx":866
 *                 self.debug(1, "obj without id, no node update")
 *         else:
 *             self.debug(2, "obj of type %r" % obj.y)             # <<<<<<<<<<<<<<
 * 
 *     def sendto(self, msg, addr):
 */
  /*else*/ {
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 866, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 866, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_11 = __Pyx_PyString_FormatSafe(__pyx_kp_s_obj_of_type_r, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 866, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_int_2, __pyx_t_11};
      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 866, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_int_2, __pyx_t_11};
      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 866, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    } else
    #endif
    {
      __pyx_t_12 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 866, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      if (__pyx_t_2) {
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_2); __pyx_t_2 = NULL;
      }
      __Pyx_INCREF(__pyx_int_2);
      __Pyx_GIVEREF(__pyx_int_2);
      PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_10, __pyx_int_2);
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_10, __pyx_t_11);
      __pyx_t_11 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_12, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 866, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __pyx_L3:;

  /* "btdht/dht.pyx":841
 * 
 * 
 *     def _update_node(self, obj):             # <<<<<<<<<<<<<<
 *         """
 *             Update a node the in routing table on msg receival, especially its
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._update_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_id);
  __Pyx_XDECREF(__pyx_v_node);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":868
 *             self.debug(2, "obj of type %r" % obj.y)
 * 
 *     def sendto(self, msg, addr):             # <<<<<<<<<<<<<<
 *         """
 *             Program a msg to be send over the network
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_42sendto(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_41sendto[] = "\n            Program a msg to be send over the network\n\n            :param bytes msg: The message to send\n            :param tuple addr: A couple (ip, port) to send the message to. ip is in dotted notation\n\n            Notes:\n                The message is push to the :attr:`to_send` queue.\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_42sendto(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_msg = 0;
  PyObject *__pyx_v_addr = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sendto (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_msg,&__pyx_n_s_addr,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_msg)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_addr)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sendto", 1, 2, 2, 1); __PYX_ERR(0, 868, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sendto") < 0)) __PYX_ERR(0, 868, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_msg = values[0];
    __pyx_v_addr = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("sendto", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 868, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.sendto", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_41sendto(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_msg, __pyx_v_addr);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_41sendto(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_msg, PyObject *__pyx_v_addr) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sendto", 0);

  /* "btdht/dht.pyx":878
 *                 The message is push to the :attr:`to_send` queue.
 *         """
 *         self.to_send.put((msg, addr))             # <<<<<<<<<<<<<<
 * 
 *     def _process_outgoing_message(self):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_send); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 878, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_put); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 878, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 878, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_msg);
  __Pyx_GIVEREF(__pyx_v_msg);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_msg);
  __Pyx_INCREF(__pyx_v_addr);
  __Pyx_GIVEREF(__pyx_v_addr);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_addr);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 878, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":868
 *             self.debug(2, "obj of type %r" % obj.y)
 * 
 *     def sendto(self, msg, addr):             # <<<<<<<<<<<<<<
 *         """
 *             Program a msg to be send over the network
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.sendto", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":880
 *         self.to_send.put((msg, addr))
 * 
 *     def _process_outgoing_message(self):             # <<<<<<<<<<<<<<
 *         """
 *             Process a new outgoing message. The message is retrieved from the queue :attr:`to_send`
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_44_process_outgoing_message(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_43_process_outgoing_message[] = "\n            Process a new outgoing message. The message is retrieved from the queue :attr:`to_send`\n            and send to :attr:`sock`. So the method should only be called then there is a message\n            in the send queue and then :attr:`sock` is ready for a write.\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_44_process_outgoing_message(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_process_outgoing_message (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_43_process_outgoing_message(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_43_process_outgoing_message(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_v_addr = NULL;
  PyObject *__pyx_v_e = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_t_17;
  int __pyx_t_18;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_process_outgoing_message", 0);

  /* "btdht/dht.pyx":886
 *             in the send queue and then :attr:`sock` is ready for a write.
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             (msg, addr) = self.to_send.get_nowait()
 *             try:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "btdht/dht.pyx":887
 *         """
 *         try:
 *             (msg, addr) = self.to_send.get_nowait()             # <<<<<<<<<<<<<<
 *             try:
 *                 self.sock.sendto(msg, addr)
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_send); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 887, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_get_nowait); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 887, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 887, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
        PyObject* sequence = __pyx_t_4;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 887, __pyx_L3_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        #else
        __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 887, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 887, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 887, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext;
        index = 0; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_6);
        index = 1; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_5);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 887, __pyx_L3_error)
        __pyx_t_8 = NULL;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        goto __pyx_L10_unpacking_done;
        __pyx_L9_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_8 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 887, __pyx_L3_error)
        __pyx_L10_unpacking_done:;
      }
      __pyx_v_msg = __pyx_t_6;
      __pyx_t_6 = 0;
      __pyx_v_addr = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "btdht/dht.pyx":888
 *         try:
 *             (msg, addr) = self.to_send.get_nowait()
 *             try:             # <<<<<<<<<<<<<<
 *                 self.sock.sendto(msg, addr)
 *                 self._socket_out+=1
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
        __Pyx_XGOTREF(__pyx_t_9);
        __Pyx_XGOTREF(__pyx_t_10);
        __Pyx_XGOTREF(__pyx_t_11);
        /*try:*/ {

          /* "btdht/dht.pyx":889
 *             (msg, addr) = self.to_send.get_nowait()
 *             try:
 *                 self.sock.sendto(msg, addr)             # <<<<<<<<<<<<<<
 *                 self._socket_out+=1
 *             except socket.gaierror as e:
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sock); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 889, __pyx_L11_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_sendto); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 889, __pyx_L11_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_5 = NULL;
          __pyx_t_12 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
            __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
            if (likely(__pyx_t_5)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
              __Pyx_INCREF(__pyx_t_5);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_6, function);
              __pyx_t_12 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_msg, __pyx_v_addr};
            __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 889, __pyx_L11_error)
            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_GOTREF(__pyx_t_4);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_msg, __pyx_v_addr};
            __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 889, __pyx_L11_error)
            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_GOTREF(__pyx_t_4);
          } else
          #endif
          {
            __pyx_t_7 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 889, __pyx_L11_error)
            __Pyx_GOTREF(__pyx_t_7);
            if (__pyx_t_5) {
              __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
            }
            __Pyx_INCREF(__pyx_v_msg);
            __Pyx_GIVEREF(__pyx_v_msg);
            PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_12, __pyx_v_msg);
            __Pyx_INCREF(__pyx_v_addr);
            __Pyx_GIVEREF(__pyx_v_addr);
            PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_12, __pyx_v_addr);
            __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 889, __pyx_L11_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          }
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

          /* "btdht/dht.pyx":890
 *             try:
 *                 self.sock.sendto(msg, addr)
 *                 self._socket_out+=1             # <<<<<<<<<<<<<<
 *             except socket.gaierror as e:
 *                 self.debug(0, "send:%r %r %r" % (e, addr, msg))
 */
          __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_out); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 890, __pyx_L11_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 890, __pyx_L11_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_out, __pyx_t_6) < 0) __PYX_ERR(0, 890, __pyx_L11_error)
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

          /* "btdht/dht.pyx":888
 *         try:
 *             (msg, addr) = self.to_send.get_nowait()
 *             try:             # <<<<<<<<<<<<<<
 *                 self.sock.sendto(msg, addr)
 *                 self._socket_out+=1
 */
        }
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        goto __pyx_L16_try_end;
        __pyx_L11_error:;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "btdht/dht.pyx":891
 *                 self.sock.sendto(msg, addr)
 *                 self._socket_out+=1
 *             except socket.gaierror as e:             # <<<<<<<<<<<<<<
 *                 self.debug(0, "send:%r %r %r" % (e, addr, msg))
 *             except socket.error as e:
 */
        __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_4, &__pyx_t_7);
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_socket); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 891, __pyx_L13_except_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_gaierror); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 891, __pyx_L13_except_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_12 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_6, __pyx_t_13);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_ErrRestore(__pyx_t_6, __pyx_t_4, __pyx_t_7);
        __pyx_t_6 = 0; __pyx_t_4 = 0; __pyx_t_7 = 0;
        if (__pyx_t_12) {
          __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_outgoing_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_4, &__pyx_t_6) < 0) __PYX_ERR(0, 891, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_4);
          __pyx_v_e = __pyx_t_4;

          /* "btdht/dht.pyx":892
 *                 self._socket_out+=1
 *             except socket.gaierror as e:
 *                 self.debug(0, "send:%r %r %r" % (e, addr, msg))             # <<<<<<<<<<<<<<
 *             except socket.error as e:
 *                 # 90: Message too long
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 892, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_14 = PyTuple_New(3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 892, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_INCREF(__pyx_v_e);
          __Pyx_GIVEREF(__pyx_v_e);
          PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_e);
          __Pyx_INCREF(__pyx_v_addr);
          __Pyx_GIVEREF(__pyx_v_addr);
          PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_v_addr);
          __Pyx_INCREF(__pyx_v_msg);
          __Pyx_GIVEREF(__pyx_v_msg);
          PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_v_msg);
          __pyx_t_15 = __Pyx_PyString_Format(__pyx_kp_s_send_r_r_r, __pyx_t_14); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 892, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_15);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __pyx_t_14 = NULL;
          __pyx_t_12 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_14)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_14);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
              __pyx_t_12 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_5)) {
            PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_int_0, __pyx_t_15};
            __pyx_t_13 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 892, __pyx_L13_except_error)
            __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
            __Pyx_GOTREF(__pyx_t_13);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
            PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_int_0, __pyx_t_15};
            __pyx_t_13 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 892, __pyx_L13_except_error)
            __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
            __Pyx_GOTREF(__pyx_t_13);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          } else
          #endif
          {
            __pyx_t_16 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 892, __pyx_L13_except_error)
            __Pyx_GOTREF(__pyx_t_16);
            if (__pyx_t_14) {
              __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_14); __pyx_t_14 = NULL;
            }
            __Pyx_INCREF(__pyx_int_0);
            __Pyx_GIVEREF(__pyx_int_0);
            PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_12, __pyx_int_0);
            __Pyx_GIVEREF(__pyx_t_15);
            PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_12, __pyx_t_15);
            __pyx_t_15 = 0;
            __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_16, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 892, __pyx_L13_except_error)
            __Pyx_GOTREF(__pyx_t_13);
            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          }
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          goto __pyx_L12_exception_handled;
        }

        /* "btdht/dht.pyx":893
 *             except socket.gaierror as e:
 *                 self.debug(0, "send:%r %r %r" % (e, addr, msg))
 *             except socket.error as e:             # <<<<<<<<<<<<<<
 *                 # 90: Message too long
 *                 # 13: Permission denied
 */
        __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_4, &__pyx_t_7);
        __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_socket); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 893, __pyx_L13_except_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_error); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 893, __pyx_L13_except_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_12 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_6, __pyx_t_5);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_ErrRestore(__pyx_t_6, __pyx_t_4, __pyx_t_7);
        __pyx_t_6 = 0; __pyx_t_4 = 0; __pyx_t_7 = 0;
        if (__pyx_t_12) {
          __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_outgoing_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_4, &__pyx_t_6) < 0) __PYX_ERR(0, 893, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_4);
          __pyx_v_e = __pyx_t_4;

          /* "btdht/dht.pyx":898
 *                 #: 10013: same as 13 but on windows
 *                 #: 10040: same as 90 but on windows
 *                 if e.errno in [90, 13, 10013, 10040]:             # <<<<<<<<<<<<<<
 *                     self.debug(0, "send:%r %r %r" % (e, addr, msg))
 *                 # 11: Resource temporarily unavailable, try again
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_e, __pyx_n_s_errno); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 898, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_13 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_90, 90, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 898, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 898, __pyx_L13_except_error)
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          if (!__pyx_t_18) {
          } else {
            __pyx_t_17 = __pyx_t_18;
            goto __pyx_L22_bool_binop_done;
          }
          __pyx_t_13 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_13, 13, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 898, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 898, __pyx_L13_except_error)
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          if (!__pyx_t_18) {
          } else {
            __pyx_t_17 = __pyx_t_18;
            goto __pyx_L22_bool_binop_done;
          }
          __pyx_t_13 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_10013, 0x271D, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 898, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 898, __pyx_L13_except_error)
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          if (!__pyx_t_18) {
          } else {
            __pyx_t_17 = __pyx_t_18;
            goto __pyx_L22_bool_binop_done;
          }
          __pyx_t_13 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_10040, 0x2738, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 898, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_18 < 0)) __PYX_ERR(0, 898, __pyx_L13_except_error)
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_17 = __pyx_t_18;
          __pyx_L22_bool_binop_done:;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_18 = (__pyx_t_17 != 0);
          if (__pyx_t_18) {

            /* "btdht/dht.pyx":899
 *                 #: 10040: same as 90 but on windows
 *                 if e.errno in [90, 13, 10013, 10040]:
 *                     self.debug(0, "send:%r %r %r" % (e, addr, msg))             # <<<<<<<<<<<<<<
 *                 # 11: Resource temporarily unavailable, try again
 *                 #  1: Operation not permitted
 */
            __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 899, __pyx_L13_except_error)
            __Pyx_GOTREF(__pyx_t_13);
            __pyx_t_16 = PyTuple_New(3); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 899, __pyx_L13_except_error)
            __Pyx_GOTREF(__pyx_t_16);
            __Pyx_INCREF(__pyx_v_e);
            __Pyx_GIVEREF(__pyx_v_e);
            PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_v_e);
            __Pyx_INCREF(__pyx_v_addr);
            __Pyx_GIVEREF(__pyx_v_addr);
            PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_v_addr);
            __Pyx_INCREF(__pyx_v_msg);
            __Pyx_GIVEREF(__pyx_v_msg);
            PyTuple_SET_ITEM(__pyx_t_16, 2, __pyx_v_msg);
            __pyx_t_15 = __Pyx_PyString_Format(__pyx_kp_s_send_r_r_r, __pyx_t_16); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 899, __pyx_L13_except_error)
            __Pyx_GOTREF(__pyx_t_15);
            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
            __pyx_t_16 = NULL;
            __pyx_t_12 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
              __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_13);
              if (likely(__pyx_t_16)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
                __Pyx_INCREF(__pyx_t_16);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_13, function);
                __pyx_t_12 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_13)) {
              PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_int_0, __pyx_t_15};
              __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 899, __pyx_L13_except_error)
              __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) {
              PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_int_0, __pyx_t_15};
              __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 899, __pyx_L13_except_error)
              __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            } else
            #endif
            {
              __pyx_t_14 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 899, __pyx_L13_except_error)
              __Pyx_GOTREF(__pyx_t_14);
              if (__pyx_t_16) {
                __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_16); __pyx_t_16 = NULL;
              }
              __Pyx_INCREF(__pyx_int_0);
              __Pyx_GIVEREF(__pyx_int_0);
              PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_12, __pyx_int_0);
              __Pyx_GIVEREF(__pyx_t_15);
              PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_12, __pyx_t_15);
              __pyx_t_15 = 0;
              __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_14, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 899, __pyx_L13_except_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
            }
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

            /* "btdht/dht.pyx":898
 *                 #: 10013: same as 13 but on windows
 *                 #: 10040: same as 90 but on windows
 *                 if e.errno in [90, 13, 10013, 10040]:             # <<<<<<<<<<<<<<
 *                     self.debug(0, "send:%r %r %r" % (e, addr, msg))
 *                 # 11: Resource temporarily unavailable, try again
 */
            goto __pyx_L21;
          }

          /* "btdht/dht.pyx":903
 *                 #  1: Operation not permitted
 *                 # 10035: same as 11 but on windows
 *                 elif e.errno in [11, 1, 10035]:             # <<<<<<<<<<<<<<
 *                     pass
 *                 else:
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_e, __pyx_n_s_errno); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 903, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_13 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_11, 11, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 903, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 903, __pyx_L13_except_error)
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          if (!__pyx_t_17) {
          } else {
            __pyx_t_18 = __pyx_t_17;
            goto __pyx_L26_bool_binop_done;
          }
          __pyx_t_13 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 903, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 903, __pyx_L13_except_error)
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          if (!__pyx_t_17) {
          } else {
            __pyx_t_18 = __pyx_t_17;
            goto __pyx_L26_bool_binop_done;
          }
          __pyx_t_13 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_10035, 0x2733, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 903, __pyx_L13_except_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 903, __pyx_L13_except_error)
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_18 = __pyx_t_17;
          __pyx_L26_bool_binop_done:;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_17 = (__pyx_t_18 != 0);
          if (likely(__pyx_t_17)) {
            goto __pyx_L21;
          }

          /* "btdht/dht.pyx":906
 *                     pass
 *                 else:
 *                     self.debug(0, "send:%r %r" % (e, addr) )             # <<<<<<<<<<<<<<
 *                     raise
 *         except Queue.Empty:
 */
          /*else*/ {
            __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 906, __pyx_L13_except_error)
            __Pyx_GOTREF(__pyx_t_13);
            __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 906, __pyx_L13_except_error)
            __Pyx_GOTREF(__pyx_t_14);
            __Pyx_INCREF(__pyx_v_e);
            __Pyx_GIVEREF(__pyx_v_e);
            PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_e);
            __Pyx_INCREF(__pyx_v_addr);
            __Pyx_GIVEREF(__pyx_v_addr);
            PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_v_addr);
            __pyx_t_15 = __Pyx_PyString_Format(__pyx_kp_s_send_r_r, __pyx_t_14); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 906, __pyx_L13_except_error)
            __Pyx_GOTREF(__pyx_t_15);
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
            __pyx_t_14 = NULL;
            __pyx_t_12 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
              __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_13);
              if (likely(__pyx_t_14)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
                __Pyx_INCREF(__pyx_t_14);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_13, function);
                __pyx_t_12 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_13)) {
              PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_int_0, __pyx_t_15};
              __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 906, __pyx_L13_except_error)
              __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) {
              PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_int_0, __pyx_t_15};
              __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 906, __pyx_L13_except_error)
              __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            } else
            #endif
            {
              __pyx_t_16 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 906, __pyx_L13_except_error)
              __Pyx_GOTREF(__pyx_t_16);
              if (__pyx_t_14) {
                __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_14); __pyx_t_14 = NULL;
              }
              __Pyx_INCREF(__pyx_int_0);
              __Pyx_GIVEREF(__pyx_int_0);
              PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_12, __pyx_int_0);
              __Pyx_GIVEREF(__pyx_t_15);
              PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_12, __pyx_t_15);
              __pyx_t_15 = 0;
              __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_16, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 906, __pyx_L13_except_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
            }
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

            /* "btdht/dht.pyx":907
 *                 else:
 *                     self.debug(0, "send:%r %r" % (e, addr) )
 *                     raise             # <<<<<<<<<<<<<<
 *         except Queue.Empty:
 *             pass
 */
            __Pyx_GIVEREF(__pyx_t_7);
            __Pyx_GIVEREF(__pyx_t_4);
            __Pyx_XGIVEREF(__pyx_t_6);
            __Pyx_ErrRestoreWithState(__pyx_t_7, __pyx_t_4, __pyx_t_6);
            __pyx_t_7 = 0; __pyx_t_4 = 0; __pyx_t_6 = 0; 
            __PYX_ERR(0, 907, __pyx_L13_except_error)
          }
          __pyx_L21:;
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          goto __pyx_L12_exception_handled;
        }
        goto __pyx_L13_except_error;
        __pyx_L13_except_error:;

        /* "btdht/dht.pyx":888
 *         try:
 *             (msg, addr) = self.to_send.get_nowait()
 *             try:             # <<<<<<<<<<<<<<
 *                 self.sock.sendto(msg, addr)
 *                 self._socket_out+=1
 */
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        goto __pyx_L3_error;
        __pyx_L12_exception_handled:;
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        __pyx_L16_try_end:;
      }

      /* "btdht/dht.pyx":886
 *             in the send queue and then :attr:`sock` is ready for a write.
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             (msg, addr) = self.to_send.get_nowait()
 *             try:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "btdht/dht.pyx":908
 *                     self.debug(0, "send:%r %r" % (e, addr) )
 *                     raise
 *         except Queue.Empty:             # <<<<<<<<<<<<<<
 *             pass
 * 
 */
    __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_4, &__pyx_t_7);
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_Queue); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 908, __pyx_L5_except_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_Empty); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 908, __pyx_L5_except_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_12 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_6, __pyx_t_13);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_ErrRestore(__pyx_t_6, __pyx_t_4, __pyx_t_7);
    __pyx_t_6 = 0; __pyx_t_4 = 0; __pyx_t_7 = 0;
    if (__pyx_t_12) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "btdht/dht.pyx":886
 *             in the send queue and then :attr:`sock` is ready for a write.
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             (msg, addr) = self.to_send.get_nowait()
 *             try:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L4_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    __pyx_L8_try_end:;
  }

  /* "btdht/dht.pyx":880
 *         self.to_send.put((msg, addr))
 * 
 *     def _process_outgoing_message(self):             # <<<<<<<<<<<<<<
 *         """
 *             Process a new outgoing message. The message is retrieved from the queue :attr:`to_send`
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_outgoing_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_addr);
  __Pyx_XDECREF(__pyx_v_e);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":911
 *             pass
 * 
 *     def _process_incoming_message(self):             # <<<<<<<<<<<<<<
 *         """
 *             Process a new incoming message. The message is read from :attr:`sock`, so this
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_46_process_incoming_message(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_45_process_incoming_message[] = "\n            Process a new incoming message. The message is read from :attr:`sock`, so this\n            method should only be called when :attr:`sock` is ready for a read.\n\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_46_process_incoming_message(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_process_incoming_message (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_45_process_incoming_message(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_45_process_incoming_message(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  PyObject *__pyx_v_data = NULL;
  PyObject *__pyx_v_addr = NULL;
  PyObject *__pyx_v_obj = NULL;
  PyObject *__pyx_v_obj_opt = NULL;
  PyObject *__pyx_v_reponse = NULL;
  PyObject *__pyx_v_error = NULL;
  PyObject *__pyx_v_e = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *(*__pyx_t_8)(PyObject *);
  int __pyx_t_9;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  Py_ssize_t __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  PyObject *__pyx_t_21 = NULL;
  PyObject *__pyx_t_22 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_process_incoming_message", 0);

  /* "btdht/dht.pyx":917
 * 
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             data, addr = self.sock.recvfrom(4048)
 *             if addr[0] in self.ignored_ip:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "btdht/dht.pyx":918
 *         """
 *         try:
 *             data, addr = self.sock.recvfrom(4048)             # <<<<<<<<<<<<<<
 *             if addr[0] in self.ignored_ip:
 *                 return
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sock); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 918, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_recvfrom); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 918, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_int_4048) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_int_4048);
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 918, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
        PyObject* sequence = __pyx_t_4;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 918, __pyx_L3_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        #else
        __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 918, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 918, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 918, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext;
        index = 0; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_6);
        index = 1; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_5);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 918, __pyx_L3_error)
        __pyx_t_8 = NULL;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        goto __pyx_L10_unpacking_done;
        __pyx_L9_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_8 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 918, __pyx_L3_error)
        __pyx_L10_unpacking_done:;
      }
      __pyx_v_data = __pyx_t_6;
      __pyx_t_6 = 0;
      __pyx_v_addr = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "btdht/dht.pyx":919
 *         try:
 *             data, addr = self.sock.recvfrom(4048)
 *             if addr[0] in self.ignored_ip:             # <<<<<<<<<<<<<<
 *                 return
 *             elif utils.ip_in_nets(addr[0], self.ignored_net):
 */
      __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_addr, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 919, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ignored_ip); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 919, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_9 = (__Pyx_PySequence_ContainsTF(__pyx_t_4, __pyx_t_5, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 919, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_10 = (__pyx_t_9 != 0);
      if (__pyx_t_10) {

        /* "btdht/dht.pyx":920
 *             data, addr = self.sock.recvfrom(4048)
 *             if addr[0] in self.ignored_ip:
 *                 return             # <<<<<<<<<<<<<<
 *             elif utils.ip_in_nets(addr[0], self.ignored_net):
 *                 return
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        goto __pyx_L7_try_return;

        /* "btdht/dht.pyx":919
 *         try:
 *             data, addr = self.sock.recvfrom(4048)
 *             if addr[0] in self.ignored_ip:             # <<<<<<<<<<<<<<
 *                 return
 *             elif utils.ip_in_nets(addr[0], self.ignored_net):
 */
      }

      /* "btdht/dht.pyx":921
 *             if addr[0] in self.ignored_ip:
 *                 return
 *             elif utils.ip_in_nets(addr[0], self.ignored_net):             # <<<<<<<<<<<<<<
 *                 return
 *             elif addr[1] < 1 or addr[1] > 65535:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_utils); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 921, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ip_in_nets); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 921, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_addr, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 921, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ignored_net); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 921, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_11 = NULL;
      __pyx_t_12 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_11)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
          __pyx_t_12 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_t_4, __pyx_t_7};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 921, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_t_4, __pyx_t_7};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 921, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else
      #endif
      {
        __pyx_t_13 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 921, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_13);
        if (__pyx_t_11) {
          __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __pyx_t_11 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_12, __pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_12, __pyx_t_7);
        __pyx_t_4 = 0;
        __pyx_t_7 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_13, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 921, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 921, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_10) {

        /* "btdht/dht.pyx":922
 *                 return
 *             elif utils.ip_in_nets(addr[0], self.ignored_net):
 *                 return             # <<<<<<<<<<<<<<
 *             elif addr[1] < 1 or addr[1] > 65535:
 *                 self.debug(1, "Port should be whithin 1 and 65535, not %s" % addr[1])
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        goto __pyx_L7_try_return;

        /* "btdht/dht.pyx":921
 *             if addr[0] in self.ignored_ip:
 *                 return
 *             elif utils.ip_in_nets(addr[0], self.ignored_net):             # <<<<<<<<<<<<<<
 *                 return
 *             elif addr[1] < 1 or addr[1] > 65535:
 */
      }

      /* "btdht/dht.pyx":923
 *             elif utils.ip_in_nets(addr[0], self.ignored_net):
 *                 return
 *             elif addr[1] < 1 or addr[1] > 65535:             # <<<<<<<<<<<<<<
 *                 self.debug(1, "Port should be whithin 1 and 65535, not %s" % addr[1])
 *                 return
 */
      __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_addr, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 923, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyObject_RichCompare(__pyx_t_5, __pyx_int_1, Py_LT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 923, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 923, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (!__pyx_t_9) {
      } else {
        __pyx_t_10 = __pyx_t_9;
        goto __pyx_L12_bool_binop_done;
      }
      __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_addr, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 923, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = PyObject_RichCompare(__pyx_t_6, __pyx_int_65535, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 923, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 923, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_10 = __pyx_t_9;
      __pyx_L12_bool_binop_done:;
      if (__pyx_t_10) {

        /* "btdht/dht.pyx":924
 *                 return
 *             elif addr[1] < 1 or addr[1] > 65535:
 *                 self.debug(1, "Port should be whithin 1 and 65535, not %s" % addr[1])             # <<<<<<<<<<<<<<
 *                 return
 *             elif len(data) < 20:
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 924, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_13 = __Pyx_GetItemInt(__pyx_v_addr, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 924, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_13);
        __pyx_t_7 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Port_should_be_whithin_1_and_655, __pyx_t_13); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 924, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_13 = NULL;
        __pyx_t_12 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_13)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
            __pyx_t_12 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_int_1, __pyx_t_7};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 924, __pyx_L3_error)
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_int_1, __pyx_t_7};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 924, __pyx_L3_error)
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        } else
        #endif
        {
          __pyx_t_4 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 924, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_4);
          if (__pyx_t_13) {
            __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_13); __pyx_t_13 = NULL;
          }
          __Pyx_INCREF(__pyx_int_1);
          __Pyx_GIVEREF(__pyx_int_1);
          PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_12, __pyx_int_1);
          __Pyx_GIVEREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_12, __pyx_t_7);
          __pyx_t_7 = 0;
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 924, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        }
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "btdht/dht.pyx":925
 *             elif addr[1] < 1 or addr[1] > 65535:
 *                 self.debug(1, "Port should be whithin 1 and 65535, not %s" % addr[1])
 *                 return             # <<<<<<<<<<<<<<
 *             elif len(data) < 20:
 *                 return
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        goto __pyx_L7_try_return;

        /* "btdht/dht.pyx":923
 *             elif utils.ip_in_nets(addr[0], self.ignored_net):
 *                 return
 *             elif addr[1] < 1 or addr[1] > 65535:             # <<<<<<<<<<<<<<
 *                 self.debug(1, "Port should be whithin 1 and 65535, not %s" % addr[1])
 *                 return
 */
      }

      /* "btdht/dht.pyx":926
 *                 self.debug(1, "Port should be whithin 1 and 65535, not %s" % addr[1])
 *                 return
 *             elif len(data) < 20:             # <<<<<<<<<<<<<<
 *                 return
 *             else:
 */
      __pyx_t_14 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_14 == ((Py_ssize_t)-1))) __PYX_ERR(0, 926, __pyx_L3_error)
      __pyx_t_10 = ((__pyx_t_14 < 20) != 0);
      if (__pyx_t_10) {

        /* "btdht/dht.pyx":927
 *                 return
 *             elif len(data) < 20:
 *                 return             # <<<<<<<<<<<<<<
 *             else:
 *                 # Building python object from bencoded data
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        goto __pyx_L7_try_return;

        /* "btdht/dht.pyx":926
 *                 self.debug(1, "Port should be whithin 1 and 65535, not %s" % addr[1])
 *                 return
 *             elif len(data) < 20:             # <<<<<<<<<<<<<<
 *                 return
 *             else:
 */
      }

      /* "btdht/dht.pyx":930
 *             else:
 *                 # Building python object from bencoded data
 *                 obj, obj_opt = self._decode(data, addr)             # <<<<<<<<<<<<<<
 *                 # Update sender node in routing table
 *                 try:
 */
      /*else*/ {
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_decode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 930, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_4 = NULL;
        __pyx_t_12 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
            __pyx_t_12 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_data, __pyx_v_addr};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 930, __pyx_L3_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_5);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_data, __pyx_v_addr};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 930, __pyx_L3_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_5);
        } else
        #endif
        {
          __pyx_t_7 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 930, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          if (__pyx_t_4) {
            __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL;
          }
          __Pyx_INCREF(__pyx_v_data);
          __Pyx_GIVEREF(__pyx_v_data);
          PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_12, __pyx_v_data);
          __Pyx_INCREF(__pyx_v_addr);
          __Pyx_GIVEREF(__pyx_v_addr);
          PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_12, __pyx_v_addr);
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 930, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        }
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
          PyObject* sequence = __pyx_t_5;
          Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
          if (unlikely(size != 2)) {
            if (size > 2) __Pyx_RaiseTooManyValuesError(2);
            else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
            __PYX_ERR(0, 930, __pyx_L3_error)
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          if (likely(PyTuple_CheckExact(sequence))) {
            __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
            __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_7);
          #else
          __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 930, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 930, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          #endif
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        } else {
          Py_ssize_t index = -1;
          __pyx_t_4 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 930, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext;
          index = 0; __pyx_t_6 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L14_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_6);
          index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_4); if (unlikely(!__pyx_t_7)) goto __pyx_L14_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_7);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_4), 2) < 0) __PYX_ERR(0, 930, __pyx_L3_error)
          __pyx_t_8 = NULL;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          goto __pyx_L15_unpacking_done;
          __pyx_L14_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_8 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          __PYX_ERR(0, 930, __pyx_L3_error)
          __pyx_L15_unpacking_done:;
        }
        __pyx_v_obj = __pyx_t_6;
        __pyx_t_6 = 0;
        __pyx_v_obj_opt = __pyx_t_7;
        __pyx_t_7 = 0;

        /* "btdht/dht.pyx":932
 *                 obj, obj_opt = self._decode(data, addr)
 *                 # Update sender node in routing table
 *                 try:             # <<<<<<<<<<<<<<
 *                     self._update_node(obj)
 *                 except TypeError:
 */
        {
          __Pyx_PyThreadState_declare
          __Pyx_PyThreadState_assign
          __Pyx_ExceptionSave(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
          __Pyx_XGOTREF(__pyx_t_15);
          __Pyx_XGOTREF(__pyx_t_16);
          __Pyx_XGOTREF(__pyx_t_17);
          /*try:*/ {

            /* "btdht/dht.pyx":933
 *                 # Update sender node in routing table
 *                 try:
 *                     self._update_node(obj)             # <<<<<<<<<<<<<<
 *                 except TypeError:
 *                     print("TypeError: %r in _recv_loop" % obj)
 */
            __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_update_node); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 933, __pyx_L16_error)
            __Pyx_GOTREF(__pyx_t_7);
            __pyx_t_6 = NULL;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
              __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
              if (likely(__pyx_t_6)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
                __Pyx_INCREF(__pyx_t_6);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_7, function);
              }
            }
            __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_6, __pyx_v_obj) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_obj);
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 933, __pyx_L16_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

            /* "btdht/dht.pyx":932
 *                 obj, obj_opt = self._decode(data, addr)
 *                 # Update sender node in routing table
 *                 try:             # <<<<<<<<<<<<<<
 *                     self._update_node(obj)
 *                 except TypeError:
 */
          }
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
          goto __pyx_L21_try_end;
          __pyx_L16_error:;
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "btdht/dht.pyx":934
 *                 try:
 *                     self._update_node(obj)
 *                 except TypeError:             # <<<<<<<<<<<<<<
 *                     print("TypeError: %r in _recv_loop" % obj)
 *                     raise
 */
          __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError);
          if (__pyx_t_12) {
            __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_incoming_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
            if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_7, &__pyx_t_6) < 0) __PYX_ERR(0, 934, __pyx_L18_except_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_GOTREF(__pyx_t_6);

            /* "btdht/dht.pyx":935
 *                     self._update_node(obj)
 *                 except TypeError:
 *                     print("TypeError: %r in _recv_loop" % obj)             # <<<<<<<<<<<<<<
 *                     raise
 *                 # On query
 */
            __pyx_t_4 = __Pyx_PyString_FormatSafe(__pyx_kp_s_TypeError_r_in__recv_loop, __pyx_v_obj); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 935, __pyx_L18_except_error)
            __Pyx_GOTREF(__pyx_t_4);
            if (__Pyx_PrintOne(0, __pyx_t_4) < 0) __PYX_ERR(0, 935, __pyx_L18_except_error)
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

            /* "btdht/dht.pyx":936
 *                 except TypeError:
 *                     print("TypeError: %r in _recv_loop" % obj)
 *                     raise             # <<<<<<<<<<<<<<
 *                 # On query
 *                 if obj.y == b"q":
 */
            __Pyx_GIVEREF(__pyx_t_5);
            __Pyx_GIVEREF(__pyx_t_7);
            __Pyx_XGIVEREF(__pyx_t_6);
            __Pyx_ErrRestoreWithState(__pyx_t_5, __pyx_t_7, __pyx_t_6);
            __pyx_t_5 = 0; __pyx_t_7 = 0; __pyx_t_6 = 0; 
            __PYX_ERR(0, 936, __pyx_L18_except_error)
          }
          goto __pyx_L18_except_error;
          __pyx_L18_except_error:;

          /* "btdht/dht.pyx":932
 *                 obj, obj_opt = self._decode(data, addr)
 *                 # Update sender node in routing table
 *                 try:             # <<<<<<<<<<<<<<
 *                     self._update_node(obj)
 *                 except TypeError:
 */
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_XGIVEREF(__pyx_t_16);
          __Pyx_XGIVEREF(__pyx_t_17);
          __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_16, __pyx_t_17);
          goto __pyx_L3_error;
          __pyx_L21_try_end:;
        }

        /* "btdht/dht.pyx":938
 *                     raise
 *                 # On query
 *                 if obj.y == b"q":             # <<<<<<<<<<<<<<
 *                     # process the query
 *                     self._process_query(obj)
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_y); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 938, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_10 = (__Pyx_PyBytes_Equals(__pyx_t_6, __pyx_n_b_q, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 938, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__pyx_t_10) {

          /* "btdht/dht.pyx":940
 *                 if obj.y == b"q":
 *                     # process the query
 *                     self._process_query(obj)             # <<<<<<<<<<<<<<
 *                     # build the response object
 *                     reponse = obj.response(self)
 */
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_process_query); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 940, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_5 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
            __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7);
            if (likely(__pyx_t_5)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
              __Pyx_INCREF(__pyx_t_5);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_7, function);
            }
          }
          __pyx_t_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_5, __pyx_v_obj) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_obj);
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 940, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

          /* "btdht/dht.pyx":942
 *                     self._process_query(obj)
 *                     # build the response object
 *                     reponse = obj.response(self)             # <<<<<<<<<<<<<<
 * 
 *                     self._socket_in+=1
 */
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_response); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 942, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_5 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
            __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7);
            if (likely(__pyx_t_5)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
              __Pyx_INCREF(__pyx_t_5);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_7, function);
            }
          }
          __pyx_t_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_5, ((PyObject *)__pyx_v_self)) : __Pyx_PyObject_CallOneArg(__pyx_t_7, ((PyObject *)__pyx_v_self));
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 942, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_v_reponse = __pyx_t_6;
          __pyx_t_6 = 0;

          /* "btdht/dht.pyx":944
 *                     reponse = obj.response(self)
 * 
 *                     self._socket_in+=1             # <<<<<<<<<<<<<<
 *                     self.last_msg = time.time()
 * 
 */
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_in); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 944, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_6, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 944, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_in, __pyx_t_7) < 0) __PYX_ERR(0, 944, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "btdht/dht.pyx":945
 * 
 *                     self._socket_in+=1
 *                     self.last_msg = time.time()             # <<<<<<<<<<<<<<
 * 
 *                     # send it
 */
          __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 945, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 945, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_6)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_6);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
            }
          }
          __pyx_t_7 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 945, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_msg, __pyx_t_7) < 0) __PYX_ERR(0, 945, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "btdht/dht.pyx":948
 * 
 *                     # send it
 *                     self.sendto(reponse.encode(), addr)             # <<<<<<<<<<<<<<
 *                 # on response
 *                 elif obj.y == b"r":
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sendto); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 948, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_reponse, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 948, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_13 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
            __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_4);
            if (likely(__pyx_t_13)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_13);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_4, function);
            }
          }
          __pyx_t_6 = (__pyx_t_13) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_13) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 948, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_4 = NULL;
          __pyx_t_12 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_4)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_4);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
              __pyx_t_12 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_5)) {
            PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_6, __pyx_v_addr};
            __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 948, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
            PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_6, __pyx_v_addr};
            __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 948, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          } else
          #endif
          {
            __pyx_t_13 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 948, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_13);
            if (__pyx_t_4) {
              __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_4); __pyx_t_4 = NULL;
            }
            __Pyx_GIVEREF(__pyx_t_6);
            PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_12, __pyx_t_6);
            __Pyx_INCREF(__pyx_v_addr);
            __Pyx_GIVEREF(__pyx_v_addr);
            PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_12, __pyx_v_addr);
            __pyx_t_6 = 0;
            __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_13, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 948, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          }
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "btdht/dht.pyx":938
 *                     raise
 *                 # On query
 *                 if obj.y == b"q":             # <<<<<<<<<<<<<<
 *                     # process the query
 *                     self._process_query(obj)
 */
          goto __pyx_L24;
        }

        /* "btdht/dht.pyx":950
 *                     self.sendto(reponse.encode(), addr)
 *                 # on response
 *                 elif obj.y == b"r":             # <<<<<<<<<<<<<<
 *                     # process the response
 *                     try:
 */
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_y); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 950, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_10 = (__Pyx_PyBytes_Equals(__pyx_t_7, __pyx_n_b_r, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 950, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (__pyx_t_10) {

          /* "btdht/dht.pyx":952
 *                 elif obj.y == b"r":
 *                     # process the response
 *                     try:             # <<<<<<<<<<<<<<
 *                         self._process_response(obj, obj_opt)
 *                     except ValueError as error:
 */
          {
            __Pyx_PyThreadState_declare
            __Pyx_PyThreadState_assign
            __Pyx_ExceptionSave(&__pyx_t_17, &__pyx_t_16, &__pyx_t_15);
            __Pyx_XGOTREF(__pyx_t_17);
            __Pyx_XGOTREF(__pyx_t_16);
            __Pyx_XGOTREF(__pyx_t_15);
            /*try:*/ {

              /* "btdht/dht.pyx":953
 *                     # process the response
 *                     try:
 *                         self._process_response(obj, obj_opt)             # <<<<<<<<<<<<<<
 *                     except ValueError as error:
 *                         raise ProtocolError(obj.t, error.args[0])
 */
              __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_process_response); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 953, __pyx_L25_error)
              __Pyx_GOTREF(__pyx_t_5);
              __pyx_t_13 = NULL;
              __pyx_t_12 = 0;
              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
                __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_5);
                if (likely(__pyx_t_13)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
                  __Pyx_INCREF(__pyx_t_13);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_5, function);
                  __pyx_t_12 = 1;
                }
              }
              #if CYTHON_FAST_PYCALL
              if (PyFunction_Check(__pyx_t_5)) {
                PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_obj, __pyx_v_obj_opt};
                __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 953, __pyx_L25_error)
                __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
                __Pyx_GOTREF(__pyx_t_7);
              } else
              #endif
              #if CYTHON_FAST_PYCCALL
              if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
                PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_obj, __pyx_v_obj_opt};
                __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 953, __pyx_L25_error)
                __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
                __Pyx_GOTREF(__pyx_t_7);
              } else
              #endif
              {
                __pyx_t_6 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 953, __pyx_L25_error)
                __Pyx_GOTREF(__pyx_t_6);
                if (__pyx_t_13) {
                  __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_13); __pyx_t_13 = NULL;
                }
                __Pyx_INCREF(__pyx_v_obj);
                __Pyx_GIVEREF(__pyx_v_obj);
                PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_12, __pyx_v_obj);
                __Pyx_INCREF(__pyx_v_obj_opt);
                __Pyx_GIVEREF(__pyx_v_obj_opt);
                PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_12, __pyx_v_obj_opt);
                __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 953, __pyx_L25_error)
                __Pyx_GOTREF(__pyx_t_7);
                __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
              }
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

              /* "btdht/dht.pyx":952
 *                 elif obj.y == b"r":
 *                     # process the response
 *                     try:             # <<<<<<<<<<<<<<
 *                         self._process_response(obj, obj_opt)
 *                     except ValueError as error:
 */
            }
            __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
            __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
            __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
            goto __pyx_L30_try_end;
            __pyx_L25_error:;
            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

            /* "btdht/dht.pyx":954
 *                     try:
 *                         self._process_response(obj, obj_opt)
 *                     except ValueError as error:             # <<<<<<<<<<<<<<
 *                         raise ProtocolError(obj.t, error.args[0])
 * 
 */
            __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
            if (__pyx_t_12) {
              __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_incoming_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
              if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_5, &__pyx_t_6) < 0) __PYX_ERR(0, 954, __pyx_L27_except_error)
              __Pyx_GOTREF(__pyx_t_7);
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_INCREF(__pyx_t_5);
              __pyx_v_error = __pyx_t_5;

              /* "btdht/dht.pyx":955
 *                         self._process_response(obj, obj_opt)
 *                     except ValueError as error:
 *                         raise ProtocolError(obj.t, error.args[0])             # <<<<<<<<<<<<<<
 * 
 *                     self._socket_in+=1
 */
              __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ProtocolError); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 955, __pyx_L27_except_error)
              __Pyx_GOTREF(__pyx_t_4);
              __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_t); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 955, __pyx_L27_except_error)
              __Pyx_GOTREF(__pyx_t_11);
              __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_v_error, __pyx_n_s_args); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 955, __pyx_L27_except_error)
              __Pyx_GOTREF(__pyx_t_18);
              __pyx_t_19 = __Pyx_GetItemInt(__pyx_t_18, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 955, __pyx_L27_except_error)
              __Pyx_GOTREF(__pyx_t_19);
              __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
              __pyx_t_18 = NULL;
              __pyx_t_12 = 0;
              if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
                __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_4);
                if (likely(__pyx_t_18)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
                  __Pyx_INCREF(__pyx_t_18);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_4, function);
                  __pyx_t_12 = 1;
                }
              }
              #if CYTHON_FAST_PYCALL
              if (PyFunction_Check(__pyx_t_4)) {
                PyObject *__pyx_temp[3] = {__pyx_t_18, __pyx_t_11, __pyx_t_19};
                __pyx_t_13 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 955, __pyx_L27_except_error)
                __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
                __Pyx_GOTREF(__pyx_t_13);
                __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
                __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
              } else
              #endif
              #if CYTHON_FAST_PYCCALL
              if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
                PyObject *__pyx_temp[3] = {__pyx_t_18, __pyx_t_11, __pyx_t_19};
                __pyx_t_13 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 955, __pyx_L27_except_error)
                __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
                __Pyx_GOTREF(__pyx_t_13);
                __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
                __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
              } else
              #endif
              {
                __pyx_t_20 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 955, __pyx_L27_except_error)
                __Pyx_GOTREF(__pyx_t_20);
                if (__pyx_t_18) {
                  __Pyx_GIVEREF(__pyx_t_18); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_18); __pyx_t_18 = NULL;
                }
                __Pyx_GIVEREF(__pyx_t_11);
                PyTuple_SET_ITEM(__pyx_t_20, 0+__pyx_t_12, __pyx_t_11);
                __Pyx_GIVEREF(__pyx_t_19);
                PyTuple_SET_ITEM(__pyx_t_20, 1+__pyx_t_12, __pyx_t_19);
                __pyx_t_11 = 0;
                __pyx_t_19 = 0;
                __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_20, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 955, __pyx_L27_except_error)
                __Pyx_GOTREF(__pyx_t_13);
                __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
              }
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              __Pyx_Raise(__pyx_t_13, 0, 0, 0);
              __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
              __PYX_ERR(0, 955, __pyx_L27_except_error)
            }
            goto __pyx_L27_except_error;
            __pyx_L27_except_error:;

            /* "btdht/dht.pyx":952
 *                 elif obj.y == b"r":
 *                     # process the response
 *                     try:             # <<<<<<<<<<<<<<
 *                         self._process_response(obj, obj_opt)
 *                     except ValueError as error:
 */
            __Pyx_XGIVEREF(__pyx_t_17);
            __Pyx_XGIVEREF(__pyx_t_16);
            __Pyx_XGIVEREF(__pyx_t_15);
            __Pyx_ExceptionReset(__pyx_t_17, __pyx_t_16, __pyx_t_15);
            goto __pyx_L3_error;
            __pyx_L30_try_end:;
          }

          /* "btdht/dht.pyx":957
 *                         raise ProtocolError(obj.t, error.args[0])
 * 
 *                     self._socket_in+=1             # <<<<<<<<<<<<<<
 *                     self.last_msg = time.time()
 *                     self.last_msg_rep = time.time()
 */
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_in); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 957, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_5 = __Pyx_PyInt_AddObjC(__pyx_t_6, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 957, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_socket_in, __pyx_t_5) < 0) __PYX_ERR(0, 957, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

          /* "btdht/dht.pyx":958
 * 
 *                     self._socket_in+=1
 *                     self.last_msg = time.time()             # <<<<<<<<<<<<<<
 *                     self.last_msg_rep = time.time()
 *                 # on error
 */
          __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 958, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 958, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
            __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
            if (likely(__pyx_t_6)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
              __Pyx_INCREF(__pyx_t_6);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_7, function);
            }
          }
          __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 958, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_msg, __pyx_t_5) < 0) __PYX_ERR(0, 958, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

          /* "btdht/dht.pyx":959
 *                     self._socket_in+=1
 *                     self.last_msg = time.time()
 *                     self.last_msg_rep = time.time()             # <<<<<<<<<<<<<<
 *                 # on error
 *                 elif obj.y == b"e":
 */
          __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_time); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 959, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 959, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
            __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
            if (likely(__pyx_t_7)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
              __Pyx_INCREF(__pyx_t_7);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_6, function);
            }
          }
          __pyx_t_5 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 959, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_msg_rep, __pyx_t_5) < 0) __PYX_ERR(0, 959, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

          /* "btdht/dht.pyx":950
 *                     self.sendto(reponse.encode(), addr)
 *                 # on response
 *                 elif obj.y == b"r":             # <<<<<<<<<<<<<<
 *                     # process the response
 *                     try:
 */
          goto __pyx_L24;
        }

        /* "btdht/dht.pyx":961
 *                     self.last_msg_rep = time.time()
 *                 # on error
 *                 elif obj.y == b"e":             # <<<<<<<<<<<<<<
 *                     # process it
 *                     self._process_error(obj, obj_opt)
 */
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_y); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 961, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_10 = (__Pyx_PyBytes_Equals(__pyx_t_5, __pyx_n_b_e, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 961, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (__pyx_t_10) {

          /* "btdht/dht.pyx":963
 *                 elif obj.y == b"e":
 *                     # process it
 *                     self._process_error(obj, obj_opt)             # <<<<<<<<<<<<<<
 *         # if we raised a BError, send it
 *         except (BError,) as error:
 */
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_process_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 963, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_7 = NULL;
          __pyx_t_12 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
            __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
            if (likely(__pyx_t_7)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
              __Pyx_INCREF(__pyx_t_7);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_6, function);
              __pyx_t_12 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_obj, __pyx_v_obj_opt};
            __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 963, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_GOTREF(__pyx_t_5);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_obj, __pyx_v_obj_opt};
            __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 963, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_GOTREF(__pyx_t_5);
          } else
          #endif
          {
            __pyx_t_13 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 963, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_13);
            if (__pyx_t_7) {
              __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_7); __pyx_t_7 = NULL;
            }
            __Pyx_INCREF(__pyx_v_obj);
            __Pyx_GIVEREF(__pyx_v_obj);
            PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_12, __pyx_v_obj);
            __Pyx_INCREF(__pyx_v_obj_opt);
            __Pyx_GIVEREF(__pyx_v_obj_opt);
            PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_12, __pyx_v_obj_opt);
            __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_13, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 963, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          }
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

          /* "btdht/dht.pyx":961
 *                     self.last_msg_rep = time.time()
 *                 # on error
 *                 elif obj.y == b"e":             # <<<<<<<<<<<<<<
 *                     # process it
 *                     self._process_error(obj, obj_opt)
 */
        }
        __pyx_L24:;
      }

      /* "btdht/dht.pyx":917
 * 
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             data, addr = self.sock.recvfrom(4048)
 *             if addr[0] in self.ignored_ip:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
    __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
    __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "btdht/dht.pyx":965
 *                     self._process_error(obj, obj_opt)
 *         # if we raised a BError, send it
 *         except (BError,) as error:             # <<<<<<<<<<<<<<
 *             if self.debuglvl > 1:
 *                 traceback.print_exc()
 */
    __Pyx_ErrFetch(&__pyx_t_5, &__pyx_t_6, &__pyx_t_13);
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_BError); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 965, __pyx_L5_except_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_12 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_5, __pyx_t_7);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_ErrRestore(__pyx_t_5, __pyx_t_6, __pyx_t_13);
    __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_13 = 0;
    if (__pyx_t_12) {
      __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_incoming_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_13, &__pyx_t_6, &__pyx_t_5) < 0) __PYX_ERR(0, 965, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_XDECREF_SET(__pyx_v_error, __pyx_t_6);

      /* "btdht/dht.pyx":966
 *         # if we raised a BError, send it
 *         except (BError,) as error:
 *             if self.debuglvl > 1:             # <<<<<<<<<<<<<<
 *                 traceback.print_exc()
 *                 self.debug(2, "error %r" % error)
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debuglvl); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 966, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_4 = PyObject_RichCompare(__pyx_t_7, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 966, __pyx_L5_except_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 966, __pyx_L5_except_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_10) {

        /* "btdht/dht.pyx":967
 *         except (BError,) as error:
 *             if self.debuglvl > 1:
 *                 traceback.print_exc()             # <<<<<<<<<<<<<<
 *                 self.debug(2, "error %r" % error)
 *             self.sendto(error.encode(), addr)
 */
        __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_traceback); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 967, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_print_exc); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 967, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_20);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_20);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_20, function);
          }
        }
        __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_20, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_20);
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 967, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "btdht/dht.pyx":968
 *             if self.debuglvl > 1:
 *                 traceback.print_exc()
 *                 self.debug(2, "error %r" % error)             # <<<<<<<<<<<<<<
 *             self.sendto(error.encode(), addr)
 *         # socket unavailable ?
 */
        __pyx_t_20 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 968, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_20);
        __pyx_t_7 = __Pyx_PyString_FormatSafe(__pyx_kp_s_error_r, __pyx_v_error); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 968, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_19 = NULL;
        __pyx_t_12 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_20))) {
          __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_20);
          if (likely(__pyx_t_19)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20);
            __Pyx_INCREF(__pyx_t_19);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_20, function);
            __pyx_t_12 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_20)) {
          PyObject *__pyx_temp[3] = {__pyx_t_19, __pyx_int_2, __pyx_t_7};
          __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 968, __pyx_L5_except_error)
          __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_20)) {
          PyObject *__pyx_temp[3] = {__pyx_t_19, __pyx_int_2, __pyx_t_7};
          __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 968, __pyx_L5_except_error)
          __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        } else
        #endif
        {
          __pyx_t_11 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 968, __pyx_L5_except_error)
          __Pyx_GOTREF(__pyx_t_11);
          if (__pyx_t_19) {
            __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_19); __pyx_t_19 = NULL;
          }
          __Pyx_INCREF(__pyx_int_2);
          __Pyx_GIVEREF(__pyx_int_2);
          PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_12, __pyx_int_2);
          __Pyx_GIVEREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_12, __pyx_t_7);
          __pyx_t_7 = 0;
          __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 968, __pyx_L5_except_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        }
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "btdht/dht.pyx":966
 *         # if we raised a BError, send it
 *         except (BError,) as error:
 *             if self.debuglvl > 1:             # <<<<<<<<<<<<<<
 *                 traceback.print_exc()
 *                 self.debug(2, "error %r" % error)
 */
      }

      /* "btdht/dht.pyx":969
 *                 traceback.print_exc()
 *                 self.debug(2, "error %r" % error)
 *             self.sendto(error.encode(), addr)             # <<<<<<<<<<<<<<
 *         # socket unavailable ?
 *         except socket.error as e:
 */
      __pyx_t_20 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_sendto); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 969, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_20);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_error, __pyx_n_s_encode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 969, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_19 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_19)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_19);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
        }
      }
      __pyx_t_11 = (__pyx_t_19) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_19) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
      if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 969, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_v_addr)) { __Pyx_RaiseUnboundLocalError("addr"); __PYX_ERR(0, 969, __pyx_L5_except_error) }
      __pyx_t_7 = NULL;
      __pyx_t_12 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_20))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_20);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_20, function);
          __pyx_t_12 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_20)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_11, __pyx_v_addr};
        __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 969, __pyx_L5_except_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_20)) {
        PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_11, __pyx_v_addr};
        __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 969, __pyx_L5_except_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      } else
      #endif
      {
        __pyx_t_19 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 969, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_19);
        if (__pyx_t_7) {
          __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_7); __pyx_t_7 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_12, __pyx_t_11);
        __Pyx_INCREF(__pyx_v_addr);
        __Pyx_GIVEREF(__pyx_v_addr);
        PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_12, __pyx_v_addr);
        __pyx_t_11 = 0;
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_19, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 969, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      }
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L4_exception_handled;
    }

    /* "btdht/dht.pyx":971
 *             self.sendto(error.encode(), addr)
 *         # socket unavailable ?
 *         except socket.error as e:             # <<<<<<<<<<<<<<
 *             # 11: Resource temporarily unavailable
 *             # 10035: same as 11 but on windows
 */
    __Pyx_ErrFetch(&__pyx_t_5, &__pyx_t_6, &__pyx_t_13);
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_socket); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 971, __pyx_L5_except_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_error); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 971, __pyx_L5_except_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_12 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_5, __pyx_t_20);
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_ErrRestore(__pyx_t_5, __pyx_t_6, __pyx_t_13);
    __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_13 = 0;
    if (__pyx_t_12) {
      __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_incoming_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_13, &__pyx_t_6, &__pyx_t_5) < 0) __PYX_ERR(0, 971, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __pyx_v_e = __pyx_t_6;

      /* "btdht/dht.pyx":976
 *             # 1: premission denied
 *             # 10013: same as 1 but on windows
 *             if e.errno not in [11, 1, 10035, 10013]:             # <<<<<<<<<<<<<<
 *                 try:
 *                     self.debug(0, "recv:%r : (%r, %r)" % (e, data, addr))
 */
      __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_e, __pyx_n_s_errno); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 976, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_20);
      __pyx_t_4 = __Pyx_PyInt_NeObjC(__pyx_t_20, __pyx_int_11, 11, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 976, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 976, __pyx_L5_except_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_9) {
      } else {
        __pyx_t_10 = __pyx_t_9;
        goto __pyx_L39_bool_binop_done;
      }
      __pyx_t_4 = __Pyx_PyInt_NeObjC(__pyx_t_20, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 976, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 976, __pyx_L5_except_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_9) {
      } else {
        __pyx_t_10 = __pyx_t_9;
        goto __pyx_L39_bool_binop_done;
      }
      __pyx_t_4 = __Pyx_PyInt_NeObjC(__pyx_t_20, __pyx_int_10035, 0x2733, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 976, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 976, __pyx_L5_except_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_9) {
      } else {
        __pyx_t_10 = __pyx_t_9;
        goto __pyx_L39_bool_binop_done;
      }
      __pyx_t_4 = __Pyx_PyInt_NeObjC(__pyx_t_20, __pyx_int_10013, 0x271D, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 976, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 976, __pyx_L5_except_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_10 = __pyx_t_9;
      __pyx_L39_bool_binop_done:;
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __pyx_t_9 = (__pyx_t_10 != 0);
      if (__pyx_t_9) {

        /* "btdht/dht.pyx":977
 *             # 10013: same as 1 but on windows
 *             if e.errno not in [11, 1, 10035, 10013]:
 *                 try:             # <<<<<<<<<<<<<<
 *                     self.debug(0, "recv:%r : (%r, %r)" % (e, data, addr))
 *                 except UnboundLocalError:
 */
        {
          __Pyx_PyThreadState_declare
          __Pyx_PyThreadState_assign
          __Pyx_ExceptionSave(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
          __Pyx_XGOTREF(__pyx_t_15);
          __Pyx_XGOTREF(__pyx_t_16);
          __Pyx_XGOTREF(__pyx_t_17);
          /*try:*/ {

            /* "btdht/dht.pyx":978
 *             if e.errno not in [11, 1, 10035, 10013]:
 *                 try:
 *                     self.debug(0, "recv:%r : (%r, %r)" % (e, data, addr))             # <<<<<<<<<<<<<<
 *                 except UnboundLocalError:
 *                     self.debug(0, "recv:%r" % (e,))
 */
            __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 978, __pyx_L43_error)
            __Pyx_GOTREF(__pyx_t_4);
            if (unlikely(!__pyx_v_data)) { __Pyx_RaiseUnboundLocalError("data"); __PYX_ERR(0, 978, __pyx_L43_error) }
            if (unlikely(!__pyx_v_addr)) { __Pyx_RaiseUnboundLocalError("addr"); __PYX_ERR(0, 978, __pyx_L43_error) }
            __pyx_t_19 = PyTuple_New(3); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 978, __pyx_L43_error)
            __Pyx_GOTREF(__pyx_t_19);
            __Pyx_INCREF(__pyx_v_e);
            __Pyx_GIVEREF(__pyx_v_e);
            PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_v_e);
            __Pyx_INCREF(__pyx_v_data);
            __Pyx_GIVEREF(__pyx_v_data);
            PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_v_data);
            __Pyx_INCREF(__pyx_v_addr);
            __Pyx_GIVEREF(__pyx_v_addr);
            PyTuple_SET_ITEM(__pyx_t_19, 2, __pyx_v_addr);
            __pyx_t_11 = __Pyx_PyString_Format(__pyx_kp_s_recv_r_r_r, __pyx_t_19); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 978, __pyx_L43_error)
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
            __pyx_t_19 = NULL;
            __pyx_t_12 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_4);
              if (likely(__pyx_t_19)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
                __Pyx_INCREF(__pyx_t_19);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_4, function);
                __pyx_t_12 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_4)) {
              PyObject *__pyx_temp[3] = {__pyx_t_19, __pyx_int_0, __pyx_t_11};
              __pyx_t_20 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 978, __pyx_L43_error)
              __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
              __Pyx_GOTREF(__pyx_t_20);
              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
              PyObject *__pyx_temp[3] = {__pyx_t_19, __pyx_int_0, __pyx_t_11};
              __pyx_t_20 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 978, __pyx_L43_error)
              __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
              __Pyx_GOTREF(__pyx_t_20);
              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            } else
            #endif
            {
              __pyx_t_7 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 978, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_7);
              if (__pyx_t_19) {
                __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_19); __pyx_t_19 = NULL;
              }
              __Pyx_INCREF(__pyx_int_0);
              __Pyx_GIVEREF(__pyx_int_0);
              PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_12, __pyx_int_0);
              __Pyx_GIVEREF(__pyx_t_11);
              PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_12, __pyx_t_11);
              __pyx_t_11 = 0;
              __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 978, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_20);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            }
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;

            /* "btdht/dht.pyx":977
 *             # 10013: same as 1 but on windows
 *             if e.errno not in [11, 1, 10035, 10013]:
 *                 try:             # <<<<<<<<<<<<<<
 *                     self.debug(0, "recv:%r : (%r, %r)" % (e, data, addr))
 *                 except UnboundLocalError:
 */
          }
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
          goto __pyx_L50_try_end;
          __pyx_L43_error:;
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
          __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
          __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "btdht/dht.pyx":979
 *                 try:
 *                     self.debug(0, "recv:%r : (%r, %r)" % (e, data, addr))
 *                 except UnboundLocalError:             # <<<<<<<<<<<<<<
 *                     self.debug(0, "recv:%r" % (e,))
 *                 raise
 */
          __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_UnboundLocalError);
          if (__pyx_t_12) {
            __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_incoming_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
            if (__Pyx_GetException(&__pyx_t_20, &__pyx_t_4, &__pyx_t_7) < 0) __PYX_ERR(0, 979, __pyx_L45_except_error)
            __Pyx_GOTREF(__pyx_t_20);
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_GOTREF(__pyx_t_7);

            /* "btdht/dht.pyx":980
 *                     self.debug(0, "recv:%r : (%r, %r)" % (e, data, addr))
 *                 except UnboundLocalError:
 *                     self.debug(0, "recv:%r" % (e,))             # <<<<<<<<<<<<<<
 *                 raise
 *         except MissingT:
 */
            __pyx_t_19 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 980, __pyx_L45_except_error)
            __Pyx_GOTREF(__pyx_t_19);
            __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 980, __pyx_L45_except_error)
            __Pyx_GOTREF(__pyx_t_18);
            __Pyx_INCREF(__pyx_v_e);
            __Pyx_GIVEREF(__pyx_v_e);
            PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_v_e);
            __pyx_t_21 = __Pyx_PyString_Format(__pyx_kp_s_recv_r, __pyx_t_18); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 980, __pyx_L45_except_error)
            __Pyx_GOTREF(__pyx_t_21);
            __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
            __pyx_t_18 = NULL;
            __pyx_t_12 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_19))) {
              __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_19);
              if (likely(__pyx_t_18)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19);
                __Pyx_INCREF(__pyx_t_18);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_19, function);
                __pyx_t_12 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_19)) {
              PyObject *__pyx_temp[3] = {__pyx_t_18, __pyx_int_0, __pyx_t_21};
              __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 980, __pyx_L45_except_error)
              __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
              __Pyx_GOTREF(__pyx_t_11);
              __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_19)) {
              PyObject *__pyx_temp[3] = {__pyx_t_18, __pyx_int_0, __pyx_t_21};
              __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 980, __pyx_L45_except_error)
              __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
              __Pyx_GOTREF(__pyx_t_11);
              __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
            } else
            #endif
            {
              __pyx_t_22 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 980, __pyx_L45_except_error)
              __Pyx_GOTREF(__pyx_t_22);
              if (__pyx_t_18) {
                __Pyx_GIVEREF(__pyx_t_18); PyTuple_SET_ITEM(__pyx_t_22, 0, __pyx_t_18); __pyx_t_18 = NULL;
              }
              __Pyx_INCREF(__pyx_int_0);
              __Pyx_GIVEREF(__pyx_int_0);
              PyTuple_SET_ITEM(__pyx_t_22, 0+__pyx_t_12, __pyx_int_0);
              __Pyx_GIVEREF(__pyx_t_21);
              PyTuple_SET_ITEM(__pyx_t_22, 1+__pyx_t_12, __pyx_t_21);
              __pyx_t_21 = 0;
              __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_22, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 980, __pyx_L45_except_error)
              __Pyx_GOTREF(__pyx_t_11);
              __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
            }
            __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
            goto __pyx_L44_exception_handled;
          }
          goto __pyx_L45_except_error;
          __pyx_L45_except_error:;

          /* "btdht/dht.pyx":977
 *             # 10013: same as 1 but on windows
 *             if e.errno not in [11, 1, 10035, 10013]:
 *                 try:             # <<<<<<<<<<<<<<
 *                     self.debug(0, "recv:%r : (%r, %r)" % (e, data, addr))
 *                 except UnboundLocalError:
 */
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_XGIVEREF(__pyx_t_16);
          __Pyx_XGIVEREF(__pyx_t_17);
          __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_16, __pyx_t_17);
          goto __pyx_L5_except_error;
          __pyx_L44_exception_handled:;
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_XGIVEREF(__pyx_t_16);
          __Pyx_XGIVEREF(__pyx_t_17);
          __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_16, __pyx_t_17);
          __pyx_L50_try_end:;
        }

        /* "btdht/dht.pyx":981
 *                 except UnboundLocalError:
 *                     self.debug(0, "recv:%r" % (e,))
 *                 raise             # <<<<<<<<<<<<<<
 *         except MissingT:
 *             pass
 */
        __Pyx_GIVEREF(__pyx_t_13);
        __Pyx_GIVEREF(__pyx_t_6);
        __Pyx_XGIVEREF(__pyx_t_5);
        __Pyx_ErrRestoreWithState(__pyx_t_13, __pyx_t_6, __pyx_t_5);
        __pyx_t_13 = 0; __pyx_t_6 = 0; __pyx_t_5 = 0; 
        __PYX_ERR(0, 981, __pyx_L5_except_error)

        /* "btdht/dht.pyx":976
 *             # 1: premission denied
 *             # 10013: same as 1 but on windows
 *             if e.errno not in [11, 1, 10035, 10013]:             # <<<<<<<<<<<<<<
 *                 try:
 *                     self.debug(0, "recv:%r : (%r, %r)" % (e, data, addr))
 */
      }
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L4_exception_handled;
    }

    /* "btdht/dht.pyx":982
 *                     self.debug(0, "recv:%r" % (e,))
 *                 raise
 *         except MissingT:             # <<<<<<<<<<<<<<
 *             pass
 *         except DecodeError:
 */
    __Pyx_ErrFetch(&__pyx_t_5, &__pyx_t_6, &__pyx_t_13);
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_MissingT); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 982, __pyx_L5_except_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_12 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_5, __pyx_t_7);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_ErrRestore(__pyx_t_5, __pyx_t_6, __pyx_t_13);
    __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_13 = 0;
    if (__pyx_t_12) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L4_exception_handled;
    }

    /* "btdht/dht.pyx":984
 *         except MissingT:
 *             pass
 *         except DecodeError:             # <<<<<<<<<<<<<<
 *             pass
 *         except TransactionIdUnknown:
 */
    __Pyx_ErrFetch(&__pyx_t_13, &__pyx_t_6, &__pyx_t_5);
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_DecodeError); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 984, __pyx_L5_except_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_12 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_13, __pyx_t_7);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_ErrRestore(__pyx_t_13, __pyx_t_6, __pyx_t_5);
    __pyx_t_13 = 0; __pyx_t_6 = 0; __pyx_t_5 = 0;
    if (__pyx_t_12) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L4_exception_handled;
    }

    /* "btdht/dht.pyx":986
 *         except DecodeError:
 *             pass
 *         except TransactionIdUnknown:             # <<<<<<<<<<<<<<
 *             pass
 *         except ValueError as e:
 */
    __Pyx_ErrFetch(&__pyx_t_5, &__pyx_t_6, &__pyx_t_13);
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_TransactionIdUnknown); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 986, __pyx_L5_except_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_12 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_5, __pyx_t_7);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_ErrRestore(__pyx_t_5, __pyx_t_6, __pyx_t_13);
    __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_13 = 0;
    if (__pyx_t_12) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L4_exception_handled;
    }

    /* "btdht/dht.pyx":988
 *         except TransactionIdUnknown:
 *             pass
 *         except ValueError as e:             # <<<<<<<<<<<<<<
 *             #if self.debuglvl > 0:
 *             #    traceback.print_exc()
 */
    __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
    if (__pyx_t_12) {
      __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_incoming_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_13, &__pyx_t_6, &__pyx_t_5) < 0) __PYX_ERR(0, 988, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __pyx_v_e = __pyx_t_6;

      /* "btdht/dht.pyx":992
 *             #    traceback.print_exc()
 *             #    self.debug(1, "%s for %r" % (e, addr))
 *             traceback.print_exc()             # <<<<<<<<<<<<<<
 *             #self.debug(-100, e.args[0])
 * 
 */
      __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_traceback); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 992, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_print_exc); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 992, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_20);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_20);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_20, function);
        }
      }
      __pyx_t_7 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_20, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_20);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 992, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "btdht/dht.pyx":917
 * 
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             data, addr = self.sock.recvfrom(4048)
 *             if addr[0] in self.ignored_ip:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L7_try_return:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L0;
    __pyx_L4_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    __pyx_L8_try_end:;
  }

  /* "btdht/dht.pyx":911
 *             pass
 * 
 *     def _process_incoming_message(self):             # <<<<<<<<<<<<<<
 *         """
 *             Process a new incoming message. The message is read from :attr:`sock`, so this
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_XDECREF(__pyx_t_22);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_incoming_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_data);
  __Pyx_XDECREF(__pyx_v_addr);
  __Pyx_XDECREF(__pyx_v_obj);
  __Pyx_XDECREF(__pyx_v_obj_opt);
  __Pyx_XDECREF(__pyx_v_reponse);
  __Pyx_XDECREF(__pyx_v_error);
  __Pyx_XDECREF(__pyx_v_e);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":997
 * 
 * 
 *     cdef void _set_transaction_id(self, BMessage query, int id_len=6):             # <<<<<<<<<<<<<<
 *         """
 *             Set the transaction id (key t of the dictionnary) on a query
 */

static void __pyx_f_5btdht_3dht_8DHT_BASE__set_transaction_id(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, struct __pyx_obj_5btdht_4krcp_BMessage *__pyx_v_query, struct __pyx_opt_args_5btdht_3dht_8DHT_BASE__set_transaction_id *__pyx_optional_args) {
  int __pyx_v_id_len = ((int)6);
  PyObject *__pyx_v_id = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  struct __pyx_opt_args_5btdht_3dht_8DHT_BASE__set_transaction_id __pyx_t_7;
  char *__pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_set_transaction_id", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_id_len = __pyx_optional_args->id_len;
    }
  }

  /* "btdht/dht.pyx":1008
 *                 called again, incrementing ``id_len``.
 *         """
 *         id = os.urandom(id_len)             # <<<<<<<<<<<<<<
 *         if id in self.transaction_type:
 *             self._set_transaction_id(query, id_len=id_len+1)
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_urandom); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_id_len); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_id = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1009
 *         """
 *         id = os.urandom(id_len)
 *         if id in self.transaction_type:             # <<<<<<<<<<<<<<
 *             self._set_transaction_id(query, id_len=id_len+1)
 *         self.transaction_type[id] = (None, time.time(), query)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1009, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_v_id, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1009, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {

    /* "btdht/dht.pyx":1010
 *         id = os.urandom(id_len)
 *         if id in self.transaction_type:
 *             self._set_transaction_id(query, id_len=id_len+1)             # <<<<<<<<<<<<<<
 *         self.transaction_type[id] = (None, time.time(), query)
 *         query.set_t(id, id_len)
 */
    __pyx_t_7.__pyx_n = 1;
    __pyx_t_7.id_len = (__pyx_v_id_len + 1);
    ((struct __pyx_vtabstruct_5btdht_3dht_DHT_BASE *)__pyx_v_self->__pyx_vtab)->_set_transaction_id(__pyx_v_self, __pyx_v_query, &__pyx_t_7); 

    /* "btdht/dht.pyx":1009
 *         """
 *         id = os.urandom(id_len)
 *         if id in self.transaction_type:             # <<<<<<<<<<<<<<
 *             self._set_transaction_id(query, id_len=id_len+1)
 *         self.transaction_type[id] = (None, time.time(), query)
 */
  }

  /* "btdht/dht.pyx":1011
 *         if id in self.transaction_type:
 *             self._set_transaction_id(query, id_len=id_len+1)
 *         self.transaction_type[id] = (None, time.time(), query)             # <<<<<<<<<<<<<<
 *         query.set_t(id, id_len)
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1011, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1011, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1011, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1011, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  PyTuple_SET_ITEM(__pyx_t_2, 0, Py_None);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_query));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_query));
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_query));
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1011, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_v_id, __pyx_t_2) < 0)) __PYX_ERR(0, 1011, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1012
 *             self._set_transaction_id(query, id_len=id_len+1)
 *         self.transaction_type[id] = (None, time.time(), query)
 *         query.set_t(id, id_len)             # <<<<<<<<<<<<<<
 * 
 *     def _get_token(self, ip):
 */
  __pyx_t_8 = __Pyx_PyObject_AsWritableString(__pyx_v_id); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 1012, __pyx_L1_error)
  (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_query->__pyx_vtab)->set_t(__pyx_v_query, __pyx_t_8, __pyx_v_id_len));

  /* "btdht/dht.pyx":997
 * 
 * 
 *     cdef void _set_transaction_id(self, BMessage query, int id_len=6):             # <<<<<<<<<<<<<<
 *         """
 *             Set the transaction id (key t of the dictionnary) on a query
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("btdht.dht.DHT_BASE._set_transaction_id", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_id);
  __Pyx_RefNannyFinishContext();
}

/* "btdht/dht.pyx":1014
 *         query.set_t(id, id_len)
 * 
 *     def _get_token(self, ip):             # <<<<<<<<<<<<<<
 *         """
 *             Return a token for ``ip``
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_48_get_token(PyObject *__pyx_v_self, PyObject *__pyx_v_ip); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_47_get_token[] = "\n            Return a token for ``ip``\n\n            :param str ip: A ip address in dotted notation\n            :return: A random id of lendth 4\n            :rtype: bytes\n\n            Notes:\n                Generate at most 1 new token by ip every 5 min. A token is considered valid\n                until 10 min after it has been generated.\n\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_48_get_token(PyObject *__pyx_v_self, PyObject *__pyx_v_ip) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_get_token (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_47_get_token(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v_ip));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_47_get_token(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_ip) {
  PyObject *__pyx_v_id = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_get_token", 0);

  /* "btdht/dht.pyx":1027
 * 
 *         """
 *         if ip in self.token and self.token[ip][-1][1] < 300:             # <<<<<<<<<<<<<<
 *             return self.token[ip][-1][0]
 *         else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_token); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_v_ip, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1027, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_1 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_token); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_ip); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_5, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1027, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_5, __pyx_int_300, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1027, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1027, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "btdht/dht.pyx":1028
 *         """
 *         if ip in self.token and self.token[ip][-1][1] < 300:
 *             return self.token[ip][-1][0]             # <<<<<<<<<<<<<<
 *         else:
 *             id = os.urandom(4)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_token); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1028, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_ip); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1028, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_5, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1028, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1028, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "btdht/dht.pyx":1027
 * 
 *         """
 *         if ip in self.token and self.token[ip][-1][1] < 300:             # <<<<<<<<<<<<<<
 *             return self.token[ip][-1][0]
 *         else:
 */
  }

  /* "btdht/dht.pyx":1030
 *             return self.token[ip][-1][0]
 *         else:
 *             id = os.urandom(4)             # <<<<<<<<<<<<<<
 *             self.token[ip].append((id, time.time()))
 *             return id
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1030, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_urandom); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1030, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_5 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_2, __pyx_int_4) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_int_4);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1030, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_id = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "btdht/dht.pyx":1031
 *         else:
 *             id = os.urandom(4)
 *             self.token[ip].append((id, time.time()))             # <<<<<<<<<<<<<<
 *             return id
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_token); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1031, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_5, __pyx_v_ip); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1031, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1031, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1031, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_5 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1031, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1031, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_v_id);
    __Pyx_GIVEREF(__pyx_v_id);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_id);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_8 = __Pyx_PyObject_Append(__pyx_t_6, __pyx_t_7); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1031, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "btdht/dht.pyx":1032
 *             id = os.urandom(4)
 *             self.token[ip].append((id, time.time()))
 *             return id             # <<<<<<<<<<<<<<
 * 
 *     def _get_valid_token(self, ip):
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_id);
    __pyx_r = __pyx_v_id;
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":1014
 *         query.set_t(id, id_len)
 * 
 *     def _get_token(self, ip):             # <<<<<<<<<<<<<<
 *         """
 *             Return a token for ``ip``
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._get_token", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_id);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1034
 *             return id
 * 
 *     def _get_valid_token(self, ip):             # <<<<<<<<<<<<<<
 *         """
 *             Return a list of valid tokens for ``ip``
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_50_get_valid_token(PyObject *__pyx_v_self, PyObject *__pyx_v_ip); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_49_get_valid_token[] = "\n            Return a list of valid tokens for ``ip``\n\n            :param str ip: A ip address in dotted notation\n            :return: A list of valid tokens for ``ip``\n            :rtype: list\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_50_get_valid_token(PyObject *__pyx_v_self, PyObject *__pyx_v_ip) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_get_valid_token (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_49_get_valid_token(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v_ip));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_49_get_valid_token(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_ip) {
  PyObject *__pyx_v_now = NULL;
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_get_valid_token", 0);

  /* "btdht/dht.pyx":1042
 *             :rtype: list
 *         """
 *         if ip in self.token:             # <<<<<<<<<<<<<<
 *             now = time.time()
 *             return [t[0] for t in self.token[ip] if (now - t[1]) < 600]
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_token); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1042, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_ip, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1042, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":1043
 *         """
 *         if ip in self.token:
 *             now = time.time()             # <<<<<<<<<<<<<<
 *             return [t[0] for t in self.token[ip] if (now - t[1]) < 600]
 *         else:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1043, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1043, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1043, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_now = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1044
 *         if ip in self.token:
 *             now = time.time()
 *             return [t[0] for t in self.token[ip] if (now - t[1]) < 600]             # <<<<<<<<<<<<<<
 *         else:
 *             return []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1044, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_token); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1044, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_5, __pyx_v_ip); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1044, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
      __pyx_t_5 = __pyx_t_4; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0;
      __pyx_t_7 = NULL;
    } else {
      __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1044, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1044, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    for (;;) {
      if (likely(!__pyx_t_7)) {
        if (likely(PyList_CheckExact(__pyx_t_5))) {
          if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1044, __pyx_L1_error)
          #else
          __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1044, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          #endif
        } else {
          if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1044, __pyx_L1_error)
          #else
          __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1044, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          #endif
        }
      } else {
        __pyx_t_4 = __pyx_t_7(__pyx_t_5);
        if (unlikely(!__pyx_t_4)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1044, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_4);
      }
      __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_t, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1044, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_8 = PyNumber_Subtract(__pyx_v_now, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1044, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_RichCompare(__pyx_t_8, __pyx_int_600, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1044, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1044, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_3) {
        __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_t, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1044, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 1044, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "btdht/dht.pyx":1042
 *             :rtype: list
 *         """
 *         if ip in self.token:             # <<<<<<<<<<<<<<
 *             now = time.time()
 *             return [t[0] for t in self.token[ip] if (now - t[1]) < 600]
 */
  }

  /* "btdht/dht.pyx":1046
 *             return [t[0] for t in self.token[ip] if (now - t[1]) < 600]
 *         else:
 *             return []             # <<<<<<<<<<<<<<
 * 
 *     def clean(self):
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1046, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":1034
 *             return id
 * 
 *     def _get_valid_token(self, ip):             # <<<<<<<<<<<<<<
 *         """
 *             Return a list of valid tokens for ``ip``
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._get_valid_token", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_now);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1048
 *             return []
 * 
 *     def clean(self):             # <<<<<<<<<<<<<<
 *         """Function called every 15s to do some cleanning. It can safely be overload"""
 *         pass
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_52clean(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_51clean[] = "Function called every 15s to do some cleanning. It can safely be overload";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_52clean(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("clean (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_51clean(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_51clean(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("clean", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1051
 *         """Function called every 15s to do some cleanning. It can safely be overload"""
 *         pass
 *     def clean_long(self):             # <<<<<<<<<<<<<<
 *         """Function called every 15min to do some cleanning. It can safely be overload"""
 *         pass
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_54clean_long(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_53clean_long[] = "Function called every 15min to do some cleanning. It can safely be overload";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_54clean_long(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("clean_long (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_53clean_long(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_53clean_long(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("clean_long", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1055
 *         pass
 * 
 *     def _clean(self):             # <<<<<<<<<<<<<<
 *         """
 *             Function cleaning datastructures of the DHT
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_56_clean(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_55_clean[] = "\n            Function cleaning datastructures of the DHT\n\n            The following cleaning is done every 15 seconds\n                * delete entries from :attr:`transaction_type` (query without response) older than\n                  30 seconds\n                * Remove dead threads from :attr:`_threads`\n                * If no message has been received since more than 2 minutes, stop the DHT\n                * If no response to our query has been received since more than 5 minutes,\n                  stop the DHT\n                * call the :meth:`clean` method\n\n            The following cleaning is done every 15 minutes\n                * delete expired tokens (older than 10 min) from :attr:`token`\n                * delete received token older than 10 min from :attr:`mytoken`\n                * delete peers not annonced since more than 30min from :attr:`_peers`\n                * delete peers from get_peer response older than 15min from :attr:`_got_peers`\n                * call the :meth:`clean_long` method\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_56_clean(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_clean (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_55_clean(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_55_clean(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  PyObject *__pyx_v_now = NULL;
  PyObject *__pyx_v_to_delete = NULL;
  PyObject *__pyx_v_id = NULL;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_v_ip = NULL;
  PyObject *__pyx_v_hash = NULL;
  PyObject *__pyx_v_peers = NULL;
  PyObject *__pyx_v_peer = NULL;
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  Py_ssize_t __pyx_t_11;
  PyObject *(*__pyx_t_12)(PyObject *);
  int __pyx_t_13;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *(*__pyx_t_17)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_clean", 0);

  /* "btdht/dht.pyx":1075
 *                 * call the :meth:`clean_long` method
 *         """
 *         now = time.time()             # <<<<<<<<<<<<<<
 * 
 *         to_delete = []
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_now = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1077
 *         now = time.time()
 * 
 *         to_delete = []             # <<<<<<<<<<<<<<
 *         for id in self.transaction_type:
 *             if now - self.transaction_type[id][1] > 30:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1077, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_to_delete = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1078
 * 
 *         to_delete = []
 *         for id in self.transaction_type:             # <<<<<<<<<<<<<<
 *             if now - self.transaction_type[id][1] > 30:
 *                 to_delete.append(id)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1078, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1078, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1078, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1078, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1078, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1078, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1078, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_5(__pyx_t_3);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1078, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_id, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1079
 *         to_delete = []
 *         for id in self.transaction_type:
 *             if now - self.transaction_type[id][1] > 30:             # <<<<<<<<<<<<<<
 *                 to_delete.append(id)
 *         for key in to_delete:
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1079, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1079, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1079, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Subtract(__pyx_v_now, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1079, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_30, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1079, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1079, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_6) {

      /* "btdht/dht.pyx":1080
 *         for id in self.transaction_type:
 *             if now - self.transaction_type[id][1] > 30:
 *                 to_delete.append(id)             # <<<<<<<<<<<<<<
 *         for key in to_delete:
 *             del self.transaction_type[key]
 */
      __pyx_t_7 = __Pyx_PyObject_Append(__pyx_v_to_delete, __pyx_v_id); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 1080, __pyx_L1_error)

      /* "btdht/dht.pyx":1079
 *         to_delete = []
 *         for id in self.transaction_type:
 *             if now - self.transaction_type[id][1] > 30:             # <<<<<<<<<<<<<<
 *                 to_delete.append(id)
 *         for key in to_delete:
 */
    }

    /* "btdht/dht.pyx":1078
 * 
 *         to_delete = []
 *         for id in self.transaction_type:             # <<<<<<<<<<<<<<
 *             if now - self.transaction_type[id][1] > 30:
 *                 to_delete.append(id)
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "btdht/dht.pyx":1081
 *             if now - self.transaction_type[id][1] > 30:
 *                 to_delete.append(id)
 *         for key in to_delete:             # <<<<<<<<<<<<<<
 *             del self.transaction_type[key]
 * 
 */
  __pyx_t_3 = __pyx_v_to_delete; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
  for (;;) {
    if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1081, __pyx_L1_error)
    #else
    __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1081, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1082
 *                 to_delete.append(id)
 *         for key in to_delete:
 *             del self.transaction_type[key]             # <<<<<<<<<<<<<<
 * 
 *         self._threads = [t for t in self._threads[:] if t.is_alive()]
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1082, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (unlikely(PyObject_DelItem(__pyx_t_1, __pyx_v_key) < 0)) __PYX_ERR(0, 1082, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1081
 *             if now - self.transaction_type[id][1] > 30:
 *                 to_delete.append(id)
 *         for key in to_delete:             # <<<<<<<<<<<<<<
 *             del self.transaction_type[key]
 * 
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "btdht/dht.pyx":1084
 *             del self.transaction_type[key]
 * 
 *         self._threads = [t for t in self._threads[:] if t.is_alive()]             # <<<<<<<<<<<<<<
 * 
 *         if now - self.last_msg > 2 * 60:
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1084, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1084, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_t_1, 0, 0, NULL, NULL, &__pyx_slice__7, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1084, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1084, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1084, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1084, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1084, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1084, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1084, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_5(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1084, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_is_alive); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1084, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    __pyx_t_2 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_8);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1084, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1084, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_6) {
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_v_t))) __PYX_ERR(0, 1084, __pyx_L1_error)
    }
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_threads_2, __pyx_t_3) < 0) __PYX_ERR(0, 1084, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "btdht/dht.pyx":1086
 *         self._threads = [t for t in self._threads[:] if t.is_alive()]
 * 
 *         if now - self.last_msg > 2 * 60:             # <<<<<<<<<<<<<<
 *             self.debug(-10, "No msg since more than 2 minutes on udp port %d" % self.bind_port)
 *             self.stop()
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_msg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1086, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyNumber_Subtract(__pyx_v_now, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1086, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_int_120, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1086, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1086, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_6) {

    /* "btdht/dht.pyx":1087
 * 
 *         if now - self.last_msg > 2 * 60:
 *             self.debug(-10, "No msg since more than 2 minutes on udp port %d" % self.bind_port)             # <<<<<<<<<<<<<<
 *             self.stop()
 *         elif now - self.last_msg_rep > 5 * 60:
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1087, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_bind_port); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1087, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyString_FormatSafe(__pyx_kp_s_No_msg_since_more_than_2_minutes, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1087, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_int_neg_10, __pyx_t_8};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1087, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_int_neg_10, __pyx_t_8};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1087, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else
    #endif
    {
      __pyx_t_9 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1087, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (__pyx_t_2) {
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2); __pyx_t_2 = NULL;
      }
      __Pyx_INCREF(__pyx_int_neg_10);
      __Pyx_GIVEREF(__pyx_int_neg_10);
      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_10, __pyx_int_neg_10);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_10, __pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1087, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1088
 *         if now - self.last_msg > 2 * 60:
 *             self.debug(-10, "No msg since more than 2 minutes on udp port %d" % self.bind_port)
 *             self.stop()             # <<<<<<<<<<<<<<
 *         elif now - self.last_msg_rep > 5 * 60:
 *             self.debug(
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stop); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1088, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1088, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1086
 *         self._threads = [t for t in self._threads[:] if t.is_alive()]
 * 
 *         if now - self.last_msg > 2 * 60:             # <<<<<<<<<<<<<<
 *             self.debug(-10, "No msg since more than 2 minutes on udp port %d" % self.bind_port)
 *             self.stop()
 */
    goto __pyx_L11;
  }

  /* "btdht/dht.pyx":1089
 *             self.debug(-10, "No msg since more than 2 minutes on udp port %d" % self.bind_port)
 *             self.stop()
 *         elif now - self.last_msg_rep > 5 * 60:             # <<<<<<<<<<<<<<
 *             self.debug(
 *                 -10,
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_msg_rep); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1089, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyNumber_Subtract(__pyx_v_now, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1089, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_int_300, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1089, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1089, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_6) {

    /* "btdht/dht.pyx":1090
 *             self.stop()
 *         elif now - self.last_msg_rep > 5 * 60:
 *             self.debug(             # <<<<<<<<<<<<<<
 *                 -10,
 *                 "No msg response since more than 5 minutes on udp port %d" % self.bind_port
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "btdht/dht.pyx":1092
 *             self.debug(
 *                 -10,
 *                 "No msg response since more than 5 minutes on udp port %d" % self.bind_port             # <<<<<<<<<<<<<<
 *             )
 *             self.stop()
 */
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_bind_port); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1092, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_8 = __Pyx_PyString_FormatSafe(__pyx_kp_s_No_msg_response_since_more_than, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1092, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_int_neg_10, __pyx_t_8};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1090, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_int_neg_10, __pyx_t_8};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1090, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1090, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (__pyx_t_9) {
        __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_9); __pyx_t_9 = NULL;
      }
      __Pyx_INCREF(__pyx_int_neg_10);
      __Pyx_GIVEREF(__pyx_int_neg_10);
      PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_10, __pyx_int_neg_10);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_10, __pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1090, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1094
 *                 "No msg response since more than 5 minutes on udp port %d" % self.bind_port
 *             )
 *             self.stop()             # <<<<<<<<<<<<<<
 * 
 *         self.clean()
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_stop); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1094, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1094, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1089
 *             self.debug(-10, "No msg since more than 2 minutes on udp port %d" % self.bind_port)
 *             self.stop()
 *         elif now - self.last_msg_rep > 5 * 60:             # <<<<<<<<<<<<<<
 *             self.debug(
 *                 -10,
 */
  }
  __pyx_L11:;

  /* "btdht/dht.pyx":1096
 *             self.stop()
 * 
 *         self.clean()             # <<<<<<<<<<<<<<
 * 
 *         # Long cleaning
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_clean); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1096, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1096, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "btdht/dht.pyx":1099
 * 
 *         # Long cleaning
 *         if now - self._long_clean >= 15 * 60:             # <<<<<<<<<<<<<<
 *             # cleaning old tokens
 *             to_delete = []
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_long_clean); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1099, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyNumber_Subtract(__pyx_v_now, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1099, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_int_900, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1099, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1099, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_6) {

    /* "btdht/dht.pyx":1101
 *         if now - self._long_clean >= 15 * 60:
 *             # cleaning old tokens
 *             to_delete = []             # <<<<<<<<<<<<<<
 *             for ip in self.token:
 *                 self.token[ip] = [t for t in self.token[ip] if (now - t[1]) < 600]
 */
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1101, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF_SET(__pyx_v_to_delete, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1102
 *             # cleaning old tokens
 *             to_delete = []
 *             for ip in self.token:             # <<<<<<<<<<<<<<
 *                 self.token[ip] = [t for t in self.token[ip] if (now - t[1]) < 600]
 *                 if not self.token[ip]:
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_token); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1102, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
      __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1102, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1102, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1102, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1102, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1102, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1102, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        }
      } else {
        __pyx_t_3 = __pyx_t_5(__pyx_t_1);
        if (unlikely(!__pyx_t_3)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1102, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_XDECREF_SET(__pyx_v_ip, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "btdht/dht.pyx":1103
 *             to_delete = []
 *             for ip in self.token:
 *                 self.token[ip] = [t for t in self.token[ip] if (now - t[1]) < 600]             # <<<<<<<<<<<<<<
 *                 if not self.token[ip]:
 *                     to_delete.append(ip)
 */
      __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1103, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_token); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1103, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_ip); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1103, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) {
        __pyx_t_2 = __pyx_t_8; __Pyx_INCREF(__pyx_t_2); __pyx_t_11 = 0;
        __pyx_t_12 = NULL;
      } else {
        __pyx_t_11 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1103, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_12 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1103, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      for (;;) {
        if (likely(!__pyx_t_12)) {
          if (likely(PyList_CheckExact(__pyx_t_2))) {
            if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_2)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_8 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_11); __Pyx_INCREF(__pyx_t_8); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1103, __pyx_L1_error)
            #else
            __pyx_t_8 = PySequence_ITEM(__pyx_t_2, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1103, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            #endif
          } else {
            if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_11); __Pyx_INCREF(__pyx_t_8); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1103, __pyx_L1_error)
            #else
            __pyx_t_8 = PySequence_ITEM(__pyx_t_2, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1103, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            #endif
          }
        } else {
          __pyx_t_8 = __pyx_t_12(__pyx_t_2);
          if (unlikely(!__pyx_t_8)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 1103, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_8);
        }
        __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_8);
        __pyx_t_8 = 0;
        __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_t, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1103, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = PyNumber_Subtract(__pyx_v_now, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1103, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_8 = PyObject_RichCompare(__pyx_t_9, __pyx_int_600, Py_LT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1103, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1103, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (__pyx_t_6) {
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_v_t))) __PYX_ERR(0, 1103, __pyx_L1_error)
        }
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_token); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1103, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (unlikely(PyObject_SetItem(__pyx_t_2, __pyx_v_ip, __pyx_t_3) < 0)) __PYX_ERR(0, 1103, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "btdht/dht.pyx":1104
 *             for ip in self.token:
 *                 self.token[ip] = [t for t in self.token[ip] if (now - t[1]) < 600]
 *                 if not self.token[ip]:             # <<<<<<<<<<<<<<
 *                     to_delete.append(ip)
 *             for key in to_delete:
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_token); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1104, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_3, __pyx_v_ip); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1104, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1104, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_13 = ((!__pyx_t_6) != 0);
      if (__pyx_t_13) {

        /* "btdht/dht.pyx":1105
 *                 self.token[ip] = [t for t in self.token[ip] if (now - t[1]) < 600]
 *                 if not self.token[ip]:
 *                     to_delete.append(ip)             # <<<<<<<<<<<<<<
 *             for key in to_delete:
 *                 del self.token[key]
 */
        __pyx_t_7 = __Pyx_PyObject_Append(__pyx_v_to_delete, __pyx_v_ip); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 1105, __pyx_L1_error)

        /* "btdht/dht.pyx":1104
 *             for ip in self.token:
 *                 self.token[ip] = [t for t in self.token[ip] if (now - t[1]) < 600]
 *                 if not self.token[ip]:             # <<<<<<<<<<<<<<
 *                     to_delete.append(ip)
 *             for key in to_delete:
 */
      }

      /* "btdht/dht.pyx":1102
 *             # cleaning old tokens
 *             to_delete = []
 *             for ip in self.token:             # <<<<<<<<<<<<<<
 *                 self.token[ip] = [t for t in self.token[ip] if (now - t[1]) < 600]
 *                 if not self.token[ip]:
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1106
 *                 if not self.token[ip]:
 *                     to_delete.append(ip)
 *             for key in to_delete:             # <<<<<<<<<<<<<<
 *                 del self.token[key]
 *             to_delete = []
 */
    __pyx_t_1 = __pyx_v_to_delete; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
    for (;;) {
      if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1106, __pyx_L1_error)
      #else
      __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1106, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      #endif
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "btdht/dht.pyx":1107
 *                     to_delete.append(ip)
 *             for key in to_delete:
 *                 del self.token[key]             # <<<<<<<<<<<<<<
 *             to_delete = []
 *             for id in self.mytoken:
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_token); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1107, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (unlikely(PyObject_DelItem(__pyx_t_2, __pyx_v_key) < 0)) __PYX_ERR(0, 1107, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "btdht/dht.pyx":1106
 *                 if not self.token[ip]:
 *                     to_delete.append(ip)
 *             for key in to_delete:             # <<<<<<<<<<<<<<
 *                 del self.token[key]
 *             to_delete = []
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1108
 *             for key in to_delete:
 *                 del self.token[key]
 *             to_delete = []             # <<<<<<<<<<<<<<
 *             for id in self.mytoken:
 *                 try:
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1108, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_to_delete, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1109
 *                 del self.token[key]
 *             to_delete = []
 *             for id in self.mytoken:             # <<<<<<<<<<<<<<
 *                 try:
 *                     if now - self.mytoken[id][1] > 600:
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mytoken); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1109, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1109, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1109, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1109, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1109, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1109, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1109, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_5(__pyx_t_2);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1109, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF_SET(__pyx_v_id, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "btdht/dht.pyx":1110
 *             to_delete = []
 *             for id in self.mytoken:
 *                 try:             # <<<<<<<<<<<<<<
 *                     if now - self.mytoken[id][1] > 600:
 *                         to_delete.append(id)
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16);
        __Pyx_XGOTREF(__pyx_t_14);
        __Pyx_XGOTREF(__pyx_t_15);
        __Pyx_XGOTREF(__pyx_t_16);
        /*try:*/ {

          /* "btdht/dht.pyx":1111
 *             for id in self.mytoken:
 *                 try:
 *                     if now - self.mytoken[id][1] > 600:             # <<<<<<<<<<<<<<
 *                         to_delete.append(id)
 *                 except KeyError:
 */
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mytoken); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1111, __pyx_L23_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1111, __pyx_L23_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_3, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1111, __pyx_L23_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_3 = PyNumber_Subtract(__pyx_v_now, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1111, __pyx_L23_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_int_600, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1111, __pyx_L23_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1111, __pyx_L23_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (__pyx_t_13) {

            /* "btdht/dht.pyx":1112
 *                 try:
 *                     if now - self.mytoken[id][1] > 600:
 *                         to_delete.append(id)             # <<<<<<<<<<<<<<
 *                 except KeyError:
 *                     pass
 */
            __pyx_t_7 = __Pyx_PyObject_Append(__pyx_v_to_delete, __pyx_v_id); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 1112, __pyx_L23_error)

            /* "btdht/dht.pyx":1111
 *             for id in self.mytoken:
 *                 try:
 *                     if now - self.mytoken[id][1] > 600:             # <<<<<<<<<<<<<<
 *                         to_delete.append(id)
 *                 except KeyError:
 */
          }

          /* "btdht/dht.pyx":1110
 *             to_delete = []
 *             for id in self.mytoken:
 *                 try:             # <<<<<<<<<<<<<<
 *                     if now - self.mytoken[id][1] > 600:
 *                         to_delete.append(id)
 */
        }
        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
        goto __pyx_L30_try_end;
        __pyx_L23_error:;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "btdht/dht.pyx":1113
 *                     if now - self.mytoken[id][1] > 600:
 *                         to_delete.append(id)
 *                 except KeyError:             # <<<<<<<<<<<<<<
 *                     pass
 *             for key in to_delete:
 */
        __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
        if (__pyx_t_10) {
          __Pyx_ErrRestore(0,0,0);
          goto __pyx_L24_exception_handled;
        }
        goto __pyx_L25_except_error;
        __pyx_L25_except_error:;

        /* "btdht/dht.pyx":1110
 *             to_delete = []
 *             for id in self.mytoken:
 *                 try:             # <<<<<<<<<<<<<<
 *                     if now - self.mytoken[id][1] > 600:
 *                         to_delete.append(id)
 */
        __Pyx_XGIVEREF(__pyx_t_14);
        __Pyx_XGIVEREF(__pyx_t_15);
        __Pyx_XGIVEREF(__pyx_t_16);
        __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16);
        goto __pyx_L1_error;
        __pyx_L24_exception_handled:;
        __Pyx_XGIVEREF(__pyx_t_14);
        __Pyx_XGIVEREF(__pyx_t_15);
        __Pyx_XGIVEREF(__pyx_t_16);
        __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16);
        __pyx_L30_try_end:;
      }

      /* "btdht/dht.pyx":1109
 *                 del self.token[key]
 *             to_delete = []
 *             for id in self.mytoken:             # <<<<<<<<<<<<<<
 *                 try:
 *                     if now - self.mytoken[id][1] > 600:
 */
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "btdht/dht.pyx":1115
 *                 except KeyError:
 *                     pass
 *             for key in to_delete:             # <<<<<<<<<<<<<<
 *                 try:
 *                     del self.mytoken[id]
 */
    __pyx_t_2 = __pyx_v_to_delete; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
    for (;;) {
      if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1115, __pyx_L1_error)
      #else
      __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1115, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      #endif
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "btdht/dht.pyx":1116
 *                     pass
 *             for key in to_delete:
 *                 try:             # <<<<<<<<<<<<<<
 *                     del self.mytoken[id]
 *                 except KeyError:
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14);
        __Pyx_XGOTREF(__pyx_t_16);
        __Pyx_XGOTREF(__pyx_t_15);
        __Pyx_XGOTREF(__pyx_t_14);
        /*try:*/ {

          /* "btdht/dht.pyx":1117
 *             for key in to_delete:
 *                 try:
 *                     del self.mytoken[id]             # <<<<<<<<<<<<<<
 *                 except KeyError:
 *                     pass
 */
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mytoken); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1117, __pyx_L34_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (unlikely(!__pyx_v_id)) { __Pyx_RaiseUnboundLocalError("id"); __PYX_ERR(0, 1117, __pyx_L34_error) }
          if (unlikely(PyObject_DelItem(__pyx_t_1, __pyx_v_id) < 0)) __PYX_ERR(0, 1117, __pyx_L34_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "btdht/dht.pyx":1116
 *                     pass
 *             for key in to_delete:
 *                 try:             # <<<<<<<<<<<<<<
 *                     del self.mytoken[id]
 *                 except KeyError:
 */
        }
        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
        goto __pyx_L41_try_end;
        __pyx_L34_error:;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "btdht/dht.pyx":1118
 *                 try:
 *                     del self.mytoken[id]
 *                 except KeyError:             # <<<<<<<<<<<<<<
 *                     pass
 * 
 */
        __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
        if (__pyx_t_10) {
          __Pyx_ErrRestore(0,0,0);
          goto __pyx_L35_exception_handled;
        }
        goto __pyx_L36_except_error;
        __pyx_L36_except_error:;

        /* "btdht/dht.pyx":1116
 *                     pass
 *             for key in to_delete:
 *                 try:             # <<<<<<<<<<<<<<
 *                     del self.mytoken[id]
 *                 except KeyError:
 */
        __Pyx_XGIVEREF(__pyx_t_16);
        __Pyx_XGIVEREF(__pyx_t_15);
        __Pyx_XGIVEREF(__pyx_t_14);
        __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_15, __pyx_t_14);
        goto __pyx_L1_error;
        __pyx_L35_exception_handled:;
        __Pyx_XGIVEREF(__pyx_t_16);
        __Pyx_XGIVEREF(__pyx_t_15);
        __Pyx_XGIVEREF(__pyx_t_14);
        __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_15, __pyx_t_14);
        __pyx_L41_try_end:;
      }

      /* "btdht/dht.pyx":1115
 *                 except KeyError:
 *                     pass
 *             for key in to_delete:             # <<<<<<<<<<<<<<
 *                 try:
 *                     del self.mytoken[id]
 */
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "btdht/dht.pyx":1122
 * 
 *             # cleaning old peer for announce_peer
 *             to_delete = collections.defaultdict(list)             # <<<<<<<<<<<<<<
 *             for hash, peers in six.iteritems(self._peers):
 *                 for peer in peers:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_collections); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1122, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1122, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, ((PyObject *)(&PyList_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)(&PyList_Type)));
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1122, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_to_delete, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "btdht/dht.pyx":1123
 *             # cleaning old peer for announce_peer
 *             to_delete = collections.defaultdict(list)
 *             for hash, peers in six.iteritems(self._peers):             # <<<<<<<<<<<<<<
 *                 for peer in peers:
 *                     try:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_six); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1123, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_iteritems); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1123, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_peers); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1123, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_2 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_8, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1123, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
      __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1123, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1123, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1123, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1123, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1123, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1123, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_5(__pyx_t_1);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1123, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
        PyObject* sequence = __pyx_t_2;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 1123, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_8 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_8);
        #else
        __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1123, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1123, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        #endif
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_9 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1123, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_17 = Py_TYPE(__pyx_t_9)->tp_iternext;
        index = 0; __pyx_t_3 = __pyx_t_17(__pyx_t_9); if (unlikely(!__pyx_t_3)) goto __pyx_L44_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        index = 1; __pyx_t_8 = __pyx_t_17(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L44_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_8);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_9), 2) < 0) __PYX_ERR(0, 1123, __pyx_L1_error)
        __pyx_t_17 = NULL;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L45_unpacking_done;
        __pyx_L44_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_17 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 1123, __pyx_L1_error)
        __pyx_L45_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_hash, __pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_XDECREF_SET(__pyx_v_peers, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "btdht/dht.pyx":1124
 *             to_delete = collections.defaultdict(list)
 *             for hash, peers in six.iteritems(self._peers):
 *                 for peer in peers:             # <<<<<<<<<<<<<<
 *                     try:
 *                         if now - self._peers[hash][peer] > 30 * 60:
 */
      if (likely(PyList_CheckExact(__pyx_v_peers)) || PyTuple_CheckExact(__pyx_v_peers)) {
        __pyx_t_2 = __pyx_v_peers; __Pyx_INCREF(__pyx_t_2); __pyx_t_11 = 0;
        __pyx_t_12 = NULL;
      } else {
        __pyx_t_11 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_peers); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1124, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_12 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1124, __pyx_L1_error)
      }
      for (;;) {
        if (likely(!__pyx_t_12)) {
          if (likely(PyList_CheckExact(__pyx_t_2))) {
            if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_2)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_8 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_11); __Pyx_INCREF(__pyx_t_8); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1124, __pyx_L1_error)
            #else
            __pyx_t_8 = PySequence_ITEM(__pyx_t_2, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1124, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            #endif
          } else {
            if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_11); __Pyx_INCREF(__pyx_t_8); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1124, __pyx_L1_error)
            #else
            __pyx_t_8 = PySequence_ITEM(__pyx_t_2, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1124, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            #endif
          }
        } else {
          __pyx_t_8 = __pyx_t_12(__pyx_t_2);
          if (unlikely(!__pyx_t_8)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 1124, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_8);
        }
        __Pyx_XDECREF_SET(__pyx_v_peer, __pyx_t_8);
        __pyx_t_8 = 0;

        /* "btdht/dht.pyx":1125
 *             for hash, peers in six.iteritems(self._peers):
 *                 for peer in peers:
 *                     try:             # <<<<<<<<<<<<<<
 *                         if now - self._peers[hash][peer] > 30 * 60:
 *                             to_delete[hash].append(peer)
 */
        {
          __Pyx_PyThreadState_declare
          __Pyx_PyThreadState_assign
          __Pyx_ExceptionSave(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16);
          __Pyx_XGOTREF(__pyx_t_14);
          __Pyx_XGOTREF(__pyx_t_15);
          __Pyx_XGOTREF(__pyx_t_16);
          /*try:*/ {

            /* "btdht/dht.pyx":1126
 *                 for peer in peers:
 *                     try:
 *                         if now - self._peers[hash][peer] > 30 * 60:             # <<<<<<<<<<<<<<
 *                             to_delete[hash].append(peer)
 *                     except KeyError:
 */
            __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_peers); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1126, __pyx_L48_error)
            __Pyx_GOTREF(__pyx_t_8);
            __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_8, __pyx_v_hash); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1126, __pyx_L48_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_3, __pyx_v_peer); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1126, __pyx_L48_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_t_3 = PyNumber_Subtract(__pyx_v_now, __pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1126, __pyx_L48_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            __pyx_t_8 = PyObject_RichCompare(__pyx_t_3, __pyx_int_1800, Py_GT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1126, __pyx_L48_error)
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1126, __pyx_L48_error)
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            if (__pyx_t_13) {

              /* "btdht/dht.pyx":1127
 *                     try:
 *                         if now - self._peers[hash][peer] > 30 * 60:
 *                             to_delete[hash].append(peer)             # <<<<<<<<<<<<<<
 *                     except KeyError:
 *                         pass
 */
              __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_to_delete, __pyx_v_hash); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1127, __pyx_L48_error)
              __Pyx_GOTREF(__pyx_t_8);
              __pyx_t_7 = __Pyx_PyObject_Append(__pyx_t_8, __pyx_v_peer); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 1127, __pyx_L48_error)
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

              /* "btdht/dht.pyx":1126
 *                 for peer in peers:
 *                     try:
 *                         if now - self._peers[hash][peer] > 30 * 60:             # <<<<<<<<<<<<<<
 *                             to_delete[hash].append(peer)
 *                     except KeyError:
 */
            }

            /* "btdht/dht.pyx":1125
 *             for hash, peers in six.iteritems(self._peers):
 *                 for peer in peers:
 *                     try:             # <<<<<<<<<<<<<<
 *                         if now - self._peers[hash][peer] > 30 * 60:
 *                             to_delete[hash].append(peer)
 */
          }
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
          goto __pyx_L55_try_end;
          __pyx_L48_error:;
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "btdht/dht.pyx":1128
 *                         if now - self._peers[hash][peer] > 30 * 60:
 *                             to_delete[hash].append(peer)
 *                     except KeyError:             # <<<<<<<<<<<<<<
 *                         pass
 *             for hash in to_delete:
 */
          __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
          if (__pyx_t_10) {
            __Pyx_ErrRestore(0,0,0);
            goto __pyx_L49_exception_handled;
          }
          goto __pyx_L50_except_error;
          __pyx_L50_except_error:;

          /* "btdht/dht.pyx":1125
 *             for hash, peers in six.iteritems(self._peers):
 *                 for peer in peers:
 *                     try:             # <<<<<<<<<<<<<<
 *                         if now - self._peers[hash][peer] > 30 * 60:
 *                             to_delete[hash].append(peer)
 */
          __Pyx_XGIVEREF(__pyx_t_14);
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_XGIVEREF(__pyx_t_16);
          __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16);
          goto __pyx_L1_error;
          __pyx_L49_exception_handled:;
          __Pyx_XGIVEREF(__pyx_t_14);
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_XGIVEREF(__pyx_t_16);
          __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16);
          __pyx_L55_try_end:;
        }

        /* "btdht/dht.pyx":1124
 *             to_delete = collections.defaultdict(list)
 *             for hash, peers in six.iteritems(self._peers):
 *                 for peer in peers:             # <<<<<<<<<<<<<<
 *                     try:
 *                         if now - self._peers[hash][peer] > 30 * 60:
 */
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "btdht/dht.pyx":1123
 *             # cleaning old peer for announce_peer
 *             to_delete = collections.defaultdict(list)
 *             for hash, peers in six.iteritems(self._peers):             # <<<<<<<<<<<<<<
 *                 for peer in peers:
 *                     try:
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1130
 *                     except KeyError:
 *                         pass
 *             for hash in to_delete:             # <<<<<<<<<<<<<<
 *                 for peer in to_delete[hash]:
 *                     try:
 */
    if (likely(PyList_CheckExact(__pyx_v_to_delete)) || PyTuple_CheckExact(__pyx_v_to_delete)) {
      __pyx_t_1 = __pyx_v_to_delete; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_to_delete); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1130, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1130, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1130, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1130, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1130, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1130, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_5(__pyx_t_1);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1130, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_v_hash, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "btdht/dht.pyx":1131
 *                         pass
 *             for hash in to_delete:
 *                 for peer in to_delete[hash]:             # <<<<<<<<<<<<<<
 *                     try:
 *                         del self._peers[hash][peer]
 */
      __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_to_delete, __pyx_v_hash); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1131, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
        __pyx_t_8 = __pyx_t_2; __Pyx_INCREF(__pyx_t_8); __pyx_t_11 = 0;
        __pyx_t_12 = NULL;
      } else {
        __pyx_t_11 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1131, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_12 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1131, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      for (;;) {
        if (likely(!__pyx_t_12)) {
          if (likely(PyList_CheckExact(__pyx_t_8))) {
            if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_8)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_2 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_11); __Pyx_INCREF(__pyx_t_2); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1131, __pyx_L1_error)
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_8, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1131, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            #endif
          } else {
            if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_11); __Pyx_INCREF(__pyx_t_2); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1131, __pyx_L1_error)
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_8, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1131, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            #endif
          }
        } else {
          __pyx_t_2 = __pyx_t_12(__pyx_t_8);
          if (unlikely(!__pyx_t_2)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 1131, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_2);
        }
        __Pyx_XDECREF_SET(__pyx_v_peer, __pyx_t_2);
        __pyx_t_2 = 0;

        /* "btdht/dht.pyx":1132
 *             for hash in to_delete:
 *                 for peer in to_delete[hash]:
 *                     try:             # <<<<<<<<<<<<<<
 *                         del self._peers[hash][peer]
 *                     except KeyError:
 */
        {
          __Pyx_PyThreadState_declare
          __Pyx_PyThreadState_assign
          __Pyx_ExceptionSave(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14);
          __Pyx_XGOTREF(__pyx_t_16);
          __Pyx_XGOTREF(__pyx_t_15);
          __Pyx_XGOTREF(__pyx_t_14);
          /*try:*/ {

            /* "btdht/dht.pyx":1133
 *                 for peer in to_delete[hash]:
 *                     try:
 *                         del self._peers[hash][peer]             # <<<<<<<<<<<<<<
 *                     except KeyError:
 *                         pass
 */
            __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_peers); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1133, __pyx_L61_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_hash); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1133, __pyx_L61_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            if (unlikely(PyObject_DelItem(__pyx_t_3, __pyx_v_peer) < 0)) __PYX_ERR(0, 1133, __pyx_L61_error)
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

            /* "btdht/dht.pyx":1132
 *             for hash in to_delete:
 *                 for peer in to_delete[hash]:
 *                     try:             # <<<<<<<<<<<<<<
 *                         del self._peers[hash][peer]
 *                     except KeyError:
 */
          }
          __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          goto __pyx_L68_try_end;
          __pyx_L61_error:;
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "btdht/dht.pyx":1134
 *                     try:
 *                         del self._peers[hash][peer]
 *                     except KeyError:             # <<<<<<<<<<<<<<
 *                         pass
 *                 if not self._peers[hash]:
 */
          __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
          if (__pyx_t_10) {
            __Pyx_ErrRestore(0,0,0);
            goto __pyx_L62_exception_handled;
          }
          goto __pyx_L63_except_error;
          __pyx_L63_except_error:;

          /* "btdht/dht.pyx":1132
 *             for hash in to_delete:
 *                 for peer in to_delete[hash]:
 *                     try:             # <<<<<<<<<<<<<<
 *                         del self._peers[hash][peer]
 *                     except KeyError:
 */
          __Pyx_XGIVEREF(__pyx_t_16);
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_XGIVEREF(__pyx_t_14);
          __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_15, __pyx_t_14);
          goto __pyx_L1_error;
          __pyx_L62_exception_handled:;
          __Pyx_XGIVEREF(__pyx_t_16);
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_XGIVEREF(__pyx_t_14);
          __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_15, __pyx_t_14);
          __pyx_L68_try_end:;
        }

        /* "btdht/dht.pyx":1131
 *                         pass
 *             for hash in to_delete:
 *                 for peer in to_delete[hash]:             # <<<<<<<<<<<<<<
 *                     try:
 *                         del self._peers[hash][peer]
 */
      }
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "btdht/dht.pyx":1136
 *                     except KeyError:
 *                         pass
 *                 if not self._peers[hash]:             # <<<<<<<<<<<<<<
 *                     del self._peers[hash]
 * 
 */
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_peers); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1136, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_8, __pyx_v_hash); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1136, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 1136, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = ((!__pyx_t_13) != 0);
      if (__pyx_t_6) {

        /* "btdht/dht.pyx":1137
 *                         pass
 *                 if not self._peers[hash]:
 *                     del self._peers[hash]             # <<<<<<<<<<<<<<
 * 
 *             to_delete = collections.defaultdict(list)
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_peers); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1137, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        if (unlikely(PyObject_DelItem(__pyx_t_3, __pyx_v_hash) < 0)) __PYX_ERR(0, 1137, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "btdht/dht.pyx":1136
 *                     except KeyError:
 *                         pass
 *                 if not self._peers[hash]:             # <<<<<<<<<<<<<<
 *                     del self._peers[hash]
 * 
 */
      }

      /* "btdht/dht.pyx":1130
 *                     except KeyError:
 *                         pass
 *             for hash in to_delete:             # <<<<<<<<<<<<<<
 *                 for peer in to_delete[hash]:
 *                     try:
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1139
 *                     del self._peers[hash]
 * 
 *             to_delete = collections.defaultdict(list)             # <<<<<<<<<<<<<<
 *             for hash, peers in six.iteritems(self._got_peers):
 *                 for peer in peers:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_collections); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1139, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1139, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, ((PyObject *)(&PyList_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_8, ((PyObject *)(&PyList_Type)));
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1139, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF_SET(__pyx_v_to_delete, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1140
 * 
 *             to_delete = collections.defaultdict(list)
 *             for hash, peers in six.iteritems(self._got_peers):             # <<<<<<<<<<<<<<
 *                 for peer in peers:
 *                     try:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_six); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_iteritems); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_8);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1140, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1140, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1140, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_3))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1140, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1140, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1140, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1140, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_5(__pyx_t_3);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1140, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
        PyObject* sequence = __pyx_t_1;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 1140, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_2);
        #else
        __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1140, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1140, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1140, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_17 = Py_TYPE(__pyx_t_9)->tp_iternext;
        index = 0; __pyx_t_8 = __pyx_t_17(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L72_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_8);
        index = 1; __pyx_t_2 = __pyx_t_17(__pyx_t_9); if (unlikely(!__pyx_t_2)) goto __pyx_L72_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_2);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_9), 2) < 0) __PYX_ERR(0, 1140, __pyx_L1_error)
        __pyx_t_17 = NULL;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L73_unpacking_done;
        __pyx_L72_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_17 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 1140, __pyx_L1_error)
        __pyx_L73_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_hash, __pyx_t_8);
      __pyx_t_8 = 0;
      __Pyx_XDECREF_SET(__pyx_v_peers, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "btdht/dht.pyx":1141
 *             to_delete = collections.defaultdict(list)
 *             for hash, peers in six.iteritems(self._got_peers):
 *                 for peer in peers:             # <<<<<<<<<<<<<<
 *                     try:
 *                         if now - self._got_peers[hash][peer] > 15 * 60:
 */
      if (likely(PyList_CheckExact(__pyx_v_peers)) || PyTuple_CheckExact(__pyx_v_peers)) {
        __pyx_t_1 = __pyx_v_peers; __Pyx_INCREF(__pyx_t_1); __pyx_t_11 = 0;
        __pyx_t_12 = NULL;
      } else {
        __pyx_t_11 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_peers); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1141, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_12 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1141, __pyx_L1_error)
      }
      for (;;) {
        if (likely(!__pyx_t_12)) {
          if (likely(PyList_CheckExact(__pyx_t_1))) {
            if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_1)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_11); __Pyx_INCREF(__pyx_t_2); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1141, __pyx_L1_error)
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1141, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            #endif
          } else {
            if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_11); __Pyx_INCREF(__pyx_t_2); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1141, __pyx_L1_error)
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1141, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            #endif
          }
        } else {
          __pyx_t_2 = __pyx_t_12(__pyx_t_1);
          if (unlikely(!__pyx_t_2)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 1141, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_2);
        }
        __Pyx_XDECREF_SET(__pyx_v_peer, __pyx_t_2);
        __pyx_t_2 = 0;

        /* "btdht/dht.pyx":1142
 *             for hash, peers in six.iteritems(self._got_peers):
 *                 for peer in peers:
 *                     try:             # <<<<<<<<<<<<<<
 *                         if now - self._got_peers[hash][peer] > 15 * 60:
 *                             to_delete[hash].append(peer)
 */
        {
          __Pyx_PyThreadState_declare
          __Pyx_PyThreadState_assign
          __Pyx_ExceptionSave(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16);
          __Pyx_XGOTREF(__pyx_t_14);
          __Pyx_XGOTREF(__pyx_t_15);
          __Pyx_XGOTREF(__pyx_t_16);
          /*try:*/ {

            /* "btdht/dht.pyx":1143
 *                 for peer in peers:
 *                     try:
 *                         if now - self._got_peers[hash][peer] > 15 * 60:             # <<<<<<<<<<<<<<
 *                             to_delete[hash].append(peer)
 *                     except KeyError:
 */
            __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1143, __pyx_L76_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_hash); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1143, __pyx_L76_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_8, __pyx_v_peer); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1143, __pyx_L76_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            __pyx_t_8 = PyNumber_Subtract(__pyx_v_now, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1143, __pyx_L76_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __pyx_t_2 = PyObject_RichCompare(__pyx_t_8, __pyx_int_900, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1143, __pyx_L76_error)
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1143, __pyx_L76_error)
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            if (__pyx_t_6) {

              /* "btdht/dht.pyx":1144
 *                     try:
 *                         if now - self._got_peers[hash][peer] > 15 * 60:
 *                             to_delete[hash].append(peer)             # <<<<<<<<<<<<<<
 *                     except KeyError:
 *                         pass
 */
              __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_to_delete, __pyx_v_hash); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1144, __pyx_L76_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_7 = __Pyx_PyObject_Append(__pyx_t_2, __pyx_v_peer); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 1144, __pyx_L76_error)
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

              /* "btdht/dht.pyx":1143
 *                 for peer in peers:
 *                     try:
 *                         if now - self._got_peers[hash][peer] > 15 * 60:             # <<<<<<<<<<<<<<
 *                             to_delete[hash].append(peer)
 *                     except KeyError:
 */
            }

            /* "btdht/dht.pyx":1142
 *             for hash, peers in six.iteritems(self._got_peers):
 *                 for peer in peers:
 *                     try:             # <<<<<<<<<<<<<<
 *                         if now - self._got_peers[hash][peer] > 15 * 60:
 *                             to_delete[hash].append(peer)
 */
          }
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
          goto __pyx_L83_try_end;
          __pyx_L76_error:;
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "btdht/dht.pyx":1145
 *                         if now - self._got_peers[hash][peer] > 15 * 60:
 *                             to_delete[hash].append(peer)
 *                     except KeyError:             # <<<<<<<<<<<<<<
 *                         pass
 *             for hash in to_delete:
 */
          __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
          if (__pyx_t_10) {
            __Pyx_ErrRestore(0,0,0);
            goto __pyx_L77_exception_handled;
          }
          goto __pyx_L78_except_error;
          __pyx_L78_except_error:;

          /* "btdht/dht.pyx":1142
 *             for hash, peers in six.iteritems(self._got_peers):
 *                 for peer in peers:
 *                     try:             # <<<<<<<<<<<<<<
 *                         if now - self._got_peers[hash][peer] > 15 * 60:
 *                             to_delete[hash].append(peer)
 */
          __Pyx_XGIVEREF(__pyx_t_14);
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_XGIVEREF(__pyx_t_16);
          __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16);
          goto __pyx_L1_error;
          __pyx_L77_exception_handled:;
          __Pyx_XGIVEREF(__pyx_t_14);
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_XGIVEREF(__pyx_t_16);
          __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16);
          __pyx_L83_try_end:;
        }

        /* "btdht/dht.pyx":1141
 *             to_delete = collections.defaultdict(list)
 *             for hash, peers in six.iteritems(self._got_peers):
 *                 for peer in peers:             # <<<<<<<<<<<<<<
 *                     try:
 *                         if now - self._got_peers[hash][peer] > 15 * 60:
 */
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "btdht/dht.pyx":1140
 * 
 *             to_delete = collections.defaultdict(list)
 *             for hash, peers in six.iteritems(self._got_peers):             # <<<<<<<<<<<<<<
 *                 for peer in peers:
 *                     try:
 */
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1147
 *                     except KeyError:
 *                         pass
 *             for hash in to_delete:             # <<<<<<<<<<<<<<
 *                 for peer in to_delete[hash]:
 *                     try:
 */
    if (likely(PyList_CheckExact(__pyx_v_to_delete)) || PyTuple_CheckExact(__pyx_v_to_delete)) {
      __pyx_t_3 = __pyx_v_to_delete; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
      __pyx_t_5 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_to_delete); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1147, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1147, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_5)) {
        if (likely(PyList_CheckExact(__pyx_t_3))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1147, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1147, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 1147, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1147, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_5(__pyx_t_3);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1147, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF_SET(__pyx_v_hash, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "btdht/dht.pyx":1148
 *                         pass
 *             for hash in to_delete:
 *                 for peer in to_delete[hash]:             # <<<<<<<<<<<<<<
 *                     try:
 *                         del self._got_peers[hash][peer]
 */
      __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_to_delete, __pyx_v_hash); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1148, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
        __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_11 = 0;
        __pyx_t_12 = NULL;
      } else {
        __pyx_t_11 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1148, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_12 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1148, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      for (;;) {
        if (likely(!__pyx_t_12)) {
          if (likely(PyList_CheckExact(__pyx_t_2))) {
            if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_2)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_11); __Pyx_INCREF(__pyx_t_1); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1148, __pyx_L1_error)
            #else
            __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1148, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            #endif
          } else {
            if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_11); __Pyx_INCREF(__pyx_t_1); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1148, __pyx_L1_error)
            #else
            __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1148, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            #endif
          }
        } else {
          __pyx_t_1 = __pyx_t_12(__pyx_t_2);
          if (unlikely(!__pyx_t_1)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 1148, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_1);
        }
        __Pyx_XDECREF_SET(__pyx_v_peer, __pyx_t_1);
        __pyx_t_1 = 0;

        /* "btdht/dht.pyx":1149
 *             for hash in to_delete:
 *                 for peer in to_delete[hash]:
 *                     try:             # <<<<<<<<<<<<<<
 *                         del self._got_peers[hash][peer]
 *                     except KeyError:
 */
        {
          __Pyx_PyThreadState_declare
          __Pyx_PyThreadState_assign
          __Pyx_ExceptionSave(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14);
          __Pyx_XGOTREF(__pyx_t_16);
          __Pyx_XGOTREF(__pyx_t_15);
          __Pyx_XGOTREF(__pyx_t_14);
          /*try:*/ {

            /* "btdht/dht.pyx":1150
 *                 for peer in to_delete[hash]:
 *                     try:
 *                         del self._got_peers[hash][peer]             # <<<<<<<<<<<<<<
 *                     except KeyError:
 *                         pass
 */
            __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1150, __pyx_L89_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_hash); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1150, __pyx_L89_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            if (unlikely(PyObject_DelItem(__pyx_t_8, __pyx_v_peer) < 0)) __PYX_ERR(0, 1150, __pyx_L89_error)
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

            /* "btdht/dht.pyx":1149
 *             for hash in to_delete:
 *                 for peer in to_delete[hash]:
 *                     try:             # <<<<<<<<<<<<<<
 *                         del self._got_peers[hash][peer]
 *                     except KeyError:
 */
          }
          __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          goto __pyx_L96_try_end;
          __pyx_L89_error:;
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "btdht/dht.pyx":1151
 *                     try:
 *                         del self._got_peers[hash][peer]
 *                     except KeyError:             # <<<<<<<<<<<<<<
 *                         pass
 *                 if not self._got_peers[hash]:
 */
          __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
          if (__pyx_t_10) {
            __Pyx_ErrRestore(0,0,0);
            goto __pyx_L90_exception_handled;
          }
          goto __pyx_L91_except_error;
          __pyx_L91_except_error:;

          /* "btdht/dht.pyx":1149
 *             for hash in to_delete:
 *                 for peer in to_delete[hash]:
 *                     try:             # <<<<<<<<<<<<<<
 *                         del self._got_peers[hash][peer]
 *                     except KeyError:
 */
          __Pyx_XGIVEREF(__pyx_t_16);
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_XGIVEREF(__pyx_t_14);
          __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_15, __pyx_t_14);
          goto __pyx_L1_error;
          __pyx_L90_exception_handled:;
          __Pyx_XGIVEREF(__pyx_t_16);
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_XGIVEREF(__pyx_t_14);
          __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_15, __pyx_t_14);
          __pyx_L96_try_end:;
        }

        /* "btdht/dht.pyx":1148
 *                         pass
 *             for hash in to_delete:
 *                 for peer in to_delete[hash]:             # <<<<<<<<<<<<<<
 *                     try:
 *                         del self._got_peers[hash][peer]
 */
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "btdht/dht.pyx":1153
 *                     except KeyError:
 *                         pass
 *                 if not self._got_peers[hash]:             # <<<<<<<<<<<<<<
 *                     del self._got_peers[hash]
 * 
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_hash); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1153, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_13 = ((!__pyx_t_6) != 0);
      if (__pyx_t_13) {

        /* "btdht/dht.pyx":1154
 *                         pass
 *                 if not self._got_peers[hash]:
 *                     del self._got_peers[hash]             # <<<<<<<<<<<<<<
 * 
 *             self.clean_long()
 */
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_got_peers); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1154, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        if (unlikely(PyObject_DelItem(__pyx_t_8, __pyx_v_hash) < 0)) __PYX_ERR(0, 1154, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

        /* "btdht/dht.pyx":1153
 *                     except KeyError:
 *                         pass
 *                 if not self._got_peers[hash]:             # <<<<<<<<<<<<<<
 *                     del self._got_peers[hash]
 * 
 */
      }

      /* "btdht/dht.pyx":1147
 *                     except KeyError:
 *                         pass
 *             for hash in to_delete:             # <<<<<<<<<<<<<<
 *                 for peer in to_delete[hash]:
 *                     try:
 */
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1156
 *                     del self._got_peers[hash]
 * 
 *             self.clean_long()             # <<<<<<<<<<<<<<
 * 
 *             self._long_clean = now
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_clean_long); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1156, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_8);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1156, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1158
 *             self.clean_long()
 * 
 *             self._long_clean = now             # <<<<<<<<<<<<<<
 * 
 *     def build_table(self):
 */
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_long_clean, __pyx_v_now) < 0) __PYX_ERR(0, 1158, __pyx_L1_error)

    /* "btdht/dht.pyx":1099
 * 
 *         # Long cleaning
 *         if now - self._long_clean >= 15 * 60:             # <<<<<<<<<<<<<<
 *             # cleaning old tokens
 *             to_delete = []
 */
  }

  /* "btdht/dht.pyx":1055
 *         pass
 * 
 *     def _clean(self):             # <<<<<<<<<<<<<<
 *         """
 *             Function cleaning datastructures of the DHT
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._clean", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_now);
  __Pyx_XDECREF(__pyx_v_to_delete);
  __Pyx_XDECREF(__pyx_v_id);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XDECREF(__pyx_v_ip);
  __Pyx_XDECREF(__pyx_v_hash);
  __Pyx_XDECREF(__pyx_v_peers);
  __Pyx_XDECREF(__pyx_v_peer);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1160
 *             self._long_clean = now
 * 
 *     def build_table(self):             # <<<<<<<<<<<<<<
 *         """Build the routing table by querying find_nodes on the dht own id :attr:`myid`"""
 *         nodes = self.get_closest_nodes(self.myid)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_58build_table(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_57build_table[] = "Build the routing table by querying find_nodes on the dht own id :attr:`myid`";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_58build_table(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("build_table (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_57build_table(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_57build_table(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  PyObject *__pyx_v_nodes = NULL;
  PyObject *__pyx_v_node = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("build_table", 0);

  /* "btdht/dht.pyx":1162
 *     def build_table(self):
 *         """Build the routing table by querying find_nodes on the dht own id :attr:`myid`"""
 *         nodes = self.get_closest_nodes(self.myid)             # <<<<<<<<<<<<<<
 *         for node in nodes:
 *             node.find_node(self, self.myid)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_closest_nodes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_myid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_nodes = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1163
 *         """Build the routing table by querying find_nodes on the dht own id :attr:`myid`"""
 *         nodes = self.get_closest_nodes(self.myid)
 *         for node in nodes:             # <<<<<<<<<<<<<<
 *             node.find_node(self, self.myid)
 *         return bool(nodes)
 */
  if (likely(PyList_CheckExact(__pyx_v_nodes)) || PyTuple_CheckExact(__pyx_v_nodes)) {
    __pyx_t_1 = __pyx_v_nodes; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_nodes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1163, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1163, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1163, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1163, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1163, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1163, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1163, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XDECREF_SET(__pyx_v_node, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "btdht/dht.pyx":1164
 *         nodes = self.get_closest_nodes(self.myid)
 *         for node in nodes:
 *             node.find_node(self, self.myid)             # <<<<<<<<<<<<<<
 *         return bool(nodes)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_find_node); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1164, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_myid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1164, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = NULL;
    __pyx_t_8 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_8 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, ((PyObject *)__pyx_v_self), __pyx_t_4};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1164, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, ((PyObject *)__pyx_v_self), __pyx_t_4};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1164, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1164, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (__pyx_t_7) {
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, ((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1164, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "btdht/dht.pyx":1163
 *         """Build the routing table by querying find_nodes on the dht own id :attr:`myid`"""
 *         nodes = self.get_closest_nodes(self.myid)
 *         for node in nodes:             # <<<<<<<<<<<<<<
 *             node.find_node(self, self.myid)
 *         return bool(nodes)
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1165
 *         for node in nodes:
 *             node.find_node(self, self.myid)
 *         return bool(nodes)             # <<<<<<<<<<<<<<
 * 
 *     def _routine(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_nodes); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 1165, __pyx_L1_error)
  __pyx_t_1 = __Pyx_PyBool_FromLong((!(!__pyx_t_10))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1165, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":1160
 *             self._long_clean = now
 * 
 *     def build_table(self):             # <<<<<<<<<<<<<<
 *         """Build the routing table by querying find_nodes on the dht own id :attr:`myid`"""
 *         nodes = self.get_closest_nodes(self.myid)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.build_table", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_nodes);
  __Pyx_XDECREF(__pyx_v_node);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_5btdht_3dht_8DHT_BASE_61generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "btdht/dht.pyx":1167
 *         return bool(nodes)
 * 
 *     def _routine(self):             # <<<<<<<<<<<<<<
 *         """
 *             Weigthless thread performing some routine (boostraping, building the routing table,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_60_routine(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_59_routine[] = "\n            Weigthless thread performing some routine (boostraping, building the routing table,\n            cleaning) on the DHT\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_60_routine(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_routine (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_59_routine(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_59_routine(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_routine", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct_4__routine(__pyx_ptype_5btdht_3dht___pyx_scope_struct_4__routine, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 1167, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5btdht_3dht_8DHT_BASE_61generator1, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_routine, __pyx_n_s_DHT_BASE__routine, __pyx_n_s_btdht_dht); if (unlikely(!gen)) __PYX_ERR(0, 1167, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._routine", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5btdht_3dht_8DHT_BASE_61generator1(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine *__pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_routine", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L4_resume_from_yield;
    case 2: goto __pyx_L8_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1167, __pyx_L1_error)

  /* "btdht/dht.pyx":1172
 *             cleaning) on the DHT
 *         """
 *         yield 0             # <<<<<<<<<<<<<<
 *         next_routine = time.time() + 15
 *         while True:
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_r = __pyx_int_0;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  /* return from generator, yielding value */
  __pyx_generator->resume_label = 1;
  return __pyx_r;
  __pyx_L4_resume_from_yield:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1172, __pyx_L1_error)

  /* "btdht/dht.pyx":1173
 *         """
 *         yield 0
 *         next_routine = time.time() + 15             # <<<<<<<<<<<<<<
 *         while True:
 *             if self.stoped:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1173, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1173, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1173, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_15, 15, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1173, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_cur_scope->__pyx_v_next_routine = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "btdht/dht.pyx":1174
 *         yield 0
 *         next_routine = time.time() + 15
 *         while True:             # <<<<<<<<<<<<<<
 *             if self.stoped:
 *                 return
 */
  while (1) {

    /* "btdht/dht.pyx":1175
 *         next_routine = time.time() + 15
 *         while True:
 *             if self.stoped:             # <<<<<<<<<<<<<<
 *                 return
 *             yield next_routine
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_stoped); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1175, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1175, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_4) {

      /* "btdht/dht.pyx":1176
 *         while True:
 *             if self.stoped:
 *                 return             # <<<<<<<<<<<<<<
 *             yield next_routine
 *             now = time.time()
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_r = NULL;
      goto __pyx_L0;

      /* "btdht/dht.pyx":1175
 *         next_routine = time.time() + 15
 *         while True:
 *             if self.stoped:             # <<<<<<<<<<<<<<
 *                 return
 *             yield next_routine
 */
    }

    /* "btdht/dht.pyx":1177
 *             if self.stoped:
 *                 return
 *             yield next_routine             # <<<<<<<<<<<<<<
 *             now = time.time()
 *             next_routine = now + 15
 */
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_next_routine);
    __pyx_r = __pyx_cur_scope->__pyx_v_next_routine;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 2;
    return __pyx_r;
    __pyx_L8_resume_from_yield:;
    if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1177, __pyx_L1_error)

    /* "btdht/dht.pyx":1178
 *                 return
 *             yield next_routine
 *             now = time.time()             # <<<<<<<<<<<<<<
 *             next_routine = now + 15
 * 
 */
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1178, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1178, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1178, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_now);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_now, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1179
 *             yield next_routine
 *             now = time.time()
 *             next_routine = now + 15             # <<<<<<<<<<<<<<
 * 
 *             # calling clean every 15s
 */
    __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_cur_scope->__pyx_v_now, __pyx_int_15, 15, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1179, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_next_routine);
    __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_next_routine, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1182
 * 
 *             # calling clean every 15s
 *             self._clean()             # <<<<<<<<<<<<<<
 * 
 *             # Searching its own id while the Routing table is growing
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_clean_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1182, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1182, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1185
 * 
 *             # Searching its own id while the Routing table is growing
 *             if self._root_heigth != self.root.heigth():             # <<<<<<<<<<<<<<
 *                 self.debug(1, "Fetching my own id")
 *                 if self.build_table():
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_root_heigth); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_heigth); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_4) {

      /* "btdht/dht.pyx":1186
 *             # Searching its own id while the Routing table is growing
 *             if self._root_heigth != self.root.heigth():
 *                 self.debug(1, "Fetching my own id")             # <<<<<<<<<<<<<<
 *                 if self.build_table():
 *                     self._root_heigth = self.root.heigth()
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1186, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1186, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "btdht/dht.pyx":1187
 *             if self._root_heigth != self.root.heigth():
 *                 self.debug(1, "Fetching my own id")
 *                 if self.build_table():             # <<<<<<<<<<<<<<
 *                     self._root_heigth = self.root.heigth()
 * 
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_build_table); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1187, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1187, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1187, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_4) {

        /* "btdht/dht.pyx":1188
 *                 self.debug(1, "Fetching my own id")
 *                 if self.build_table():
 *                     self._root_heigth = self.root.heigth()             # <<<<<<<<<<<<<<
 * 
 *             # displaying some stats
 */
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1188, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_heigth); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1188, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1188, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_root_heigth, __pyx_t_2) < 0) __PYX_ERR(0, 1188, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "btdht/dht.pyx":1187
 *             if self._root_heigth != self.root.heigth():
 *                 self.debug(1, "Fetching my own id")
 *                 if self.build_table():             # <<<<<<<<<<<<<<
 *                     self._root_heigth = self.root.heigth()
 * 
 */
      }

      /* "btdht/dht.pyx":1185
 * 
 *             # Searching its own id while the Routing table is growing
 *             if self._root_heigth != self.root.heigth():             # <<<<<<<<<<<<<<
 *                 self.debug(1, "Fetching my own id")
 *                 if self.build_table():
 */
    }

    /* "btdht/dht.pyx":1191
 * 
 *             # displaying some stats
 *             (in_s, out_s, delta) = self._socket_stats()             # <<<<<<<<<<<<<<
 *             if in_s <= 0 or self.debuglvl > 0:
 *                 (nodes, goods, bads) = self.root.stats()
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_socket_stats); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1191, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1191, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
      PyObject* sequence = __pyx_t_2;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 3)) {
        if (size > 3) __Pyx_RaiseTooManyValuesError(3);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 1191, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); 
      } else {
        __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_1 = PyList_GET_ITEM(sequence, 2); 
      }
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_1);
      #else
      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1191, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1191, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1191, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      #endif
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_6 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1191, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext;
      index = 0; __pyx_t_3 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L11_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_3);
      index = 1; __pyx_t_5 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L11_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_5);
      index = 2; __pyx_t_1 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_1)) goto __pyx_L11_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_1);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 3) < 0) __PYX_ERR(0, 1191, __pyx_L1_error)
      __pyx_t_7 = NULL;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L12_unpacking_done;
      __pyx_L11_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_7 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 1191, __pyx_L1_error)
      __pyx_L12_unpacking_done:;
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_in_s);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_in_s, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_out_s);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_out_s, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_delta);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_delta, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1192
 *             # displaying some stats
 *             (in_s, out_s, delta) = self._socket_stats()
 *             if in_s <= 0 or self.debuglvl > 0:             # <<<<<<<<<<<<<<
 *                 (nodes, goods, bads) = self.root.stats()
 *                 if goods <= 0:
 */
    __pyx_t_2 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_in_s, __pyx_int_0, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1192, __pyx_L1_error)
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1192, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!__pyx_t_8) {
    } else {
      __pyx_t_4 = __pyx_t_8;
      goto __pyx_L14_bool_binop_done;
    }
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_debuglvl); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1192, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1192, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1192, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = __pyx_t_8;
    __pyx_L14_bool_binop_done:;
    if (__pyx_t_4) {

      /* "btdht/dht.pyx":1193
 *             (in_s, out_s, delta) = self._socket_stats()
 *             if in_s <= 0 or self.debuglvl > 0:
 *                 (nodes, goods, bads) = self.root.stats()             # <<<<<<<<<<<<<<
 *                 if goods <= 0:
 *                     self.bootstarp()
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1193, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_stats); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1193, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1193, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
        PyObject* sequence = __pyx_t_1;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 3)) {
          if (size > 3) __Pyx_RaiseTooManyValuesError(3);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 1193, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); 
        } else {
          __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
          __pyx_t_3 = PyList_GET_ITEM(sequence, 2); 
        }
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        #else
        __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1193, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1193, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1193, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_6 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1193, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext;
        index = 0; __pyx_t_5 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L16_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_5);
        index = 1; __pyx_t_2 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_2)) goto __pyx_L16_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_2);
        index = 2; __pyx_t_3 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L16_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 3) < 0) __PYX_ERR(0, 1193, __pyx_L1_error)
        __pyx_t_7 = NULL;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        goto __pyx_L17_unpacking_done;
        __pyx_L16_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_7 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 1193, __pyx_L1_error)
        __pyx_L17_unpacking_done:;
      }
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_nodes);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_nodes, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_5 = 0;
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_goods);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_goods, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_bads);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_bads, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;

      /* "btdht/dht.pyx":1194
 *             if in_s <= 0 or self.debuglvl > 0:
 *                 (nodes, goods, bads) = self.root.stats()
 *                 if goods <= 0:             # <<<<<<<<<<<<<<
 *                     self.bootstarp()
 *                     next_routine = now + 1
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_goods, __pyx_int_0, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1194, __pyx_L1_error)
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1194, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_4) {

        /* "btdht/dht.pyx":1195
 *                 (nodes, goods, bads) = self.root.stats()
 *                 if goods <= 0:
 *                     self.bootstarp()             # <<<<<<<<<<<<<<
 *                     next_routine = now + 1
 *                 self.debug(
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_bootstarp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1195, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_2 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_2)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1195, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "btdht/dht.pyx":1196
 *                 if goods <= 0:
 *                     self.bootstarp()
 *                     next_routine = now + 1             # <<<<<<<<<<<<<<
 *                 self.debug(
 *                     0 if in_s <= 0 and out_s > 0 and goods < 20 else 1,
 */
        __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_cur_scope->__pyx_v_now, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1196, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_next_routine);
        __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_next_routine, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_1);
        __pyx_t_1 = 0;

        /* "btdht/dht.pyx":1194
 *             if in_s <= 0 or self.debuglvl > 0:
 *                 (nodes, goods, bads) = self.root.stats()
 *                 if goods <= 0:             # <<<<<<<<<<<<<<
 *                     self.bootstarp()
 *                     next_routine = now + 1
 */
      }

      /* "btdht/dht.pyx":1197
 *                     self.bootstarp()
 *                     next_routine = now + 1
 *                 self.debug(             # <<<<<<<<<<<<<<
 *                     0 if in_s <= 0 and out_s > 0 and goods < 20 else 1,
 *                     "%d nodes, %d goods, %d bads | in: %s, out: %s en %ss" % (
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1197, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);

      /* "btdht/dht.pyx":1198
 *                     next_routine = now + 1
 *                 self.debug(
 *                     0 if in_s <= 0 and out_s > 0 and goods < 20 else 1,             # <<<<<<<<<<<<<<
 *                     "%d nodes, %d goods, %d bads | in: %s, out: %s en %ss" % (
 *                         nodes, goods, bads, in_s, out_s, int(delta)
 */
      __pyx_t_5 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_in_s, __pyx_int_0, Py_LE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1198, __pyx_L1_error)
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1198, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_8) {
      } else {
        __pyx_t_4 = __pyx_t_8;
        goto __pyx_L19_bool_binop_done;
      }
      __pyx_t_5 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_out_s, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1198, __pyx_L1_error)
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1198, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_8) {
      } else {
        __pyx_t_4 = __pyx_t_8;
        goto __pyx_L19_bool_binop_done;
      }
      __pyx_t_5 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_goods, __pyx_int_20, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1198, __pyx_L1_error)
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1198, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_4 = __pyx_t_8;
      __pyx_L19_bool_binop_done:;
      if (__pyx_t_4) {
        __Pyx_INCREF(__pyx_int_0);
        __pyx_t_2 = __pyx_int_0;
      } else {
        __Pyx_INCREF(__pyx_int_1);
        __pyx_t_2 = __pyx_int_1;
      }

      /* "btdht/dht.pyx":1200
 *                     0 if in_s <= 0 and out_s > 0 and goods < 20 else 1,
 *                     "%d nodes, %d goods, %d bads | in: %s, out: %s en %ss" % (
 *                         nodes, goods, bads, in_s, out_s, int(delta)             # <<<<<<<<<<<<<<
 *                     )
 *                 )
 */
      __pyx_t_5 = __Pyx_PyNumber_Int(__pyx_cur_scope->__pyx_v_delta); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1200, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyTuple_New(6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1200, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_nodes);
      __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_nodes);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_cur_scope->__pyx_v_nodes);
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_goods);
      __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_goods);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_cur_scope->__pyx_v_goods);
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_bads);
      __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_bads);
      PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_cur_scope->__pyx_v_bads);
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_in_s);
      __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_in_s);
      PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_cur_scope->__pyx_v_in_s);
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_out_s);
      __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_out_s);
      PyTuple_SET_ITEM(__pyx_t_6, 4, __pyx_cur_scope->__pyx_v_out_s);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_6, 5, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "btdht/dht.pyx":1199
 *                 self.debug(
 *                     0 if in_s <= 0 and out_s > 0 and goods < 20 else 1,
 *                     "%d nodes, %d goods, %d bads | in: %s, out: %s en %ss" % (             # <<<<<<<<<<<<<<
 *                         nodes, goods, bads, in_s, out_s, int(delta)
 *                     )
 */
      __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_d_nodes_d_goods_d_bads_in_s_out, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1199, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_9 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_3)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_2, __pyx_t_5};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1197, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_2, __pyx_t_5};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1197, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else
      #endif
      {
        __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1197, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        if (__pyx_t_6) {
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_6); __pyx_t_6 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_5);
        __pyx_t_2 = 0;
        __pyx_t_5 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1197, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "btdht/dht.pyx":1192
 *             # displaying some stats
 *             (in_s, out_s, delta) = self._socket_stats()
 *             if in_s <= 0 or self.debuglvl > 0:             # <<<<<<<<<<<<<<
 *                 (nodes, goods, bads) = self.root.stats()
 *                 if goods <= 0:
 */
    }
  }
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* "btdht/dht.pyx":1167
 *         return bool(nodes)
 * 
 *     def _routine(self):             # <<<<<<<<<<<<<<
 *         """
 *             Weigthless thread performing some routine (boostraping, building the routing table,
 */

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("_routine", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1205
 * 
 * 
 *     def register_message(self, msg):             # <<<<<<<<<<<<<<
 *         """
 *             Register a dht message to be processed by the following user defined functions
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_63register_message(PyObject *__pyx_v_self, PyObject *__pyx_v_msg); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_62register_message[] = "\n            Register a dht message to be processed by the following user defined functions\n                * :meth:`on_error`\n                * :meth:`on_ping_query`\n                * :meth:`on_ping_response`\n                * :meth:`on_find_node_query`\n                * :meth:`on_find_node_response`\n                * :meth:`on_get_peers_query`\n                * :meth:`on_get_peers_response`\n                * :meth:`on_announce_peer_query`\n                * :meth:`on_announce_peer_response`\n                * ...\n\n            :param bytes msg: A dht message to register like ``b'error'``, ``b'ping'``,\n                ``b'find_node'``, ``b'get_peers'`` or ``b'announce_peer'``\n\n            Note:\n              * on query reception, the function on_``msg``_query will be call with the\n                query as parameter\n              * on response reception, the function on_``msg``_response will be called with\n                the query and the response as parameters\n              * on error reception, the function ``on_error`` will be called with the error and\n                the query as parameter\n              * The message kind is in the ``q`` key of any dht query message\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_63register_message(PyObject *__pyx_v_self, PyObject *__pyx_v_msg) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("register_message (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_62register_message(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v_msg));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_62register_message(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_msg) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("register_message", 0);

  /* "btdht/dht.pyx":1231
 *               * The message kind is in the ``q`` key of any dht query message
 *         """
 *         self._to_process_registered.add(msg)             # <<<<<<<<<<<<<<
 * 
 *     def on_error(self, error, query=None):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_process_registered); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1231, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_add); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1231, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_msg) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_msg);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1231, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1205
 * 
 * 
 *     def register_message(self, msg):             # <<<<<<<<<<<<<<
 *         """
 *             Register a dht message to be processed by the following user defined functions
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.register_message", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1233
 *         self._to_process_registered.add(msg)
 * 
 *     def on_error(self, error, query=None):             # <<<<<<<<<<<<<<
 *         """
 *             Function called then a query has be responded by an error message.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_65on_error(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_64on_error[] = "\n            Function called then a query has be responded by an error message.\n            Can safely the overloaded.\n\n            :param krcp.Berror error: An error instance\n            :param krcp.BMessage query: An optional query raising the error message\n\n            Notes:\n                For this function to be called on error reception, you need to call\n                :meth:`register_message` with the parameter ``b'error'``\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_65on_error(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_error = 0;
  CYTHON_UNUSED PyObject *__pyx_v_query = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_error (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_error,&__pyx_n_s_query,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_error)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "on_error") < 0)) __PYX_ERR(0, 1233, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_error = values[0];
    __pyx_v_query = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("on_error", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1233, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.on_error", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_64on_error(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_error, __pyx_v_query);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_64on_error(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_error, CYTHON_UNUSED PyObject *__pyx_v_query) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_error", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1246
 *         """
 *         pass
 *     def on_ping_response(self, query, response):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a ping response reception. Can safely the overloaded
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_67on_ping_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_66on_ping_response[] = "\n            Function called on a ping response reception. Can safely the overloaded\n\n            :param krcp.BMessage query: the sent query object\n            :param krcp.BMessage response: the received response object\n\n            Notes:\n                For this function to be called on ping response reception, you need to call\n                :meth:`register_message` with the parameter ``b'ping'``\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_67on_ping_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_query = 0;
  CYTHON_UNUSED PyObject *__pyx_v_response = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_ping_response (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query,&__pyx_n_s_response,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_response)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("on_ping_response", 1, 2, 2, 1); __PYX_ERR(0, 1246, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "on_ping_response") < 0)) __PYX_ERR(0, 1246, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_query = values[0];
    __pyx_v_response = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("on_ping_response", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1246, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.on_ping_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_66on_ping_response(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_query, __pyx_v_response);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_66on_ping_response(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, CYTHON_UNUSED PyObject *__pyx_v_response) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_ping_response", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1258
 *         """
 *         pass
 *     def on_find_node_response(self, query, response):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a find_node response reception. Can safely the overloaded
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_69on_find_node_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_68on_find_node_response[] = "\n            Function called on a find_node response reception. Can safely the overloaded\n\n            :param krcp.BMessage query: the sent query object\n            :param krcp.BMessage response: the received response object\n\n            Notes:\n                For this function to be called on find_node response reception, you need to call\n                :meth:`register_message` with the parameter ``b'find_node'``\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_69on_find_node_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_query = 0;
  CYTHON_UNUSED PyObject *__pyx_v_response = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_find_node_response (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query,&__pyx_n_s_response,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_response)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("on_find_node_response", 1, 2, 2, 1); __PYX_ERR(0, 1258, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "on_find_node_response") < 0)) __PYX_ERR(0, 1258, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_query = values[0];
    __pyx_v_response = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("on_find_node_response", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1258, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.on_find_node_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_68on_find_node_response(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_query, __pyx_v_response);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_68on_find_node_response(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, CYTHON_UNUSED PyObject *__pyx_v_response) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_find_node_response", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1270
 *         """
 *         pass
 *     def on_get_peers_response(self, query, response):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a get_peers response reception. Can safely the overloaded
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_71on_get_peers_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_70on_get_peers_response[] = "\n            Function called on a get_peers response reception. Can safely the overloaded\n\n            :param krcp.BMessage query: the sent query object\n            :param krcp.BMessage response: the received response object\n\n            Notes:\n                For this function to be called on get_peers response reception, you need to call\n                :meth:`register_message` with the parameter ``b'get_peers'``\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_71on_get_peers_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_query = 0;
  CYTHON_UNUSED PyObject *__pyx_v_response = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_get_peers_response (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query,&__pyx_n_s_response,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_response)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("on_get_peers_response", 1, 2, 2, 1); __PYX_ERR(0, 1270, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "on_get_peers_response") < 0)) __PYX_ERR(0, 1270, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_query = values[0];
    __pyx_v_response = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("on_get_peers_response", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1270, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.on_get_peers_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_70on_get_peers_response(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_query, __pyx_v_response);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_70on_get_peers_response(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, CYTHON_UNUSED PyObject *__pyx_v_response) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_get_peers_response", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1282
 *         """
 *         pass
 *     def on_announce_peer_response(self, query, response):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a announce_peer response reception. Can safely the overloaded
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_73on_announce_peer_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_72on_announce_peer_response[] = "\n            Function called on a announce_peer response reception. Can safely the overloaded\n\n            :param krcp.BMessage query: the sent query object\n            :param krcp.BMessage response: the received response object\n\n            Notes:\n                For this function to be called on announce_peer response reception, you need to call\n                :meth:`register_message` with the parameter ``b'announce_peer'``\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_73on_announce_peer_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_query = 0;
  CYTHON_UNUSED PyObject *__pyx_v_response = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_announce_peer_response (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query,&__pyx_n_s_response,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_response)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("on_announce_peer_response", 1, 2, 2, 1); __PYX_ERR(0, 1282, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "on_announce_peer_response") < 0)) __PYX_ERR(0, 1282, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_query = values[0];
    __pyx_v_response = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("on_announce_peer_response", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1282, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.on_announce_peer_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_72on_announce_peer_response(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_query, __pyx_v_response);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_72on_announce_peer_response(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, CYTHON_UNUSED PyObject *__pyx_v_response) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_announce_peer_response", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1294
 *         """
 *         pass
 *     def on_ping_query(self, query):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a ping query reception. Can safely the overloaded
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_75on_ping_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_74on_ping_query[] = "\n            Function called on a ping query reception. Can safely the overloaded\n\n            :param krcp.BMessage query: the received query object\n\n            Notes:\n                For this function to be called on ping query reception, you need to call\n                :meth:`register_message` with the parameter ``b'ping'``\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_75on_ping_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_ping_query (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_74on_ping_query(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v_query));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_74on_ping_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_ping_query", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1305
 *         """
 *         pass
 *     def on_find_node_query(self, query):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a find_node query reception. Can safely the overloaded
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_77on_find_node_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_76on_find_node_query[] = "\n            Function called on a find_node query reception. Can safely the overloaded\n\n            :param krcp.BMessage query: the received query object\n\n            Notes:\n                For this function to be called on find_node query reception, you need to call\n                :meth:`register_message` with the parameter ``b'find_node'``\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_77on_find_node_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_find_node_query (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_76on_find_node_query(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v_query));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_76on_find_node_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_find_node_query", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1316
 *         """
 *         pass
 *     def on_get_peers_query(self, query):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a get_peers query reception. Can safely the overloaded
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_79on_get_peers_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_78on_get_peers_query[] = "\n            Function called on a get_peers query reception. Can safely the overloaded\n\n            :param krcp.BMessage query: the received query object\n\n            Notes:\n                For this function to be called on get_peers query reception, you need to call\n                :meth:`register_message` with the parameter ``b'get_peers'``\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_79on_get_peers_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_get_peers_query (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_78on_get_peers_query(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v_query));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_78on_get_peers_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_get_peers_query", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1327
 *         """
 *         pass
 *     def on_announce_peer_query(self, query):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a announce query reception. Can safely the overloaded
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_81on_announce_peer_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_80on_announce_peer_query[] = "\n            Function called on a announce query reception. Can safely the overloaded\n\n            :param krcp.BMessage query: the received query object\n\n            Notes:\n                For this function to be called on announce_peer query reception, you need to call\n                :meth:`register_message` with the parameter ``b'announce_peer'``\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_81on_announce_peer_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_announce_peer_query (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_80on_announce_peer_query(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v_query));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_80on_announce_peer_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("on_announce_peer_query", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1338
 *         """
 *         pass
 *     def _on_ping_response(self, query, response):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a ping response reception, do not overload, use
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_83_on_ping_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_82_on_ping_response[] = "\n            Function called on a ping response reception, do not overload, use\n            :meth:`on_ping_response` instead.\n\n            :param krcp.BMessage query: the sent query object\n            :param krcp.BMessage response: the received response object\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_83_on_ping_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_query = 0;
  CYTHON_UNUSED PyObject *__pyx_v_response = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_on_ping_response (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query,&__pyx_n_s_response,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_response)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_on_ping_response", 1, 2, 2, 1); __PYX_ERR(0, 1338, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_on_ping_response") < 0)) __PYX_ERR(0, 1338, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_query = values[0];
    __pyx_v_response = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_on_ping_response", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1338, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._on_ping_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_82_on_ping_response(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_query, __pyx_v_response);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_82_on_ping_response(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, CYTHON_UNUSED PyObject *__pyx_v_response) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_on_ping_response", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1347
 *         """
 *         pass
 *     def _on_find_node_response(self, query, response):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a find_node response reception, do not overload, use
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_85_on_find_node_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_84_on_find_node_response[] = "\n            Function called on a find_node response reception, do not overload, use\n            :meth:`find_node_response` instead.\n\n            :param krcp.BMessage query: the sent query object\n            :param krcp.BMessage response: the received response object\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_85_on_find_node_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_query = 0;
  PyObject *__pyx_v_response = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_on_find_node_response (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query,&__pyx_n_s_response,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_response)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_on_find_node_response", 1, 2, 2, 1); __PYX_ERR(0, 1347, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_on_find_node_response") < 0)) __PYX_ERR(0, 1347, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_query = values[0];
    __pyx_v_response = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_on_find_node_response", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1347, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._on_find_node_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_84_on_find_node_response(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_query, __pyx_v_response);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_84_on_find_node_response(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, PyObject *__pyx_v_response) {
  PyObject *__pyx_v_nodes = NULL;
  PyObject *__pyx_v_node = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_on_find_node_response", 0);

  /* "btdht/dht.pyx":1355
 *             :param krcp.BMessage response: the received response object
 *         """
 *         nodes = Node.from_compact_infos(response.get(b"nodes", b""))             # <<<<<<<<<<<<<<
 *         for node in nodes:
 *             try:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5btdht_3dht_Node), __pyx_n_s_from_compact_infos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_response, __pyx_n_s_get); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_nodes = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1356
 *         """
 *         nodes = Node.from_compact_infos(response.get(b"nodes", b""))
 *         for node in nodes:             # <<<<<<<<<<<<<<
 *             try:
 *                 self.root.add(self, node)
 */
  if (likely(PyList_CheckExact(__pyx_v_nodes)) || PyTuple_CheckExact(__pyx_v_nodes)) {
    __pyx_t_1 = __pyx_v_nodes; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_nodes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1356, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1356, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1356, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1356, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1356, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1356, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1356, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XDECREF_SET(__pyx_v_node, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "btdht/dht.pyx":1357
 *         nodes = Node.from_compact_infos(response.get(b"nodes", b""))
 *         for node in nodes:
 *             try:             # <<<<<<<<<<<<<<
 *                 self.root.add(self, node)
 *             except AttributeError:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_8);
      __Pyx_XGOTREF(__pyx_t_9);
      /*try:*/ {

        /* "btdht/dht.pyx":1358
 *         for node in nodes:
 *             try:
 *                 self.root.add(self, node)             # <<<<<<<<<<<<<<
 *             except AttributeError:
 *                 print("AttributeError: %r in _on_find_node_response" % node)
 */
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1358, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_add); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1358, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = NULL;
        __pyx_t_10 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
            __pyx_t_10 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[3] = {__pyx_t_4, ((PyObject *)__pyx_v_self), __pyx_v_node};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1358, __pyx_L5_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[3] = {__pyx_t_4, ((PyObject *)__pyx_v_self), __pyx_v_node};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1358, __pyx_L5_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        {
          __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1358, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_11);
          if (__pyx_t_4) {
            __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4); __pyx_t_4 = NULL;
          }
          __Pyx_INCREF(((PyObject *)__pyx_v_self));
          __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
          PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, ((PyObject *)__pyx_v_self));
          __Pyx_INCREF(__pyx_v_node);
          __Pyx_GIVEREF(__pyx_v_node);
          PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_v_node);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1358, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "btdht/dht.pyx":1357
 *         nodes = Node.from_compact_infos(response.get(b"nodes", b""))
 *         for node in nodes:
 *             try:             # <<<<<<<<<<<<<<
 *                 self.root.add(self, node)
 *             except AttributeError:
 */
      }
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      goto __pyx_L12_try_end;
      __pyx_L5_error:;
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "btdht/dht.pyx":1359
 *             try:
 *                 self.root.add(self, node)
 *             except AttributeError:             # <<<<<<<<<<<<<<
 *                 print("AttributeError: %r in _on_find_node_response" % node)
 *                 raise
 */
      __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
      if (__pyx_t_10) {
        __Pyx_AddTraceback("btdht.dht.DHT_BASE._on_find_node_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_3, &__pyx_t_11) < 0) __PYX_ERR(0, 1359, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GOTREF(__pyx_t_11);

        /* "btdht/dht.pyx":1360
 *                 self.root.add(self, node)
 *             except AttributeError:
 *                 print("AttributeError: %r in _on_find_node_response" % node)             # <<<<<<<<<<<<<<
 *                 raise
 *         self.debug(2, "%s nodes added to routing table" % len(nodes))
 */
        __pyx_t_4 = __Pyx_PyString_FormatSafe(__pyx_kp_s_AttributeError_r_in__on_find_nod, __pyx_v_node); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1360, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_4);
        if (__Pyx_PrintOne(0, __pyx_t_4) < 0) __PYX_ERR(0, 1360, __pyx_L7_except_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "btdht/dht.pyx":1361
 *             except AttributeError:
 *                 print("AttributeError: %r in _on_find_node_response" % node)
 *                 raise             # <<<<<<<<<<<<<<
 *         self.debug(2, "%s nodes added to routing table" % len(nodes))
 *     def _on_get_peers_response(self, query, response):
 */
        __Pyx_GIVEREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_3);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_ErrRestoreWithState(__pyx_t_2, __pyx_t_3, __pyx_t_11);
        __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_11 = 0; 
        __PYX_ERR(0, 1361, __pyx_L7_except_error)
      }
      goto __pyx_L7_except_error;
      __pyx_L7_except_error:;

      /* "btdht/dht.pyx":1357
 *         nodes = Node.from_compact_infos(response.get(b"nodes", b""))
 *         for node in nodes:
 *             try:             # <<<<<<<<<<<<<<
 *                 self.root.add(self, node)
 *             except AttributeError:
 */
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      goto __pyx_L1_error;
      __pyx_L12_try_end:;
    }

    /* "btdht/dht.pyx":1356
 *         """
 *         nodes = Node.from_compact_infos(response.get(b"nodes", b""))
 *         for node in nodes:             # <<<<<<<<<<<<<<
 *             try:
 *                 self.root.add(self, node)
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1362
 *                 print("AttributeError: %r in _on_find_node_response" % node)
 *                 raise
 *         self.debug(2, "%s nodes added to routing table" % len(nodes))             # <<<<<<<<<<<<<<
 *     def _on_get_peers_response(self, query, response):
 *         """
 */
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1362, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_5 = PyObject_Length(__pyx_v_nodes); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1362, __pyx_L1_error)
  __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1362, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_nodes_added_to_routing_table, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1362, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  __pyx_t_10 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_11);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_11, function);
      __pyx_t_10 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_11)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_2, __pyx_t_2};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1362, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_2, __pyx_t_2};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1362, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  {
    __pyx_t_4 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(__pyx_int_2);
    __Pyx_GIVEREF(__pyx_int_2);
    PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_10, __pyx_int_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_10, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1347
 *         """
 *         pass
 *     def _on_find_node_response(self, query, response):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a find_node response reception, do not overload, use
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._on_find_node_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_nodes);
  __Pyx_XDECREF(__pyx_v_node);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1363
 *                 raise
 *         self.debug(2, "%s nodes added to routing table" % len(nodes))
 *     def _on_get_peers_response(self, query, response):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a get_peers response reception, do not overload, use
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_87_on_get_peers_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_86_on_get_peers_response[] = "\n            Function called on a get_peers response reception, do not overload, use\n            :meth:`on_get_peers_response` instead.\n\n            :param krcp.BMessage query: the sent query object\n            :param krcp.BMessage response: the received response object\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_87_on_get_peers_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_query = 0;
  PyObject *__pyx_v_response = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_on_get_peers_response (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query,&__pyx_n_s_response,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_response)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_on_get_peers_response", 1, 2, 2, 1); __PYX_ERR(0, 1363, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_on_get_peers_response") < 0)) __PYX_ERR(0, 1363, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_query = values[0];
    __pyx_v_response = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_on_get_peers_response", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1363, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._on_get_peers_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_86_on_get_peers_response(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_query, __pyx_v_response);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_86_on_get_peers_response(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_query, PyObject *__pyx_v_response) {
  PyObject *__pyx_v_token = NULL;
  PyObject *__pyx_v_node = NULL;
  PyObject *__pyx_v_ipport = NULL;
  PyObject *__pyx_v_ip = NULL;
  PyObject *__pyx_v_port = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *(*__pyx_t_10)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_on_get_peers_response", 0);

  /* "btdht/dht.pyx":1371
 *             :param krcp.BMessage response: the received response object
 *         """
 *         token = response.get(b"token")             # <<<<<<<<<<<<<<
 *         if token:
 *             self.mytoken[response[b"id"]]=(token, time.time())
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_response, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1371, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_n_b_token) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_b_token);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1371, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_token = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1372
 *         """
 *         token = response.get(b"token")
 *         if token:             # <<<<<<<<<<<<<<
 *             self.mytoken[response[b"id"]]=(token, time.time())
 *         for node in Node.from_compact_infos(response.get(b"nodes", "")):
 */
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_token); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1372, __pyx_L1_error)
  if (__pyx_t_4) {

    /* "btdht/dht.pyx":1373
 *         token = response.get(b"token")
 *         if token:
 *             self.mytoken[response[b"id"]]=(token, time.time())             # <<<<<<<<<<<<<<
 *         for node in Node.from_compact_infos(response.get(b"nodes", "")):
 *             self.root.add(self, node)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_token);
    __Pyx_GIVEREF(__pyx_v_token);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_token);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mytoken); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_response, __pyx_n_b_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_t_2, __pyx_t_3) < 0)) __PYX_ERR(0, 1373, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1372
 *         """
 *         token = response.get(b"token")
 *         if token:             # <<<<<<<<<<<<<<
 *             self.mytoken[response[b"id"]]=(token, time.time())
 *         for node in Node.from_compact_infos(response.get(b"nodes", "")):
 */
  }

  /* "btdht/dht.pyx":1374
 *         if token:
 *             self.mytoken[response[b"id"]]=(token, time.time())
 *         for node in Node.from_compact_infos(response.get(b"nodes", "")):             # <<<<<<<<<<<<<<
 *             self.root.add(self, node)
 *         for ipport in response.get(b"values", []):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5btdht_3dht_Node), __pyx_n_s_from_compact_infos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1374, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_response, __pyx_n_s_get); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1374, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1374, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_1, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1374, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_6 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1374, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1374, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1374, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1374, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1374, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1374, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_7(__pyx_t_2);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1374, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_XDECREF_SET(__pyx_v_node, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1375
 *             self.mytoken[response[b"id"]]=(token, time.time())
 *         for node in Node.from_compact_infos(response.get(b"nodes", "")):
 *             self.root.add(self, node)             # <<<<<<<<<<<<<<
 *         for ipport in response.get(b"values", []):
 *             (ip, port) = struct.unpack("!4sH", ipport)
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1375, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_add); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1375, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    __pyx_t_8 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
        __pyx_t_8 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_self), __pyx_v_node};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1375, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_self), __pyx_v_node};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1375, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    {
      __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1375, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, ((PyObject *)__pyx_v_self));
      __Pyx_INCREF(__pyx_v_node);
      __Pyx_GIVEREF(__pyx_v_node);
      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_node);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1375, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1374
 *         if token:
 *             self.mytoken[response[b"id"]]=(token, time.time())
 *         for node in Node.from_compact_infos(response.get(b"nodes", "")):             # <<<<<<<<<<<<<<
 *             self.root.add(self, node)
 *         for ipport in response.get(b"values", []):
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1376
 *         for node in Node.from_compact_infos(response.get(b"nodes", "")):
 *             self.root.add(self, node)
 *         for ipport in response.get(b"values", []):             # <<<<<<<<<<<<<<
 *             (ip, port) = struct.unpack("!4sH", ipport)
 *             ip = socket.inet_ntoa(ip)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_response, __pyx_n_s_get); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1376, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1376, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = NULL;
  __pyx_t_8 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_8 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_b_values, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1376, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_n_b_values, __pyx_t_1};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1376, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1376, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_9) {
      __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_9); __pyx_t_9 = NULL;
    }
    __Pyx_INCREF(__pyx_n_b_values);
    __Pyx_GIVEREF(__pyx_n_b_values);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_8, __pyx_n_b_values);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_8, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1376, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1376, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1376, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1376, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1376, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1376, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1376, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_3);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1376, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XDECREF_SET(__pyx_v_ipport, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "btdht/dht.pyx":1377
 *             self.root.add(self, node)
 *         for ipport in response.get(b"values", []):
 *             (ip, port) = struct.unpack("!4sH", ipport)             # <<<<<<<<<<<<<<
 *             ip = socket.inet_ntoa(ip)
 *             self._add_peer_queried(query[b"info_hash"], ip=ip, port=port)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_struct); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1377, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_unpack); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1377, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    __pyx_t_8 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
        __pyx_t_8 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_kp_s_4sH, __pyx_v_ipport};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1377, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_kp_s_4sH, __pyx_v_ipport};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1377, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    {
      __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1377, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_INCREF(__pyx_kp_s_4sH);
      __Pyx_GIVEREF(__pyx_kp_s_4sH);
      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_kp_s_4sH);
      __Pyx_INCREF(__pyx_v_ipport);
      __Pyx_GIVEREF(__pyx_v_ipport);
      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_ipport);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1377, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
      PyObject* sequence = __pyx_t_2;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 1377, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_9);
      #else
      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1377, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1377, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1377, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_10 = Py_TYPE(__pyx_t_5)->tp_iternext;
      index = 0; __pyx_t_1 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_1)) goto __pyx_L8_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_1);
      index = 1; __pyx_t_9 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_9)) goto __pyx_L8_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_5), 2) < 0) __PYX_ERR(0, 1377, __pyx_L1_error)
      __pyx_t_10 = NULL;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L9_unpacking_done;
      __pyx_L8_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_10 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 1377, __pyx_L1_error)
      __pyx_L9_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_ip, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_port, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "btdht/dht.pyx":1378
 *         for ipport in response.get(b"values", []):
 *             (ip, port) = struct.unpack("!4sH", ipport)
 *             ip = socket.inet_ntoa(ip)             # <<<<<<<<<<<<<<
 *             self._add_peer_queried(query[b"info_hash"], ip=ip, port=port)
 *     def _on_announce_peer_response(self, query, response):
 */
    __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_socket); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_inet_ntoa); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_2 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_9, __pyx_v_ip) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_ip);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_ip, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "btdht/dht.pyx":1379
 *             (ip, port) = struct.unpack("!4sH", ipport)
 *             ip = socket.inet_ntoa(ip)
 *             self._add_peer_queried(query[b"info_hash"], ip=ip, port=port)             # <<<<<<<<<<<<<<
 *     def _on_announce_peer_response(self, query, response):
 *         """
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_peer_queried); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1379, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_query, __pyx_n_b_info_hash); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1379, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1379, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1379, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_ip, __pyx_v_ip) < 0) __PYX_ERR(0, 1379, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_port, __pyx_v_port) < 0) __PYX_ERR(0, 1379, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1379, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "btdht/dht.pyx":1376
 *         for node in Node.from_compact_infos(response.get(b"nodes", "")):
 *             self.root.add(self, node)
 *         for ipport in response.get(b"values", []):             # <<<<<<<<<<<<<<
 *             (ip, port) = struct.unpack("!4sH", ipport)
 *             ip = socket.inet_ntoa(ip)
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "btdht/dht.pyx":1363
 *                 raise
 *         self.debug(2, "%s nodes added to routing table" % len(nodes))
 *     def _on_get_peers_response(self, query, response):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a get_peers response reception, do not overload, use
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._on_get_peers_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_token);
  __Pyx_XDECREF(__pyx_v_node);
  __Pyx_XDECREF(__pyx_v_ipport);
  __Pyx_XDECREF(__pyx_v_ip);
  __Pyx_XDECREF(__pyx_v_port);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1380
 *             ip = socket.inet_ntoa(ip)
 *             self._add_peer_queried(query[b"info_hash"], ip=ip, port=port)
 *     def _on_announce_peer_response(self, query, response):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a announce_peer response reception, do not overload, use
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_89_on_announce_peer_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_88_on_announce_peer_response[] = "\n            Function called on a announce_peer response reception, do not overload, use\n            :meth:`on_announce_peer_response` instead.\n\n            :param krcp.BMessage query: the sent query object\n            :param krcp.BMessage response: the received response object\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_89_on_announce_peer_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_query = 0;
  CYTHON_UNUSED PyObject *__pyx_v_response = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_on_announce_peer_response (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query,&__pyx_n_s_response,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_response)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_on_announce_peer_response", 1, 2, 2, 1); __PYX_ERR(0, 1380, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_on_announce_peer_response") < 0)) __PYX_ERR(0, 1380, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_query = values[0];
    __pyx_v_response = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_on_announce_peer_response", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1380, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._on_announce_peer_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_88_on_announce_peer_response(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_query, __pyx_v_response);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_88_on_announce_peer_response(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query, CYTHON_UNUSED PyObject *__pyx_v_response) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_on_announce_peer_response", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1390
 *         pass
 * 
 *     def _on_ping_query(self, query):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a ping query reception, do not overload, use
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_91_on_ping_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_90_on_ping_query[] = "\n            Function called on a ping query reception, do not overload, use\n            :meth:`on_ping_query` instead.\n\n            :param krcp.BMessage query: the received query object\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_91_on_ping_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_on_ping_query (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_90_on_ping_query(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v_query));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_90_on_ping_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_on_ping_query", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1398
 *         """
 *         pass
 *     def _on_find_node_query(self, query):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a find_node query reception, do not overload, use
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_93_on_find_node_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_92_on_find_node_query[] = "\n            Function called on a find_node query reception, do not overload, use\n            :meth:`on_find_node_query` instead.\n\n            :param krcp.BMessage query: the received query object\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_93_on_find_node_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_on_find_node_query (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_92_on_find_node_query(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v_query));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_92_on_find_node_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_on_find_node_query", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1406
 *         """
 *         pass
 *     def _on_get_peers_query(self, query):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a get_peers query reception, do not overload, use
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_95_on_get_peers_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_94_on_get_peers_query[] = "\n            Function called on a get_peers query reception, do not overload, use\n            :meth:`on_get_peers_query` instead.\n\n            :param krcp.BMessage query: the received query object\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_95_on_get_peers_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_on_get_peers_query (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_94_on_get_peers_query(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v_query));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_94_on_get_peers_query(CYTHON_UNUSED struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_query) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_on_get_peers_query", 0);

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1414
 *         """
 *         pass
 *     def _on_announce_peer_query(self, query):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a announce_peer query reception, do not overload, use
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_97_on_announce_peer_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_96_on_announce_peer_query[] = "\n            Function called on a announce_peer query reception, do not overload, use\n            :meth:`on_announce_peer_query` instead.\n\n            :param krcp.BMessage query: the received query object\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_97_on_announce_peer_query(PyObject *__pyx_v_self, PyObject *__pyx_v_query) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_on_announce_peer_query (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_96_on_announce_peer_query(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v_query));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_96_on_announce_peer_query(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_query) {
  PyObject *__pyx_v_e = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_on_announce_peer_query", 0);

  /* "btdht/dht.pyx":1421
 *             :param krcp.BMessage query: the received query object
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             if query.get(b"implied_port", 0) != 0:
 *                 if query.addr[1] > 0 and query.addr[1] < 65536:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "btdht/dht.pyx":1422
 *         """
 *         try:
 *             if query.get(b"implied_port", 0) != 0:             # <<<<<<<<<<<<<<
 *                 if query.addr[1] > 0 and query.addr[1] < 65536:
 *                     self._add_peer(
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_get); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1422, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1422, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyInt_NeObjC(__pyx_t_5, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1422, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1422, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {

        /* "btdht/dht.pyx":1423
 *         try:
 *             if query.get(b"implied_port", 0) != 0:
 *                 if query.addr[1] > 0 and query.addr[1] < 65536:             # <<<<<<<<<<<<<<
 *                     self._add_peer(
 *                         info_hash=query[b"info_hash"],
 */
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_addr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1423, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_4, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1423, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1423, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1423, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (__pyx_t_7) {
        } else {
          __pyx_t_6 = __pyx_t_7;
          goto __pyx_L11_bool_binop_done;
        }
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_addr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1423, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_4, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1423, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_int_65536, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1423, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1423, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_6 = __pyx_t_7;
        __pyx_L11_bool_binop_done:;
        if (__pyx_t_6) {

          /* "btdht/dht.pyx":1424
 *             if query.get(b"implied_port", 0) != 0:
 *                 if query.addr[1] > 0 and query.addr[1] < 65536:
 *                     self._add_peer(             # <<<<<<<<<<<<<<
 *                         info_hash=query[b"info_hash"],
 *                         ip=query.addr[0],
 */
          __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_peer); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1424, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_4);

          /* "btdht/dht.pyx":1425
 *                 if query.addr[1] > 0 and query.addr[1] < 65536:
 *                     self._add_peer(
 *                         info_hash=query[b"info_hash"],             # <<<<<<<<<<<<<<
 *                         ip=query.addr[0],
 *                         port=query.addr[1]
 */
          __pyx_t_5 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1425, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_query, __pyx_n_b_info_hash); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1425, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_8);
          if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_info_hash, __pyx_t_8) < 0) __PYX_ERR(0, 1425, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

          /* "btdht/dht.pyx":1426
 *                     self._add_peer(
 *                         info_hash=query[b"info_hash"],
 *                         ip=query.addr[0],             # <<<<<<<<<<<<<<
 *                         port=query.addr[1]
 *                     )
 */
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_addr); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1426, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_8, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1426, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_ip, __pyx_t_9) < 0) __PYX_ERR(0, 1425, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "btdht/dht.pyx":1427
 *                         info_hash=query[b"info_hash"],
 *                         ip=query.addr[0],
 *                         port=query.addr[1]             # <<<<<<<<<<<<<<
 *                     )
 *                 else:
 */
          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_addr); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1427, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_9, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1427, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_port, __pyx_t_8) < 0) __PYX_ERR(0, 1425, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

          /* "btdht/dht.pyx":1424
 *             if query.get(b"implied_port", 0) != 0:
 *                 if query.addr[1] > 0 and query.addr[1] < 65536:
 *                     self._add_peer(             # <<<<<<<<<<<<<<
 *                         info_hash=query[b"info_hash"],
 *                         ip=query.addr[0],
 */
          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1424, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

          /* "btdht/dht.pyx":1423
 *         try:
 *             if query.get(b"implied_port", 0) != 0:
 *                 if query.addr[1] > 0 and query.addr[1] < 65536:             # <<<<<<<<<<<<<<
 *                     self._add_peer(
 *                         info_hash=query[b"info_hash"],
 */
          goto __pyx_L10;
        }

        /* "btdht/dht.pyx":1430
 *                     )
 *                 else:
 *                     self.debug(             # <<<<<<<<<<<<<<
 *                         1,
 *                         "Invalid port number on announce %s, sould be within 1 and 65535" % (
 */
        /*else*/ {
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1430, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);

          /* "btdht/dht.pyx":1433
 *                         1,
 *                         "Invalid port number on announce %s, sould be within 1 and 65535" % (
 *                             query.addr[1],             # <<<<<<<<<<<<<<
 *                         )
 *                     )
 */
          __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_addr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1433, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_4, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1433, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1433, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_GIVEREF(__pyx_t_9);
          PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_9);
          __pyx_t_9 = 0;

          /* "btdht/dht.pyx":1432
 *                     self.debug(
 *                         1,
 *                         "Invalid port number on announce %s, sould be within 1 and 65535" % (             # <<<<<<<<<<<<<<
 *                             query.addr[1],
 *                         )
 */
          __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_port_number_on_announce, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1432, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_4 = NULL;
          __pyx_t_10 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_4)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_4);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
              __pyx_t_10 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_5)) {
            PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_int_1, __pyx_t_9};
            __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1430, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
            PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_int_1, __pyx_t_9};
            __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1430, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          } else
          #endif
          {
            __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1430, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_11);
            if (__pyx_t_4) {
              __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4); __pyx_t_4 = NULL;
            }
            __Pyx_INCREF(__pyx_int_1);
            __Pyx_GIVEREF(__pyx_int_1);
            PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_int_1);
            __Pyx_GIVEREF(__pyx_t_9);
            PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_9);
            __pyx_t_9 = 0;
            __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_11, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1430, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          }
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        }
        __pyx_L10:;

        /* "btdht/dht.pyx":1422
 *         """
 *         try:
 *             if query.get(b"implied_port", 0) != 0:             # <<<<<<<<<<<<<<
 *                 if query.addr[1] > 0 and query.addr[1] < 65536:
 *                     self._add_peer(
 */
        goto __pyx_L9;
      }

      /* "btdht/dht.pyx":1437
 *                     )
 *             else:
 *                 if query[b"port"] > 0 and query[b"port"] < 65536:             # <<<<<<<<<<<<<<
 *                     self._add_peer(
 *                         info_hash=query[b"info_hash"],
 */
      /*else*/ {
        __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_query, __pyx_n_b_port); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1437, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_5 = PyObject_RichCompare(__pyx_t_8, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1437, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1437, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (__pyx_t_7) {
        } else {
          __pyx_t_6 = __pyx_t_7;
          goto __pyx_L14_bool_binop_done;
        }
        __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_query, __pyx_n_b_port); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1437, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_8 = PyObject_RichCompare(__pyx_t_5, __pyx_int_65536, Py_LT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1437, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 1437, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_6 = __pyx_t_7;
        __pyx_L14_bool_binop_done:;
        if (__pyx_t_6) {

          /* "btdht/dht.pyx":1438
 *             else:
 *                 if query[b"port"] > 0 and query[b"port"] < 65536:
 *                     self._add_peer(             # <<<<<<<<<<<<<<
 *                         info_hash=query[b"info_hash"],
 *                         ip=query.addr[0],
 */
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_peer); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1438, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_8);

          /* "btdht/dht.pyx":1439
 *                 if query[b"port"] > 0 and query[b"port"] < 65536:
 *                     self._add_peer(
 *                         info_hash=query[b"info_hash"],             # <<<<<<<<<<<<<<
 *                         ip=query.addr[0],
 *                         port=query[b"port"]
 */
          __pyx_t_5 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1439, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_v_query, __pyx_n_b_info_hash); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1439, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_11);
          if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_info_hash, __pyx_t_11) < 0) __PYX_ERR(0, 1439, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

          /* "btdht/dht.pyx":1440
 *                     self._add_peer(
 *                         info_hash=query[b"info_hash"],
 *                         ip=query.addr[0],             # <<<<<<<<<<<<<<
 *                         port=query[b"port"]
 *                     )
 */
          __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_addr); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1440, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_11, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1440, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_ip, __pyx_t_9) < 0) __PYX_ERR(0, 1439, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "btdht/dht.pyx":1441
 *                         info_hash=query[b"info_hash"],
 *                         ip=query.addr[0],
 *                         port=query[b"port"]             # <<<<<<<<<<<<<<
 *                     )
 *                 else:
 */
          __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_v_query, __pyx_n_b_port); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1441, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_9);
          if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_port, __pyx_t_9) < 0) __PYX_ERR(0, 1439, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "btdht/dht.pyx":1438
 *             else:
 *                 if query[b"port"] > 0 and query[b"port"] < 65536:
 *                     self._add_peer(             # <<<<<<<<<<<<<<
 *                         info_hash=query[b"info_hash"],
 *                         ip=query.addr[0],
 */
          __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_empty_tuple, __pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1438, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "btdht/dht.pyx":1437
 *                     )
 *             else:
 *                 if query[b"port"] > 0 and query[b"port"] < 65536:             # <<<<<<<<<<<<<<
 *                     self._add_peer(
 *                         info_hash=query[b"info_hash"],
 */
          goto __pyx_L13;
        }

        /* "btdht/dht.pyx":1444
 *                     )
 *                 else:
 *                     self.debug(             # <<<<<<<<<<<<<<
 *                         1,
 *                         "Invalid port number on announce %s, sould be within 1 and 65535" % (
 */
        /*else*/ {
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1444, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);

          /* "btdht/dht.pyx":1447
 *                         1,
 *                         "Invalid port number on announce %s, sould be within 1 and 65535" % (
 *                             query["port"],             # <<<<<<<<<<<<<<
 *                         )
 *                     )
 */
          __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_v_query, __pyx_n_s_port); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1447, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1447, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_GIVEREF(__pyx_t_8);
          PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8);
          __pyx_t_8 = 0;

          /* "btdht/dht.pyx":1446
 *                     self.debug(
 *                         1,
 *                         "Invalid port number on announce %s, sould be within 1 and 65535" % (             # <<<<<<<<<<<<<<
 *                             query["port"],
 *                         )
 */
          __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_port_number_on_announce, __pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1446, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __pyx_t_11 = NULL;
          __pyx_t_10 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_11)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_11);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
              __pyx_t_10 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_5)) {
            PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_int_1, __pyx_t_8};
            __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1444, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
            PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_int_1, __pyx_t_8};
            __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1444, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          } else
          #endif
          {
            __pyx_t_4 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1444, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_4);
            if (__pyx_t_11) {
              __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_11); __pyx_t_11 = NULL;
            }
            __Pyx_INCREF(__pyx_int_1);
            __Pyx_GIVEREF(__pyx_int_1);
            PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_10, __pyx_int_1);
            __Pyx_GIVEREF(__pyx_t_8);
            PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_10, __pyx_t_8);
            __pyx_t_8 = 0;
            __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1444, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          }
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __pyx_L13:;
      }
      __pyx_L9:;

      /* "btdht/dht.pyx":1421
 *             :param krcp.BMessage query: the received query object
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             if query.get(b"implied_port", 0) != 0:
 *                 if query.addr[1] > 0 and query.addr[1] < 65536:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "btdht/dht.pyx":1450
 *                         )
 *                     )
 *         except KeyError as e:             # <<<<<<<<<<<<<<
 *             raise ProtocolError(query.t, b"Message malformed: %s key is missing" % e.args[0])
 * 
 */
    __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
    if (__pyx_t_10) {
      __Pyx_AddTraceback("btdht.dht.DHT_BASE._on_announce_peer_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_5, &__pyx_t_4) < 0) __PYX_ERR(0, 1450, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __pyx_v_e = __pyx_t_5;

      /* "btdht/dht.pyx":1451
 *                     )
 *         except KeyError as e:
 *             raise ProtocolError(query.t, b"Message malformed: %s key is missing" % e.args[0])             # <<<<<<<<<<<<<<
 * 
 *     def _process_error(self, obj, query):
 */
      __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_ProtocolError); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1451, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_t); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1451, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_e, __pyx_n_s_args); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1451, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_14 = __Pyx_GetItemInt(__pyx_t_13, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1451, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __pyx_t_13 = PyNumber_Remainder(__pyx_kp_b_Message_malformed_s_key_is_missi, __pyx_t_14); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1451, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_14 = NULL;
      __pyx_t_10 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
        __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_11);
        if (likely(__pyx_t_14)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_14);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_11, function);
          __pyx_t_10 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_t_12, __pyx_t_13};
        __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1451, __pyx_L5_except_error)
        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_t_12, __pyx_t_13};
        __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1451, __pyx_L5_except_error)
        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      } else
      #endif
      {
        __pyx_t_15 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1451, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_15);
        if (__pyx_t_14) {
          __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); __pyx_t_14 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_12);
        PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_10, __pyx_t_12);
        __Pyx_GIVEREF(__pyx_t_13);
        PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_10, __pyx_t_13);
        __pyx_t_12 = 0;
        __pyx_t_13 = 0;
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_15, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1451, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      }
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(0, 1451, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "btdht/dht.pyx":1421
 *             :param krcp.BMessage query: the received query object
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             if query.get(b"implied_port", 0) != 0:
 *                 if query.addr[1] > 0 and query.addr[1] < 65536:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L8_try_end:;
  }

  /* "btdht/dht.pyx":1414
 *         """
 *         pass
 *     def _on_announce_peer_query(self, query):             # <<<<<<<<<<<<<<
 *         """
 *             Function called on a announce_peer query reception, do not overload, use
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._on_announce_peer_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_e);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1453
 *             raise ProtocolError(query.t, b"Message malformed: %s key is missing" % e.args[0])
 * 
 *     def _process_error(self, obj, query):             # <<<<<<<<<<<<<<
 *         if "error" in self._to_process_registered:
 *             try:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_99_process_error(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_99_process_error(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_obj = 0;
  PyObject *__pyx_v_query = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_process_error (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_obj,&__pyx_n_s_query,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_obj)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_process_error", 1, 2, 2, 1); __PYX_ERR(0, 1453, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_process_error") < 0)) __PYX_ERR(0, 1453, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_obj = values[0];
    __pyx_v_query = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_process_error", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1453, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_error", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_98_process_error(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_obj, __pyx_v_query);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_98_process_error(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_obj, PyObject *__pyx_v_query) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_process_error", 0);

  /* "btdht/dht.pyx":1454
 * 
 *     def _process_error(self, obj, query):
 *         if "error" in self._to_process_registered:             # <<<<<<<<<<<<<<
 *             try:
 *                 self._to_process.put_nowait((query, obj))
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_process_registered); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1454, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_error, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1454, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":1455
 *     def _process_error(self, obj, query):
 *         if "error" in self._to_process_registered:
 *             try:             # <<<<<<<<<<<<<<
 *                 self._to_process.put_nowait((query, obj))
 *             except Queue.Full:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
      __Pyx_XGOTREF(__pyx_t_4);
      __Pyx_XGOTREF(__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_6);
      /*try:*/ {

        /* "btdht/dht.pyx":1456
 *         if "error" in self._to_process_registered:
 *             try:
 *                 self._to_process.put_nowait((query, obj))             # <<<<<<<<<<<<<<
 *             except Queue.Full:
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")
 */
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_process); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1456, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_put_nowait); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1456, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1456, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_v_query);
        __Pyx_GIVEREF(__pyx_v_query);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_query);
        __Pyx_INCREF(__pyx_v_obj);
        __Pyx_GIVEREF(__pyx_v_obj);
        PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_obj);
        __pyx_t_9 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_9)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
          }
        }
        __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7);
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1456, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "btdht/dht.pyx":1455
 *     def _process_error(self, obj, query):
 *         if "error" in self._to_process_registered:
 *             try:             # <<<<<<<<<<<<<<
 *                 self._to_process.put_nowait((query, obj))
 *             except Queue.Full:
 */
      }
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L9_try_end;
      __pyx_L4_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "btdht/dht.pyx":1457
 *             try:
 *                 self._to_process.put_nowait((query, obj))
 *             except Queue.Full:             # <<<<<<<<<<<<<<
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")
 * 
 */
      __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_8, &__pyx_t_7);
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_Queue); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1457, __pyx_L6_except_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_Full); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1457, __pyx_L6_except_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_11 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_10);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_ErrRestore(__pyx_t_1, __pyx_t_8, __pyx_t_7);
      __pyx_t_1 = 0; __pyx_t_8 = 0; __pyx_t_7 = 0;
      if (__pyx_t_11) {
        __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_error", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_1) < 0) __PYX_ERR(0, 1457, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GOTREF(__pyx_t_1);

        /* "btdht/dht.pyx":1458
 *                 self._to_process.put_nowait((query, obj))
 *             except Queue.Full:
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")             # <<<<<<<<<<<<<<
 * 
 *     def _process_response(self, obj, query):
 */
        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1458, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1458, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L5_exception_handled;
      }
      goto __pyx_L6_except_error;
      __pyx_L6_except_error:;

      /* "btdht/dht.pyx":1455
 *     def _process_error(self, obj, query):
 *         if "error" in self._to_process_registered:
 *             try:             # <<<<<<<<<<<<<<
 *                 self._to_process.put_nowait((query, obj))
 *             except Queue.Full:
 */
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
      goto __pyx_L1_error;
      __pyx_L5_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
      __pyx_L9_try_end:;
    }

    /* "btdht/dht.pyx":1454
 * 
 *     def _process_error(self, obj, query):
 *         if "error" in self._to_process_registered:             # <<<<<<<<<<<<<<
 *             try:
 *                 self._to_process.put_nowait((query, obj))
 */
  }

  /* "btdht/dht.pyx":1453
 *             raise ProtocolError(query.t, b"Message malformed: %s key is missing" % e.args[0])
 * 
 *     def _process_error(self, obj, query):             # <<<<<<<<<<<<<<
 *         if "error" in self._to_process_registered:
 *             try:
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_error", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1460
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")
 * 
 *     def _process_response(self, obj, query):             # <<<<<<<<<<<<<<
 *         if query.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:
 *             getattr(self, '_on_%s_response' % query.q.decode())(query, obj)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_101_process_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_101_process_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_obj = 0;
  PyObject *__pyx_v_query = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_process_response (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_obj,&__pyx_n_s_query,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_obj)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_process_response", 1, 2, 2, 1); __PYX_ERR(0, 1460, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_process_response") < 0)) __PYX_ERR(0, 1460, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_obj = values[0];
    __pyx_v_query = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_process_response", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1460, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_100_process_response(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_obj, __pyx_v_query);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_100_process_response(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_obj, PyObject *__pyx_v_query) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_process_response", 0);

  /* "btdht/dht.pyx":1461
 * 
 *     def _process_response(self, obj, query):
 *         if query.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:             # <<<<<<<<<<<<<<
 *             getattr(self, '_on_%s_response' % query.q.decode())(query, obj)
 *         if query.q in self._to_process_registered:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_q); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1461, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = (__Pyx_PyBytes_Equals(__pyx_t_1, __pyx_n_b_find_node, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1461, __pyx_L1_error)
  if (!__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (__Pyx_PyBytes_Equals(__pyx_t_1, __pyx_n_b_ping, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1461, __pyx_L1_error)
  if (!__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (__Pyx_PyBytes_Equals(__pyx_t_1, __pyx_n_b_get_peers, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1461, __pyx_L1_error)
  if (!__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (__Pyx_PyBytes_Equals(__pyx_t_1, __pyx_n_b_announce_peer, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1461, __pyx_L1_error)
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":1462
 *     def _process_response(self, obj, query):
 *         if query.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:
 *             getattr(self, '_on_%s_response' % query.q.decode())(query, obj)             # <<<<<<<<<<<<<<
 *         if query.q in self._to_process_registered:
 *             try:
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_q); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1462, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_decode_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1462, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1462, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyString_FormatSafe(__pyx_kp_s_on__s_response, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1462, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetAttr(((PyObject *)__pyx_v_self), __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1462, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    __pyx_t_7 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_7 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_query, __pyx_v_obj};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1462, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_query, __pyx_v_obj};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1462, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_5 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1462, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (__pyx_t_6) {
        __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL;
      }
      __Pyx_INCREF(__pyx_v_query);
      __Pyx_GIVEREF(__pyx_v_query);
      PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_7, __pyx_v_query);
      __Pyx_INCREF(__pyx_v_obj);
      __Pyx_GIVEREF(__pyx_v_obj);
      PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_7, __pyx_v_obj);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1462, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1461
 * 
 *     def _process_response(self, obj, query):
 *         if query.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:             # <<<<<<<<<<<<<<
 *             getattr(self, '_on_%s_response' % query.q.decode())(query, obj)
 *         if query.q in self._to_process_registered:
 */
  }

  /* "btdht/dht.pyx":1463
 *         if query.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:
 *             getattr(self, '_on_%s_response' % query.q.decode())(query, obj)
 *         if query.q in self._to_process_registered:             # <<<<<<<<<<<<<<
 *             try:
 *                 self._to_process.put_nowait((query, obj))
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_q); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_process_registered); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, __pyx_t_4, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1463, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "btdht/dht.pyx":1464
 *             getattr(self, '_on_%s_response' % query.q.decode())(query, obj)
 *         if query.q in self._to_process_registered:
 *             try:             # <<<<<<<<<<<<<<
 *                 self._to_process.put_nowait((query, obj))
 *             except Queue.Full:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      __Pyx_XGOTREF(__pyx_t_8);
      __Pyx_XGOTREF(__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_10);
      /*try:*/ {

        /* "btdht/dht.pyx":1465
 *         if query.q in self._to_process_registered:
 *             try:
 *                 self._to_process.put_nowait((query, obj))             # <<<<<<<<<<<<<<
 *             except Queue.Full:
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_process); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1465, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_put_nowait); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1465, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1465, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_v_query);
        __Pyx_GIVEREF(__pyx_v_query);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_query);
        __Pyx_INCREF(__pyx_v_obj);
        __Pyx_GIVEREF(__pyx_v_obj);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_obj);
        __pyx_t_6 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_6)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
          }
        }
        __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_1);
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1465, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "btdht/dht.pyx":1464
 *             getattr(self, '_on_%s_response' % query.q.decode())(query, obj)
 *         if query.q in self._to_process_registered:
 *             try:             # <<<<<<<<<<<<<<
 *                 self._to_process.put_nowait((query, obj))
 *             except Queue.Full:
 */
      }
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      goto __pyx_L14_try_end;
      __pyx_L9_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "btdht/dht.pyx":1466
 *             try:
 *                 self._to_process.put_nowait((query, obj))
 *             except Queue.Full:             # <<<<<<<<<<<<<<
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")
 * 
 */
      __Pyx_ErrFetch(&__pyx_t_4, &__pyx_t_5, &__pyx_t_1);
      __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_Queue); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1466, __pyx_L11_except_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_Full); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1466, __pyx_L11_except_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_7 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_4, __pyx_t_11);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_ErrRestore(__pyx_t_4, __pyx_t_5, __pyx_t_1);
      __pyx_t_4 = 0; __pyx_t_5 = 0; __pyx_t_1 = 0;
      if (__pyx_t_7) {
        __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_5, &__pyx_t_4) < 0) __PYX_ERR(0, 1466, __pyx_L11_except_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GOTREF(__pyx_t_4);

        /* "btdht/dht.pyx":1467
 *                 self._to_process.put_nowait((query, obj))
 *             except Queue.Full:
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")             # <<<<<<<<<<<<<<
 * 
 *     def _process_query(self, obj):
 */
        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1467, __pyx_L11_except_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1467, __pyx_L11_except_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        goto __pyx_L10_exception_handled;
      }
      goto __pyx_L11_except_error;
      __pyx_L11_except_error:;

      /* "btdht/dht.pyx":1464
 *             getattr(self, '_on_%s_response' % query.q.decode())(query, obj)
 *         if query.q in self._to_process_registered:
 *             try:             # <<<<<<<<<<<<<<
 *                 self._to_process.put_nowait((query, obj))
 *             except Queue.Full:
 */
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      goto __pyx_L1_error;
      __pyx_L10_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      __pyx_L14_try_end:;
    }

    /* "btdht/dht.pyx":1463
 *         if query.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:
 *             getattr(self, '_on_%s_response' % query.q.decode())(query, obj)
 *         if query.q in self._to_process_registered:             # <<<<<<<<<<<<<<
 *             try:
 *                 self._to_process.put_nowait((query, obj))
 */
  }

  /* "btdht/dht.pyx":1460
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")
 * 
 *     def _process_response(self, obj, query):             # <<<<<<<<<<<<<<
 *         if query.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:
 *             getattr(self, '_on_%s_response' % query.q.decode())(query, obj)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_response", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1469
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")
 * 
 *     def _process_query(self, obj):             # <<<<<<<<<<<<<<
 *         if obj.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:
 *             getattr(self, '_on_%s_query' % obj.q.decode())(obj)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_103_process_query(PyObject *__pyx_v_self, PyObject *__pyx_v_obj); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_103_process_query(PyObject *__pyx_v_self, PyObject *__pyx_v_obj) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_process_query (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_102_process_query(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v_obj));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_102_process_query(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_obj) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_process_query", 0);

  /* "btdht/dht.pyx":1470
 * 
 *     def _process_query(self, obj):
 *         if obj.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:             # <<<<<<<<<<<<<<
 *             getattr(self, '_on_%s_query' % obj.q.decode())(obj)
 *         if obj.q in self._to_process_registered:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_q); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1470, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = (__Pyx_PyBytes_Equals(__pyx_t_1, __pyx_n_b_find_node, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1470, __pyx_L1_error)
  if (!__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (__Pyx_PyBytes_Equals(__pyx_t_1, __pyx_n_b_ping, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1470, __pyx_L1_error)
  if (!__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (__Pyx_PyBytes_Equals(__pyx_t_1, __pyx_n_b_get_peers, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1470, __pyx_L1_error)
  if (!__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (__Pyx_PyBytes_Equals(__pyx_t_1, __pyx_n_b_announce_peer, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1470, __pyx_L1_error)
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":1471
 *     def _process_query(self, obj):
 *         if obj.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:
 *             getattr(self, '_on_%s_query' % obj.q.decode())(obj)             # <<<<<<<<<<<<<<
 *         if obj.q in self._to_process_registered:
 *             try:
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_q); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1471, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_decode_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1471, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1471, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyString_FormatSafe(__pyx_kp_s_on__s_query, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1471, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetAttr(((PyObject *)__pyx_v_self), __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1471, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_v_obj) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_obj);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1471, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1470
 * 
 *     def _process_query(self, obj):
 *         if obj.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:             # <<<<<<<<<<<<<<
 *             getattr(self, '_on_%s_query' % obj.q.decode())(obj)
 *         if obj.q in self._to_process_registered:
 */
  }

  /* "btdht/dht.pyx":1472
 *         if obj.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:
 *             getattr(self, '_on_%s_query' % obj.q.decode())(obj)
 *         if obj.q in self._to_process_registered:             # <<<<<<<<<<<<<<
 *             try:
 *                 self._to_process.put_nowait((obj, None))
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_obj, __pyx_n_s_q); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_process_registered); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1472, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, __pyx_t_4, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1472, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "btdht/dht.pyx":1473
 *             getattr(self, '_on_%s_query' % obj.q.decode())(obj)
 *         if obj.q in self._to_process_registered:
 *             try:             # <<<<<<<<<<<<<<
 *                 self._to_process.put_nowait((obj, None))
 *             except Queue.Full:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_8);
      __Pyx_XGOTREF(__pyx_t_9);
      /*try:*/ {

        /* "btdht/dht.pyx":1474
 *         if obj.q in self._to_process_registered:
 *             try:
 *                 self._to_process.put_nowait((obj, None))             # <<<<<<<<<<<<<<
 *             except Queue.Full:
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_process); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1474, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_put_nowait); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1474, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1474, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_v_obj);
        __Pyx_GIVEREF(__pyx_v_obj);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_obj);
        __Pyx_INCREF(Py_None);
        __Pyx_GIVEREF(Py_None);
        PyTuple_SET_ITEM(__pyx_t_1, 1, Py_None);
        __pyx_t_5 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
          }
        }
        __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_1);
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1474, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "btdht/dht.pyx":1473
 *             getattr(self, '_on_%s_query' % obj.q.decode())(obj)
 *         if obj.q in self._to_process_registered:
 *             try:             # <<<<<<<<<<<<<<
 *                 self._to_process.put_nowait((obj, None))
 *             except Queue.Full:
 */
      }
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      goto __pyx_L14_try_end;
      __pyx_L9_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "btdht/dht.pyx":1475
 *             try:
 *                 self._to_process.put_nowait((obj, None))
 *             except Queue.Full:             # <<<<<<<<<<<<<<
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")
 * 
 */
      __Pyx_ErrFetch(&__pyx_t_4, &__pyx_t_6, &__pyx_t_1);
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_Queue); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1475, __pyx_L11_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_Full); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1475, __pyx_L11_except_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_11 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_4, __pyx_t_10);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_ErrRestore(__pyx_t_4, __pyx_t_6, __pyx_t_1);
      __pyx_t_4 = 0; __pyx_t_6 = 0; __pyx_t_1 = 0;
      if (__pyx_t_11) {
        __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_6, &__pyx_t_4) < 0) __PYX_ERR(0, 1475, __pyx_L11_except_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_GOTREF(__pyx_t_4);

        /* "btdht/dht.pyx":1476
 *                 self._to_process.put_nowait((obj, None))
 *             except Queue.Full:
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")             # <<<<<<<<<<<<<<
 * 
 *     def _process_loop(self):
 */
        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1476, __pyx_L11_except_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1476, __pyx_L11_except_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        goto __pyx_L10_exception_handled;
      }
      goto __pyx_L11_except_error;
      __pyx_L11_except_error:;

      /* "btdht/dht.pyx":1473
 *             getattr(self, '_on_%s_query' % obj.q.decode())(obj)
 *         if obj.q in self._to_process_registered:
 *             try:             # <<<<<<<<<<<<<<
 *                 self._to_process.put_nowait((obj, None))
 *             except Queue.Full:
 */
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      goto __pyx_L1_error;
      __pyx_L10_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      __pyx_L14_try_end:;
    }

    /* "btdht/dht.pyx":1472
 *         if obj.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:
 *             getattr(self, '_on_%s_query' % obj.q.decode())(obj)
 *         if obj.q in self._to_process_registered:             # <<<<<<<<<<<<<<
 *             try:
 *                 self._to_process.put_nowait((obj, None))
 */
  }

  /* "btdht/dht.pyx":1469
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")
 * 
 *     def _process_query(self, obj):             # <<<<<<<<<<<<<<
 *         if obj.q in [b"find_node", b"ping", b"get_peers", b"announce_peer"]:
 *             getattr(self, '_on_%s_query' % obj.q.decode())(obj)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_query", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_5btdht_3dht_8DHT_BASE_106generator2(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "btdht/dht.pyx":1478
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")
 * 
 *     def _process_loop(self):             # <<<<<<<<<<<<<<
 *         """function lauch by the thread processing messages"""
 *         yield 1
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_105_process_loop(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_104_process_loop[] = "function lauch by the thread processing messages";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_105_process_loop(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_process_loop (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_104_process_loop(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_104_process_loop(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_process_loop", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct_5__process_loop(__pyx_ptype_5btdht_3dht___pyx_scope_struct_5__process_loop, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 1478, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5btdht_3dht_8DHT_BASE_106generator2, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_process_loop, __pyx_n_s_DHT_BASE__process_loop, __pyx_n_s_btdht_dht); if (unlikely(!gen)) __PYX_ERR(0, 1478, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._process_loop", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5btdht_3dht_8DHT_BASE_106generator2(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop *__pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  int __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_process_loop", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L4_resume_from_yield;
    case 2: goto __pyx_L5_resume_from_yield;
    case 3: goto __pyx_L20_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1478, __pyx_L1_error)

  /* "btdht/dht.pyx":1480
 *     def _process_loop(self):
 *         """function lauch by the thread processing messages"""
 *         yield 1             # <<<<<<<<<<<<<<
 *         yield self._to_process
 *         while True:
 */
  __Pyx_INCREF(__pyx_int_1);
  __pyx_r = __pyx_int_1;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  /* return from generator, yielding value */
  __pyx_generator->resume_label = 1;
  return __pyx_r;
  __pyx_L4_resume_from_yield:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1480, __pyx_L1_error)

  /* "btdht/dht.pyx":1481
 *         """function lauch by the thread processing messages"""
 *         yield 1
 *         yield self._to_process             # <<<<<<<<<<<<<<
 *         while True:
 *             if self.stoped:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_to_process); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1481, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  /* return from generator, yielding value */
  __pyx_generator->resume_label = 2;
  return __pyx_r;
  __pyx_L5_resume_from_yield:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1481, __pyx_L1_error)

  /* "btdht/dht.pyx":1482
 *         yield 1
 *         yield self._to_process
 *         while True:             # <<<<<<<<<<<<<<
 *             if self.stoped:
 *                 return
 */
  while (1) {

    /* "btdht/dht.pyx":1483
 *         yield self._to_process
 *         while True:
 *             if self.stoped:             # <<<<<<<<<<<<<<
 *                 return
 *             try:
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_stoped); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1483, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_2) {

      /* "btdht/dht.pyx":1484
 *         while True:
 *             if self.stoped:
 *                 return             # <<<<<<<<<<<<<<
 *             try:
 *                 (query, response) = self._to_process.get_nowait()
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_r = NULL;
      goto __pyx_L0;

      /* "btdht/dht.pyx":1483
 *         yield self._to_process
 *         while True:
 *             if self.stoped:             # <<<<<<<<<<<<<<
 *                 return
 *             try:
 */
    }

    /* "btdht/dht.pyx":1485
 *             if self.stoped:
 *                 return
 *             try:             # <<<<<<<<<<<<<<
 *                 (query, response) = self._to_process.get_nowait()
 *                 if response is None:
 */
    {
      __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_3);
      __Pyx_XGOTREF(__pyx_t_4);
      __Pyx_XGOTREF(__pyx_t_5);
      /*try:*/ {

        /* "btdht/dht.pyx":1486
 *                 return
 *             try:
 *                 (query, response) = self._to_process.get_nowait()             # <<<<<<<<<<<<<<
 *                 if response is None:
 *                     getattr(self, 'on_%s_query' % query.q.decode())(query)
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_to_process); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1486, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_get_nowait); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1486, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_6)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
          }
        }
        __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1486, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
          PyObject* sequence = __pyx_t_1;
          Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
          if (unlikely(size != 2)) {
            if (size > 2) __Pyx_RaiseTooManyValuesError(2);
            else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
            __PYX_ERR(0, 1486, __pyx_L9_error)
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          if (likely(PyTuple_CheckExact(sequence))) {
            __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
            __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_6);
          #else
          __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1486, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1486, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        } else {
          Py_ssize_t index = -1;
          __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1486, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
          index = 0; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L17_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_7);
          index = 1; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L17_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_6);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) __PYX_ERR(0, 1486, __pyx_L9_error)
          __pyx_t_9 = NULL;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          goto __pyx_L18_unpacking_done;
          __pyx_L17_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_9 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          __PYX_ERR(0, 1486, __pyx_L9_error)
          __pyx_L18_unpacking_done:;
        }
        __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_query);
        __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_query, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_7);
        __pyx_t_7 = 0;
        __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_response);
        __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_response, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_6);
        __pyx_t_6 = 0;

        /* "btdht/dht.pyx":1487
 *             try:
 *                 (query, response) = self._to_process.get_nowait()
 *                 if response is None:             # <<<<<<<<<<<<<<
 *                     getattr(self, 'on_%s_query' % query.q.decode())(query)
 *                 elif response.y == b"e":
 */
        __pyx_t_2 = (__pyx_cur_scope->__pyx_v_response == Py_None);
        __pyx_t_10 = (__pyx_t_2 != 0);
        if (__pyx_t_10) {

          /* "btdht/dht.pyx":1488
 *                 (query, response) = self._to_process.get_nowait()
 *                 if response is None:
 *                     getattr(self, 'on_%s_query' % query.q.decode())(query)             # <<<<<<<<<<<<<<
 *                 elif response.y == b"e":
 *                     self.on_error(response, query)
 */
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_query, __pyx_n_s_q); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1488, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_decode_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1488, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
            __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
            if (likely(__pyx_t_7)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
              __Pyx_INCREF(__pyx_t_7);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_8, function);
            }
          }
          __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_8);
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1488, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = __Pyx_PyString_FormatSafe(__pyx_kp_s_on__s_query_2, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1488, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1488, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
            if (likely(__pyx_t_8)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_6, function);
            }
          }
          __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_cur_scope->__pyx_v_query) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_cur_scope->__pyx_v_query);
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1488, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "btdht/dht.pyx":1487
 *             try:
 *                 (query, response) = self._to_process.get_nowait()
 *                 if response is None:             # <<<<<<<<<<<<<<
 *                     getattr(self, 'on_%s_query' % query.q.decode())(query)
 *                 elif response.y == b"e":
 */
          goto __pyx_L19;
        }

        /* "btdht/dht.pyx":1489
 *                 if response is None:
 *                     getattr(self, 'on_%s_query' % query.q.decode())(query)
 *                 elif response.y == b"e":             # <<<<<<<<<<<<<<
 *                     self.on_error(response, query)
 *                 else:
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_response, __pyx_n_s_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1489, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_10 = (__Pyx_PyBytes_Equals(__pyx_t_1, __pyx_n_b_e, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 1489, __pyx_L9_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (__pyx_t_10) {

          /* "btdht/dht.pyx":1490
 *                     getattr(self, 'on_%s_query' % query.q.decode())(query)
 *                 elif response.y == b"e":
 *                     self.on_error(response, query)             # <<<<<<<<<<<<<<
 *                 else:
 *                     getattr(self, 'on_%s_response' % query.q.decode())(query, response)
 */
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_on_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1490, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_8 = NULL;
          __pyx_t_11 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
            if (likely(__pyx_t_8)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_6, function);
              __pyx_t_11 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_cur_scope->__pyx_v_response, __pyx_cur_scope->__pyx_v_query};
            __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1490, __pyx_L9_error)
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_GOTREF(__pyx_t_1);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_cur_scope->__pyx_v_response, __pyx_cur_scope->__pyx_v_query};
            __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1490, __pyx_L9_error)
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_GOTREF(__pyx_t_1);
          } else
          #endif
          {
            __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1490, __pyx_L9_error)
            __Pyx_GOTREF(__pyx_t_7);
            if (__pyx_t_8) {
              __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); __pyx_t_8 = NULL;
            }
            __Pyx_INCREF(__pyx_cur_scope->__pyx_v_response);
            __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_response);
            PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_cur_scope->__pyx_v_response);
            __Pyx_INCREF(__pyx_cur_scope->__pyx_v_query);
            __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_query);
            PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_cur_scope->__pyx_v_query);
            __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1490, __pyx_L9_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          }
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "btdht/dht.pyx":1489
 *                 if response is None:
 *                     getattr(self, 'on_%s_query' % query.q.decode())(query)
 *                 elif response.y == b"e":             # <<<<<<<<<<<<<<
 *                     self.on_error(response, query)
 *                 else:
 */
          goto __pyx_L19;
        }

        /* "btdht/dht.pyx":1492
 *                     self.on_error(response, query)
 *                 else:
 *                     getattr(self, 'on_%s_response' % query.q.decode())(query, response)             # <<<<<<<<<<<<<<
 *             except Queue.Empty:
 *                 pass
 */
        /*else*/ {
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_query, __pyx_n_s_q); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1492, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_decode_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1492, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
            __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
            if (likely(__pyx_t_7)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
              __Pyx_INCREF(__pyx_t_7);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_8, function);
            }
          }
          __pyx_t_6 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_8);
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1492, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = __Pyx_PyString_FormatSafe(__pyx_kp_s_on__s_response_2, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1492, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1492, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = NULL;
          __pyx_t_11 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
            if (likely(__pyx_t_8)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_6, function);
              __pyx_t_11 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_cur_scope->__pyx_v_query, __pyx_cur_scope->__pyx_v_response};
            __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1492, __pyx_L9_error)
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_GOTREF(__pyx_t_1);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_cur_scope->__pyx_v_query, __pyx_cur_scope->__pyx_v_response};
            __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1492, __pyx_L9_error)
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_GOTREF(__pyx_t_1);
          } else
          #endif
          {
            __pyx_t_7 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1492, __pyx_L9_error)
            __Pyx_GOTREF(__pyx_t_7);
            if (__pyx_t_8) {
              __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); __pyx_t_8 = NULL;
            }
            __Pyx_INCREF(__pyx_cur_scope->__pyx_v_query);
            __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_query);
            PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_11, __pyx_cur_scope->__pyx_v_query);
            __Pyx_INCREF(__pyx_cur_scope->__pyx_v_response);
            __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_response);
            PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_11, __pyx_cur_scope->__pyx_v_response);
            __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1492, __pyx_L9_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          }
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        }
        __pyx_L19:;

        /* "btdht/dht.pyx":1485
 *             if self.stoped:
 *                 return
 *             try:             # <<<<<<<<<<<<<<
 *                 (query, response) = self._to_process.get_nowait()
 *                 if response is None:
 */
      }
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L16_try_end;
      __pyx_L9_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "btdht/dht.pyx":1493
 *                 else:
 *                     getattr(self, 'on_%s_response' % query.q.decode())(query, response)
 *             except Queue.Empty:             # <<<<<<<<<<<<<<
 *                 pass
 *             yield
 */
      __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_6, &__pyx_t_7);
      __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_Queue); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1493, __pyx_L11_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_Empty); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1493, __pyx_L11_except_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_11 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_12);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_ErrRestore(__pyx_t_1, __pyx_t_6, __pyx_t_7);
      __pyx_t_1 = 0; __pyx_t_6 = 0; __pyx_t_7 = 0;
      if (__pyx_t_11) {
        __Pyx_ErrRestore(0,0,0);
        goto __pyx_L10_exception_handled;
      }
      goto __pyx_L11_except_error;
      __pyx_L11_except_error:;

      /* "btdht/dht.pyx":1485
 *             if self.stoped:
 *                 return
 *             try:             # <<<<<<<<<<<<<<
 *                 (query, response) = self._to_process.get_nowait()
 *                 if response is None:
 */
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      goto __pyx_L1_error;
      __pyx_L10_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_3);
      __Pyx_XGIVEREF(__pyx_t_4);
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      __pyx_L16_try_end:;
    }

    /* "btdht/dht.pyx":1495
 *             except Queue.Empty:
 *                 pass
 *             yield             # <<<<<<<<<<<<<<
 * 
 *     def _decode(self, s, addr):
 */
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 3;
    return __pyx_r;
    __pyx_L20_resume_from_yield:;
    if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1495, __pyx_L1_error)
  }
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* "btdht/dht.pyx":1478
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")
 * 
 *     def _process_loop(self):             # <<<<<<<<<<<<<<
 *         """function lauch by the thread processing messages"""
 *         yield 1
 */

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("_process_loop", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1497
 *             yield
 * 
 *     def _decode(self, s, addr):             # <<<<<<<<<<<<<<
 *         """
 *             decode a message
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_108_decode(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_8DHT_BASE_107_decode[] = "\n            decode a message\n\n            :param bytes s: A newly received message\n            :param tuple addr: A couple (ip, port) with ip in dotted notation\n            :return A couple (decoded message, query) if the message is a response or an error,\n                (decoded message, None) otherwise\n            :rtype: tuple\n            :raises TransactionIdUnknown: If the decoded message has no ``t`` key\n            :raises MethodUnknownError: If the queried method is unknown\n            :raises ValueError: If the message is neither a query, a response or an error\n            :raises ProtocolError: If the message is malformed\n        ";
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_108_decode(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_s = 0;
  PyObject *__pyx_v_addr = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_decode (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_s,&__pyx_n_s_addr,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_s)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_addr)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_decode", 1, 2, 2, 1); __PYX_ERR(0, 1497, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_decode") < 0)) __PYX_ERR(0, 1497, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_s = values[0];
    __pyx_v_addr = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_decode", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1497, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_107_decode(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), __pyx_v_s, __pyx_v_addr);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_107_decode(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v_s, PyObject *__pyx_v_addr) {
  struct __pyx_obj_5btdht_4krcp_BMessage *__pyx_v_msg = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_ttype = NULL;
  PyObject *__pyx_v_query = NULL;
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_v_e = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_decode", 0);

  /* "btdht/dht.pyx":1511
 *             :raises ProtocolError: If the message is malformed
 *         """
 *         msg = BMessage(addr=addr, debug=self.debuglvl)             # <<<<<<<<<<<<<<
 *         msg.decode(s, len(s))
 *         try:
 */
  __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_addr, __pyx_v_addr) < 0) __PYX_ERR(0, 1511, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debuglvl); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_debug, __pyx_t_2) < 0) __PYX_ERR(0, 1511, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5btdht_4krcp_BMessage), __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1511, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_msg = ((struct __pyx_obj_5btdht_4krcp_BMessage *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1512
 *         """
 *         msg = BMessage(addr=addr, debug=self.debuglvl)
 *         msg.decode(s, len(s))             # <<<<<<<<<<<<<<
 *         try:
 *             if msg.y == b"q":
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_decode_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1512, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_Length(__pyx_v_s); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1512, __pyx_L1_error)
  __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1512, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
      __pyx_t_6 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_s, __pyx_t_4};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1512, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_s, __pyx_t_4};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1512, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1512, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_INCREF(__pyx_v_s);
    __Pyx_GIVEREF(__pyx_v_s);
    PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_s);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1512, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1513
 *         msg = BMessage(addr=addr, debug=self.debuglvl)
 *         msg.decode(s, len(s))
 *         try:             # <<<<<<<<<<<<<<
 *             if msg.y == b"q":
 *                 return msg, None
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
    __Pyx_XGOTREF(__pyx_t_8);
    __Pyx_XGOTREF(__pyx_t_9);
    __Pyx_XGOTREF(__pyx_t_10);
    /*try:*/ {

      /* "btdht/dht.pyx":1514
 *         msg.decode(s, len(s))
 *         try:
 *             if msg.y == b"q":             # <<<<<<<<<<<<<<
 *                 return msg, None
 *             elif msg.y == b"r":
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1514, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_11 = (__Pyx_PyBytes_Equals(__pyx_t_2, __pyx_n_b_q, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1514, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_11) {

        /* "btdht/dht.pyx":1515
 *         try:
 *             if msg.y == b"q":
 *                 return msg, None             # <<<<<<<<<<<<<<
 *             elif msg.y == b"r":
 *                 if msg.t in self.transaction_type:
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1515, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF(((PyObject *)__pyx_v_msg));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_msg));
        PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_msg));
        __Pyx_INCREF(Py_None);
        __Pyx_GIVEREF(Py_None);
        PyTuple_SET_ITEM(__pyx_t_2, 1, Py_None);
        __pyx_r = __pyx_t_2;
        __pyx_t_2 = 0;
        goto __pyx_L7_try_return;

        /* "btdht/dht.pyx":1514
 *         msg.decode(s, len(s))
 *         try:
 *             if msg.y == b"q":             # <<<<<<<<<<<<<<
 *                 return msg, None
 *             elif msg.y == b"r":
 */
      }

      /* "btdht/dht.pyx":1516
 *             if msg.y == b"q":
 *                 return msg, None
 *             elif msg.y == b"r":             # <<<<<<<<<<<<<<
 *                 if msg.t in self.transaction_type:
 *                     ttype = self.transaction_type[msg.t][0]
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_y); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1516, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_11 = (__Pyx_PyBytes_Equals(__pyx_t_2, __pyx_n_b_r, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1516, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_11) {

        /* "btdht/dht.pyx":1517
 *                 return msg, None
 *             elif msg.y == b"r":
 *                 if msg.t in self.transaction_type:             # <<<<<<<<<<<<<<
 *                     ttype = self.transaction_type[msg.t][0]
 *                     query = self.transaction_type[msg.t][2]
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1517, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1517, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_11 = (__Pyx_PySequence_ContainsTF(__pyx_t_2, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1517, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_12 = (__pyx_t_11 != 0);
        if (likely(__pyx_t_12)) {

          /* "btdht/dht.pyx":1518
 *             elif msg.y == b"r":
 *                 if msg.t in self.transaction_type:
 *                     ttype = self.transaction_type[msg.t][0]             # <<<<<<<<<<<<<<
 *                     query = self.transaction_type[msg.t][2]
 *                     return msg, query
 */
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1518, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1518, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1518, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_7, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1518, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_v_ttype = __pyx_t_2;
          __pyx_t_2 = 0;

          /* "btdht/dht.pyx":1519
 *                 if msg.t in self.transaction_type:
 *                     ttype = self.transaction_type[msg.t][0]
 *                     query = self.transaction_type[msg.t][2]             # <<<<<<<<<<<<<<
 *                     return msg, query
 *                 else:
 */
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1519, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1519, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1519, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_1, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1519, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_v_query = __pyx_t_7;
          __pyx_t_7 = 0;

          /* "btdht/dht.pyx":1520
 *                     ttype = self.transaction_type[msg.t][0]
 *                     query = self.transaction_type[msg.t][2]
 *                     return msg, query             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise TransactionIdUnknown(msg.t)
 */
          __Pyx_XDECREF(__pyx_r);
          __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1520, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_INCREF(((PyObject *)__pyx_v_msg));
          __Pyx_GIVEREF(((PyObject *)__pyx_v_msg));
          PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_msg));
          __Pyx_INCREF(__pyx_v_query);
          __Pyx_GIVEREF(__pyx_v_query);
          PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_query);
          __pyx_r = __pyx_t_7;
          __pyx_t_7 = 0;
          goto __pyx_L7_try_return;

          /* "btdht/dht.pyx":1517
 *                 return msg, None
 *             elif msg.y == b"r":
 *                 if msg.t in self.transaction_type:             # <<<<<<<<<<<<<<
 *                     ttype = self.transaction_type[msg.t][0]
 *                     query = self.transaction_type[msg.t][2]
 */
        }

        /* "btdht/dht.pyx":1522
 *                     return msg, query
 *                 else:
 *                     raise TransactionIdUnknown(msg.t)             # <<<<<<<<<<<<<<
 *             elif msg.y == b"e":
 *                 query = self.transaction_type.get(msg.t, (None, None, None))[2]
 */
        /*else*/ {
          __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_TransactionIdUnknown); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1522, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1522, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_4 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
            if (likely(__pyx_t_4)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
              __Pyx_INCREF(__pyx_t_4);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_1, function);
            }
          }
          __pyx_t_7 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2);
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1522, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_Raise(__pyx_t_7, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __PYX_ERR(0, 1522, __pyx_L3_error)
        }

        /* "btdht/dht.pyx":1516
 *             if msg.y == b"q":
 *                 return msg, None
 *             elif msg.y == b"r":             # <<<<<<<<<<<<<<
 *                 if msg.t in self.transaction_type:
 *                     ttype = self.transaction_type[msg.t][0]
 */
      }

      /* "btdht/dht.pyx":1523
 *                 else:
 *                     raise TransactionIdUnknown(msg.t)
 *             elif msg.y == b"e":             # <<<<<<<<<<<<<<
 *                 query = self.transaction_type.get(msg.t, (None, None, None))[2]
 *                 if msg.errno == 201:
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_y); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1523, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_12 = (__Pyx_PyBytes_Equals(__pyx_t_7, __pyx_n_b_e, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1523, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (likely(__pyx_t_12)) {

        /* "btdht/dht.pyx":1524
 *                     raise TransactionIdUnknown(msg.t)
 *             elif msg.y == b"e":
 *                 query = self.transaction_type.get(msg.t, (None, None, None))[2]             # <<<<<<<<<<<<<<
 *                 if msg.errno == 201:
 *                     self.debug(
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1524, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1524, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1524, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = NULL;
        __pyx_t_6 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
            __pyx_t_6 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_1, __pyx_tuple__5};
          __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1524, __pyx_L3_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_1, __pyx_tuple__5};
          __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1524, __pyx_L3_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        } else
        #endif
        {
          __pyx_t_5 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1524, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          if (__pyx_t_4) {
            __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_6, __pyx_t_1);
          __Pyx_INCREF(__pyx_tuple__5);
          __Pyx_GIVEREF(__pyx_tuple__5);
          PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_6, __pyx_tuple__5);
          __pyx_t_1 = 0;
          __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1524, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_7, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1524, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_v_query = __pyx_t_2;
        __pyx_t_2 = 0;

        /* "btdht/dht.pyx":1525
 *             elif msg.y == b"e":
 *                 query = self.transaction_type.get(msg.t, (None, None, None))[2]
 *                 if msg.errno == 201:             # <<<<<<<<<<<<<<
 *                     self.debug(
 *                         2,
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1525, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = __Pyx_PyInt_EqObjC(__pyx_t_2, __pyx_int_201, 0xC9, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1525, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1525, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (__pyx_t_12) {

          /* "btdht/dht.pyx":1526
 *                 query = self.transaction_type.get(msg.t, (None, None, None))[2]
 *                 if msg.errno == 201:
 *                     self.debug(             # <<<<<<<<<<<<<<
 *                         2,
 *                         "ERROR:201:%s pour %r" % (msg.errmsg, self.transaction_type.get(msg.t, {}))
 */
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1526, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);

          /* "btdht/dht.pyx":1528
 *                     self.debug(
 *                         2,
 *                         "ERROR:201:%s pour %r" % (msg.errmsg, self.transaction_type.get(msg.t, {}))             # <<<<<<<<<<<<<<
 *                     )
 *                     return GenericError(msg.t, msg.errmsg), query
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errmsg); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1528, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1528, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_get); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1528, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1528, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_14 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1528, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_14);
          __pyx_t_15 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
            __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_13);
            if (likely(__pyx_t_15)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
              __Pyx_INCREF(__pyx_t_15);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_13, function);
              __pyx_t_6 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_13)) {
            PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_t_4, __pyx_t_14};
            __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1528, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) {
            PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_t_4, __pyx_t_14};
            __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1528, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          } else
          #endif
          {
            __pyx_t_16 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1528, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_16);
            if (__pyx_t_15) {
              __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_15); __pyx_t_15 = NULL;
            }
            __Pyx_GIVEREF(__pyx_t_4);
            PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_6, __pyx_t_4);
            __Pyx_GIVEREF(__pyx_t_14);
            PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_6, __pyx_t_14);
            __pyx_t_4 = 0;
            __pyx_t_14 = 0;
            __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_16, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1528, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          }
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_13 = PyTuple_New(2); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1528, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_GIVEREF(__pyx_t_5);
          PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_5);
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_1);
          __pyx_t_5 = 0;
          __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_ERROR_201_s_pour_r, __pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1528, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_13 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
            __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_2);
            if (likely(__pyx_t_13)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
              __Pyx_INCREF(__pyx_t_13);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_2, function);
              __pyx_t_6 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_2)) {
            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_int_2, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1526, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_int_2, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1526, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          {
            __pyx_t_5 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1526, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_5);
            if (__pyx_t_13) {
              __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_13); __pyx_t_13 = NULL;
            }
            __Pyx_INCREF(__pyx_int_2);
            __Pyx_GIVEREF(__pyx_int_2);
            PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_6, __pyx_int_2);
            __Pyx_GIVEREF(__pyx_t_1);
            PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_6, __pyx_t_1);
            __pyx_t_1 = 0;
            __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1526, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "btdht/dht.pyx":1530
 *                         "ERROR:201:%s pour %r" % (msg.errmsg, self.transaction_type.get(msg.t, {}))
 *                     )
 *                     return GenericError(msg.t, msg.errmsg), query             # <<<<<<<<<<<<<<
 *                 elif msg.errno == 202:
 *                     self.debug(
 */
          __Pyx_XDECREF(__pyx_r);
          __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_GenericError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1530, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1530, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errmsg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1530, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_13 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
            __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_2);
            if (likely(__pyx_t_13)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
              __Pyx_INCREF(__pyx_t_13);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_2, function);
              __pyx_t_6 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_2)) {
            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_t_5, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1530, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_t_5, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1530, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          {
            __pyx_t_16 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1530, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_16);
            if (__pyx_t_13) {
              __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_13); __pyx_t_13 = NULL;
            }
            __Pyx_GIVEREF(__pyx_t_5);
            PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_6, __pyx_t_5);
            __Pyx_GIVEREF(__pyx_t_1);
            PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_6, __pyx_t_1);
            __pyx_t_5 = 0;
            __pyx_t_1 = 0;
            __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_16, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1530, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          }
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1530, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7);
          __Pyx_INCREF(__pyx_v_query);
          __Pyx_GIVEREF(__pyx_v_query);
          PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_query);
          __pyx_t_7 = 0;
          __pyx_r = __pyx_t_2;
          __pyx_t_2 = 0;
          goto __pyx_L7_try_return;

          /* "btdht/dht.pyx":1525
 *             elif msg.y == b"e":
 *                 query = self.transaction_type.get(msg.t, (None, None, None))[2]
 *                 if msg.errno == 201:             # <<<<<<<<<<<<<<
 *                     self.debug(
 *                         2,
 */
        }

        /* "btdht/dht.pyx":1531
 *                     )
 *                     return GenericError(msg.t, msg.errmsg), query
 *                 elif msg.errno == 202:             # <<<<<<<<<<<<<<
 *                     self.debug(
 *                         2,
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1531, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = __Pyx_PyInt_EqObjC(__pyx_t_2, __pyx_int_202, 0xCA, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1531, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1531, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (__pyx_t_12) {

          /* "btdht/dht.pyx":1532
 *                     return GenericError(msg.t, msg.errmsg), query
 *                 elif msg.errno == 202:
 *                     self.debug(             # <<<<<<<<<<<<<<
 *                         2,
 *                         "ERROR:202:%s pour %r" % (msg.errmsg, self.transaction_type.get(msg.t, {}))
 */
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1532, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);

          /* "btdht/dht.pyx":1534
 *                     self.debug(
 *                         2,
 *                         "ERROR:202:%s pour %r" % (msg.errmsg, self.transaction_type.get(msg.t, {}))             # <<<<<<<<<<<<<<
 *                     )
 *                     return ServerError(msg.t, msg.errmsg), query
 */
          __pyx_t_16 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errmsg); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1534, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_16);
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1534, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_get); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1534, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1534, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_14 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1534, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_14);
          __pyx_t_4 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
            __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_13);
            if (likely(__pyx_t_4)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
              __Pyx_INCREF(__pyx_t_4);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_13, function);
              __pyx_t_6 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_13)) {
            PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_5, __pyx_t_14};
            __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1534, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) {
            PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_5, __pyx_t_14};
            __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1534, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          } else
          #endif
          {
            __pyx_t_15 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1534, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_15);
            if (__pyx_t_4) {
              __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_4); __pyx_t_4 = NULL;
            }
            __Pyx_GIVEREF(__pyx_t_5);
            PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_6, __pyx_t_5);
            __Pyx_GIVEREF(__pyx_t_14);
            PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_6, __pyx_t_14);
            __pyx_t_5 = 0;
            __pyx_t_14 = 0;
            __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_15, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1534, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          }
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_13 = PyTuple_New(2); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1534, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_GIVEREF(__pyx_t_16);
          PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_16);
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_1);
          __pyx_t_16 = 0;
          __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_ERROR_202_s_pour_r, __pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1534, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_13 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
            __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_2);
            if (likely(__pyx_t_13)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
              __Pyx_INCREF(__pyx_t_13);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_2, function);
              __pyx_t_6 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_2)) {
            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_int_2, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1532, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_int_2, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1532, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          {
            __pyx_t_16 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1532, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_16);
            if (__pyx_t_13) {
              __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_13); __pyx_t_13 = NULL;
            }
            __Pyx_INCREF(__pyx_int_2);
            __Pyx_GIVEREF(__pyx_int_2);
            PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_6, __pyx_int_2);
            __Pyx_GIVEREF(__pyx_t_1);
            PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_6, __pyx_t_1);
            __pyx_t_1 = 0;
            __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_16, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1532, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          }
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "btdht/dht.pyx":1536
 *                         "ERROR:202:%s pour %r" % (msg.errmsg, self.transaction_type.get(msg.t, {}))
 *                     )
 *                     return ServerError(msg.t, msg.errmsg), query             # <<<<<<<<<<<<<<
 *                 elif msg.errno == 203:
 *                     t = self.transaction_type.get(msg.t)
 */
          __Pyx_XDECREF(__pyx_r);
          __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ServerError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1536, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_16 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1536, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_16);
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errmsg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1536, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_13 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
            __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_2);
            if (likely(__pyx_t_13)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
              __Pyx_INCREF(__pyx_t_13);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_2, function);
              __pyx_t_6 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_2)) {
            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_t_16, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1536, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_t_16, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1536, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          {
            __pyx_t_15 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1536, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_15);
            if (__pyx_t_13) {
              __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_13); __pyx_t_13 = NULL;
            }
            __Pyx_GIVEREF(__pyx_t_16);
            PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_6, __pyx_t_16);
            __Pyx_GIVEREF(__pyx_t_1);
            PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_6, __pyx_t_1);
            __pyx_t_16 = 0;
            __pyx_t_1 = 0;
            __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_15, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1536, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          }
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1536, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7);
          __Pyx_INCREF(__pyx_v_query);
          __Pyx_GIVEREF(__pyx_v_query);
          PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_query);
          __pyx_t_7 = 0;
          __pyx_r = __pyx_t_2;
          __pyx_t_2 = 0;
          goto __pyx_L7_try_return;

          /* "btdht/dht.pyx":1531
 *                     )
 *                     return GenericError(msg.t, msg.errmsg), query
 *                 elif msg.errno == 202:             # <<<<<<<<<<<<<<
 *                     self.debug(
 *                         2,
 */
        }

        /* "btdht/dht.pyx":1537
 *                     )
 *                     return ServerError(msg.t, msg.errmsg), query
 *                 elif msg.errno == 203:             # <<<<<<<<<<<<<<
 *                     t = self.transaction_type.get(msg.t)
 *                     self.debug(1 if t else 2, "ERROR:203:%s pour %r" % (msg.errmsg, t))
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1537, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = __Pyx_PyInt_EqObjC(__pyx_t_2, __pyx_int_203, 0xCB, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1537, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1537, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (__pyx_t_12) {

          /* "btdht/dht.pyx":1538
 *                     return ServerError(msg.t, msg.errmsg), query
 *                 elif msg.errno == 203:
 *                     t = self.transaction_type.get(msg.t)             # <<<<<<<<<<<<<<
 *                     self.debug(1 if t else 2, "ERROR:203:%s pour %r" % (msg.errmsg, t))
 *                     return ProtocolError(msg.t, msg.errmsg), query
 */
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1538, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1538, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_15);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1538, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_1 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
            __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_15);
            if (likely(__pyx_t_1)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
              __Pyx_INCREF(__pyx_t_1);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_15, function);
            }
          }
          __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_15, __pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_2);
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1538, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          __pyx_v_t = __pyx_t_7;
          __pyx_t_7 = 0;

          /* "btdht/dht.pyx":1539
 *                 elif msg.errno == 203:
 *                     t = self.transaction_type.get(msg.t)
 *                     self.debug(1 if t else 2, "ERROR:203:%s pour %r" % (msg.errmsg, t))             # <<<<<<<<<<<<<<
 *                     return ProtocolError(msg.t, msg.errmsg), query
 *                 elif msg.errno == 204:
 */
          __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1539, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_15);
          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_t); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1539, __pyx_L3_error)
          if (__pyx_t_12) {
            __Pyx_INCREF(__pyx_int_1);
            __pyx_t_2 = __pyx_int_1;
          } else {
            __Pyx_INCREF(__pyx_int_2);
            __pyx_t_2 = __pyx_int_2;
          }
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errmsg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1539, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1539, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_16);
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_1);
          __Pyx_INCREF(__pyx_v_t);
          __Pyx_GIVEREF(__pyx_v_t);
          PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_v_t);
          __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_ERROR_203_s_pour_r, __pyx_t_16); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1539, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __pyx_t_16 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_15))) {
            __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_15);
            if (likely(__pyx_t_16)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
              __Pyx_INCREF(__pyx_t_16);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_15, function);
              __pyx_t_6 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_15)) {
            PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_t_2, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1539, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_15)) {
            PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_t_2, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1539, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          {
            __pyx_t_13 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1539, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_13);
            if (__pyx_t_16) {
              __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_16); __pyx_t_16 = NULL;
            }
            __Pyx_GIVEREF(__pyx_t_2);
            PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_6, __pyx_t_2);
            __Pyx_GIVEREF(__pyx_t_1);
            PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_6, __pyx_t_1);
            __pyx_t_2 = 0;
            __pyx_t_1 = 0;
            __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_13, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1539, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          }
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "btdht/dht.pyx":1540
 *                     t = self.transaction_type.get(msg.t)
 *                     self.debug(1 if t else 2, "ERROR:203:%s pour %r" % (msg.errmsg, t))
 *                     return ProtocolError(msg.t, msg.errmsg), query             # <<<<<<<<<<<<<<
 *                 elif msg.errno == 204:
 *                     t = self.transaction_type.get(msg.t)
 */
          __Pyx_XDECREF(__pyx_r);
          __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_ProtocolError); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1540, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_15);
          __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1540, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errmsg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1540, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_2 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_15))) {
            __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_15);
            if (likely(__pyx_t_2)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
              __Pyx_INCREF(__pyx_t_2);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_15, function);
              __pyx_t_6 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_15)) {
            PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_13, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1540, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_15)) {
            PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_13, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1540, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          {
            __pyx_t_16 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1540, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_16);
            if (__pyx_t_2) {
              __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_2); __pyx_t_2 = NULL;
            }
            __Pyx_GIVEREF(__pyx_t_13);
            PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_6, __pyx_t_13);
            __Pyx_GIVEREF(__pyx_t_1);
            PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_6, __pyx_t_1);
            __pyx_t_13 = 0;
            __pyx_t_1 = 0;
            __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_16, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1540, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          }
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1540, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_15);
          __Pyx_GIVEREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_7);
          __Pyx_INCREF(__pyx_v_query);
          __Pyx_GIVEREF(__pyx_v_query);
          PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_v_query);
          __pyx_t_7 = 0;
          __pyx_r = __pyx_t_15;
          __pyx_t_15 = 0;
          goto __pyx_L7_try_return;

          /* "btdht/dht.pyx":1537
 *                     )
 *                     return ServerError(msg.t, msg.errmsg), query
 *                 elif msg.errno == 203:             # <<<<<<<<<<<<<<
 *                     t = self.transaction_type.get(msg.t)
 *                     self.debug(1 if t else 2, "ERROR:203:%s pour %r" % (msg.errmsg, t))
 */
        }

        /* "btdht/dht.pyx":1541
 *                     self.debug(1 if t else 2, "ERROR:203:%s pour %r" % (msg.errmsg, t))
 *                     return ProtocolError(msg.t, msg.errmsg), query
 *                 elif msg.errno == 204:             # <<<<<<<<<<<<<<
 *                     t = self.transaction_type.get(msg.t)
 *                     self.debug(0 if t else 1, "ERROR:204:%s pour %r" % (msg.errmsg, t))
 */
        __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errno); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1541, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_15);
        __pyx_t_7 = __Pyx_PyInt_EqObjC(__pyx_t_15, __pyx_int_204, 0xCC, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1541, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1541, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (likely(__pyx_t_12)) {

          /* "btdht/dht.pyx":1542
 *                     return ProtocolError(msg.t, msg.errmsg), query
 *                 elif msg.errno == 204:
 *                     t = self.transaction_type.get(msg.t)             # <<<<<<<<<<<<<<
 *                     self.debug(0 if t else 1, "ERROR:204:%s pour %r" % (msg.errmsg, t))
 *                     return MethodUnknownError(msg.t, msg.errmsg), query
 */
          __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1542, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_15);
          __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_get); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1542, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_16);
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1542, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_15);
          __pyx_t_1 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_16))) {
            __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_16);
            if (likely(__pyx_t_1)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
              __Pyx_INCREF(__pyx_t_1);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_16, function);
            }
          }
          __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_16, __pyx_t_1, __pyx_t_15) : __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_15);
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1542, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __pyx_v_t = __pyx_t_7;
          __pyx_t_7 = 0;

          /* "btdht/dht.pyx":1543
 *                 elif msg.errno == 204:
 *                     t = self.transaction_type.get(msg.t)
 *                     self.debug(0 if t else 1, "ERROR:204:%s pour %r" % (msg.errmsg, t))             # <<<<<<<<<<<<<<
 *                     return MethodUnknownError(msg.t, msg.errmsg), query
 *                 else:
 */
          __pyx_t_16 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1543, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_16);
          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_t); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 1543, __pyx_L3_error)
          if (__pyx_t_12) {
            __Pyx_INCREF(__pyx_int_0);
            __pyx_t_15 = __pyx_int_0;
          } else {
            __Pyx_INCREF(__pyx_int_1);
            __pyx_t_15 = __pyx_int_1;
          }
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errmsg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1543, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_13 = PyTuple_New(2); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1543, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1);
          __Pyx_INCREF(__pyx_v_t);
          __Pyx_GIVEREF(__pyx_v_t);
          PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_v_t);
          __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_ERROR_204_s_pour_r, __pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1543, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_13 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_16))) {
            __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_16);
            if (likely(__pyx_t_13)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
              __Pyx_INCREF(__pyx_t_13);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_16, function);
              __pyx_t_6 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_16)) {
            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_t_15, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_16, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1543, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_16)) {
            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_t_15, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_16, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1543, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          {
            __pyx_t_2 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1543, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_2);
            if (__pyx_t_13) {
              __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_13); __pyx_t_13 = NULL;
            }
            __Pyx_GIVEREF(__pyx_t_15);
            PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_6, __pyx_t_15);
            __Pyx_GIVEREF(__pyx_t_1);
            PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_6, __pyx_t_1);
            __pyx_t_15 = 0;
            __pyx_t_1 = 0;
            __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_t_2, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1543, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          }
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "btdht/dht.pyx":1544
 *                     t = self.transaction_type.get(msg.t)
 *                     self.debug(0 if t else 1, "ERROR:204:%s pour %r" % (msg.errmsg, t))
 *                     return MethodUnknownError(msg.t, msg.errmsg), query             # <<<<<<<<<<<<<<
 *                 else:
 *                     self.debug(
 */
          __Pyx_XDECREF(__pyx_r);
          __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_MethodUnknownError); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1544, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_16);
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1544, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errmsg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1544, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_15 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_16))) {
            __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_16);
            if (likely(__pyx_t_15)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
              __Pyx_INCREF(__pyx_t_15);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_16, function);
              __pyx_t_6 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_16)) {
            PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_t_2, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_16, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1544, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_16)) {
            PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_t_2, __pyx_t_1};
            __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_16, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1544, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          } else
          #endif
          {
            __pyx_t_13 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1544, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_13);
            if (__pyx_t_15) {
              __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_15); __pyx_t_15 = NULL;
            }
            __Pyx_GIVEREF(__pyx_t_2);
            PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_6, __pyx_t_2);
            __Pyx_GIVEREF(__pyx_t_1);
            PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_6, __pyx_t_1);
            __pyx_t_2 = 0;
            __pyx_t_1 = 0;
            __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_t_13, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1544, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_7);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          }
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1544, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_16);
          __Pyx_GIVEREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_7);
          __Pyx_INCREF(__pyx_v_query);
          __Pyx_GIVEREF(__pyx_v_query);
          PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_v_query);
          __pyx_t_7 = 0;
          __pyx_r = __pyx_t_16;
          __pyx_t_16 = 0;
          goto __pyx_L7_try_return;

          /* "btdht/dht.pyx":1541
 *                     self.debug(1 if t else 2, "ERROR:203:%s pour %r" % (msg.errmsg, t))
 *                     return ProtocolError(msg.t, msg.errmsg), query
 *                 elif msg.errno == 204:             # <<<<<<<<<<<<<<
 *                     t = self.transaction_type.get(msg.t)
 *                     self.debug(0 if t else 1, "ERROR:204:%s pour %r" % (msg.errmsg, t))
 */
        }

        /* "btdht/dht.pyx":1546
 *                     return MethodUnknownError(msg.t, msg.errmsg), query
 *                 else:
 *                     self.debug(             # <<<<<<<<<<<<<<
 *                         3,
 *                         "ERROR:%s:%s pour %r" % (
 */
        /*else*/ {
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_debug); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1546, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);

          /* "btdht/dht.pyx":1549
 *                         3,
 *                         "ERROR:%s:%s pour %r" % (
 *                             msg.errno, msg.errmsg, self.transaction_type.get(msg.t, {})             # <<<<<<<<<<<<<<
 *                         )
 *                     )
 */
          __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errno); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1549, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errmsg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1549, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_transaction_type); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1549, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_15);
          __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_get); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1549, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1549, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_15);
          __pyx_t_5 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1549, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_4 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) {
            __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_14);
            if (likely(__pyx_t_4)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
              __Pyx_INCREF(__pyx_t_4);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_14, function);
              __pyx_t_6 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_14)) {
            PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_15, __pyx_t_5};
            __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1549, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) {
            PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_15, __pyx_t_5};
            __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1549, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          } else
          #endif
          {
            __pyx_t_17 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1549, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_17);
            if (__pyx_t_4) {
              __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_4); __pyx_t_4 = NULL;
            }
            __Pyx_GIVEREF(__pyx_t_15);
            PyTuple_SET_ITEM(__pyx_t_17, 0+__pyx_t_6, __pyx_t_15);
            __Pyx_GIVEREF(__pyx_t_5);
            PyTuple_SET_ITEM(__pyx_t_17, 1+__pyx_t_6, __pyx_t_5);
            __pyx_t_15 = 0;
            __pyx_t_5 = 0;
            __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_17, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1549, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
          }
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __pyx_t_14 = PyTuple_New(3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1549, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_GIVEREF(__pyx_t_13);
          PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_13);
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_1);
          __Pyx_GIVEREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_t_2);
          __pyx_t_13 = 0;
          __pyx_t_1 = 0;
          __pyx_t_2 = 0;

          /* "btdht/dht.pyx":1548
 *                     self.debug(
 *                         3,
 *                         "ERROR:%s:%s pour %r" % (             # <<<<<<<<<<<<<<
 *                             msg.errno, msg.errmsg, self.transaction_type.get(msg.t, {})
 *                         )
 */
          __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_ERROR_s_s_pour_r, __pyx_t_14); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1548, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __pyx_t_14 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
            __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_7);
            if (likely(__pyx_t_14)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
              __Pyx_INCREF(__pyx_t_14);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_7, function);
              __pyx_t_6 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_7)) {
            PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_int_3, __pyx_t_2};
            __pyx_t_16 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1546, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
            __Pyx_GOTREF(__pyx_t_16);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
            PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_int_3, __pyx_t_2};
            __pyx_t_16 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1546, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
            __Pyx_GOTREF(__pyx_t_16);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          } else
          #endif
          {
            __pyx_t_1 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1546, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_1);
            if (__pyx_t_14) {
              __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_14); __pyx_t_14 = NULL;
            }
            __Pyx_INCREF(__pyx_int_3);
            __Pyx_GIVEREF(__pyx_int_3);
            PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_6, __pyx_int_3);
            __Pyx_GIVEREF(__pyx_t_2);
            PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_6, __pyx_t_2);
            __pyx_t_2 = 0;
            __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_1, NULL); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1546, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_16);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          }
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;

          /* "btdht/dht.pyx":1552
 *                         )
 *                     )
 *                     raise MethodUnknownError(msg.t, b"Error code %s unknown" % msg.errno)             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError("UNKNOWN MSG: %r decoded as %r from %r" % (s, msg, addr))
 */
          __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_MethodUnknownError); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1552, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1552, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1552, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_14 = PyNumber_Remainder(__pyx_kp_b_Error_code_s_unknown, __pyx_t_2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1552, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_2 = NULL;
          __pyx_t_6 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
            __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
            if (likely(__pyx_t_2)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
              __Pyx_INCREF(__pyx_t_2);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_7, function);
              __pyx_t_6 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_7)) {
            PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_1, __pyx_t_14};
            __pyx_t_16 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1552, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_GOTREF(__pyx_t_16);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
            PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_t_1, __pyx_t_14};
            __pyx_t_16 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1552, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_GOTREF(__pyx_t_16);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          } else
          #endif
          {
            __pyx_t_13 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1552, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_13);
            if (__pyx_t_2) {
              __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_2); __pyx_t_2 = NULL;
            }
            __Pyx_GIVEREF(__pyx_t_1);
            PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_6, __pyx_t_1);
            __Pyx_GIVEREF(__pyx_t_14);
            PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_6, __pyx_t_14);
            __pyx_t_1 = 0;
            __pyx_t_14 = 0;
            __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_13, NULL); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1552, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_16);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          }
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_Raise(__pyx_t_16, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __PYX_ERR(0, 1552, __pyx_L3_error)
        }

        /* "btdht/dht.pyx":1523
 *                 else:
 *                     raise TransactionIdUnknown(msg.t)
 *             elif msg.y == b"e":             # <<<<<<<<<<<<<<
 *                 query = self.transaction_type.get(msg.t, (None, None, None))[2]
 *                 if msg.errno == 201:
 */
      }

      /* "btdht/dht.pyx":1554
 *                     raise MethodUnknownError(msg.t, b"Error code %s unknown" % msg.errno)
 *             else:
 *                 raise ValueError("UNKNOWN MSG: %r decoded as %r from %r" % (s, msg, addr))             # <<<<<<<<<<<<<<
 *         except KeyError as e:
 *             raise ProtocolError(msg.t, b"Message malformed: %s key is missing" % e.args[0])
 */
      /*else*/ {
        __pyx_t_16 = PyTuple_New(3); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1554, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_INCREF(__pyx_v_s);
        __Pyx_GIVEREF(__pyx_v_s);
        PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_v_s);
        __Pyx_INCREF(((PyObject *)__pyx_v_msg));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_msg));
        PyTuple_SET_ITEM(__pyx_t_16, 1, ((PyObject *)__pyx_v_msg));
        __Pyx_INCREF(__pyx_v_addr);
        __Pyx_GIVEREF(__pyx_v_addr);
        PyTuple_SET_ITEM(__pyx_t_16, 2, __pyx_v_addr);
        __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_UNKNOWN_MSG_r_decoded_as_r_from, __pyx_t_16); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1554, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __pyx_t_16 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_7); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1554, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_Raise(__pyx_t_16, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __PYX_ERR(0, 1554, __pyx_L3_error)
      }

      /* "btdht/dht.pyx":1513
 *         msg = BMessage(addr=addr, debug=self.debuglvl)
 *         msg.decode(s, len(s))
 *         try:             # <<<<<<<<<<<<<<
 *             if msg.y == b"q":
 *                 return msg, None
 */
    }
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "btdht/dht.pyx":1555
 *             else:
 *                 raise ValueError("UNKNOWN MSG: %r decoded as %r from %r" % (s, msg, addr))
 *         except KeyError as e:             # <<<<<<<<<<<<<<
 *             raise ProtocolError(msg.t, b"Message malformed: %s key is missing" % e.args[0])
 *         except IndexError:
 */
    __pyx_t_6 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
    if (__pyx_t_6) {
      __Pyx_AddTraceback("btdht.dht.DHT_BASE._decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_16, &__pyx_t_7, &__pyx_t_13) < 0) __PYX_ERR(0, 1555, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_INCREF(__pyx_t_7);
      __pyx_v_e = __pyx_t_7;

      /* "btdht/dht.pyx":1556
 *                 raise ValueError("UNKNOWN MSG: %r decoded as %r from %r" % (s, msg, addr))
 *         except KeyError as e:
 *             raise ProtocolError(msg.t, b"Message malformed: %s key is missing" % e.args[0])             # <<<<<<<<<<<<<<
 *         except IndexError:
 *             raise ProtocolError(msg.t, b"Message malformed")
 */
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ProtocolError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1556, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1556, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_v_e, __pyx_n_s_args); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1556, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_17);
      __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_17, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1556, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      __pyx_t_17 = PyNumber_Remainder(__pyx_kp_b_Message_malformed_s_key_is_missi, __pyx_t_5); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1556, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_17);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = NULL;
      __pyx_t_6 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
          __pyx_t_6 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_2, __pyx_t_17};
        __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1556, __pyx_L5_except_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_2, __pyx_t_17};
        __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1556, __pyx_L5_except_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      } else
      #endif
      {
        __pyx_t_15 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1556, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_15);
        if (__pyx_t_5) {
          __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_5); __pyx_t_5 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_6, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_17);
        PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_6, __pyx_t_17);
        __pyx_t_2 = 0;
        __pyx_t_17 = 0;
        __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_15, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1556, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_14, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __PYX_ERR(0, 1556, __pyx_L5_except_error)
    }

    /* "btdht/dht.pyx":1557
 *         except KeyError as e:
 *             raise ProtocolError(msg.t, b"Message malformed: %s key is missing" % e.args[0])
 *         except IndexError:             # <<<<<<<<<<<<<<
 *             raise ProtocolError(msg.t, b"Message malformed")
 * 
 */
    __pyx_t_6 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_IndexError);
    if (__pyx_t_6) {
      __Pyx_AddTraceback("btdht.dht.DHT_BASE._decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_13, &__pyx_t_7, &__pyx_t_16) < 0) __PYX_ERR(0, 1557, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GOTREF(__pyx_t_16);

      /* "btdht/dht.pyx":1558
 *             raise ProtocolError(msg.t, b"Message malformed: %s key is missing" % e.args[0])
 *         except IndexError:
 *             raise ProtocolError(msg.t, b"Message malformed")             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ProtocolError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1558, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_t); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1558, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_15);
      __pyx_t_17 = NULL;
      __pyx_t_6 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_17)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_17);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
          __pyx_t_6 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_17, __pyx_t_15, __pyx_kp_b_Message_malformed};
        __pyx_t_14 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1558, __pyx_L5_except_error)
        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[3] = {__pyx_t_17, __pyx_t_15, __pyx_kp_b_Message_malformed};
        __pyx_t_14 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1558, __pyx_L5_except_error)
        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1558, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (__pyx_t_17) {
          __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_17); __pyx_t_17 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_15);
        PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_6, __pyx_t_15);
        __Pyx_INCREF(__pyx_kp_b_Message_malformed);
        __Pyx_GIVEREF(__pyx_kp_b_Message_malformed);
        PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_6, __pyx_kp_b_Message_malformed);
        __pyx_t_15 = 0;
        __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1558, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_14, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __PYX_ERR(0, 1558, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "btdht/dht.pyx":1513
 *         msg = BMessage(addr=addr, debug=self.debuglvl)
 *         msg.decode(s, len(s))
 *         try:             # <<<<<<<<<<<<<<
 *             if msg.y == b"q":
 *                 return msg, None
 */
    __Pyx_XGIVEREF(__pyx_t_8);
    __Pyx_XGIVEREF(__pyx_t_9);
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
    goto __pyx_L1_error;
    __pyx_L7_try_return:;
    __Pyx_XGIVEREF(__pyx_t_8);
    __Pyx_XGIVEREF(__pyx_t_9);
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":1497
 *             yield
 * 
 *     def _decode(self, s, addr):             # <<<<<<<<<<<<<<
 *         """
 *             decode a message
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE._decode", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_ttype);
  __Pyx_XDECREF(__pyx_v_query);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v_e);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_110__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_110__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_109__reduce_cython__(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_109__reduce_cython__(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self) {
  PyObject *__pyx_v_state = 0;
  PyObject *__pyx_v__dict = 0;
  int __pyx_v_use_setstate;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);

  /* "(tree fragment)":5
 *     cdef object _dict
 *     cdef bint use_setstate
 *     state = (self._myid,)             # <<<<<<<<<<<<<<
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:
 */
  __pyx_t_1 = __Pyx_PyObject_FromString(__pyx_v_self->_myid); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_v_state = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "(tree fragment)":6
 *     cdef bint use_setstate
 *     state = (self._myid,)
 *     _dict = getattr(self, '__dict__', None)             # <<<<<<<<<<<<<<
 *     if _dict is not None:
 *         state += (_dict,)
 */
  __pyx_t_2 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v__dict = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "(tree fragment)":7
 *     state = (self._myid,)
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:             # <<<<<<<<<<<<<<
 *         state += (_dict,)
 *         use_setstate = True
 */
  __pyx_t_3 = (__pyx_v__dict != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {

    /* "(tree fragment)":8
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:
 *         state += (_dict,)             # <<<<<<<<<<<<<<
 *         use_setstate = True
 *     else:
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 8, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v__dict);
    __Pyx_GIVEREF(__pyx_v__dict);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v__dict);
    __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 8, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "(tree fragment)":9
 *     if _dict is not None:
 *         state += (_dict,)
 *         use_setstate = True             # <<<<<<<<<<<<<<
 *     else:
 *         use_setstate = False
 */
    __pyx_v_use_setstate = 1;

    /* "(tree fragment)":7
 *     state = (self._myid,)
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:             # <<<<<<<<<<<<<<
 *         state += (_dict,)
 *         use_setstate = True
 */
    goto __pyx_L3;
  }

  /* "(tree fragment)":11
 *         use_setstate = True
 *     else:
 *         use_setstate = False             # <<<<<<<<<<<<<<
 *     if use_setstate:
 *         return __pyx_unpickle_DHT_BASE, (type(self), 0x4d4fbc6, None), state
 */
  /*else*/ {
    __pyx_v_use_setstate = 0;
  }
  __pyx_L3:;

  /* "(tree fragment)":12
 *     else:
 *         use_setstate = False
 *     if use_setstate:             # <<<<<<<<<<<<<<
 *         return __pyx_unpickle_DHT_BASE, (type(self), 0x4d4fbc6, None), state
 *     else:
 */
  __pyx_t_4 = (__pyx_v_use_setstate != 0);
  if (__pyx_t_4) {

    /* "(tree fragment)":13
 *         use_setstate = False
 *     if use_setstate:
 *         return __pyx_unpickle_DHT_BASE, (type(self), 0x4d4fbc6, None), state             # <<<<<<<<<<<<<<
 *     else:
 *         return __pyx_unpickle_DHT_BASE, (type(self), 0x4d4fbc6, state)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pyx_unpickle_DHT_BASE); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_INCREF(__pyx_int_81066950);
    __Pyx_GIVEREF(__pyx_int_81066950);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_81066950);
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    PyTuple_SET_ITEM(__pyx_t_2, 2, Py_None);
    __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
    __Pyx_INCREF(__pyx_v_state);
    __Pyx_GIVEREF(__pyx_v_state);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state);
    __pyx_t_1 = 0;
    __pyx_t_2 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "(tree fragment)":12
 *     else:
 *         use_setstate = False
 *     if use_setstate:             # <<<<<<<<<<<<<<
 *         return __pyx_unpickle_DHT_BASE, (type(self), 0x4d4fbc6, None), state
 *     else:
 */
  }

  /* "(tree fragment)":15
 *         return __pyx_unpickle_DHT_BASE, (type(self), 0x4d4fbc6, None), state
 *     else:
 *         return __pyx_unpickle_DHT_BASE, (type(self), 0x4d4fbc6, state)             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     __pyx_unpickle_DHT_BASE__set_state(self, __pyx_state)
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_DHT_BASE); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_INCREF(__pyx_int_81066950);
    __Pyx_GIVEREF(__pyx_int_81066950);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_81066950);
    __Pyx_INCREF(__pyx_v_state);
    __Pyx_GIVEREF(__pyx_v_state);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_state);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
    __pyx_t_5 = 0;
    __pyx_t_2 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
  }

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_state);
  __Pyx_XDECREF(__pyx_v__dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_DHT_BASE, (type(self), 0x4d4fbc6, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_DHT_BASE__set_state(self, __pyx_state)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_112__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_8DHT_BASE_112__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_8DHT_BASE_111__setstate_cython__(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_8DHT_BASE_111__setstate_cython__(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);

  /* "(tree fragment)":17
 *         return __pyx_unpickle_DHT_BASE, (type(self), 0x4d4fbc6, state)
 * def __setstate_cython__(self, __pyx_state):
 *     __pyx_unpickle_DHT_BASE__set_state(self, __pyx_state)             # <<<<<<<<<<<<<<
 */
  if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error)
  __pyx_t_1 = __pyx_f_5btdht_3dht___pyx_unpickle_DHT_BASE__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_DHT_BASE, (type(self), 0x4d4fbc6, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_DHT_BASE__set_state(self, __pyx_state)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("btdht.dht.DHT_BASE.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1595
 *     #: UDP port of the node
 *     property port:
 *         def __get__(self):return self._port             # <<<<<<<<<<<<<<
 *         def __set__(self, int i):self._port = i
 *     #: Unix timestamp of the last received response from this node
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_4port_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_4Node_4port_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_4port___get__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_4port___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_port); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1595, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("btdht.dht.Node.port.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1596
 *     property port:
 *         def __get__(self):return self._port
 *         def __set__(self, int i):self._port = i             # <<<<<<<<<<<<<<
 *     #: Unix timestamp of the last received response from this node
 *     property last_response:
 */

/* Python wrapper */
static int __pyx_pw_5btdht_3dht_4Node_4port_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_arg_i); /*proto*/
static int __pyx_pw_5btdht_3dht_4Node_4port_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_arg_i) {
  int __pyx_v_i;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  assert(__pyx_arg_i); {
    __pyx_v_i = __Pyx_PyInt_As_int(__pyx_arg_i); if (unlikely((__pyx_v_i == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1596, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Node.port.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_4port_2__set__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self), ((int)__pyx_v_i));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5btdht_3dht_4Node_4port_2__set__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, int __pyx_v_i) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __pyx_v_self->_port = __pyx_v_i;

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1599
 *     #: Unix timestamp of the last received response from this node
 *     property last_response:
 *         def __get__(self):return self._last_response             # <<<<<<<<<<<<<<
 *         def __set__(self, int i):self._last_response = i
 *     #: Unix timestamp of the last received query from this node
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_13last_response_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_4Node_13last_response_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_13last_response___get__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_13last_response___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_last_response); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1599, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("btdht.dht.Node.last_response.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1600
 *     property last_response:
 *         def __get__(self):return self._last_response
 *         def __set__(self, int i):self._last_response = i             # <<<<<<<<<<<<<<
 *     #: Unix timestamp of the last received query from this node
 *     property last_query:
 */

/* Python wrapper */
static int __pyx_pw_5btdht_3dht_4Node_13last_response_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_arg_i); /*proto*/
static int __pyx_pw_5btdht_3dht_4Node_13last_response_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_arg_i) {
  int __pyx_v_i;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  assert(__pyx_arg_i); {
    __pyx_v_i = __Pyx_PyInt_As_int(__pyx_arg_i); if (unlikely((__pyx_v_i == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1600, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Node.last_response.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_13last_response_2__set__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self), ((int)__pyx_v_i));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5btdht_3dht_4Node_13last_response_2__set__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, int __pyx_v_i) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __pyx_v_self->_last_response = __pyx_v_i;

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1603
 *     #: Unix timestamp of the last received query from this node
 *     property last_query:
 *         def __get__(self):return self._last_query             # <<<<<<<<<<<<<<
 *         def __set__(self, int i):self._last_query = i
 *     #: Number of reponse pending (increase on sending query to the node, set to 0 on reception from
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_10last_query_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_4Node_10last_query_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_10last_query___get__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_10last_query___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_last_query); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1603, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("btdht.dht.Node.last_query.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1604
 *     property last_query:
 *         def __get__(self):return self._last_query
 *         def __set__(self, int i):self._last_query = i             # <<<<<<<<<<<<<<
 *     #: Number of reponse pending (increase on sending query to the node, set to 0 on reception from
 *     #: the node)
 */

/* Python wrapper */
static int __pyx_pw_5btdht_3dht_4Node_10last_query_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_arg_i); /*proto*/
static int __pyx_pw_5btdht_3dht_4Node_10last_query_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_arg_i) {
  int __pyx_v_i;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  assert(__pyx_arg_i); {
    __pyx_v_i = __Pyx_PyInt_As_int(__pyx_arg_i); if (unlikely((__pyx_v_i == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1604, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Node.last_query.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_10last_query_2__set__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self), ((int)__pyx_v_i));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5btdht_3dht_4Node_10last_query_2__set__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, int __pyx_v_i) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __pyx_v_self->_last_query = __pyx_v_i;

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1608
 *     #: the node)
 *     property failed:
 *         def __get__(self):return self._failed             # <<<<<<<<<<<<<<
 *         def __set__(self, int i):self._failed = i
 *     #: 160bits (20 Bytes) identifier of the node
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_6failed_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_4Node_6failed_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_6failed___get__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_6failed___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_failed); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1608, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("btdht.dht.Node.failed.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1609
 *     property failed:
 *         def __get__(self):return self._failed
 *         def __set__(self, int i):self._failed = i             # <<<<<<<<<<<<<<
 *     #: 160bits (20 Bytes) identifier of the node
 *     property id:
 */

/* Python wrapper */
static int __pyx_pw_5btdht_3dht_4Node_6failed_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_arg_i); /*proto*/
static int __pyx_pw_5btdht_3dht_4Node_6failed_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_arg_i) {
  int __pyx_v_i;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  assert(__pyx_arg_i); {
    __pyx_v_i = __Pyx_PyInt_As_int(__pyx_arg_i); if (unlikely((__pyx_v_i == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1609, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Node.failed.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_6failed_2__set__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self), ((int)__pyx_v_i));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5btdht_3dht_4Node_6failed_2__set__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, int __pyx_v_i) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__", 0);
  __pyx_v_self->_failed = __pyx_v_i;

  /* function exit code */
  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1612
 *     #: 160bits (20 Bytes) identifier of the node
 *     property id:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._id[:20]
 *     #: ``True`` if the node is a good node. A good node is a node has responded to one of our
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_2id_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_4Node_2id_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_2id___get__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_2id___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "btdht/dht.pyx":1613
 *     property id:
 *         def __get__(self):
 *             return self._id[:20]             # <<<<<<<<<<<<<<
 *     #: ``True`` if the node is a good node. A good node is a node has responded to one of our
 *     #: queries within the last 15 minutes. A node is also good if it has ever responded to one of
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(((const char*)__pyx_v_self->_id) + 0, 20 - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":1612
 *     #: 160bits (20 Bytes) identifier of the node
 *     property id:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._id[:20]
 *     #: ``True`` if the node is a good node. A good node is a node has responded to one of our
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("btdht.dht.Node.id.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1618
 *     #: our queries and has sent us a query within the last 15 minutes.
 *     property good:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             now = time.time()
 *             # A good node is a node has responded to one of our queries within the last 15 minutes.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_4good_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_4Node_4good_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_4good___get__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_4good___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self) {
  PyObject *__pyx_v_now = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "btdht/dht.pyx":1619
 *     property good:
 *         def __get__(self):
 *             now = time.time()             # <<<<<<<<<<<<<<
 *             # A good node is a node has responded to one of our queries within the last 15 minutes.
 *             # A node is also good if it has ever responded to one of our queries and has sent us
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1619, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1619, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1619, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_now = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1623
 *             # A node is also good if it has ever responded to one of our queries and has sent us
 *             # a query within the last 15 minutes.
 *             return (             # <<<<<<<<<<<<<<
 *                 ((now - self.last_response) < 15 * 60) or
 *                 (self.last_response > 0 and (now - self.last_query) < 15 * 60)
 */
  __Pyx_XDECREF(__pyx_r);

  /* "btdht/dht.pyx":1624
 *             # a query within the last 15 minutes.
 *             return (
 *                 ((now - self.last_response) < 15 * 60) or             # <<<<<<<<<<<<<<
 *                 (self.last_response > 0 and (now - self.last_query) < 15 * 60)
 *             )
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_response); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1624, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Subtract(__pyx_v_now, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1624, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, __pyx_int_900, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1624, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1624, __pyx_L1_error)
  if (!__pyx_t_4) {
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_1 = __pyx_t_3;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L3_bool_binop_done;
  }

  /* "btdht/dht.pyx":1625
 *             return (
 *                 ((now - self.last_response) < 15 * 60) or
 *                 (self.last_response > 0 and (now - self.last_query) < 15 * 60)             # <<<<<<<<<<<<<<
 *             )
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_response); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1625, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1625, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1625, __pyx_L1_error)
  if (__pyx_t_4) {
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L3_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_query); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1625, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Subtract(__pyx_v_now, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1625, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_900, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1625, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_1 = __pyx_t_2;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_L3_bool_binop_done:;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":1618
 *     #: our queries and has sent us a query within the last 15 minutes.
 *     property good:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             now = time.time()
 *             # A good node is a node has responded to one of our queries within the last 15 minutes.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("btdht.dht.Node.good.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_now);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1631
 *     #: become bad when they fail to respond to 3 queries in a row.
 *     property bad:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             # Nodes become bad when they fail to respond to multiple queries in a row.
 *             return not self.good and self.failed > 3
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_3bad_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_4Node_3bad_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_3bad___get__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_3bad___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "btdht/dht.pyx":1633
 *         def __get__(self):
 *             # Nodes become bad when they fail to respond to multiple queries in a row.
 *             return not self.good and self.failed > 3             # <<<<<<<<<<<<<<
 * 
 *     #: IP address of the node in dotted notation
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_good); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1633, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1633, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_3);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L3_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_failed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1633, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_int_3, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1633, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_INCREF(__pyx_t_5);
  __pyx_t_1 = __pyx_t_5;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_L3_bool_binop_done:;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":1631
 *     #: become bad when they fail to respond to 3 queries in a row.
 *     property bad:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             # Nodes become bad when they fail to respond to multiple queries in a row.
 *             return not self.good and self.failed > 3
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("btdht.dht.Node.bad.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1637
 *     #: IP address of the node in dotted notation
 *     property ip:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             ip = socket.inet_ntoa(self._ip[:4])
 *             if ip[0] == '0':
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_2ip_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_4Node_2ip_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_2ip___get__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_2ip___get__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self) {
  PyObject *__pyx_v_ip = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);

  /* "btdht/dht.pyx":1638
 *     property ip:
 *         def __get__(self):
 *             ip = socket.inet_ntoa(self._ip[:4])             # <<<<<<<<<<<<<<
 *             if ip[0] == '0':
 *                 raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_socket); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_inet_ntoa); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(((const char*)__pyx_v_self->_ip) + 0, 4 - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_ip = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1639
 *         def __get__(self):
 *             ip = socket.inet_ntoa(self._ip[:4])
 *             if ip[0] == '0':             # <<<<<<<<<<<<<<
 *                 raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 *             return ip
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_ip, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1639, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_kp_s_0, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1639, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(__pyx_t_5)) {

    /* "btdht/dht.pyx":1640
 *             ip = socket.inet_ntoa(self._ip[:4])
 *             if ip[0] == '0':
 *                 raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))             # <<<<<<<<<<<<<<
 *             return ip
 *         def __set__(self, ip):
 */
    __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(((const char*)__pyx_v_self->_ip) + 0, 4 - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1640, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1640, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_ip);
    __Pyx_GIVEREF(__pyx_v_ip);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_ip);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_IP_start_with_0___r_r, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1640, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1640, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 1640, __pyx_L1_error)

    /* "btdht/dht.pyx":1639
 *         def __get__(self):
 *             ip = socket.inet_ntoa(self._ip[:4])
 *             if ip[0] == '0':             # <<<<<<<<<<<<<<
 *                 raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 *             return ip
 */
  }

  /* "btdht/dht.pyx":1641
 *             if ip[0] == '0':
 *                 raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 *             return ip             # <<<<<<<<<<<<<<
 *         def __set__(self, ip):
 *             cdef char* cip
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ip);
  __pyx_r = __pyx_v_ip;
  goto __pyx_L0;

  /* "btdht/dht.pyx":1637
 *     #: IP address of the node in dotted notation
 *     property ip:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             ip = socket.inet_ntoa(self._ip[:4])
 *             if ip[0] == '0':
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("btdht.dht.Node.ip.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ip);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1642
 *                 raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 *             return ip
 *         def __set__(self, ip):             # <<<<<<<<<<<<<<
 *             cdef char* cip
 *             if ip[0] == u'0':
 */

/* Python wrapper */
static int __pyx_pw_5btdht_3dht_4Node_2ip_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_ip); /*proto*/
static int __pyx_pw_5btdht_3dht_4Node_2ip_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_ip) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_2ip_2__set__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self), ((PyObject *)__pyx_v_ip));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5btdht_3dht_4Node_2ip_2__set__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, PyObject *__pyx_v_ip) {
  char *__pyx_v_cip;
  PyObject *__pyx_v_tip = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  char *__pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);

  /* "btdht/dht.pyx":1644
 *         def __set__(self, ip):
 *             cdef char* cip
 *             if ip[0] == u'0':             # <<<<<<<<<<<<<<
 *                 raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 *             tip = socket.inet_aton(ip)
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_ip, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1644, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_kp_u_0, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1644, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(__pyx_t_2)) {

    /* "btdht/dht.pyx":1645
 *             cdef char* cip
 *             if ip[0] == u'0':
 *                 raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))             # <<<<<<<<<<<<<<
 *             tip = socket.inet_aton(ip)
 *             cip = tip
 */
    __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(((const char*)__pyx_v_self->_ip) + 0, 4 - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1645, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1645, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_ip);
    __Pyx_GIVEREF(__pyx_v_ip);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_ip);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_IP_start_with_0___r_r, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1645, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1645, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 1645, __pyx_L1_error)

    /* "btdht/dht.pyx":1644
 *         def __set__(self, ip):
 *             cdef char* cip
 *             if ip[0] == u'0':             # <<<<<<<<<<<<<<
 *                 raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 *             tip = socket.inet_aton(ip)
 */
  }

  /* "btdht/dht.pyx":1646
 *             if ip[0] == u'0':
 *                 raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 *             tip = socket.inet_aton(ip)             # <<<<<<<<<<<<<<
 *             cip = tip
 *             with nogil:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_socket); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1646, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_inet_aton); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1646, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_v_ip) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_ip);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1646, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_tip = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "btdht/dht.pyx":1647
 *                 raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 *             tip = socket.inet_aton(ip)
 *             cip = tip             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 strncmp(self._ip, cip, 4)
 */
  __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_tip); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 1647, __pyx_L1_error)
  __pyx_v_cip = __pyx_t_5;

  /* "btdht/dht.pyx":1648
 *             tip = socket.inet_aton(ip)
 *             cip = tip
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 strncmp(self._ip, cip, 4)
 * 
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "btdht/dht.pyx":1649
 *             cip = tip
 *             with nogil:
 *                 strncmp(self._ip, cip, 4)             # <<<<<<<<<<<<<<
 * 
 *     def __init__(self, bytes id, ip, int port, int last_response=0, int last_query=0, int failed=0):
 */
        (void)(strncmp(__pyx_v_self->_ip, __pyx_v_cip, 4));
      }

      /* "btdht/dht.pyx":1648
 *             tip = socket.inet_aton(ip)
 *             cip = tip
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 strncmp(self._ip, cip, 4)
 * 
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L6;
        }
        __pyx_L6:;
      }
  }

  /* "btdht/dht.pyx":1642
 *                 raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 *             return ip
 *         def __set__(self, ip):             # <<<<<<<<<<<<<<
 *             cdef char* cip
 *             if ip[0] == u'0':
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("btdht.dht.Node.ip.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_tip);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1651
 *                 strncmp(self._ip, cip, 4)
 * 
 *     def __init__(self, bytes id, ip, int port, int last_response=0, int last_query=0, int failed=0):             # <<<<<<<<<<<<<<
 *         cdef char* cip
 *         cdef char* cid
 */

/* Python wrapper */
static int __pyx_pw_5btdht_3dht_4Node_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5btdht_3dht_4Node_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_id = 0;
  PyObject *__pyx_v_ip = 0;
  int __pyx_v_port;
  int __pyx_v_last_response;
  int __pyx_v_last_query;
  int __pyx_v_failed;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_id,&__pyx_n_s_ip,&__pyx_n_s_port,&__pyx_n_s_last_response,&__pyx_n_s_last_query,&__pyx_n_s_failed,0};
    PyObject* values[6] = {0,0,0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ip)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 3, 6, 1); __PYX_ERR(0, 1651, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_port)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 3, 6, 2); __PYX_ERR(0, 1651, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_last_response);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_last_query);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_failed);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1651, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_id = ((PyObject*)values[0]);
    __pyx_v_ip = values[1];
    __pyx_v_port = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_port == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1651, __pyx_L3_error)
    if (values[3]) {
      __pyx_v_last_response = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_last_response == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1651, __pyx_L3_error)
    } else {
      __pyx_v_last_response = ((int)0);
    }
    if (values[4]) {
      __pyx_v_last_query = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_last_query == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1651, __pyx_L3_error)
    } else {
      __pyx_v_last_query = ((int)0);
    }
    if (values[5]) {
      __pyx_v_failed = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_failed == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1651, __pyx_L3_error)
    } else {
      __pyx_v_failed = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 3, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1651, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Node.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_id), (&PyBytes_Type), 1, "id", 1))) __PYX_ERR(0, 1651, __pyx_L1_error)
  __pyx_r = __pyx_pf_5btdht_3dht_4Node___init__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self), __pyx_v_id, __pyx_v_ip, __pyx_v_port, __pyx_v_last_response, __pyx_v_last_query, __pyx_v_failed);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5btdht_3dht_4Node___init__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, PyObject *__pyx_v_id, PyObject *__pyx_v_ip, int __pyx_v_port, int __pyx_v_last_response, int __pyx_v_last_query, int __pyx_v_failed) {
  char *__pyx_v_cip;
  char *__pyx_v_cid;
  PyObject *__pyx_v_tip = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  char *__pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_INCREF(__pyx_v_id);

  /* "btdht/dht.pyx":1654
 *         cdef char* cip
 *         cdef char* cid
 *         if ip[0] == u'0':             # <<<<<<<<<<<<<<
 *             raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 *         tip = socket.inet_aton(ip)
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_ip, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1654, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_kp_u_0, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1654, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(__pyx_t_2)) {

    /* "btdht/dht.pyx":1655
 *         cdef char* cid
 *         if ip[0] == u'0':
 *             raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))             # <<<<<<<<<<<<<<
 *         tip = socket.inet_aton(ip)
 *         cip = tip
 */
    __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(((const char*)__pyx_v_self->_ip) + 0, 4 - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1655, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1655, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_ip);
    __Pyx_GIVEREF(__pyx_v_ip);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_ip);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_IP_start_with_0___r_r, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1655, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1655, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 1655, __pyx_L1_error)

    /* "btdht/dht.pyx":1654
 *         cdef char* cip
 *         cdef char* cid
 *         if ip[0] == u'0':             # <<<<<<<<<<<<<<
 *             raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 *         tip = socket.inet_aton(ip)
 */
  }

  /* "btdht/dht.pyx":1656
 *         if ip[0] == u'0':
 *             raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 *         tip = socket.inet_aton(ip)             # <<<<<<<<<<<<<<
 *         cip = tip
 *         id = ID.to_bytes(id)
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_socket); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_inet_aton); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_v_ip) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_ip);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1656, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_tip = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "btdht/dht.pyx":1657
 *             raise ValueError("IP start with 0 *_* %r %r" % (ip, self._ip[:4]))
 *         tip = socket.inet_aton(ip)
 *         cip = tip             # <<<<<<<<<<<<<<
 *         id = ID.to_bytes(id)
 *         cid = id
 */
  __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_tip); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 1657, __pyx_L1_error)
  __pyx_v_cip = __pyx_t_5;

  /* "btdht/dht.pyx":1658
 *         tip = socket.inet_aton(ip)
 *         cip = tip
 *         id = ID.to_bytes(id)             # <<<<<<<<<<<<<<
 *         cid = id
 *         with nogil:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ID); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_to_bytes); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_4, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_id);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1658, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 1658, __pyx_L1_error)
  __Pyx_DECREF_SET(__pyx_v_id, ((PyObject*)__pyx_t_3));
  __pyx_t_3 = 0;

  /* "btdht/dht.pyx":1659
 *         cip = tip
 *         id = ID.to_bytes(id)
 *         cid = id             # <<<<<<<<<<<<<<
 *         with nogil:
 *             if not port > 0 and port < 65536:
 */
  if (unlikely(__pyx_v_id == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
    __PYX_ERR(0, 1659, __pyx_L1_error)
  }
  __pyx_t_5 = __Pyx_PyBytes_AsWritableString(__pyx_v_id); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 1659, __pyx_L1_error)
  __pyx_v_cid = __pyx_t_5;

  /* "btdht/dht.pyx":1660
 *         id = ID.to_bytes(id)
 *         cid = id
 *         with nogil:             # <<<<<<<<<<<<<<
 *             if not port > 0 and port < 65536:
 *                 with gil:
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "btdht/dht.pyx":1661
 *         cid = id
 *         with nogil:
 *             if not port > 0 and port < 65536:             # <<<<<<<<<<<<<<
 *                 with gil:
 *                     raise ValueError(
 */
        __pyx_t_6 = ((!((__pyx_v_port > 0) != 0)) != 0);
        if (__pyx_t_6) {
        } else {
          __pyx_t_2 = __pyx_t_6;
          goto __pyx_L8_bool_binop_done;
        }
        __pyx_t_6 = ((__pyx_v_port < 0x10000) != 0);
        __pyx_t_2 = __pyx_t_6;
        __pyx_L8_bool_binop_done:;
        if (__pyx_t_2) {

          /* "btdht/dht.pyx":1662
 *         with nogil:
 *             if not port > 0 and port < 65536:
 *                 with gil:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "Invalid port number %s, sould be within 1 and 65535 for %s" % (port, ip)
 */
          {
              #ifdef WITH_THREAD
              PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
              #endif
              /*try:*/ {

                /* "btdht/dht.pyx":1664
 *                 with gil:
 *                     raise ValueError(
 *                         "Invalid port number %s, sould be within 1 and 65535 for %s" % (port, ip)             # <<<<<<<<<<<<<<
 *                     )
 *             #self._id = <char*>malloc(20 * sizeof(char))
 */
                __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_port); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1664, __pyx_L11_error)
                __Pyx_GOTREF(__pyx_t_3);
                __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1664, __pyx_L11_error)
                __Pyx_GOTREF(__pyx_t_1);
                __Pyx_GIVEREF(__pyx_t_3);
                PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
                __Pyx_INCREF(__pyx_v_ip);
                __Pyx_GIVEREF(__pyx_v_ip);
                PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_ip);
                __pyx_t_3 = 0;
                __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_port_number_s_sould_be_w, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1664, __pyx_L11_error)
                __Pyx_GOTREF(__pyx_t_3);
                __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

                /* "btdht/dht.pyx":1663
 *             if not port > 0 and port < 65536:
 *                 with gil:
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "Invalid port number %s, sould be within 1 and 65535 for %s" % (port, ip)
 *                     )
 */
                __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1663, __pyx_L11_error)
                __Pyx_GOTREF(__pyx_t_1);
                __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
                __Pyx_Raise(__pyx_t_1, 0, 0, 0);
                __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
                __PYX_ERR(0, 1663, __pyx_L11_error)
              }

              /* "btdht/dht.pyx":1662
 *         with nogil:
 *             if not port > 0 and port < 65536:
 *                 with gil:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "Invalid port number %s, sould be within 1 and 65535 for %s" % (port, ip)
 */
              /*finally:*/ {
                __pyx_L11_error: {
                  #ifdef WITH_THREAD
                  __Pyx_PyGILState_Release(__pyx_gilstate_save);
                  #endif
                  goto __pyx_L5_error;
                }
              }
          }

          /* "btdht/dht.pyx":1661
 *         cid = id
 *         with nogil:
 *             if not port > 0 and port < 65536:             # <<<<<<<<<<<<<<
 *                 with gil:
 *                     raise ValueError(
 */
        }

        /* "btdht/dht.pyx":1667
 *                     )
 *             #self._id = <char*>malloc(20 * sizeof(char))
 *             strncpy(self._id, cid, 20)             # <<<<<<<<<<<<<<
 *             #self._ip = <char*>malloc(4  * sizeof(char))
 *             strncpy(self._ip, cip, 4)
 */
        (void)(strncpy(__pyx_v_self->_id, __pyx_v_cid, 20));

        /* "btdht/dht.pyx":1669
 *             strncpy(self._id, cid, 20)
 *             #self._ip = <char*>malloc(4  * sizeof(char))
 *             strncpy(self._ip, cip, 4)             # <<<<<<<<<<<<<<
 *             self._port = port
 *             self._last_response = last_response
 */
        (void)(strncpy(__pyx_v_self->_ip, __pyx_v_cip, 4));

        /* "btdht/dht.pyx":1670
 *             #self._ip = <char*>malloc(4  * sizeof(char))
 *             strncpy(self._ip, cip, 4)
 *             self._port = port             # <<<<<<<<<<<<<<
 *             self._last_response = last_response
 *             self._last_query = last_query
 */
        __pyx_v_self->_port = __pyx_v_port;

        /* "btdht/dht.pyx":1671
 *             strncpy(self._ip, cip, 4)
 *             self._port = port
 *             self._last_response = last_response             # <<<<<<<<<<<<<<
 *             self._last_query = last_query
 *             self._failed = failed
 */
        __pyx_v_self->_last_response = __pyx_v_last_response;

        /* "btdht/dht.pyx":1672
 *             self._port = port
 *             self._last_response = last_response
 *             self._last_query = last_query             # <<<<<<<<<<<<<<
 *             self._failed = failed
 * 
 */
        __pyx_v_self->_last_query = __pyx_v_last_query;

        /* "btdht/dht.pyx":1673
 *             self._last_response = last_response
 *             self._last_query = last_query
 *             self._failed = failed             # <<<<<<<<<<<<<<
 * 
 * 
 */
        __pyx_v_self->_failed = __pyx_v_failed;
      }

      /* "btdht/dht.pyx":1660
 *         id = ID.to_bytes(id)
 *         cid = id
 *         with nogil:             # <<<<<<<<<<<<<<
 *             if not port > 0 and port < 65536:
 *                 with gil:
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L6;
        }
        __pyx_L5_error: {
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L1_error;
        }
        __pyx_L6:;
      }
  }

  /* "btdht/dht.pyx":1651
 *                 strncmp(self._ip, cip, 4)
 * 
 *     def __init__(self, bytes id, ip, int port, int last_response=0, int last_query=0, int failed=0):             # <<<<<<<<<<<<<<
 *         cdef char* cip
 *         cdef char* cid
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("btdht.dht.Node.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_tip);
  __Pyx_XDECREF(__pyx_v_id);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1676
 * 
 * 
 *     def __richcmp__(self, Node other, int op):             # <<<<<<<<<<<<<<
 *             if op == 2: # ==
 *                 return other.id == self.id
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_3__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_4Node_3__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5btdht_3dht_Node, 1, "other", 0))) __PYX_ERR(0, 1676, __pyx_L1_error)
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_2__richcmp__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self), ((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_other), ((int)__pyx_v_op));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_2__richcmp__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, struct __pyx_obj_5btdht_3dht_Node *__pyx_v_other, int __pyx_v_op) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__richcmp__", 0);

  /* "btdht/dht.pyx":1677
 * 
 *     def __richcmp__(self, Node other, int op):
 *             if op == 2: # ==             # <<<<<<<<<<<<<<
 *                 return other.id == self.id
 *             elif op == 3: # !=
 */
  switch (__pyx_v_op) {
    case 2:

    /* "btdht/dht.pyx":1678
 *     def __richcmp__(self, Node other, int op):
 *             if op == 2: # ==
 *                 return other.id == self.id             # <<<<<<<<<<<<<<
 *             elif op == 3: # !=
 *                 return other.id != self.id
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1678, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1678, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1678, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "btdht/dht.pyx":1677
 * 
 *     def __richcmp__(self, Node other, int op):
 *             if op == 2: # ==             # <<<<<<<<<<<<<<
 *                 return other.id == self.id
 *             elif op == 3: # !=
 */
    break;
    case 3:

    /* "btdht/dht.pyx":1680
 *                 return other.id == self.id
 *             elif op == 3: # !=
 *                 return other.id != self.id             # <<<<<<<<<<<<<<
 *             elif op == 0: # <
 *                 return max(
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1680, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1680, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1680, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "btdht/dht.pyx":1679
 *             if op == 2: # ==
 *                 return other.id == self.id
 *             elif op == 3: # !=             # <<<<<<<<<<<<<<
 *                 return other.id != self.id
 *             elif op == 0: # <
 */
    break;
    case 0:

    /* "btdht/dht.pyx":1682
 *                 return other.id != self.id
 *             elif op == 0: # <
 *                 return max(             # <<<<<<<<<<<<<<
 *                     self.last_response,
 *                     self.last_query
 */
    __Pyx_XDECREF(__pyx_r);

    /* "btdht/dht.pyx":1684
 *                 return max(
 *                     self.last_response,
 *                     self.last_query             # <<<<<<<<<<<<<<
 *                 ) < max(
 *                     other.last_response,
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_query); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1684, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "btdht/dht.pyx":1683
 *             elif op == 0: # <
 *                 return max(
 *                     self.last_response,             # <<<<<<<<<<<<<<
 *                     self.last_query
 *                 ) < max(
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_response); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1683, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "btdht/dht.pyx":1684
 *                 return max(
 *                     self.last_response,
 *                     self.last_query             # <<<<<<<<<<<<<<
 *                 ) < max(
 *                     other.last_response,
 */
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1684, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1684, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_5) {
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1;
    } else {
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_3 = __pyx_t_2;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1687
 *                 ) < max(
 *                     other.last_response,
 *                     other.last_query             # <<<<<<<<<<<<<<
 *                 )
 *             elif op == 4: # >
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_last_query); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1687, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "btdht/dht.pyx":1686
 *                     self.last_query
 *                 ) < max(
 *                     other.last_response,             # <<<<<<<<<<<<<<
 *                     other.last_query
 *                 )
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_last_response); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1686, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "btdht/dht.pyx":1687
 *                 ) < max(
 *                     other.last_response,
 *                     other.last_query             # <<<<<<<<<<<<<<
 *                 )
 *             elif op == 4: # >
 */
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1687, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1687, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_5) {
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_4 = __pyx_t_1;
    } else {
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_4 = __pyx_t_2;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1685, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "btdht/dht.pyx":1681
 *             elif op == 3: # !=
 *                 return other.id != self.id
 *             elif op == 0: # <             # <<<<<<<<<<<<<<
 *                 return max(
 *                     self.last_response,
 */
    break;
    case 4:

    /* "btdht/dht.pyx":1690
 *                 )
 *             elif op == 4: # >
 *                 return not (             # <<<<<<<<<<<<<<
 *                     max(
 *                         self.last_response,
 */
    __Pyx_XDECREF(__pyx_r);

    /* "btdht/dht.pyx":1693
 *                     max(
 *                         self.last_response,
 *                         self.last_query             # <<<<<<<<<<<<<<
 *                     ) < max(
 *                         other.last_response,
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_query); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1693, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "btdht/dht.pyx":1692
 *                 return not (
 *                     max(
 *                         self.last_response,             # <<<<<<<<<<<<<<
 *                         self.last_query
 *                     ) < max(
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_response); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1692, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "btdht/dht.pyx":1693
 *                     max(
 *                         self.last_response,
 *                         self.last_query             # <<<<<<<<<<<<<<
 *                     ) < max(
 *                         other.last_response,
 */
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1693, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1693, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_5) {
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_2 = __pyx_t_4;
    } else {
      __Pyx_INCREF(__pyx_t_3);
      __pyx_t_2 = __pyx_t_3;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "btdht/dht.pyx":1696
 *                     ) < max(
 *                         other.last_response,
 *                         other.last_query             # <<<<<<<<<<<<<<
 *                     )
 *                 ) and not (other.id == self.id)
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_last_query); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1696, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "btdht/dht.pyx":1695
 *                         self.last_query
 *                     ) < max(
 *                         other.last_response,             # <<<<<<<<<<<<<<
 *                         other.last_query
 *                     )
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_last_response); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1695, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "btdht/dht.pyx":1696
 *                     ) < max(
 *                         other.last_response,
 *                         other.last_query             # <<<<<<<<<<<<<<
 *                     )
 *                 ) and not (other.id == self.id)
 */
    __pyx_t_7 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1696, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1696, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__pyx_t_5) {
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_6 = __pyx_t_4;
    } else {
      __Pyx_INCREF(__pyx_t_3);
      __pyx_t_6 = __pyx_t_3;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_6, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1694, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "btdht/dht.pyx":1694
 *                         self.last_response,
 *                         self.last_query
 *                     ) < max(             # <<<<<<<<<<<<<<
 *                         other.last_response,
 *                         other.last_query
 */
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1694, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "btdht/dht.pyx":1690
 *                 )
 *             elif op == 4: # >
 *                 return not (             # <<<<<<<<<<<<<<
 *                     max(
 *                         self.last_response,
 */
    __pyx_t_8 = (!__pyx_t_5);
    if (__pyx_t_8) {
    } else {
      __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1690, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L3_bool_binop_done;
    }

    /* "btdht/dht.pyx":1698
 *                         other.last_query
 *                     )
 *                 ) and not (other.id == self.id)             # <<<<<<<<<<<<<<
 *             elif op == 1: # <=
 *                 return max(
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1698, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_id); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1698, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1698, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 1698, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = (!__pyx_t_8);
    __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1698, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
    __pyx_L3_bool_binop_done:;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "btdht/dht.pyx":1689
 *                     other.last_query
 *                 )
 *             elif op == 4: # >             # <<<<<<<<<<<<<<
 *                 return not (
 *                     max(
 */
    break;
    case 1:

    /* "btdht/dht.pyx":1700
 *                 ) and not (other.id == self.id)
 *             elif op == 1: # <=
 *                 return max(             # <<<<<<<<<<<<<<
 *                     self.last_response,
 *                     self.last_query
 */
    __Pyx_XDECREF(__pyx_r);

    /* "btdht/dht.pyx":1702
 *                 return max(
 *                     self.last_response,
 *                     self.last_query             # <<<<<<<<<<<<<<
 *                 ) < max(
 *                     other.last_response,
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_query); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1702, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "btdht/dht.pyx":1701
 *             elif op == 1: # <=
 *                 return max(
 *                     self.last_response,             # <<<<<<<<<<<<<<
 *                     self.last_query
 *                 ) < max(
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_response); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1701, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);

    /* "btdht/dht.pyx":1702
 *                 return max(
 *                     self.last_response,
 *                     self.last_query             # <<<<<<<<<<<<<<
 *                 ) < max(
 *                     other.last_response,
 */
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, __pyx_t_6, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1702, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1702, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_5) {
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_4 = __pyx_t_2;
    } else {
      __Pyx_INCREF(__pyx_t_6);
      __pyx_t_4 = __pyx_t_6;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "btdht/dht.pyx":1705
 *                 ) < max(
 *                     other.last_response,
 *                     other.last_query             # <<<<<<<<<<<<<<
 *                 ) or (other.id == self.id)
 *             elif op == 5: # >=
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_last_query); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1705, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "btdht/dht.pyx":1704
 *                     self.last_query
 *                 ) < max(
 *                     other.last_response,             # <<<<<<<<<<<<<<
 *                     other.last_query
 *                 ) or (other.id == self.id)
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_last_response); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1704, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);

    /* "btdht/dht.pyx":1705
 *                 ) < max(
 *                     other.last_response,
 *                     other.last_query             # <<<<<<<<<<<<<<
 *                 ) or (other.id == self.id)
 *             elif op == 5: # >=
 */
    __pyx_t_7 = PyObject_RichCompare(__pyx_t_2, __pyx_t_6, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1705, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1705, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__pyx_t_5) {
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_3 = __pyx_t_2;
    } else {
      __Pyx_INCREF(__pyx_t_6);
      __pyx_t_3 = __pyx_t_6;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1703, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1703, __pyx_L1_error)
    if (!__pyx_t_5) {
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_1 = __pyx_t_2;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      goto __pyx_L5_bool_binop_done;
    }

    /* "btdht/dht.pyx":1706
 *                     other.last_response,
 *                     other.last_query
 *                 ) or (other.id == self.id)             # <<<<<<<<<<<<<<
 *             elif op == 5: # >=
 *                 return not (
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1706, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1706, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1706, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_INCREF(__pyx_t_4);
    __pyx_t_1 = __pyx_t_4;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_L5_bool_binop_done:;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "btdht/dht.pyx":1699
 *                     )
 *                 ) and not (other.id == self.id)
 *             elif op == 1: # <=             # <<<<<<<<<<<<<<
 *                 return max(
 *                     self.last_response,
 */
    break;
    case 5:

    /* "btdht/dht.pyx":1708
 *                 ) or (other.id == self.id)
 *             elif op == 5: # >=
 *                 return not (             # <<<<<<<<<<<<<<
 *                     max(
 *                         self.last_response,
 */
    __Pyx_XDECREF(__pyx_r);

    /* "btdht/dht.pyx":1711
 *                     max(
 *                         self.last_response,
 *                         self.last_query             # <<<<<<<<<<<<<<
 *                     ) < max(
 *                         other.last_response,
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_query); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "btdht/dht.pyx":1710
 *                 return not (
 *                     max(
 *                         self.last_response,             # <<<<<<<<<<<<<<
 *                         self.last_query
 *                     ) < max(
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_last_response); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1710, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "btdht/dht.pyx":1711
 *                     max(
 *                         self.last_response,
 *                         self.last_query             # <<<<<<<<<<<<<<
 *                     ) < max(
 *                         other.last_response,
 */
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_t_4, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1711, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1711, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_5) {
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1;
    } else {
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_3 = __pyx_t_4;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1714
 *                     ) < max(
 *                         other.last_response,
 *                         other.last_query             # <<<<<<<<<<<<<<
 *                     )
 *                 )
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_last_query); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "btdht/dht.pyx":1713
 *                         self.last_query
 *                     ) < max(
 *                         other.last_response,             # <<<<<<<<<<<<<<
 *                         other.last_query
 *                     )
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_other), __pyx_n_s_last_response); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1713, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "btdht/dht.pyx":1714
 *                     ) < max(
 *                         other.last_response,
 *                         other.last_query             # <<<<<<<<<<<<<<
 *                     )
 *                 )
 */
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_t_4, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1714, __pyx_L1_error)
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1714, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_5) {
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_2 = __pyx_t_1;
    } else {
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_2 = __pyx_t_4;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1712, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "btdht/dht.pyx":1712
 *                         self.last_response,
 *                         self.last_query
 *                     ) < max(             # <<<<<<<<<<<<<<
 *                         other.last_response,
 *                         other.last_query
 */
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1712, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1708
 *                 ) or (other.id == self.id)
 *             elif op == 5: # >=
 *                 return not (             # <<<<<<<<<<<<<<
 *                     max(
 *                         self.last_response,
 */
    __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_5)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1708, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "btdht/dht.pyx":1707
 *                     other.last_query
 *                 ) or (other.id == self.id)
 *             elif op == 5: # >=             # <<<<<<<<<<<<<<
 *                 return not (
 *                     max(
 */
    break;
    default:

    /* "btdht/dht.pyx":1718
 *                 )
 *             else:
 *                 return False             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_False);
    __pyx_r = Py_False;
    goto __pyx_L0;
    break;
  }

  /* "btdht/dht.pyx":1676
 * 
 * 
 *     def __richcmp__(self, Node other, int op):             # <<<<<<<<<<<<<<
 *             if op == 2: # ==
 *                 return other.id == self.id
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("btdht.dht.Node.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1721
 * 
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return "Node: %s:%s" % (self.ip, self.port)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_5__repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_4Node_5__repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_4__repr__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_4__repr__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__repr__", 0);

  /* "btdht/dht.pyx":1722
 * 
 *     def __repr__(self):
 *         return "Node: %s:%s" % (self.ip, self.port)             # <<<<<<<<<<<<<<
 * 
 *     def compact_info(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ip); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1722, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_port); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1722, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1722, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_Node_s_s, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1722, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":1721
 * 
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return "Node: %s:%s" % (self.ip, self.port)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("btdht.dht.Node.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1724
 *         return "Node: %s:%s" % (self.ip, self.port)
 * 
 *     def compact_info(self):             # <<<<<<<<<<<<<<
 *         """
 *             Return the compact contact information of the node
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_7compact_info(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5btdht_3dht_4Node_6compact_info[] = "\n            Return the compact contact information of the node\n\n            Notes:\n                Contact information for peers is encoded as a 6-byte string.\n                Also known as \"Compact IP-address/port info\" the 4-byte IP address\n                is in network byte order with the 2 byte port in network byte order\n                concatenated onto the end.\n                Contact information for nodes is encoded as a 26-byte string.\n                Also known as \"Compact node info\" the 20-byte Node ID in network byte\n                order has the compact IP-address/port info concatenated to the end.\n        ";
static PyObject *__pyx_pw_5btdht_3dht_4Node_7compact_info(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("compact_info (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_6compact_info(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_6compact_info(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("compact_info", 0);

  /* "btdht/dht.pyx":1737
 *                 order has the compact IP-address/port info concatenated to the end.
 *         """
 *         return struct.pack("!20s4sH", self.id, self._ip, self.port)             # <<<<<<<<<<<<<<
 * 
 *     @classmethod
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_struct); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_pack); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_FromString(__pyx_v_self->_ip); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_port); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1737, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = NULL;
  __pyx_t_7 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_7 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[5] = {__pyx_t_6, __pyx_kp_s_20s4sH, __pyx_t_2, __pyx_t_4, __pyx_t_5};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 4+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1737, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[5] = {__pyx_t_6, __pyx_kp_s_20s4sH, __pyx_t_2, __pyx_t_4, __pyx_t_5};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_7, 4+__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1737, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  {
    __pyx_t_8 = PyTuple_New(4+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1737, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_INCREF(__pyx_kp_s_20s4sH);
    __Pyx_GIVEREF(__pyx_kp_s_20s4sH);
    PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_kp_s_20s4sH);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_7, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_8, 3+__pyx_t_7, __pyx_t_5);
    __pyx_t_2 = 0;
    __pyx_t_4 = 0;
    __pyx_t_5 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1737, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":1724
 *         return "Node: %s:%s" % (self.ip, self.port)
 * 
 *     def compact_info(self):             # <<<<<<<<<<<<<<
 *         """
 *             Return the compact contact information of the node
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("btdht.dht.Node.compact_info", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1740
 * 
 *     @classmethod
 *     def from_compact_infos(cls, infos):             # <<<<<<<<<<<<<<
 *         """
 *             This is a classmethod
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_9from_compact_infos(PyObject *__pyx_v_cls, PyObject *__pyx_v_infos); /*proto*/
static char __pyx_doc_5btdht_3dht_4Node_8from_compact_infos[] = "\n            This is a classmethod\n\n            Instancy nodes from multiple compact node information string\n\n            :param bytes infos: A string of size multiple of 26\n            :return: A list of :class:`Node` instances\n            :rtype: list\n\n            Notes:\n                Contact information for peers is encoded as a 6-byte string.\n                Also known as \"Compact IP-address/port info\" the 4-byte IP address\n                is in network byte order with the 2 byte port in network byte order\n                concatenated onto the end.\n                Contact information for nodes is encoded as a 26-byte string.\n                Also known as \"Compact node info\" the 20-byte Node ID in network byte\n                order has the compact IP-address/port info concatenated to the end.\n        ";
static PyObject *__pyx_pw_5btdht_3dht_4Node_9from_compact_infos(PyObject *__pyx_v_cls, PyObject *__pyx_v_infos) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_compact_infos (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_8from_compact_infos(((PyTypeObject*)__pyx_v_cls), ((PyObject *)__pyx_v_infos));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_8from_compact_infos(CYTHON_UNUSED PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_infos) {
  PyObject *__pyx_v_nodes = NULL;
  PyObject *__pyx_v_length = NULL;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("from_compact_infos", 0);

  /* "btdht/dht.pyx":1759
 *                 order has the compact IP-address/port info concatenated to the end.
 *         """
 *         nodes = []             # <<<<<<<<<<<<<<
 *         length = len(infos)
 *         if length//26*26 != length:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_nodes = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1760
 *         """
 *         nodes = []
 *         length = len(infos)             # <<<<<<<<<<<<<<
 *         if length//26*26 != length:
 *             raise ValueError(b"nodes length should be a multiple of 26")
 */
  __pyx_t_2 = PyObject_Length(__pyx_v_infos); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1760, __pyx_L1_error)
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1760, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_length = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1761
 *         nodes = []
 *         length = len(infos)
 *         if length//26*26 != length:             # <<<<<<<<<<<<<<
 *             raise ValueError(b"nodes length should be a multiple of 26")
 *         i=0
 */
  __pyx_t_1 = __Pyx_PyInt_FloorDivideObjC(__pyx_v_length, __pyx_int_26, 26, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1761, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, __pyx_int_26); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1761, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_3, __pyx_v_length, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1761, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1761, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(__pyx_t_4)) {

    /* "btdht/dht.pyx":1762
 *         length = len(infos)
 *         if length//26*26 != length:
 *             raise ValueError(b"nodes length should be a multiple of 26")             # <<<<<<<<<<<<<<
 *         i=0
 *         while i < length:
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1762, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1762, __pyx_L1_error)

    /* "btdht/dht.pyx":1761
 *         nodes = []
 *         length = len(infos)
 *         if length//26*26 != length:             # <<<<<<<<<<<<<<
 *             raise ValueError(b"nodes length should be a multiple of 26")
 *         i=0
 */
  }

  /* "btdht/dht.pyx":1763
 *         if length//26*26 != length:
 *             raise ValueError(b"nodes length should be a multiple of 26")
 *         i=0             # <<<<<<<<<<<<<<
 *         while i < length:
 *             if infos[i+20:i+24] != b'\0\0\0\0' and infos[i+24:i+26] != b'\0\0':
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_v_i = __pyx_int_0;

  /* "btdht/dht.pyx":1764
 *             raise ValueError(b"nodes length should be a multiple of 26")
 *         i=0
 *         while i < length:             # <<<<<<<<<<<<<<
 *             if infos[i+20:i+24] != b'\0\0\0\0' and infos[i+24:i+26] != b'\0\0':
 *                 #try:
 */
  while (1) {
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_i, __pyx_v_length, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1764, __pyx_L1_error)
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1764, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!__pyx_t_4) break;

    /* "btdht/dht.pyx":1765
 *         i=0
 *         while i < length:
 *             if infos[i+20:i+24] != b'\0\0\0\0' and infos[i+24:i+26] != b'\0\0':             # <<<<<<<<<<<<<<
 *                 #try:
 *                     nodes.append(Node.from_compact_info(infos[i:i+26]))
 */
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_20, 20, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1765, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_24, 24, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1765, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetSlice(__pyx_v_infos, 0, 0, &__pyx_t_1, &__pyx_t_3, NULL, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1765, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = (__Pyx_PyBytes_Equals(__pyx_t_5, __pyx_kp_b__27, Py_NE)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1765, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_6) {
    } else {
      __pyx_t_4 = __pyx_t_6;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_5 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_24, 24, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1765, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_26, 26, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1765, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_infos, 0, 0, &__pyx_t_5, &__pyx_t_3, NULL, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1765, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = (__Pyx_PyBytes_Equals(__pyx_t_1, __pyx_kp_b__28, Py_NE)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1765, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = __pyx_t_6;
    __pyx_L7_bool_binop_done:;
    if (__pyx_t_4) {

      /* "btdht/dht.pyx":1767
 *             if infos[i+20:i+24] != b'\0\0\0\0' and infos[i+24:i+26] != b'\0\0':
 *                 #try:
 *                     nodes.append(Node.from_compact_info(infos[i:i+26]))             # <<<<<<<<<<<<<<
 *                 #except ValueError as e:
 *                 #    print("%s %s" % (e, v))
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5btdht_3dht_Node), __pyx_n_s_from_compact_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1767, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_26, 26, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1767, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = __Pyx_PyObject_GetSlice(__pyx_v_infos, 0, 0, &__pyx_v_i, &__pyx_t_5, NULL, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1767, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7);
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1767, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_nodes, __pyx_t_1); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1767, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "btdht/dht.pyx":1765
 *         i=0
 *         while i < length:
 *             if infos[i+20:i+24] != b'\0\0\0\0' and infos[i+24:i+26] != b'\0\0':             # <<<<<<<<<<<<<<
 *                 #try:
 *                     nodes.append(Node.from_compact_info(infos[i:i+26]))
 */
    }

    /* "btdht/dht.pyx":1770
 *                 #except ValueError as e:
 *                 #    print("%s %s" % (e, v))
 *             i += 26             # <<<<<<<<<<<<<<
 *         return nodes
 * 
 */
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_v_i, __pyx_int_26, 26, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1770, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_i, __pyx_t_1);
    __pyx_t_1 = 0;
  }

  /* "btdht/dht.pyx":1771
 *                 #    print("%s %s" % (e, v))
 *             i += 26
 *         return nodes             # <<<<<<<<<<<<<<
 * 
 *     @classmethod
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_nodes);
  __pyx_r = __pyx_v_nodes;
  goto __pyx_L0;

  /* "btdht/dht.pyx":1740
 * 
 *     @classmethod
 *     def from_compact_infos(cls, infos):             # <<<<<<<<<<<<<<
 *         """
 *             This is a classmethod
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("btdht.dht.Node.from_compact_infos", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_nodes);
  __Pyx_XDECREF(__pyx_v_length);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1774
 * 
 *     @classmethod
 *     def from_compact_info(cls, info):             # <<<<<<<<<<<<<<
 *         """
 *             This is a classmethod
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_11from_compact_info(PyObject *__pyx_v_cls, PyObject *__pyx_v_info); /*proto*/
static char __pyx_doc_5btdht_3dht_4Node_10from_compact_info[] = "\n            This is a classmethod\n\n            Instancy a node from its compact node infoformation string\n\n            :param bytes info: A string of length 26\n            :return: A node instance\n            :rtype: Node\n\n            Notes:\n                Contact information for peers is encoded as a 6-byte string.\n                Also known as \"Compact IP-address/port info\" the 4-byte IP address\n                is in network byte order with the 2 byte port in network byte order\n                concatenated onto the end.\n                Contact information for nodes is encoded as a 26-byte string.\n                Also known as \"Compact node info\" the 20-byte Node ID in network byte\n                order has the compact IP-address/port info concatenated to the end.\n        ";
static PyObject *__pyx_pw_5btdht_3dht_4Node_11from_compact_info(PyObject *__pyx_v_cls, PyObject *__pyx_v_info) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_compact_info (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_10from_compact_info(((PyTypeObject*)__pyx_v_cls), ((PyObject *)__pyx_v_info));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_10from_compact_info(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_info) {
  PyObject *__pyx_v_id = NULL;
  PyObject *__pyx_v_ip = NULL;
  PyObject *__pyx_v_port = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("from_compact_info", 0);

  /* "btdht/dht.pyx":1793
 *                 order has the compact IP-address/port info concatenated to the end.
 *         """
 *         if len(info) != 26:             # <<<<<<<<<<<<<<
 *             raise EnvironmentError("compact node info should be 26 chars long")
 *         (id, ip, port) = struct.unpack("!20s4sH", info)
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_info); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1793, __pyx_L1_error)
  __pyx_t_2 = ((__pyx_t_1 != 26) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "btdht/dht.pyx":1794
 *         """
 *         if len(info) != 26:
 *             raise EnvironmentError("compact node info should be 26 chars long")             # <<<<<<<<<<<<<<
 *         (id, ip, port) = struct.unpack("!20s4sH", info)
 *         ip = socket.inet_ntoa(ip)
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_EnvironmentError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1794, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 1794, __pyx_L1_error)

    /* "btdht/dht.pyx":1793
 *                 order has the compact IP-address/port info concatenated to the end.
 *         """
 *         if len(info) != 26:             # <<<<<<<<<<<<<<
 *             raise EnvironmentError("compact node info should be 26 chars long")
 *         (id, ip, port) = struct.unpack("!20s4sH", info)
 */
  }

  /* "btdht/dht.pyx":1795
 *         if len(info) != 26:
 *             raise EnvironmentError("compact node info should be 26 chars long")
 *         (id, ip, port) = struct.unpack("!20s4sH", info)             # <<<<<<<<<<<<<<
 *         ip = socket.inet_ntoa(ip)
 *         #id = ID(id)
 */
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_struct); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1795, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_unpack); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1795, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
      __pyx_t_6 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_kp_s_20s4sH, __pyx_v_info};
    __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1795, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_kp_s_20s4sH, __pyx_v_info};
    __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1795, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1795, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__pyx_t_4) {
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL;
    }
    __Pyx_INCREF(__pyx_kp_s_20s4sH);
    __Pyx_GIVEREF(__pyx_kp_s_20s4sH);
    PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_kp_s_20s4sH);
    __Pyx_INCREF(__pyx_v_info);
    __Pyx_GIVEREF(__pyx_v_info);
    PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_info);
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1795, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 3)) {
      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 1795, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); 
    } else {
      __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 2); 
    }
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_t_4);
    #else
    __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1795, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1795, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1795, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1795, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
    index = 0; __pyx_t_5 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_5)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_5);
    index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_7);
    index = 2; __pyx_t_4 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_4)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 3) < 0) __PYX_ERR(0, 1795, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 1795, __pyx_L1_error)
    __pyx_L5_unpacking_done:;
  }
  __pyx_v_id = __pyx_t_5;
  __pyx_t_5 = 0;
  __pyx_v_ip = __pyx_t_7;
  __pyx_t_7 = 0;
  __pyx_v_port = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "btdht/dht.pyx":1796
 *             raise EnvironmentError("compact node info should be 26 chars long")
 *         (id, ip, port) = struct.unpack("!20s4sH", info)
 *         ip = socket.inet_ntoa(ip)             # <<<<<<<<<<<<<<
 *         #id = ID(id)
 *         return cls(id, ip, port)
 */
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_socket); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_inet_ntoa); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_4, __pyx_v_ip) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_ip);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF_SET(__pyx_v_ip, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "btdht/dht.pyx":1798
 *         ip = socket.inet_ntoa(ip)
 *         #id = ID(id)
 *         return cls(id, ip, port)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1798, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_id);
  __Pyx_GIVEREF(__pyx_v_id);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_id);
  __Pyx_INCREF(__pyx_v_ip);
  __Pyx_GIVEREF(__pyx_v_ip);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_ip);
  __Pyx_INCREF(__pyx_v_port);
  __Pyx_GIVEREF(__pyx_v_port);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_port);
  __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_v_cls), __pyx_t_3, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1798, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":1774
 * 
 *     @classmethod
 *     def from_compact_info(cls, info):             # <<<<<<<<<<<<<<
 *         """
 *             This is a classmethod
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("btdht.dht.Node.from_compact_info", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_id);
  __Pyx_XDECREF(__pyx_v_ip);
  __Pyx_XDECREF(__pyx_v_port);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1802
 * 
 * 
 *     def __cmp__(self, Node other):             # <<<<<<<<<<<<<<
 *         if self.__richcmp__(other, 0):
 *             return -1
 */

/* Python wrapper */
#if PY_MAJOR_VERSION < 3
static int __pyx_pw_5btdht_3dht_4Node_13__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static int __pyx_pw_5btdht_3dht_4Node_13__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cmp__ (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5btdht_3dht_Node, 1, "other", 0))) __PYX_ERR(0, 1802, __pyx_L1_error)
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_12__cmp__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self), ((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_other));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
#endif /*!(#if PY_MAJOR_VERSION < 3)*/

#if PY_MAJOR_VERSION < 3
static int __pyx_pf_5btdht_3dht_4Node_12__cmp__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, struct __pyx_obj_5btdht_3dht_Node *__pyx_v_other) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cmp__", 0);

  /* "btdht/dht.pyx":1803
 * 
 *     def __cmp__(self, Node other):
 *         if self.__richcmp__(other, 0):             # <<<<<<<<<<<<<<
 *             return -1
 *         elif self.__richcmp__(other, 2):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_richcmp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1803, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_other), __pyx_int_0};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1803, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_other), __pyx_int_0};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1803, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1803, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(((PyObject *)__pyx_v_other));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_other));
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_other));
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_int_0);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1803, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1803, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_6) {

    /* "btdht/dht.pyx":1804
 *     def __cmp__(self, Node other):
 *         if self.__richcmp__(other, 0):
 *             return -1             # <<<<<<<<<<<<<<
 *         elif self.__richcmp__(other, 2):
 *             return 0
 */
    __pyx_r = -1;
    goto __pyx_L0;

    /* "btdht/dht.pyx":1803
 * 
 *     def __cmp__(self, Node other):
 *         if self.__richcmp__(other, 0):             # <<<<<<<<<<<<<<
 *             return -1
 *         elif self.__richcmp__(other, 2):
 */
  }

  /* "btdht/dht.pyx":1805
 *         if self.__richcmp__(other, 0):
 *             return -1
 *         elif self.__richcmp__(other, 2):             # <<<<<<<<<<<<<<
 *             return 0
 *         else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_richcmp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1805, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_other), __pyx_int_2};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_5, ((PyObject *)__pyx_v_other), __pyx_int_2};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_3 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (__pyx_t_5) {
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL;
    }
    __Pyx_INCREF(((PyObject *)__pyx_v_other));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_other));
    PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_4, ((PyObject *)__pyx_v_other));
    __Pyx_INCREF(__pyx_int_2);
    __Pyx_GIVEREF(__pyx_int_2);
    PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_4, __pyx_int_2);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1805, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1805, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_6) {

    /* "btdht/dht.pyx":1806
 *             return -1
 *         elif self.__richcmp__(other, 2):
 *             return 0             # <<<<<<<<<<<<<<
 *         else:
 *             return 1
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "btdht/dht.pyx":1805
 *         if self.__richcmp__(other, 0):
 *             return -1
 *         elif self.__richcmp__(other, 2):             # <<<<<<<<<<<<<<
 *             return 0
 *         else:
 */
  }

  /* "btdht/dht.pyx":1808
 *             return 0
 *         else:
 *             return 1             # <<<<<<<<<<<<<<
 * 
 *     def __hash__(self):
 */
  /*else*/ {
    __pyx_r = 1;
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":1802
 * 
 * 
 *     def __cmp__(self, Node other):             # <<<<<<<<<<<<<<
 *         if self.__richcmp__(other, 0):
 *             return -1
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("btdht.dht.Node.__cmp__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
#endif /*!(#if PY_MAJOR_VERSION < 3)*/

/* "btdht/dht.pyx":1810
 *             return 1
 * 
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         return hash(self.id)
 * 
 */

/* Python wrapper */
static Py_hash_t __pyx_pw_5btdht_3dht_4Node_15__hash__(PyObject *__pyx_v_self); /*proto*/
static Py_hash_t __pyx_pw_5btdht_3dht_4Node_15__hash__(PyObject *__pyx_v_self) {
  Py_hash_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_14__hash__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static Py_hash_t __pyx_pf_5btdht_3dht_4Node_14__hash__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self) {
  Py_hash_t __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_hash_t __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__hash__", 0);

  /* "btdht/dht.pyx":1811
 * 
 *     def __hash__(self):
 *         return hash(self.id)             # <<<<<<<<<<<<<<
 * 
 *     def ping(self, DHT_BASE dht):
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Hash(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_hash_t)-1))) __PYX_ERR(0, 1811, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  goto __pyx_L0;

  /* "btdht/dht.pyx":1810
 *             return 1
 * 
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         return hash(self.id)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("btdht.dht.Node.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1813
 *         return hash(self.id)
 * 
 *     def ping(self, DHT_BASE dht):             # <<<<<<<<<<<<<<
 *         """
 *             Send a ping query to the node
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_17ping(PyObject *__pyx_v_self, PyObject *__pyx_v_dht); /*proto*/
static char __pyx_doc_5btdht_3dht_4Node_16ping[] = "\n            Send a ping query to the node\n\n            :param DHT_BASE dht: The dht instance to use to send the message\n        ";
static PyObject *__pyx_pw_5btdht_3dht_4Node_17ping(PyObject *__pyx_v_self, PyObject *__pyx_v_dht) {
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ping (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dht), __pyx_ptype_5btdht_3dht_DHT_BASE, 1, "dht", 0))) __PYX_ERR(0, 1813, __pyx_L1_error)
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_16ping(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self), ((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v_dht));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_16ping(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_dht) {
  PyObject *__pyx_v_id = NULL;
  struct __pyx_obj_5btdht_4krcp_BMessage *__pyx_v_msg = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  char *__pyx_t_3;
  Py_ssize_t __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("ping", 0);

  /* "btdht/dht.pyx":1819
 *             :param DHT_BASE dht: The dht instance to use to send the message
 *         """
 *         id = dht.myid.value             # <<<<<<<<<<<<<<
 *         msg = BMessage()
 *         dht._set_transaction_id(msg)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_myid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1819, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1819, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_id = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1820
 *         """
 *         id = dht.myid.value
 *         msg = BMessage()             # <<<<<<<<<<<<<<
 *         dht._set_transaction_id(msg)
 *         msg.set_y("q", 1)
 */
  __pyx_t_2 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_5btdht_4krcp_BMessage)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1820, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_msg = ((struct __pyx_obj_5btdht_4krcp_BMessage *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1821
 *         id = dht.myid.value
 *         msg = BMessage()
 *         dht._set_transaction_id(msg)             # <<<<<<<<<<<<<<
 *         msg.set_y("q", 1)
 *         msg.set_q("ping", 4)
 */
  ((struct __pyx_vtabstruct_5btdht_3dht_DHT_BASE *)__pyx_v_dht->__pyx_vtab)->_set_transaction_id(__pyx_v_dht, __pyx_v_msg, NULL);

  /* "btdht/dht.pyx":1822
 *         msg = BMessage()
 *         dht._set_transaction_id(msg)
 *         msg.set_y("q", 1)             # <<<<<<<<<<<<<<
 *         msg.set_q("ping", 4)
 *         msg.set_a(True)
 */
  (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_y(__pyx_v_msg, ((char *)"q"), 1));

  /* "btdht/dht.pyx":1823
 *         dht._set_transaction_id(msg)
 *         msg.set_y("q", 1)
 *         msg.set_q("ping", 4)             # <<<<<<<<<<<<<<
 *         msg.set_a(True)
 *         msg.set_id(id, len(dht.myid))
 */
  (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_q(__pyx_v_msg, ((char *)"ping"), 4));

  /* "btdht/dht.pyx":1824
 *         msg.set_y("q", 1)
 *         msg.set_q("ping", 4)
 *         msg.set_a(True)             # <<<<<<<<<<<<<<
 *         msg.set_id(id, len(dht.myid))
 *         self._failed+=1
 */
  (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_a(__pyx_v_msg, 1));

  /* "btdht/dht.pyx":1825
 *         msg.set_q("ping", 4)
 *         msg.set_a(True)
 *         msg.set_id(id, len(dht.myid))             # <<<<<<<<<<<<<<
 *         self._failed+=1
 *         dht.sendto(msg.encode(), (self.ip, self.port))
 */
  __pyx_t_3 = __Pyx_PyObject_AsWritableString(__pyx_v_id); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 1825, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_myid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1825, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1825, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_5 = ((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_id(__pyx_v_msg, __pyx_t_3, __pyx_t_4); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 1825, __pyx_L1_error)

  /* "btdht/dht.pyx":1826
 *         msg.set_a(True)
 *         msg.set_id(id, len(dht.myid))
 *         self._failed+=1             # <<<<<<<<<<<<<<
 *         dht.sendto(msg.encode(), (self.ip, self.port))
 * 
 */
  __pyx_v_self->_failed = (__pyx_v_self->_failed + 1);

  /* "btdht/dht.pyx":1827
 *         msg.set_id(id, len(dht.myid))
 *         self._failed+=1
 *         dht.sendto(msg.encode(), (self.ip, self.port))             # <<<<<<<<<<<<<<
 * 
 *     def find_node(self, DHT_BASE dht, target):
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_sendto); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1827, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_encode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1827, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_6 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1827, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ip); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1827, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_port); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1827, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1827, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8);
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;
  __pyx_t_8 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
      __pyx_t_5 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_6, __pyx_t_9};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1827, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_6, __pyx_t_9};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1827, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1827, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__pyx_t_8) {
      __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); __pyx_t_8 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_5, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_5, __pyx_t_9);
    __pyx_t_6 = 0;
    __pyx_t_9 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1827, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1813
 *         return hash(self.id)
 * 
 *     def ping(self, DHT_BASE dht):             # <<<<<<<<<<<<<<
 *         """
 *             Send a ping query to the node
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("btdht.dht.Node.ping", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_id);
  __Pyx_XDECREF((PyObject *)__pyx_v_msg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1829
 *         dht.sendto(msg.encode(), (self.ip, self.port))
 * 
 *     def find_node(self, DHT_BASE dht, target):             # <<<<<<<<<<<<<<
 *         """
 *             Send a find_node query to the node
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_19find_node(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_4Node_18find_node[] = "\n            Send a find_node query to the node\n\n            :param DHT_BASE dht: The dht instance to use to send the message\n            :param bytes target: the 160bits (20 bytes) target node id\n        ";
static PyObject *__pyx_pw_5btdht_3dht_4Node_19find_node(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_dht = 0;
  PyObject *__pyx_v_target = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find_node (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_dht,&__pyx_n_s_target,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dht)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_target)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find_node", 1, 2, 2, 1); __PYX_ERR(0, 1829, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "find_node") < 0)) __PYX_ERR(0, 1829, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_dht = ((struct __pyx_obj_5btdht_3dht_DHT_BASE *)values[0]);
    __pyx_v_target = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("find_node", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1829, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Node.find_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dht), __pyx_ptype_5btdht_3dht_DHT_BASE, 1, "dht", 0))) __PYX_ERR(0, 1829, __pyx_L1_error)
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_18find_node(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self), __pyx_v_dht, __pyx_v_target);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_18find_node(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_dht, PyObject *__pyx_v_target) {
  PyObject *__pyx_v_id = NULL;
  Py_ssize_t __pyx_v_tl;
  struct __pyx_obj_5btdht_4krcp_BMessage *__pyx_v_msg = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  char *__pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("find_node", 0);
  __Pyx_INCREF(__pyx_v_target);

  /* "btdht/dht.pyx":1836
 *             :param bytes target: the 160bits (20 bytes) target node id
 *         """
 *         id = dht.myid.value             # <<<<<<<<<<<<<<
 *         target = ID.to_bytes(target)
 *         tl = len(target)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_myid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1836, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1836, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_id = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1837
 *         """
 *         id = dht.myid.value
 *         target = ID.to_bytes(target)             # <<<<<<<<<<<<<<
 *         tl = len(target)
 *         msg = BMessage()
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ID); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1837, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_to_bytes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1837, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_v_target) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_target);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1837, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF_SET(__pyx_v_target, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1838
 *         id = dht.myid.value
 *         target = ID.to_bytes(target)
 *         tl = len(target)             # <<<<<<<<<<<<<<
 *         msg = BMessage()
 *         dht._set_transaction_id(msg)
 */
  __pyx_t_4 = PyObject_Length(__pyx_v_target); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1838, __pyx_L1_error)
  __pyx_v_tl = __pyx_t_4;

  /* "btdht/dht.pyx":1839
 *         target = ID.to_bytes(target)
 *         tl = len(target)
 *         msg = BMessage()             # <<<<<<<<<<<<<<
 *         dht._set_transaction_id(msg)
 *         msg.set_y("q", 1)
 */
  __pyx_t_2 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_5btdht_4krcp_BMessage)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1839, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_msg = ((struct __pyx_obj_5btdht_4krcp_BMessage *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1840
 *         tl = len(target)
 *         msg = BMessage()
 *         dht._set_transaction_id(msg)             # <<<<<<<<<<<<<<
 *         msg.set_y("q", 1)
 *         msg.set_q("find_node", 9)
 */
  ((struct __pyx_vtabstruct_5btdht_3dht_DHT_BASE *)__pyx_v_dht->__pyx_vtab)->_set_transaction_id(__pyx_v_dht, __pyx_v_msg, NULL);

  /* "btdht/dht.pyx":1841
 *         msg = BMessage()
 *         dht._set_transaction_id(msg)
 *         msg.set_y("q", 1)             # <<<<<<<<<<<<<<
 *         msg.set_q("find_node", 9)
 *         msg.set_a(True)
 */
  (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_y(__pyx_v_msg, ((char *)"q"), 1));

  /* "btdht/dht.pyx":1842
 *         dht._set_transaction_id(msg)
 *         msg.set_y("q", 1)
 *         msg.set_q("find_node", 9)             # <<<<<<<<<<<<<<
 *         msg.set_a(True)
 *         msg.set_id(id, len(dht.myid))
 */
  (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_q(__pyx_v_msg, ((char *)"find_node"), 9));

  /* "btdht/dht.pyx":1843
 *         msg.set_y("q", 1)
 *         msg.set_q("find_node", 9)
 *         msg.set_a(True)             # <<<<<<<<<<<<<<
 *         msg.set_id(id, len(dht.myid))
 *         msg.set_target(target, tl)
 */
  (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_a(__pyx_v_msg, 1));

  /* "btdht/dht.pyx":1844
 *         msg.set_q("find_node", 9)
 *         msg.set_a(True)
 *         msg.set_id(id, len(dht.myid))             # <<<<<<<<<<<<<<
 *         msg.set_target(target, tl)
 *         self._failed+=1
 */
  __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_id); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 1844, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_myid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1844, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1844, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_6 = ((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_id(__pyx_v_msg, __pyx_t_5, __pyx_t_4); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 1844, __pyx_L1_error)

  /* "btdht/dht.pyx":1845
 *         msg.set_a(True)
 *         msg.set_id(id, len(dht.myid))
 *         msg.set_target(target, tl)             # <<<<<<<<<<<<<<
 *         self._failed+=1
 *         dht.sendto(msg.encode(), (self.ip, self.port))
 */
  __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_target); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 1845, __pyx_L1_error)
  __pyx_t_6 = ((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_target(__pyx_v_msg, __pyx_t_5, __pyx_v_tl); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 1845, __pyx_L1_error)

  /* "btdht/dht.pyx":1846
 *         msg.set_id(id, len(dht.myid))
 *         msg.set_target(target, tl)
 *         self._failed+=1             # <<<<<<<<<<<<<<
 *         dht.sendto(msg.encode(), (self.ip, self.port))
 * 
 */
  __pyx_v_self->_failed = (__pyx_v_self->_failed + 1);

  /* "btdht/dht.pyx":1847
 *         msg.set_target(target, tl)
 *         self._failed+=1
 *         dht.sendto(msg.encode(), (self.ip, self.port))             # <<<<<<<<<<<<<<
 * 
 *     def get_peers(self, DHT_BASE dht, info_hash):
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_sendto); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1847, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_encode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1847, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1847, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ip); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1847, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_port); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1847, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1847, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8);
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;
  __pyx_t_8 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_6 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_1, __pyx_t_9};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1847, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_1, __pyx_t_9};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1847, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1847, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__pyx_t_8) {
      __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); __pyx_t_8 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_9);
    __pyx_t_1 = 0;
    __pyx_t_9 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1847, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1829
 *         dht.sendto(msg.encode(), (self.ip, self.port))
 * 
 *     def find_node(self, DHT_BASE dht, target):             # <<<<<<<<<<<<<<
 *         """
 *             Send a find_node query to the node
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("btdht.dht.Node.find_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_id);
  __Pyx_XDECREF((PyObject *)__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_target);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1849
 *         dht.sendto(msg.encode(), (self.ip, self.port))
 * 
 *     def get_peers(self, DHT_BASE dht, info_hash):             # <<<<<<<<<<<<<<
 *         """
 *             Send a get_peers query to the node
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_21get_peers(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_4Node_20get_peers[] = "\n            Send a get_peers query to the node\n\n            :param DHT_BASE dht: The dht instance to use to send the message\n            :param bytes info_hash: a 160bits (20 bytes) torrent id\n        ";
static PyObject *__pyx_pw_5btdht_3dht_4Node_21get_peers(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_dht = 0;
  PyObject *__pyx_v_info_hash = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_peers (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_dht,&__pyx_n_s_info_hash,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dht)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_info_hash)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_peers", 1, 2, 2, 1); __PYX_ERR(0, 1849, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_peers") < 0)) __PYX_ERR(0, 1849, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_dht = ((struct __pyx_obj_5btdht_3dht_DHT_BASE *)values[0]);
    __pyx_v_info_hash = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_peers", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1849, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Node.get_peers", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dht), __pyx_ptype_5btdht_3dht_DHT_BASE, 1, "dht", 0))) __PYX_ERR(0, 1849, __pyx_L1_error)
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_20get_peers(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self), __pyx_v_dht, __pyx_v_info_hash);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_20get_peers(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_dht, PyObject *__pyx_v_info_hash) {
  PyObject *__pyx_v_id = NULL;
  Py_ssize_t __pyx_v_ihl;
  struct __pyx_obj_5btdht_4krcp_BMessage *__pyx_v_msg = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  char *__pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_peers", 0);
  __Pyx_INCREF(__pyx_v_info_hash);

  /* "btdht/dht.pyx":1856
 *             :param bytes info_hash: a 160bits (20 bytes) torrent id
 *         """
 *         id = dht.myid.value             # <<<<<<<<<<<<<<
 *         info_hash = ID.to_bytes(info_hash)
 *         ihl = len(info_hash)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_myid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1856, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1856, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_id = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1857
 *         """
 *         id = dht.myid.value
 *         info_hash = ID.to_bytes(info_hash)             # <<<<<<<<<<<<<<
 *         ihl = len(info_hash)
 *         msg = BMessage()
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ID); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1857, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_to_bytes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1857, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_v_info_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_info_hash);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1857, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF_SET(__pyx_v_info_hash, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1858
 *         id = dht.myid.value
 *         info_hash = ID.to_bytes(info_hash)
 *         ihl = len(info_hash)             # <<<<<<<<<<<<<<
 *         msg = BMessage()
 *         dht._set_transaction_id(msg)
 */
  __pyx_t_4 = PyObject_Length(__pyx_v_info_hash); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1858, __pyx_L1_error)
  __pyx_v_ihl = __pyx_t_4;

  /* "btdht/dht.pyx":1859
 *         info_hash = ID.to_bytes(info_hash)
 *         ihl = len(info_hash)
 *         msg = BMessage()             # <<<<<<<<<<<<<<
 *         dht._set_transaction_id(msg)
 *         msg.set_y("q", 1)
 */
  __pyx_t_2 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_5btdht_4krcp_BMessage)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_msg = ((struct __pyx_obj_5btdht_4krcp_BMessage *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1860
 *         ihl = len(info_hash)
 *         msg = BMessage()
 *         dht._set_transaction_id(msg)             # <<<<<<<<<<<<<<
 *         msg.set_y("q", 1)
 *         msg.set_q("get_peers", 9)
 */
  ((struct __pyx_vtabstruct_5btdht_3dht_DHT_BASE *)__pyx_v_dht->__pyx_vtab)->_set_transaction_id(__pyx_v_dht, __pyx_v_msg, NULL);

  /* "btdht/dht.pyx":1861
 *         msg = BMessage()
 *         dht._set_transaction_id(msg)
 *         msg.set_y("q", 1)             # <<<<<<<<<<<<<<
 *         msg.set_q("get_peers", 9)
 *         msg.set_a(True)
 */
  (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_y(__pyx_v_msg, ((char *)"q"), 1));

  /* "btdht/dht.pyx":1862
 *         dht._set_transaction_id(msg)
 *         msg.set_y("q", 1)
 *         msg.set_q("get_peers", 9)             # <<<<<<<<<<<<<<
 *         msg.set_a(True)
 *         msg.set_id(id, len(dht.myid))
 */
  (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_q(__pyx_v_msg, ((char *)"get_peers"), 9));

  /* "btdht/dht.pyx":1863
 *         msg.set_y("q", 1)
 *         msg.set_q("get_peers", 9)
 *         msg.set_a(True)             # <<<<<<<<<<<<<<
 *         msg.set_id(id, len(dht.myid))
 *         msg.set_info_hash(info_hash, ihl)
 */
  (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_a(__pyx_v_msg, 1));

  /* "btdht/dht.pyx":1864
 *         msg.set_q("get_peers", 9)
 *         msg.set_a(True)
 *         msg.set_id(id, len(dht.myid))             # <<<<<<<<<<<<<<
 *         msg.set_info_hash(info_hash, ihl)
 *         self._failed+=1
 */
  __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_id); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 1864, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_myid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1864, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1864, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_6 = ((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_id(__pyx_v_msg, __pyx_t_5, __pyx_t_4); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 1864, __pyx_L1_error)

  /* "btdht/dht.pyx":1865
 *         msg.set_a(True)
 *         msg.set_id(id, len(dht.myid))
 *         msg.set_info_hash(info_hash, ihl)             # <<<<<<<<<<<<<<
 *         self._failed+=1
 *         dht.sendto(msg.encode(), (self.ip, self.port))
 */
  __pyx_t_5 = __Pyx_PyObject_AsWritableString(__pyx_v_info_hash); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 1865, __pyx_L1_error)
  __pyx_t_6 = ((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_info_hash(__pyx_v_msg, __pyx_t_5, __pyx_v_ihl); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 1865, __pyx_L1_error)

  /* "btdht/dht.pyx":1866
 *         msg.set_id(id, len(dht.myid))
 *         msg.set_info_hash(info_hash, ihl)
 *         self._failed+=1             # <<<<<<<<<<<<<<
 *         dht.sendto(msg.encode(), (self.ip, self.port))
 * 
 */
  __pyx_v_self->_failed = (__pyx_v_self->_failed + 1);

  /* "btdht/dht.pyx":1867
 *         msg.set_info_hash(info_hash, ihl)
 *         self._failed+=1
 *         dht.sendto(msg.encode(), (self.ip, self.port))             # <<<<<<<<<<<<<<
 * 
 *     def announce_peer(self, DHT_BASE dht, info_hash, int port):
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_sendto); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_encode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_7, function);
    }
  }
  __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ip); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_port); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8);
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;
  __pyx_t_8 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_6 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_1, __pyx_t_9};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1867, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_1, __pyx_t_9};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1867, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1867, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__pyx_t_8) {
      __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); __pyx_t_8 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_9);
    __pyx_t_1 = 0;
    __pyx_t_9 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1867, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "btdht/dht.pyx":1849
 *         dht.sendto(msg.encode(), (self.ip, self.port))
 * 
 *     def get_peers(self, DHT_BASE dht, info_hash):             # <<<<<<<<<<<<<<
 *         """
 *             Send a get_peers query to the node
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("btdht.dht.Node.get_peers", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_id);
  __Pyx_XDECREF((PyObject *)__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_info_hash);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1869
 *         dht.sendto(msg.encode(), (self.ip, self.port))
 * 
 *     def announce_peer(self, DHT_BASE dht, info_hash, int port):             # <<<<<<<<<<<<<<
 *         """
 *             Send a announce_peer query to the node
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_23announce_peer(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_4Node_22announce_peer[] = "\n            Send a announce_peer query to the node\n\n            :param DHT_BASE dht: The dht instance to use to send the message\n            :param bytes info_hash: A 160bits (20 bytes) torrent id to announce\n            :param int port: The tcp port where data for ``info_hash`` is available\n            :raises NoTokenError: if we have no valid token for ``info_hash``. Try to call\n                :meth:`get_peers` on this ``info_hash`` first.\n        ";
static PyObject *__pyx_pw_5btdht_3dht_4Node_23announce_peer(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_dht = 0;
  PyObject *__pyx_v_info_hash = 0;
  int __pyx_v_port;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("announce_peer (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_dht,&__pyx_n_s_info_hash,&__pyx_n_s_port,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dht)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_info_hash)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("announce_peer", 1, 3, 3, 1); __PYX_ERR(0, 1869, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_port)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("announce_peer", 1, 3, 3, 2); __PYX_ERR(0, 1869, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "announce_peer") < 0)) __PYX_ERR(0, 1869, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_dht = ((struct __pyx_obj_5btdht_3dht_DHT_BASE *)values[0]);
    __pyx_v_info_hash = values[1];
    __pyx_v_port = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_port == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1869, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("announce_peer", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1869, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Node.announce_peer", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_dht), __pyx_ptype_5btdht_3dht_DHT_BASE, 1, "dht", 0))) __PYX_ERR(0, 1869, __pyx_L1_error)
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_22announce_peer(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self), __pyx_v_dht, __pyx_v_info_hash, __pyx_v_port);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_22announce_peer(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v_dht, PyObject *__pyx_v_info_hash, int __pyx_v_port) {
  PyObject *__pyx_v_id = NULL;
  PyObject *__pyx_v_token = NULL;
  struct __pyx_obj_5btdht_4krcp_BMessage *__pyx_v_msg = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  char *__pyx_t_8;
  Py_ssize_t __pyx_t_9;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("announce_peer", 0);
  __Pyx_INCREF(__pyx_v_info_hash);

  /* "btdht/dht.pyx":1882
 *         cdef char* tk
 *         cdef char* ih
 *         if self.id in dht.mytoken and (time.time() - dht.mytoken[self.id][1]) < 600:             # <<<<<<<<<<<<<<
 *             id = dht.myid.value
 *             info_hash = ID.to_bytes(info_hash)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_mytoken); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_t_2, __pyx_t_3, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1882, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {
  } else {
    __pyx_t_1 = __pyx_t_5;
    goto __pyx_L4_bool_binop_done;
  }
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_mytoken); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_7, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyNumber_Subtract(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1882, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_7, __pyx_int_600, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1882, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 1882, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = __pyx_t_5;
  __pyx_L4_bool_binop_done:;
  if (likely(__pyx_t_1)) {

    /* "btdht/dht.pyx":1883
 *         cdef char* ih
 *         if self.id in dht.mytoken and (time.time() - dht.mytoken[self.id][1]) < 600:
 *             id = dht.myid.value             # <<<<<<<<<<<<<<
 *             info_hash = ID.to_bytes(info_hash)
 *             token = dht.mytoken[self.id][0]
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_myid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1883, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1883, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_id = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "btdht/dht.pyx":1884
 *         if self.id in dht.mytoken and (time.time() - dht.mytoken[self.id][1]) < 600:
 *             id = dht.myid.value
 *             info_hash = ID.to_bytes(info_hash)             # <<<<<<<<<<<<<<
 *             token = dht.mytoken[self.id][0]
 *             msg = BMessage()
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ID); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1884, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_to_bytes); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1884, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_7 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_info_hash) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_info_hash);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1884, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_info_hash, __pyx_t_7);
    __pyx_t_7 = 0;

    /* "btdht/dht.pyx":1885
 *             id = dht.myid.value
 *             info_hash = ID.to_bytes(info_hash)
 *             token = dht.mytoken[self.id][0]             # <<<<<<<<<<<<<<
 *             msg = BMessage()
 *             dht._set_transaction_id(msg)
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_mytoken); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1885, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1885, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1885, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1885, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_token = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1886
 *             info_hash = ID.to_bytes(info_hash)
 *             token = dht.mytoken[self.id][0]
 *             msg = BMessage()             # <<<<<<<<<<<<<<
 *             dht._set_transaction_id(msg)
 *             msg.set_y("q", 1)
 */
    __pyx_t_3 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_5btdht_4krcp_BMessage)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1886, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_msg = ((struct __pyx_obj_5btdht_4krcp_BMessage *)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1887
 *             token = dht.mytoken[self.id][0]
 *             msg = BMessage()
 *             dht._set_transaction_id(msg)             # <<<<<<<<<<<<<<
 *             msg.set_y("q", 1)
 *             msg.set_q("announce_peer", 13)
 */
    ((struct __pyx_vtabstruct_5btdht_3dht_DHT_BASE *)__pyx_v_dht->__pyx_vtab)->_set_transaction_id(__pyx_v_dht, __pyx_v_msg, NULL);

    /* "btdht/dht.pyx":1888
 *             msg = BMessage()
 *             dht._set_transaction_id(msg)
 *             msg.set_y("q", 1)             # <<<<<<<<<<<<<<
 *             msg.set_q("announce_peer", 13)
 *             msg.set_a(True)
 */
    (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_y(__pyx_v_msg, ((char *)"q"), 1));

    /* "btdht/dht.pyx":1889
 *             dht._set_transaction_id(msg)
 *             msg.set_y("q", 1)
 *             msg.set_q("announce_peer", 13)             # <<<<<<<<<<<<<<
 *             msg.set_a(True)
 *             msg.set_id(id, len(dht.myid))
 */
    (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_q(__pyx_v_msg, ((char *)"announce_peer"), 13));

    /* "btdht/dht.pyx":1890
 *             msg.set_y("q", 1)
 *             msg.set_q("announce_peer", 13)
 *             msg.set_a(True)             # <<<<<<<<<<<<<<
 *             msg.set_id(id, len(dht.myid))
 *             msg.set_info_hash(info_hash, len(info_hash))
 */
    (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_a(__pyx_v_msg, 1));

    /* "btdht/dht.pyx":1891
 *             msg.set_q("announce_peer", 13)
 *             msg.set_a(True)
 *             msg.set_id(id, len(dht.myid))             # <<<<<<<<<<<<<<
 *             msg.set_info_hash(info_hash, len(info_hash))
 *             msg.set_port(port)
 */
    __pyx_t_8 = __Pyx_PyObject_AsWritableString(__pyx_v_id); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 1891, __pyx_L1_error)
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_myid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1891, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_9 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1891, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_10 = ((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_id(__pyx_v_msg, __pyx_t_8, __pyx_t_9); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 1891, __pyx_L1_error)

    /* "btdht/dht.pyx":1892
 *             msg.set_a(True)
 *             msg.set_id(id, len(dht.myid))
 *             msg.set_info_hash(info_hash, len(info_hash))             # <<<<<<<<<<<<<<
 *             msg.set_port(port)
 *             msg.set_token(token, len(info_hash))
 */
    __pyx_t_8 = __Pyx_PyObject_AsWritableString(__pyx_v_info_hash); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 1892, __pyx_L1_error)
    __pyx_t_9 = PyObject_Length(__pyx_v_info_hash); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1892, __pyx_L1_error)
    __pyx_t_10 = ((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_info_hash(__pyx_v_msg, __pyx_t_8, __pyx_t_9); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 1892, __pyx_L1_error)

    /* "btdht/dht.pyx":1893
 *             msg.set_id(id, len(dht.myid))
 *             msg.set_info_hash(info_hash, len(info_hash))
 *             msg.set_port(port)             # <<<<<<<<<<<<<<
 *             msg.set_token(token, len(info_hash))
 *             self._failed+=1
 */
    (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_port(__pyx_v_msg, __pyx_v_port));

    /* "btdht/dht.pyx":1894
 *             msg.set_info_hash(info_hash, len(info_hash))
 *             msg.set_port(port)
 *             msg.set_token(token, len(info_hash))             # <<<<<<<<<<<<<<
 *             self._failed+=1
 *             dht.sendto(msg.encode(), (self.ip, self.port))
 */
    __pyx_t_8 = __Pyx_PyObject_AsWritableString(__pyx_v_token); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(0, 1894, __pyx_L1_error)
    __pyx_t_9 = PyObject_Length(__pyx_v_info_hash); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1894, __pyx_L1_error)
    (void)(((struct __pyx_vtabstruct_5btdht_4krcp_BMessage *)__pyx_v_msg->__pyx_vtab)->set_token(__pyx_v_msg, __pyx_t_8, __pyx_t_9));

    /* "btdht/dht.pyx":1895
 *             msg.set_port(port)
 *             msg.set_token(token, len(info_hash))
 *             self._failed+=1             # <<<<<<<<<<<<<<
 *             dht.sendto(msg.encode(), (self.ip, self.port))
 * 
 */
    __pyx_v_self->_failed = (__pyx_v_self->_failed + 1);

    /* "btdht/dht.pyx":1896
 *             msg.set_token(token, len(info_hash))
 *             self._failed+=1
 *             dht.sendto(msg.encode(), (self.ip, self.port))             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_dht), __pyx_n_s_sendto); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1896, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_msg), __pyx_n_s_encode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1896, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_11 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_11)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_7 = (__pyx_t_11) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_11) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1896, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ip); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1896, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_port); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1896, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1896, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_11);
    __pyx_t_6 = 0;
    __pyx_t_11 = 0;
    __pyx_t_11 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_11)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_t_7, __pyx_t_12};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1896, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_t_7, __pyx_t_12};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1896, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else
    #endif
    {
      __pyx_t_6 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1896, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      if (__pyx_t_11) {
        __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_11); __pyx_t_11 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_10, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_12);
      PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_10, __pyx_t_12);
      __pyx_t_7 = 0;
      __pyx_t_12 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1896, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1882
 *         cdef char* tk
 *         cdef char* ih
 *         if self.id in dht.mytoken and (time.time() - dht.mytoken[self.id][1]) < 600:             # <<<<<<<<<<<<<<
 *             id = dht.myid.value
 *             info_hash = ID.to_bytes(info_hash)
 */
    goto __pyx_L3;
  }

  /* "btdht/dht.pyx":1899
 * 
 *         else:
 *             raise NoTokenError()             # <<<<<<<<<<<<<<
 * 
 * @total_ordering
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_NoTokenError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1899, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1899, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 1899, __pyx_L1_error)
  }
  __pyx_L3:;

  /* "btdht/dht.pyx":1869
 *         dht.sendto(msg.encode(), (self.ip, self.port))
 * 
 *     def announce_peer(self, DHT_BASE dht, info_hash, int port):             # <<<<<<<<<<<<<<
 *         """
 *             Send a announce_peer query to the node
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("btdht.dht.Node.announce_peer", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_id);
  __Pyx_XDECREF(__pyx_v_token);
  __Pyx_XDECREF((PyObject *)__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_info_hash);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_25__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_4Node_25__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_24__reduce_cython__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_24__reduce_cython__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self) {
  PyObject *__pyx_v_state = 0;
  PyObject *__pyx_v__dict = 0;
  int __pyx_v_use_setstate;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__reduce_cython__", 0);

  /* "(tree fragment)":5
 *     cdef object _dict
 *     cdef bint use_setstate
 *     state = (self._failed, self._id, self._ip, self._last_query, self._last_response, self._port)             # <<<<<<<<<<<<<<
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_failed); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_FromString(__pyx_v_self->_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_FromString(__pyx_v_self->_ip); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->_last_query); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->_last_response); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->_port); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyTuple_New(6); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 4, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_7, 5, __pyx_t_6);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_v_state = ((PyObject*)__pyx_t_7);
  __pyx_t_7 = 0;

  /* "(tree fragment)":6
 *     cdef bint use_setstate
 *     state = (self._failed, self._id, self._ip, self._last_query, self._last_response, self._port)
 *     _dict = getattr(self, '__dict__', None)             # <<<<<<<<<<<<<<
 *     if _dict is not None:
 *         state += (_dict,)
 */
  __pyx_t_7 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 6, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_v__dict = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "(tree fragment)":7
 *     state = (self._failed, self._id, self._ip, self._last_query, self._last_response, self._port)
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:             # <<<<<<<<<<<<<<
 *         state += (_dict,)
 *         use_setstate = True
 */
  __pyx_t_8 = (__pyx_v__dict != Py_None);
  __pyx_t_9 = (__pyx_t_8 != 0);
  if (__pyx_t_9) {

    /* "(tree fragment)":8
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:
 *         state += (_dict,)             # <<<<<<<<<<<<<<
 *         use_setstate = True
 *     else:
 */
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 8, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_v__dict);
    __Pyx_GIVEREF(__pyx_v__dict);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v__dict);
    __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 8, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "(tree fragment)":9
 *     if _dict is not None:
 *         state += (_dict,)
 *         use_setstate = True             # <<<<<<<<<<<<<<
 *     else:
 *         use_setstate = False
 */
    __pyx_v_use_setstate = 1;

    /* "(tree fragment)":7
 *     state = (self._failed, self._id, self._ip, self._last_query, self._last_response, self._port)
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:             # <<<<<<<<<<<<<<
 *         state += (_dict,)
 *         use_setstate = True
 */
    goto __pyx_L3;
  }

  /* "(tree fragment)":11
 *         use_setstate = True
 *     else:
 *         use_setstate = False             # <<<<<<<<<<<<<<
 *     if use_setstate:
 *         return __pyx_unpickle_Node, (type(self), 0xe3db725, None), state
 */
  /*else*/ {
    __pyx_v_use_setstate = 0;
  }
  __pyx_L3:;

  /* "(tree fragment)":12
 *     else:
 *         use_setstate = False
 *     if use_setstate:             # <<<<<<<<<<<<<<
 *         return __pyx_unpickle_Node, (type(self), 0xe3db725, None), state
 *     else:
 */
  __pyx_t_9 = (__pyx_v_use_setstate != 0);
  if (__pyx_t_9) {

    /* "(tree fragment)":13
 *         use_setstate = False
 *     if use_setstate:
 *         return __pyx_unpickle_Node, (type(self), 0xe3db725, None), state             # <<<<<<<<<<<<<<
 *     else:
 *         return __pyx_unpickle_Node, (type(self), 0xe3db725, state)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_pyx_unpickle_Node); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_INCREF(__pyx_int_238925605);
    __Pyx_GIVEREF(__pyx_int_238925605);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_int_238925605);
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    PyTuple_SET_ITEM(__pyx_t_7, 2, Py_None);
    __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_7);
    __Pyx_INCREF(__pyx_v_state);
    __Pyx_GIVEREF(__pyx_v_state);
    PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state);
    __pyx_t_6 = 0;
    __pyx_t_7 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "(tree fragment)":12
 *     else:
 *         use_setstate = False
 *     if use_setstate:             # <<<<<<<<<<<<<<
 *         return __pyx_unpickle_Node, (type(self), 0xe3db725, None), state
 *     else:
 */
  }

  /* "(tree fragment)":15
 *         return __pyx_unpickle_Node, (type(self), 0xe3db725, None), state
 *     else:
 *         return __pyx_unpickle_Node, (type(self), 0xe3db725, state)             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     __pyx_unpickle_Node__set_state(self, __pyx_state)
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_Node); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_INCREF(__pyx_int_238925605);
    __Pyx_GIVEREF(__pyx_int_238925605);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_int_238925605);
    __Pyx_INCREF(__pyx_v_state);
    __Pyx_GIVEREF(__pyx_v_state);
    PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_v_state);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_7);
    __pyx_t_5 = 0;
    __pyx_t_7 = 0;
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L0;
  }

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("btdht.dht.Node.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_state);
  __Pyx_XDECREF(__pyx_v__dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_Node, (type(self), 0xe3db725, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_Node__set_state(self, __pyx_state)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_4Node_27__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
static PyObject *__pyx_pw_5btdht_3dht_4Node_27__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_4Node_26__setstate_cython__(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_4Node_26__setstate_cython__(struct __pyx_obj_5btdht_3dht_Node *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setstate_cython__", 0);

  /* "(tree fragment)":17
 *         return __pyx_unpickle_Node, (type(self), 0xe3db725, state)
 * def __setstate_cython__(self, __pyx_state):
 *     __pyx_unpickle_Node__set_state(self, __pyx_state)             # <<<<<<<<<<<<<<
 */
  if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error)
  __pyx_t_1 = __pyx_f_5btdht_3dht___pyx_unpickle_Node__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_Node, (type(self), 0xe3db725, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_Node__set_state(self, __pyx_state)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("btdht.dht.Node.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1921
 * 
 *     @property
 *     def to_refresh(self):             # <<<<<<<<<<<<<<
 *         """``True`` if the bucket need refreshing"""
 *         return time.time() - self.last_changed > 15 * 60
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_1to_refresh(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5btdht_3dht_6Bucket_to_refresh[] = "``True`` if the bucket need refreshing";
static PyMethodDef __pyx_mdef_5btdht_3dht_6Bucket_1to_refresh = {"to_refresh", (PyCFunction)__pyx_pw_5btdht_3dht_6Bucket_1to_refresh, METH_O, __pyx_doc_5btdht_3dht_6Bucket_to_refresh};
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_1to_refresh(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("to_refresh (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_6Bucket_to_refresh(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_6Bucket_to_refresh(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("to_refresh", 0);

  /* "btdht/dht.pyx":1923
 *     def to_refresh(self):
 *         """``True`` if the bucket need refreshing"""
 *         return time.time() - self.last_changed > 15 * 60             # <<<<<<<<<<<<<<
 * 
 *     __slot__ = ("id", "id_length")
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1923, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1923, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1923, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_last_changed); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1923, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyNumber_Subtract(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1923, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, __pyx_int_900, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1923, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":1921
 * 
 *     @property
 *     def to_refresh(self):             # <<<<<<<<<<<<<<
 *         """``True`` if the bucket need refreshing"""
 *         return time.time() - self.last_changed > 15 * 60
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("btdht.dht.Bucket.to_refresh", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1927
 *     __slot__ = ("id", "id_length")
 * 
 *     def own(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             :param bytes id: A 60bit (20 Bytes) identifier
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_3own(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_6Bucket_2own[] = "\n            :param bytes id: A 60bit (20 Bytes) identifier\n            :return: ``True`` if ``id`` is handled by this bucket\n            :rtype: bool\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_6Bucket_3own = {"own", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_6Bucket_3own, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_6Bucket_2own};
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_3own(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_id = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("own (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_id,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("own", 1, 2, 2, 1); __PYX_ERR(0, 1927, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "own") < 0)) __PYX_ERR(0, 1927, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_self = values[0];
    __pyx_v_id = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("own", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1927, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Bucket.own", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_6Bucket_2own(__pyx_self, __pyx_v_self, __pyx_v_id);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_6Bucket_2own(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id) {
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_e = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  Py_ssize_t __pyx_t_11;
  PyObject *(*__pyx_t_12)(PyObject *);
  int __pyx_t_13;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("own", 0);

  /* "btdht/dht.pyx":1933
 *             :rtype: bool
 *         """
 *         if not self.id:             # <<<<<<<<<<<<<<
 *             return True
 *         if id.startswith(self.id[:self.id_length//8]):
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1933, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 1933, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":1934
 *         """
 *         if not self.id:
 *             return True             # <<<<<<<<<<<<<<
 *         if id.startswith(self.id[:self.id_length//8]):
 *             i=-1
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_True);
    __pyx_r = Py_True;
    goto __pyx_L0;

    /* "btdht/dht.pyx":1933
 *             :rtype: bool
 *         """
 *         if not self.id:             # <<<<<<<<<<<<<<
 *             return True
 *         if id.startswith(self.id[:self.id_length//8]):
 */
  }

  /* "btdht/dht.pyx":1935
 *         if not self.id:
 *             return True
 *         if id.startswith(self.id[:self.id_length//8]):             # <<<<<<<<<<<<<<
 *             i=-1
 *             try:
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_id, __pyx_n_s_startswith); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyInt_FloorDivideObjC(__pyx_t_6, __pyx_int_8, 8, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetSlice(__pyx_t_5, 0, 0, NULL, &__pyx_t_7, NULL, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_1 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1935, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":1936
 *             return True
 *         if id.startswith(self.id[:self.id_length//8]):
 *             i=-1             # <<<<<<<<<<<<<<
 *             try:
 *                 for i in range(self.id_length//8*8, self.id_length):
 */
    __Pyx_INCREF(__pyx_int_neg_1);
    __pyx_v_i = __pyx_int_neg_1;

    /* "btdht/dht.pyx":1937
 *         if id.startswith(self.id[:self.id_length//8]):
 *             i=-1
 *             try:             # <<<<<<<<<<<<<<
 *                 for i in range(self.id_length//8*8, self.id_length):
 *                     if nbit(self.id, i) !=  nbit(id, i):
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      __Pyx_XGOTREF(__pyx_t_8);
      __Pyx_XGOTREF(__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_10);
      /*try:*/ {

        /* "btdht/dht.pyx":1938
 *             i=-1
 *             try:
 *                 for i in range(self.id_length//8*8, self.id_length):             # <<<<<<<<<<<<<<
 *                     if nbit(self.id, i) !=  nbit(id, i):
 *                         return False
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1938, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = __Pyx_PyInt_FloorDivideObjC(__pyx_t_1, __pyx_int_8, 8, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1938, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyNumber_Multiply(__pyx_t_4, __pyx_int_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1938, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1938, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1938, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_4);
        __pyx_t_1 = 0;
        __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1938, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
          __pyx_t_6 = __pyx_t_4; __Pyx_INCREF(__pyx_t_6); __pyx_t_11 = 0;
          __pyx_t_12 = NULL;
        } else {
          __pyx_t_11 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1938, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_12 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1938, __pyx_L5_error)
        }
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        for (;;) {
          if (likely(!__pyx_t_12)) {
            if (likely(PyList_CheckExact(__pyx_t_6))) {
              if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_6)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_4 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_11); __Pyx_INCREF(__pyx_t_4); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1938, __pyx_L5_error)
              #else
              __pyx_t_4 = PySequence_ITEM(__pyx_t_6, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1938, __pyx_L5_error)
              __Pyx_GOTREF(__pyx_t_4);
              #endif
            } else {
              if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_11); __Pyx_INCREF(__pyx_t_4); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1938, __pyx_L5_error)
              #else
              __pyx_t_4 = PySequence_ITEM(__pyx_t_6, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1938, __pyx_L5_error)
              __Pyx_GOTREF(__pyx_t_4);
              #endif
            }
          } else {
            __pyx_t_4 = __pyx_t_12(__pyx_t_6);
            if (unlikely(!__pyx_t_4)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 1938, __pyx_L5_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_4);
          }
          __Pyx_DECREF_SET(__pyx_v_i, __pyx_t_4);
          __pyx_t_4 = 0;

          /* "btdht/dht.pyx":1939
 *             try:
 *                 for i in range(self.id_length//8*8, self.id_length):
 *                     if nbit(self.id, i) !=  nbit(id, i):             # <<<<<<<<<<<<<<
 *                         return False
 *                 return True
 */
          __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_nbit); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1939, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1939, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_5 = NULL;
          __pyx_t_13 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
            if (likely(__pyx_t_5)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
              __Pyx_INCREF(__pyx_t_5);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_1, function);
              __pyx_t_13 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_1)) {
            PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_7, __pyx_v_i};
            __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1939, __pyx_L5_error)
            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
            PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_7, __pyx_v_i};
            __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1939, __pyx_L5_error)
            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          } else
          #endif
          {
            __pyx_t_14 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1939, __pyx_L5_error)
            __Pyx_GOTREF(__pyx_t_14);
            if (__pyx_t_5) {
              __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_5); __pyx_t_5 = NULL;
            }
            __Pyx_GIVEREF(__pyx_t_7);
            PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_13, __pyx_t_7);
            __Pyx_INCREF(__pyx_v_i);
            __Pyx_GIVEREF(__pyx_v_i);
            PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_13, __pyx_v_i);
            __pyx_t_7 = 0;
            __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_14, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1939, __pyx_L5_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          }
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_nbit); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1939, __pyx_L5_error)
          __Pyx_GOTREF(__pyx_t_14);
          __pyx_t_7 = NULL;
          __pyx_t_13 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) {
            __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_14);
            if (likely(__pyx_t_7)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
              __Pyx_INCREF(__pyx_t_7);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_14, function);
              __pyx_t_13 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_14)) {
            PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_id, __pyx_v_i};
            __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1939, __pyx_L5_error)
            __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_GOTREF(__pyx_t_1);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) {
            PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_id, __pyx_v_i};
            __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1939, __pyx_L5_error)
            __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_GOTREF(__pyx_t_1);
          } else
          #endif
          {
            __pyx_t_5 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1939, __pyx_L5_error)
            __Pyx_GOTREF(__pyx_t_5);
            if (__pyx_t_7) {
              __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7); __pyx_t_7 = NULL;
            }
            __Pyx_INCREF(__pyx_v_id);
            __Pyx_GIVEREF(__pyx_v_id);
            PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_13, __pyx_v_id);
            __Pyx_INCREF(__pyx_v_i);
            __Pyx_GIVEREF(__pyx_v_i);
            PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_13, __pyx_v_i);
            __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1939, __pyx_L5_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __pyx_t_14 = PyObject_RichCompare(__pyx_t_4, __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_14); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1939, __pyx_L5_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 1939, __pyx_L5_error)
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          if (__pyx_t_3) {

            /* "btdht/dht.pyx":1940
 *                 for i in range(self.id_length//8*8, self.id_length):
 *                     if nbit(self.id, i) !=  nbit(id, i):
 *                         return False             # <<<<<<<<<<<<<<
 *                 return True
 *             except IndexError as e:
 */
            __Pyx_XDECREF(__pyx_r);
            __Pyx_INCREF(Py_False);
            __pyx_r = Py_False;
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            goto __pyx_L9_try_return;

            /* "btdht/dht.pyx":1939
 *             try:
 *                 for i in range(self.id_length//8*8, self.id_length):
 *                     if nbit(self.id, i) !=  nbit(id, i):             # <<<<<<<<<<<<<<
 *                         return False
 *                 return True
 */
          }

          /* "btdht/dht.pyx":1938
 *             i=-1
 *             try:
 *                 for i in range(self.id_length//8*8, self.id_length):             # <<<<<<<<<<<<<<
 *                     if nbit(self.id, i) !=  nbit(id, i):
 *                         return False
 */
        }
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "btdht/dht.pyx":1941
 *                     if nbit(self.id, i) !=  nbit(id, i):
 *                         return False
 *                 return True             # <<<<<<<<<<<<<<
 *             except IndexError as e:
 *                 print(
 */
        __Pyx_XDECREF(__pyx_r);
        __Pyx_INCREF(Py_True);
        __pyx_r = Py_True;
        goto __pyx_L9_try_return;

        /* "btdht/dht.pyx":1937
 *         if id.startswith(self.id[:self.id_length//8]):
 *             i=-1
 *             try:             # <<<<<<<<<<<<<<
 *                 for i in range(self.id_length//8*8, self.id_length):
 *                     if nbit(self.id, i) !=  nbit(id, i):
 */
      }
      __pyx_L5_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "btdht/dht.pyx":1942
 *                         return False
 *                 return True
 *             except IndexError as e:             # <<<<<<<<<<<<<<
 *                 print(
 *                     "%r i:%s selfid:%s:%s:%r nodeid:%d:%r %r" % (
 */
      __pyx_t_13 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_IndexError);
      if (__pyx_t_13) {
        __Pyx_AddTraceback("btdht.dht.Bucket.own", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_14, &__pyx_t_1) < 0) __PYX_ERR(0, 1942, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_14);
        __pyx_v_e = __pyx_t_14;

        /* "btdht/dht.pyx":1945
 *                 print(
 *                     "%r i:%s selfid:%s:%s:%r nodeid:%d:%r %r" % (
 *                         e, i, len(self.id), self.id_length, self.id, len(id), id, self             # <<<<<<<<<<<<<<
 *                     )
 *                 )
 */
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1945, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_11 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1945, __pyx_L7_except_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1945, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1945, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1945, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_11 = PyObject_Length(__pyx_v_id); if (unlikely(__pyx_t_11 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1945, __pyx_L7_except_error)
        __pyx_t_15 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1945, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_15);
        __pyx_t_16 = PyTuple_New(8); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1945, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_INCREF(__pyx_v_e);
        __Pyx_GIVEREF(__pyx_v_e);
        PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_v_e);
        __Pyx_INCREF(__pyx_v_i);
        __Pyx_GIVEREF(__pyx_v_i);
        PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_v_i);
        __Pyx_GIVEREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_16, 2, __pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_16, 3, __pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_16, 4, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_15);
        PyTuple_SET_ITEM(__pyx_t_16, 5, __pyx_t_15);
        __Pyx_INCREF(__pyx_v_id);
        __Pyx_GIVEREF(__pyx_v_id);
        PyTuple_SET_ITEM(__pyx_t_16, 6, __pyx_v_id);
        __Pyx_INCREF(__pyx_v_self);
        __Pyx_GIVEREF(__pyx_v_self);
        PyTuple_SET_ITEM(__pyx_t_16, 7, __pyx_v_self);
        __pyx_t_4 = 0;
        __pyx_t_5 = 0;
        __pyx_t_7 = 0;
        __pyx_t_15 = 0;

        /* "btdht/dht.pyx":1944
 *             except IndexError as e:
 *                 print(
 *                     "%r i:%s selfid:%s:%s:%r nodeid:%d:%r %r" % (             # <<<<<<<<<<<<<<
 *                         e, i, len(self.id), self.id_length, self.id, len(id), id, self
 *                     )
 */
        __pyx_t_15 = __Pyx_PyString_Format(__pyx_kp_s_r_i_s_selfid_s_s_r_nodeid_d_r_r, __pyx_t_16); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1944, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        if (__Pyx_PrintOne(0, __pyx_t_15) < 0) __PYX_ERR(0, 1943, __pyx_L7_except_error)
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

        /* "btdht/dht.pyx":1948
 *                     )
 *                 )
 *                 return False             # <<<<<<<<<<<<<<
 *         else:
 *             return False
 */
        __Pyx_XDECREF(__pyx_r);
        __Pyx_INCREF(Py_False);
        __pyx_r = Py_False;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        goto __pyx_L8_except_return;
      }
      goto __pyx_L7_except_error;
      __pyx_L7_except_error:;

      /* "btdht/dht.pyx":1937
 *         if id.startswith(self.id[:self.id_length//8]):
 *             i=-1
 *             try:             # <<<<<<<<<<<<<<
 *                 for i in range(self.id_length//8*8, self.id_length):
 *                     if nbit(self.id, i) !=  nbit(id, i):
 */
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      goto __pyx_L1_error;
      __pyx_L9_try_return:;
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      goto __pyx_L0;
      __pyx_L8_except_return:;
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_XGIVEREF(__pyx_t_10);
      __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      goto __pyx_L0;
    }

    /* "btdht/dht.pyx":1935
 *         if not self.id:
 *             return True
 *         if id.startswith(self.id[:self.id_length//8]):             # <<<<<<<<<<<<<<
 *             i=-1
 *             try:
 */
  }

  /* "btdht/dht.pyx":1950
 *                 return False
 *         else:
 *             return False             # <<<<<<<<<<<<<<
 * 
 *     def __init__(self, id=b"", id_length=0, init=None):
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_False);
    __pyx_r = Py_False;
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":1927
 *     __slot__ = ("id", "id_length")
 * 
 *     def own(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             :param bytes id: A 60bit (20 Bytes) identifier
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("btdht.dht.Bucket.own", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_e);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1952
 *             return False
 * 
 *     def __init__(self, id=b"", id_length=0, init=None):             # <<<<<<<<<<<<<<
 *         self.id = id
 *         self.id_length = id_length # en bit
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_5__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5btdht_3dht_6Bucket_5__init__ = {"__init__", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_6Bucket_5__init__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_5__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_id = 0;
  PyObject *__pyx_v_id_length = 0;
  PyObject *__pyx_v_init = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_id,&__pyx_n_s_id_length,&__pyx_n_s_init,0};
    PyObject* values[4] = {0,0,0,0};
    values[1] = ((PyObject *)((PyObject*)__pyx_kp_b__2));
    values[2] = ((PyObject *)((PyObject *)__pyx_int_0));
    values[3] = ((PyObject *)((PyObject *)Py_None));
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id);
          if (value) { values[1] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id_length);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_init);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 1952, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_self = values[0];
    __pyx_v_id = values[1];
    __pyx_v_id_length = values[2];
    __pyx_v_init = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1952, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Bucket.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_6Bucket_4__init__(__pyx_self, __pyx_v_self, __pyx_v_id, __pyx_v_id_length, __pyx_v_init);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_6Bucket_4__init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id, PyObject *__pyx_v_id_length, PyObject *__pyx_v_init) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "btdht/dht.pyx":1953
 * 
 *     def __init__(self, id=b"", id_length=0, init=None):
 *         self.id = id             # <<<<<<<<<<<<<<
 *         self.id_length = id_length # en bit
 *         if init:
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_id, __pyx_v_id) < 0) __PYX_ERR(0, 1953, __pyx_L1_error)

  /* "btdht/dht.pyx":1954
 *     def __init__(self, id=b"", id_length=0, init=None):
 *         self.id = id
 *         self.id_length = id_length # en bit             # <<<<<<<<<<<<<<
 *         if init:
 *             super(Bucket, self).__init__(init)
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_id_length, __pyx_v_id_length) < 0) __PYX_ERR(0, 1954, __pyx_L1_error)

  /* "btdht/dht.pyx":1955
 *         self.id = id
 *         self.id_length = id_length # en bit
 *         if init:             # <<<<<<<<<<<<<<
 *             super(Bucket, self).__init__(init)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_init); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1955, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "btdht/dht.pyx":1956
 *         self.id_length = id_length # en bit
 *         if init:
 *             super(Bucket, self).__init__(init)             # <<<<<<<<<<<<<<
 * 
 *     def random_id(self):
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_Bucket); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1956, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1956, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_INCREF(__pyx_v_self);
    __Pyx_GIVEREF(__pyx_v_self);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_self);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1956, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_init_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1956, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_init) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_init);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1956, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "btdht/dht.pyx":1955
 *         self.id = id
 *         self.id_length = id_length # en bit
 *         if init:             # <<<<<<<<<<<<<<
 *             super(Bucket, self).__init__(init)
 * 
 */
  }

  /* "btdht/dht.pyx":1952
 *             return False
 * 
 *     def __init__(self, id=b"", id_length=0, init=None):             # <<<<<<<<<<<<<<
 *         self.id = id
 *         self.id_length = id_length # en bit
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("btdht.dht.Bucket.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1958
 *             super(Bucket, self).__init__(init)
 * 
 *     def random_id(self):             # <<<<<<<<<<<<<<
 *         """
 *             :return: A random id handle by the bucket
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_7random_id(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5btdht_3dht_6Bucket_6random_id[] = "\n            :return: A random id handle by the bucket\n            :rtype: bytes\n\n            This is used to send find_nodes for randoms ids in a bucket\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_6Bucket_7random_id = {"random_id", (PyCFunction)__pyx_pw_5btdht_3dht_6Bucket_7random_id, METH_O, __pyx_doc_5btdht_3dht_6Bucket_6random_id};
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_7random_id(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("random_id (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_6Bucket_6random_id(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_6Bucket_6random_id(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_v_id = NULL;
  PyObject *__pyx_v_id_length = NULL;
  PyObject *__pyx_v_id_end = NULL;
  PyObject *__pyx_v_tmp = NULL;
  PyObject *__pyx_v_id_start = NULL;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_char = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  Py_ssize_t __pyx_t_9;
  PyObject *(*__pyx_t_10)(PyObject *);
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("random_id", 0);

  /* "btdht/dht.pyx":1965
 *             This is used to send find_nodes for randoms ids in a bucket
 *         """
 *         id = ID()             # <<<<<<<<<<<<<<
 *         id_length = self.id_length
 *         id_end = bytes(bytearray((id[id_length//8],)))
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ID); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1965, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1965, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_id = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1966
 *         """
 *         id = ID()
 *         id_length = self.id_length             # <<<<<<<<<<<<<<
 *         id_end = bytes(bytearray((id[id_length//8],)))
 *         tmp = ''
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1966, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_id_length = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1967
 *         id = ID()
 *         id_length = self.id_length
 *         id_end = bytes(bytearray((id[id_length//8],)))             # <<<<<<<<<<<<<<
 *         tmp = ''
 *         if id_length>0:
 */
  __pyx_t_1 = __Pyx_PyInt_FloorDivideObjC(__pyx_v_id_length, __pyx_int_8, 8, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_id, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyByteArray_Type)), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_id_end = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1968
 *         id_length = self.id_length
 *         id_end = bytes(bytearray((id[id_length//8],)))
 *         tmp = ''             # <<<<<<<<<<<<<<
 *         if id_length>0:
 *             try:
 */
  __Pyx_INCREF(__pyx_kp_s__2);
  __pyx_v_tmp = __pyx_kp_s__2;

  /* "btdht/dht.pyx":1969
 *         id_end = bytes(bytearray((id[id_length//8],)))
 *         tmp = ''
 *         if id_length>0:             # <<<<<<<<<<<<<<
 *             try:
 *                id_start = bytes(bytearray((self.id[id_length//8],)))
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_id_length, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1969, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1969, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_4) {

    /* "btdht/dht.pyx":1970
 *         tmp = ''
 *         if id_length>0:
 *             try:             # <<<<<<<<<<<<<<
 *                id_start = bytes(bytearray((self.id[id_length//8],)))
 *             except IndexError:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_6);
      __Pyx_XGOTREF(__pyx_t_7);
      /*try:*/ {

        /* "btdht/dht.pyx":1971
 *         if id_length>0:
 *             try:
 *                id_start = bytes(bytearray((self.id[id_length//8],)))             # <<<<<<<<<<<<<<
 *             except IndexError:
 *                 id_start = b"\0"
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1971, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_2 = __Pyx_PyInt_FloorDivideObjC(__pyx_v_id_length, __pyx_int_8, 8, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1971, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1971, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1971, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
        __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyByteArray_Type)), __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1971, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1971, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_v_id_start = ((PyObject*)__pyx_t_2);
        __pyx_t_2 = 0;

        /* "btdht/dht.pyx":1970
 *         tmp = ''
 *         if id_length>0:
 *             try:             # <<<<<<<<<<<<<<
 *                id_start = bytes(bytearray((self.id[id_length//8],)))
 *             except IndexError:
 */
      }
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L9_try_end;
      __pyx_L4_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "btdht/dht.pyx":1972
 *             try:
 *                id_start = bytes(bytearray((self.id[id_length//8],)))
 *             except IndexError:             # <<<<<<<<<<<<<<
 *                 id_start = b"\0"
 *             for i in range((id_length % 8)):
 */
      __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_IndexError);
      if (__pyx_t_8) {
        __Pyx_AddTraceback("btdht.dht.Bucket.random_id", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_3, &__pyx_t_1) < 0) __PYX_ERR(0, 1972, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GOTREF(__pyx_t_1);

        /* "btdht/dht.pyx":1973
 *                id_start = bytes(bytearray((self.id[id_length//8],)))
 *             except IndexError:
 *                 id_start = b"\0"             # <<<<<<<<<<<<<<
 *             for i in range((id_length % 8)):
 *                 tmp += '1' if nbit(id_start, i) == 1 else '0'
 */
        __Pyx_INCREF(__pyx_kp_b__30);
        __Pyx_XDECREF_SET(__pyx_v_id_start, __pyx_kp_b__30);
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L5_exception_handled;
      }
      goto __pyx_L6_except_error;
      __pyx_L6_except_error:;

      /* "btdht/dht.pyx":1970
 *         tmp = ''
 *         if id_length>0:
 *             try:             # <<<<<<<<<<<<<<
 *                id_start = bytes(bytearray((self.id[id_length//8],)))
 *             except IndexError:
 */
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      goto __pyx_L1_error;
      __pyx_L5_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_5);
      __Pyx_XGIVEREF(__pyx_t_6);
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
      __pyx_L9_try_end:;
    }

    /* "btdht/dht.pyx":1974
 *             except IndexError:
 *                 id_start = b"\0"
 *             for i in range((id_length % 8)):             # <<<<<<<<<<<<<<
 *                 tmp += '1' if nbit(id_start, i) == 1 else '0'
 *         for i in range((id_length % 8), 8):
 */
    __pyx_t_1 = __Pyx_PyInt_RemainderObjC(__pyx_v_id_length, __pyx_int_8, 8, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1974, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1974, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
      __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_9 = 0;
      __pyx_t_10 = NULL;
    } else {
      __pyx_t_9 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1974, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_10 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1974, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    for (;;) {
      if (likely(!__pyx_t_10)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1974, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1974, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        } else {
          if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1974, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1974, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        }
      } else {
        __pyx_t_3 = __pyx_t_10(__pyx_t_1);
        if (unlikely(!__pyx_t_3)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1974, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "btdht/dht.pyx":1975
 *                 id_start = b"\0"
 *             for i in range((id_length % 8)):
 *                 tmp += '1' if nbit(id_start, i) == 1 else '0'             # <<<<<<<<<<<<<<
 *         for i in range((id_length % 8), 8):
 *             tmp += '1' if nbit(id_end, i) == 1 else '0'
 */
      __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_nbit); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1975, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_12 = NULL;
      __pyx_t_8 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
        __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
        if (likely(__pyx_t_12)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_12);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_11, function);
          __pyx_t_8 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_v_id_start, __pyx_v_i};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1975, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_v_id_start, __pyx_v_i};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1975, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else
      #endif
      {
        __pyx_t_13 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1975, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        if (__pyx_t_12) {
          __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_12); __pyx_t_12 = NULL;
        }
        __Pyx_INCREF(__pyx_v_id_start);
        __Pyx_GIVEREF(__pyx_v_id_start);
        PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_8, __pyx_v_id_start);
        __Pyx_INCREF(__pyx_v_i);
        __Pyx_GIVEREF(__pyx_v_i);
        PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_8, __pyx_v_i);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1975, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      }
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_11 = __Pyx_PyInt_EqObjC(__pyx_t_2, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1975, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1975, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      if (__pyx_t_4) {
        __Pyx_INCREF(__pyx_kp_s_1);
        __pyx_t_3 = __pyx_kp_s_1;
      } else {
        __Pyx_INCREF(__pyx_kp_s_0);
        __pyx_t_3 = __pyx_kp_s_0;
      }
      __pyx_t_11 = PyNumber_InPlaceAdd(__pyx_v_tmp, __pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1975, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF_SET(__pyx_v_tmp, __pyx_t_11);
      __pyx_t_11 = 0;

      /* "btdht/dht.pyx":1974
 *             except IndexError:
 *                 id_start = b"\0"
 *             for i in range((id_length % 8)):             # <<<<<<<<<<<<<<
 *                 tmp += '1' if nbit(id_start, i) == 1 else '0'
 *         for i in range((id_length % 8), 8):
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1969
 *         id_end = bytes(bytearray((id[id_length//8],)))
 *         tmp = ''
 *         if id_length>0:             # <<<<<<<<<<<<<<
 *             try:
 *                id_start = bytes(bytearray((self.id[id_length//8],)))
 */
  }

  /* "btdht/dht.pyx":1976
 *             for i in range((id_length % 8)):
 *                 tmp += '1' if nbit(id_start, i) == 1 else '0'
 *         for i in range((id_length % 8), 8):             # <<<<<<<<<<<<<<
 *             tmp += '1' if nbit(id_end, i) == 1 else '0'
 *         try:
 */
  __pyx_t_1 = __Pyx_PyInt_RemainderObjC(__pyx_v_id_length, __pyx_int_8, 8, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1976, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1976, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_1);
  __Pyx_INCREF(__pyx_int_8);
  __Pyx_GIVEREF(__pyx_int_8);
  PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_int_8);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1976, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_11 = __pyx_t_1; __Pyx_INCREF(__pyx_t_11); __pyx_t_9 = 0;
    __pyx_t_10 = NULL;
  } else {
    __pyx_t_9 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1976, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_10 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1976, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_10)) {
      if (likely(PyList_CheckExact(__pyx_t_11))) {
        if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_11)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1976, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_11, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1976, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_11)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 1976, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_11, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1976, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_10(__pyx_t_11);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1976, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "btdht/dht.pyx":1977
 *                 tmp += '1' if nbit(id_start, i) == 1 else '0'
 *         for i in range((id_length % 8), 8):
 *             tmp += '1' if nbit(id_end, i) == 1 else '0'             # <<<<<<<<<<<<<<
 *         try:
 *             char = bytes(bytearray((int(tmp, 2),)))
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_nbit); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_13 = NULL;
    __pyx_t_8 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_13)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_13);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_8 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_id_end, __pyx_v_i};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1977, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_id_end, __pyx_v_i};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1977, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    {
      __pyx_t_12 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1977, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      if (__pyx_t_13) {
        __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_13); __pyx_t_13 = NULL;
      }
      __Pyx_INCREF(__pyx_v_id_end);
      __Pyx_GIVEREF(__pyx_v_id_end);
      PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_8, __pyx_v_id_end);
      __Pyx_INCREF(__pyx_v_i);
      __Pyx_GIVEREF(__pyx_v_i);
      PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_8, __pyx_v_i);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1977, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_4) {
      __Pyx_INCREF(__pyx_kp_s_1);
      __pyx_t_1 = __pyx_kp_s_1;
    } else {
      __Pyx_INCREF(__pyx_kp_s_0);
      __pyx_t_1 = __pyx_kp_s_0;
    }
    __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_v_tmp, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1977, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_tmp, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "btdht/dht.pyx":1976
 *             for i in range((id_length % 8)):
 *                 tmp += '1' if nbit(id_start, i) == 1 else '0'
 *         for i in range((id_length % 8), 8):             # <<<<<<<<<<<<<<
 *             tmp += '1' if nbit(id_end, i) == 1 else '0'
 *         try:
 */
  }
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

  /* "btdht/dht.pyx":1978
 *         for i in range((id_length % 8), 8):
 *             tmp += '1' if nbit(id_end, i) == 1 else '0'
 *         try:             # <<<<<<<<<<<<<<
 *             char = bytes(bytearray((int(tmp, 2),)))
 *         except ValueError:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_6, &__pyx_t_5);
    __Pyx_XGOTREF(__pyx_t_7);
    __Pyx_XGOTREF(__pyx_t_6);
    __Pyx_XGOTREF(__pyx_t_5);
    /*try:*/ {

      /* "btdht/dht.pyx":1979
 *             tmp += '1' if nbit(id_end, i) == 1 else '0'
 *         try:
 *             char = bytes(bytearray((int(tmp, 2),)))             # <<<<<<<<<<<<<<
 *         except ValueError:
 *             print(tmp)
 */
      __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1979, __pyx_L16_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_INCREF(__pyx_v_tmp);
      __Pyx_GIVEREF(__pyx_v_tmp);
      PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_tmp);
      __Pyx_INCREF(__pyx_int_2);
      __Pyx_GIVEREF(__pyx_int_2);
      PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_int_2);
      __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&PyInt_Type)), __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1979, __pyx_L16_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1979, __pyx_L16_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyByteArray_Type)), __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1979, __pyx_L16_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_11 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1979, __pyx_L16_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_char = ((PyObject*)__pyx_t_11);
      __pyx_t_11 = 0;

      /* "btdht/dht.pyx":1978
 *         for i in range((id_length % 8), 8):
 *             tmp += '1' if nbit(id_end, i) == 1 else '0'
 *         try:             # <<<<<<<<<<<<<<
 *             char = bytes(bytearray((int(tmp, 2),)))
 *         except ValueError:
 */
    }
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L21_try_end;
    __pyx_L16_error:;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":1980
 *         try:
 *             char = bytes(bytearray((int(tmp, 2),)))
 *         except ValueError:             # <<<<<<<<<<<<<<
 *             print(tmp)
 *             raise
 */
    __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
    if (__pyx_t_8) {
      __Pyx_AddTraceback("btdht.dht.Bucket.random_id", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_11, &__pyx_t_2, &__pyx_t_1) < 0) __PYX_ERR(0, 1980, __pyx_L18_except_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GOTREF(__pyx_t_1);

      /* "btdht/dht.pyx":1981
 *             char = bytes(bytearray((int(tmp, 2),)))
 *         except ValueError:
 *             print(tmp)             # <<<<<<<<<<<<<<
 *             raise
 *         return ID(self.id[0:id_length//8] + char + id[id_length//8+1:])
 */
      if (__Pyx_PrintOne(0, __pyx_v_tmp) < 0) __PYX_ERR(0, 1981, __pyx_L18_except_error)

      /* "btdht/dht.pyx":1982
 *         except ValueError:
 *             print(tmp)
 *             raise             # <<<<<<<<<<<<<<
 *         return ID(self.id[0:id_length//8] + char + id[id_length//8+1:])
 * 
 */
      __Pyx_GIVEREF(__pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_2);
      __Pyx_XGIVEREF(__pyx_t_1);
      __Pyx_ErrRestoreWithState(__pyx_t_11, __pyx_t_2, __pyx_t_1);
      __pyx_t_11 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; 
      __PYX_ERR(0, 1982, __pyx_L18_except_error)
    }
    goto __pyx_L18_except_error;
    __pyx_L18_except_error:;

    /* "btdht/dht.pyx":1978
 *         for i in range((id_length % 8), 8):
 *             tmp += '1' if nbit(id_end, i) == 1 else '0'
 *         try:             # <<<<<<<<<<<<<<
 *             char = bytes(bytearray((int(tmp, 2),)))
 *         except ValueError:
 */
    __Pyx_XGIVEREF(__pyx_t_7);
    __Pyx_XGIVEREF(__pyx_t_6);
    __Pyx_XGIVEREF(__pyx_t_5);
    __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_6, __pyx_t_5);
    goto __pyx_L1_error;
    __pyx_L21_try_end:;
  }

  /* "btdht/dht.pyx":1983
 *             print(tmp)
 *             raise
 *         return ID(self.id[0:id_length//8] + char + id[id_length//8+1:])             # <<<<<<<<<<<<<<
 * 
 *     def get_node(self, id):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ID); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_3 = __Pyx_PyInt_FloorDivideObjC(__pyx_v_id_length, __pyx_int_8, 8, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_12 = __Pyx_PyObject_GetSlice(__pyx_t_11, 0, 0, NULL, &__pyx_t_3, NULL, 1, 0, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Add(__pyx_t_12, __pyx_v_char); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_12 = __Pyx_PyInt_FloorDivideObjC(__pyx_v_id_length, __pyx_int_8, 8, 0, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_11 = __Pyx_PyInt_AddObjC(__pyx_t_12, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_12 = __Pyx_PyObject_GetSlice(__pyx_v_id, 0, 0, &__pyx_t_11, NULL, NULL, 0, 0, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = PyNumber_Add(__pyx_t_3, __pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_12 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_12)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_12);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_12, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1983, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":1958
 *             super(Bucket, self).__init__(init)
 * 
 *     def random_id(self):             # <<<<<<<<<<<<<<
 *         """
 *             :return: A random id handle by the bucket
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("btdht.dht.Bucket.random_id", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_id);
  __Pyx_XDECREF(__pyx_v_id_length);
  __Pyx_XDECREF(__pyx_v_id_end);
  __Pyx_XDECREF(__pyx_v_tmp);
  __Pyx_XDECREF(__pyx_v_id_start);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_char);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1985
 *         return ID(self.id[0:id_length//8] + char + id[id_length//8+1:])
 * 
 *     def get_node(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             :return: A :class:`Node` with :attr:`Node.id` equal to ``id``
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_9get_node(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_6Bucket_8get_node[] = "\n            :return: A :class:`Node` with :attr:`Node.id` equal to ``id``\n            :rtype: Node\n            :raises NotFound: if no node is found within this bucket\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_6Bucket_9get_node = {"get_node", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_6Bucket_9get_node, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_6Bucket_8get_node};
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_9get_node(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_id = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_node (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_id,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_node", 1, 2, 2, 1); __PYX_ERR(0, 1985, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_node") < 0)) __PYX_ERR(0, 1985, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_self = values[0];
    __pyx_v_id = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_node", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1985, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Bucket.get_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_6Bucket_8get_node(__pyx_self, __pyx_v_self, __pyx_v_id);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_6Bucket_8get_node(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id) {
  PyObject *__pyx_v_n = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *(*__pyx_t_3)(PyObject *);
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_node", 0);

  /* "btdht/dht.pyx":1991
 *             :raises NotFound: if no node is found within this bucket
 *         """
 *         for n in self:             # <<<<<<<<<<<<<<
 *             if n.id == id:
 *                 return n
 */
  if (likely(PyList_CheckExact(__pyx_v_self)) || PyTuple_CheckExact(__pyx_v_self)) {
    __pyx_t_1 = __pyx_v_self; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1991, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1991, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1991, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1991, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 1991, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1991, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1991, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_n, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "btdht/dht.pyx":1992
 *         """
 *         for n in self:
 *             if n.id == id:             # <<<<<<<<<<<<<<
 *                 return n
 *         raise NotFound()
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_n, __pyx_n_s_id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1992, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_v_id, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1992, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 1992, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_6) {

      /* "btdht/dht.pyx":1993
 *         for n in self:
 *             if n.id == id:
 *                 return n             # <<<<<<<<<<<<<<
 *         raise NotFound()
 * 
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_n);
      __pyx_r = __pyx_v_n;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;

      /* "btdht/dht.pyx":1992
 *         """
 *         for n in self:
 *             if n.id == id:             # <<<<<<<<<<<<<<
 *                 return n
 *         raise NotFound()
 */
    }

    /* "btdht/dht.pyx":1991
 *             :raises NotFound: if no node is found within this bucket
 *         """
 *         for n in self:             # <<<<<<<<<<<<<<
 *             if n.id == id:
 *                 return n
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":1994
 *             if n.id == id:
 *                 return n
 *         raise NotFound()             # <<<<<<<<<<<<<<
 * 
 *     def add(self, dht, node):
 */
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_NotFound); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1994, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1994, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(0, 1994, __pyx_L1_error)

  /* "btdht/dht.pyx":1985
 *         return ID(self.id[0:id_length//8] + char + id[id_length//8+1:])
 * 
 *     def get_node(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             :return: A :class:`Node` with :attr:`Node.id` equal to ``id``
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("btdht.dht.Bucket.get_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":1996
 *         raise NotFound()
 * 
 *     def add(self, dht, node):             # <<<<<<<<<<<<<<
 *         """
 *             Try to add a node to the bucket.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_11add(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_6Bucket_10add[] = "\n            Try to add a node to the bucket.\n\n            :param DHT_BASE dht: The dht instance the node to add is from\n            :param Node node: A node to add to the bucket\n            :raises BucketFull: if the bucket is full\n\n            Notes:\n                The addition of a node to a bucket is done as follow:\n                * if the bucket is not full, just add the node\n                * if the bucket is full\n                    * if there is some bad nodes in the bucket, remove a bad node and add the\n                      node\n                    * if there is some questionnable nodes (neither good not bad), send a ping\n                      request to the oldest one, discard the node\n                    * if all nodes are good in the bucket, discard the node\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_6Bucket_11add = {"add", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_6Bucket_11add, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_6Bucket_10add};
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_11add(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_dht = 0;
  PyObject *__pyx_v_node = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("add (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_dht,&__pyx_n_s_node,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dht)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("add", 1, 3, 3, 1); __PYX_ERR(0, 1996, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_node)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("add", 1, 3, 3, 2); __PYX_ERR(0, 1996, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add") < 0)) __PYX_ERR(0, 1996, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_self = values[0];
    __pyx_v_dht = values[1];
    __pyx_v_node = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("add", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1996, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Bucket.add", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_6Bucket_10add(__pyx_self, __pyx_v_self, __pyx_v_dht, __pyx_v_node);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_6Bucket_10add(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_dht, PyObject *__pyx_v_node) {
  PyObject *__pyx_v_old_node = NULL;
  PyObject *__pyx_v_n = NULL;
  PyObject *__pyx_v_l = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  Py_ssize_t __pyx_t_16;
  int __pyx_t_17;
  PyObject *(*__pyx_t_18)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("add", 0);

  /* "btdht/dht.pyx":2014
 *                     * if all nodes are good in the bucket, discard the node
 *         """
 *         if not self.own(node.id):             # <<<<<<<<<<<<<<
 *             raise ValueError("Wrong Bucket")
 *         elif node in self:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_own); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2014, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2014, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2014, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2014, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (unlikely(__pyx_t_6)) {

    /* "btdht/dht.pyx":2015
 *         """
 *         if not self.own(node.id):
 *             raise ValueError("Wrong Bucket")             # <<<<<<<<<<<<<<
 *         elif node in self:
 *             try:
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2015, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 2015, __pyx_L1_error)

    /* "btdht/dht.pyx":2014
 *                     * if all nodes are good in the bucket, discard the node
 *         """
 *         if not self.own(node.id):             # <<<<<<<<<<<<<<
 *             raise ValueError("Wrong Bucket")
 *         elif node in self:
 */
  }

  /* "btdht/dht.pyx":2016
 *         if not self.own(node.id):
 *             raise ValueError("Wrong Bucket")
 *         elif node in self:             # <<<<<<<<<<<<<<
 *             try:
 *                 old_node = self.get_node(node.id)
 */
  __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_v_node, __pyx_v_self, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2016, __pyx_L1_error)
  __pyx_t_5 = (__pyx_t_6 != 0);
  if (__pyx_t_5) {

    /* "btdht/dht.pyx":2017
 *             raise ValueError("Wrong Bucket")
 *         elif node in self:
 *             try:             # <<<<<<<<<<<<<<
 *                 old_node = self.get_node(node.id)
 *                 old_node.ip = node.ip
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_8);
      __Pyx_XGOTREF(__pyx_t_9);
      /*try:*/ {

        /* "btdht/dht.pyx":2018
 *         elif node in self:
 *             try:
 *                 old_node = self.get_node(node.id)             # <<<<<<<<<<<<<<
 *                 old_node.ip = node.ip
 *                 old_node.port = node.port
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_get_node); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2018, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2018, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
          }
        }
        __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2018, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_v_old_node = __pyx_t_1;
        __pyx_t_1 = 0;

        /* "btdht/dht.pyx":2019
 *             try:
 *                 old_node = self.get_node(node.id)
 *                 old_node.ip = node.ip             # <<<<<<<<<<<<<<
 *                 old_node.port = node.port
 *                 self.last_changed = time.time()
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_ip); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2019, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_old_node, __pyx_n_s_ip, __pyx_t_1) < 0) __PYX_ERR(0, 2019, __pyx_L4_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "btdht/dht.pyx":2020
 *                 old_node = self.get_node(node.id)
 *                 old_node.ip = node.ip
 *                 old_node.port = node.port             # <<<<<<<<<<<<<<
 *                 self.last_changed = time.time()
 *             except NotFound:
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_port); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2020, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_old_node, __pyx_n_s_port, __pyx_t_1) < 0) __PYX_ERR(0, 2020, __pyx_L4_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "btdht/dht.pyx":2021
 *                 old_node.ip = node.ip
 *                 old_node.port = node.port
 *                 self.last_changed = time.time()             # <<<<<<<<<<<<<<
 *             except NotFound:
 *                 try:
 */
        __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2021, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2021, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_2)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2021, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_last_changed, __pyx_t_1) < 0) __PYX_ERR(0, 2021, __pyx_L4_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "btdht/dht.pyx":2017
 *             raise ValueError("Wrong Bucket")
 *         elif node in self:
 *             try:             # <<<<<<<<<<<<<<
 *                 old_node = self.get_node(node.id)
 *                 old_node.ip = node.ip
 */
      }
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      goto __pyx_L9_try_end;
      __pyx_L4_error:;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "btdht/dht.pyx":2022
 *                 old_node.port = node.port
 *                 self.last_changed = time.time()
 *             except NotFound:             # <<<<<<<<<<<<<<
 *                 try:
 *                     self.remove(node)
 */
      __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_3, &__pyx_t_2);
      __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_NotFound); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2022, __pyx_L6_except_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_10 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_4);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_ErrRestore(__pyx_t_1, __pyx_t_3, __pyx_t_2);
      __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_2 = 0;
      if (__pyx_t_10) {
        __Pyx_AddTraceback("btdht.dht.Bucket.add", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_3, &__pyx_t_1) < 0) __PYX_ERR(0, 2022, __pyx_L6_except_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GOTREF(__pyx_t_1);

        /* "btdht/dht.pyx":2023
 *                 self.last_changed = time.time()
 *             except NotFound:
 *                 try:             # <<<<<<<<<<<<<<
 *                     self.remove(node)
 *                 except: pass
 */
        {
          __Pyx_PyThreadState_declare
          __Pyx_PyThreadState_assign
          __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
          __Pyx_XGOTREF(__pyx_t_11);
          __Pyx_XGOTREF(__pyx_t_12);
          __Pyx_XGOTREF(__pyx_t_13);
          /*try:*/ {

            /* "btdht/dht.pyx":2024
 *             except NotFound:
 *                 try:
 *                     self.remove(node)             # <<<<<<<<<<<<<<
 *                 except: pass
 *         elif len(self) < self.max_size:
 */
            __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_remove); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2024, __pyx_L12_error)
            __Pyx_GOTREF(__pyx_t_14);
            __pyx_t_15 = NULL;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_14))) {
              __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_14);
              if (likely(__pyx_t_15)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
                __Pyx_INCREF(__pyx_t_15);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_14, function);
              }
            }
            __pyx_t_4 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_14, __pyx_t_15, __pyx_v_node) : __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_node);
            __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
            if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2024, __pyx_L12_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

            /* "btdht/dht.pyx":2023
 *                 self.last_changed = time.time()
 *             except NotFound:
 *                 try:             # <<<<<<<<<<<<<<
 *                     self.remove(node)
 *                 except: pass
 */
          }
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          goto __pyx_L19_try_end;
          __pyx_L12_error:;
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;

          /* "btdht/dht.pyx":2025
 *                 try:
 *                     self.remove(node)
 *                 except: pass             # <<<<<<<<<<<<<<
 *         elif len(self) < self.max_size:
 *             self.append(node)
 */
          /*except:*/ {
            __Pyx_ErrRestore(0,0,0);
            goto __pyx_L13_exception_handled;
          }
          __pyx_L13_exception_handled:;
          __Pyx_XGIVEREF(__pyx_t_11);
          __Pyx_XGIVEREF(__pyx_t_12);
          __Pyx_XGIVEREF(__pyx_t_13);
          __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
          __pyx_L19_try_end:;
        }
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L5_exception_handled;
      }
      goto __pyx_L6_except_error;
      __pyx_L6_except_error:;

      /* "btdht/dht.pyx":2017
 *             raise ValueError("Wrong Bucket")
 *         elif node in self:
 *             try:             # <<<<<<<<<<<<<<
 *                 old_node = self.get_node(node.id)
 *                 old_node.ip = node.ip
 */
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      goto __pyx_L1_error;
      __pyx_L5_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      __pyx_L9_try_end:;
    }

    /* "btdht/dht.pyx":2016
 *         if not self.own(node.id):
 *             raise ValueError("Wrong Bucket")
 *         elif node in self:             # <<<<<<<<<<<<<<
 *             try:
 *                 old_node = self.get_node(node.id)
 */
    goto __pyx_L3;
  }

  /* "btdht/dht.pyx":2026
 *                     self.remove(node)
 *                 except: pass
 *         elif len(self) < self.max_size:             # <<<<<<<<<<<<<<
 *             self.append(node)
 *             self.last_changed = time.time()
 */
  __pyx_t_16 = PyObject_Length(__pyx_v_self); if (unlikely(__pyx_t_16 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2026, __pyx_L1_error)
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_16); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_max_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2026, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2026, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2026, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_5) {

    /* "btdht/dht.pyx":2027
 *                 except: pass
 *         elif len(self) < self.max_size:
 *             self.append(node)             # <<<<<<<<<<<<<<
 *             self.last_changed = time.time()
 *         else:
 */
    __pyx_t_17 = __Pyx_PyObject_Append(__pyx_v_self, __pyx_v_node); if (unlikely(__pyx_t_17 == ((int)-1))) __PYX_ERR(0, 2027, __pyx_L1_error)

    /* "btdht/dht.pyx":2028
 *         elif len(self) < self.max_size:
 *             self.append(node)
 *             self.last_changed = time.time()             # <<<<<<<<<<<<<<
 *         else:
 *             for n in self:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2028, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2028, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2028, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_last_changed, __pyx_t_2) < 0) __PYX_ERR(0, 2028, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "btdht/dht.pyx":2026
 *                     self.remove(node)
 *                 except: pass
 *         elif len(self) < self.max_size:             # <<<<<<<<<<<<<<
 *             self.append(node)
 *             self.last_changed = time.time()
 */
    goto __pyx_L3;
  }

  /* "btdht/dht.pyx":2030
 *             self.last_changed = time.time()
 *         else:
 *             for n in self:             # <<<<<<<<<<<<<<
 *                 if n.bad:
 *                     try:
 */
  /*else*/ {
    if (likely(PyList_CheckExact(__pyx_v_self)) || PyTuple_CheckExact(__pyx_v_self)) {
      __pyx_t_2 = __pyx_v_self; __Pyx_INCREF(__pyx_t_2); __pyx_t_16 = 0;
      __pyx_t_18 = NULL;
    } else {
      __pyx_t_16 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2030, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_18 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 2030, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_18)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_16 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_16); __Pyx_INCREF(__pyx_t_1); __pyx_t_16++; if (unlikely(0 < 0)) __PYX_ERR(0, 2030, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_16); __pyx_t_16++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2030, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          if (__pyx_t_16 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_16); __Pyx_INCREF(__pyx_t_1); __pyx_t_16++; if (unlikely(0 < 0)) __PYX_ERR(0, 2030, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_16); __pyx_t_16++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2030, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_18(__pyx_t_2);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 2030, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF_SET(__pyx_v_n, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "btdht/dht.pyx":2031
 *         else:
 *             for n in self:
 *                 if n.bad:             # <<<<<<<<<<<<<<
 *                     try:
 *                         self.remove(n)
 */
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_n, __pyx_n_s_bad); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2031, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2031, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_5) {

        /* "btdht/dht.pyx":2032
 *             for n in self:
 *                 if n.bad:
 *                     try:             # <<<<<<<<<<<<<<
 *                         self.remove(n)
 *                     except ValueError:
 */
        {
          __Pyx_PyThreadState_declare
          __Pyx_PyThreadState_assign
          __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_8, &__pyx_t_7);
          __Pyx_XGOTREF(__pyx_t_9);
          __Pyx_XGOTREF(__pyx_t_8);
          __Pyx_XGOTREF(__pyx_t_7);
          /*try:*/ {

            /* "btdht/dht.pyx":2033
 *                 if n.bad:
 *                     try:
 *                         self.remove(n)             # <<<<<<<<<<<<<<
 *                     except ValueError:
 *                         pass
 */
            __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_remove); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2033, __pyx_L23_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_4 = NULL;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
              __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
              if (likely(__pyx_t_4)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
                __Pyx_INCREF(__pyx_t_4);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_3, function);
              }
            }
            __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_v_n) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_n);
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2033, __pyx_L23_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

            /* "btdht/dht.pyx":2032
 *             for n in self:
 *                 if n.bad:
 *                     try:             # <<<<<<<<<<<<<<
 *                         self.remove(n)
 *                     except ValueError:
 */
          }
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          goto __pyx_L30_try_end;
          __pyx_L23_error:;
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;

          /* "btdht/dht.pyx":2034
 *                     try:
 *                         self.remove(n)
 *                     except ValueError:             # <<<<<<<<<<<<<<
 *                         pass
 *                     self.add(dht, node)
 */
          __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
          if (__pyx_t_10) {
            __Pyx_ErrRestore(0,0,0);
            goto __pyx_L24_exception_handled;
          }
          goto __pyx_L25_except_error;
          __pyx_L25_except_error:;

          /* "btdht/dht.pyx":2032
 *             for n in self:
 *                 if n.bad:
 *                     try:             # <<<<<<<<<<<<<<
 *                         self.remove(n)
 *                     except ValueError:
 */
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_XGIVEREF(__pyx_t_8);
          __Pyx_XGIVEREF(__pyx_t_7);
          __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_8, __pyx_t_7);
          goto __pyx_L1_error;
          __pyx_L24_exception_handled:;
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_XGIVEREF(__pyx_t_8);
          __Pyx_XGIVEREF(__pyx_t_7);
          __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_8, __pyx_t_7);
          __pyx_L30_try_end:;
        }

        /* "btdht/dht.pyx":2036
 *                     except ValueError:
 *                         pass
 *                     self.add(dht, node)             # <<<<<<<<<<<<<<
 *                     return
 *             l=list(self)
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_add); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2036, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = NULL;
        __pyx_t_10 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
            __pyx_t_10 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_dht, __pyx_v_node};
          __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2036, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_1);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_dht, __pyx_v_node};
          __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2036, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_1);
        } else
        #endif
        {
          __pyx_t_14 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2036, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          if (__pyx_t_4) {
            __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_4); __pyx_t_4 = NULL;
          }
          __Pyx_INCREF(__pyx_v_dht);
          __Pyx_GIVEREF(__pyx_v_dht);
          PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_10, __pyx_v_dht);
          __Pyx_INCREF(__pyx_v_node);
          __Pyx_GIVEREF(__pyx_v_node);
          PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_10, __pyx_v_node);
          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2036, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "btdht/dht.pyx":2037
 *                         pass
 *                     self.add(dht, node)
 *                     return             # <<<<<<<<<<<<<<
 *             l=list(self)
 *             l.sort()
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        goto __pyx_L0;

        /* "btdht/dht.pyx":2031
 *         else:
 *             for n in self:
 *                 if n.bad:             # <<<<<<<<<<<<<<
 *                     try:
 *                         self.remove(n)
 */
      }

      /* "btdht/dht.pyx":2030
 *             self.last_changed = time.time()
 *         else:
 *             for n in self:             # <<<<<<<<<<<<<<
 *                 if n.bad:
 *                     try:
 */
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "btdht/dht.pyx":2038
 *                     self.add(dht, node)
 *                     return
 *             l=list(self)             # <<<<<<<<<<<<<<
 *             l.sort()
 *             if not l[-1].good:
 */
    __pyx_t_2 = PySequence_List(__pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2038, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_l = ((PyObject*)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "btdht/dht.pyx":2039
 *                     return
 *             l=list(self)
 *             l.sort()             # <<<<<<<<<<<<<<
 *             if not l[-1].good:
 *                 l[-1].ping(dht)
 */
    __pyx_t_17 = PyList_Sort(__pyx_v_l); if (unlikely(__pyx_t_17 == ((int)-1))) __PYX_ERR(0, 2039, __pyx_L1_error)

    /* "btdht/dht.pyx":2040
 *             l=list(self)
 *             l.sort()
 *             if not l[-1].good:             # <<<<<<<<<<<<<<
 *                 l[-1].ping(dht)
 *             raise BucketFull()
 */
    __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_l, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2040, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_good); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2040, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2040, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = ((!__pyx_t_5) != 0);
    if (__pyx_t_6) {

      /* "btdht/dht.pyx":2041
 *             l.sort()
 *             if not l[-1].good:
 *                 l[-1].ping(dht)             # <<<<<<<<<<<<<<
 *             raise BucketFull()
 * 
 */
      __pyx_t_2 = __Pyx_GetItemInt_List(__pyx_v_l, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2041, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ping); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2041, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_dht) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_dht);
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2041, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "btdht/dht.pyx":2040
 *             l=list(self)
 *             l.sort()
 *             if not l[-1].good:             # <<<<<<<<<<<<<<
 *                 l[-1].ping(dht)
 *             raise BucketFull()
 */
    }

    /* "btdht/dht.pyx":2042
 *             if not l[-1].good:
 *                 l[-1].ping(dht)
 *             raise BucketFull()             # <<<<<<<<<<<<<<
 * 
 *     def split(self, rt, dht):
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_BucketFull); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2042, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2042, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 2042, __pyx_L1_error)
  }
  __pyx_L3:;

  /* "btdht/dht.pyx":1996
 *         raise NotFound()
 * 
 *     def add(self, dht, node):             # <<<<<<<<<<<<<<
 *         """
 *             Try to add a node to the bucket.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("btdht.dht.Bucket.add", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_old_node);
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2044
 *             raise BucketFull()
 * 
 *     def split(self, rt, dht):             # <<<<<<<<<<<<<<
 *         """
 *             Split the bucket into two buckets
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_13split(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_6Bucket_12split[] = "\n            Split the bucket into two buckets\n\n            :param RoutingTable rt: The routing table handling the bucket\n            :param DHT_BASE dht: A dht using ``rt`` as routing table\n            :return: A couple of two bucket, the first one this the last significant bit of its id\n                equal to 0, the second, equal to 1\n            :rtype: tuple\n            :raises BucketNotFull: If the bucket has not :attr:`max_size` elements (and so the split\n                is not needed)\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_6Bucket_13split = {"split", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_6Bucket_13split, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_6Bucket_12split};
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_13split(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_rt = 0;
  PyObject *__pyx_v_dht = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("split (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_rt,&__pyx_n_s_dht,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rt)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("split", 1, 3, 3, 1); __PYX_ERR(0, 2044, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dht)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("split", 1, 3, 3, 2); __PYX_ERR(0, 2044, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "split") < 0)) __PYX_ERR(0, 2044, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_self = values[0];
    __pyx_v_rt = values[1];
    __pyx_v_dht = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("split", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2044, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Bucket.split", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_6Bucket_12split(__pyx_self, __pyx_v_self, __pyx_v_rt, __pyx_v_dht);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_6Bucket_12split(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_rt, PyObject *__pyx_v_dht) {
  PyObject *__pyx_v_new_id = NULL;
  PyObject *__pyx_v_b1 = NULL;
  PyObject *__pyx_v_b2 = NULL;
  PyObject *__pyx_v_node = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *(*__pyx_t_11)(PyObject *);
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("split", 0);

  /* "btdht/dht.pyx":2056
 *                 is not needed)
 *         """
 *         if len(self) < self.max_size:             # <<<<<<<<<<<<<<
 *             raise BucketNotFull("Bucket not Full %r" % self)
 *         if self.id_length < 8*len(self.id):
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_self); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2056, __pyx_L1_error)
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2056, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_max_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2056, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2056, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2056, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(__pyx_t_5)) {

    /* "btdht/dht.pyx":2057
 *         """
 *         if len(self) < self.max_size:
 *             raise BucketNotFull("Bucket not Full %r" % self)             # <<<<<<<<<<<<<<
 *         if self.id_length < 8*len(self.id):
 *             new_id = self.id
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_BucketNotFull); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2057, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Bucket_not_Full_r, __pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2057, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2057, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 2057, __pyx_L1_error)

    /* "btdht/dht.pyx":2056
 *                 is not needed)
 *         """
 *         if len(self) < self.max_size:             # <<<<<<<<<<<<<<
 *             raise BucketNotFull("Bucket not Full %r" % self)
 *         if self.id_length < 8*len(self.id):
 */
  }

  /* "btdht/dht.pyx":2058
 *         if len(self) < self.max_size:
 *             raise BucketNotFull("Bucket not Full %r" % self)
 *         if self.id_length < 8*len(self.id):             # <<<<<<<<<<<<<<
 *             new_id = self.id
 *         else:
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2058, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2058, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2058, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromSsize_t((8 * __pyx_t_1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2058, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2058, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2058, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_5) {

    /* "btdht/dht.pyx":2059
 *             raise BucketNotFull("Bucket not Full %r" % self)
 *         if self.id_length < 8*len(self.id):
 *             new_id = self.id             # <<<<<<<<<<<<<<
 *         else:
 *             new_id = self.id + b"\0"
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2059, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_new_id = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "btdht/dht.pyx":2058
 *         if len(self) < self.max_size:
 *             raise BucketNotFull("Bucket not Full %r" % self)
 *         if self.id_length < 8*len(self.id):             # <<<<<<<<<<<<<<
 *             new_id = self.id
 *         else:
 */
    goto __pyx_L4;
  }

  /* "btdht/dht.pyx":2061
 *             new_id = self.id
 *         else:
 *             new_id = self.id + b"\0"             # <<<<<<<<<<<<<<
 *         b1 = Bucket(id=new_id, id_length=self.id_length + 1)
 *         b2 = Bucket(id=nflip(new_id, self.id_length), id_length=self.id_length + 1)
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2061, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyNumber_Add(__pyx_t_2, __pyx_kp_b__30); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2061, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_new_id = __pyx_t_3;
    __pyx_t_3 = 0;
  }
  __pyx_L4:;

  /* "btdht/dht.pyx":2062
 *         else:
 *             new_id = self.id + b"\0"
 *         b1 = Bucket(id=new_id, id_length=self.id_length + 1)             # <<<<<<<<<<<<<<
 *         b2 = Bucket(id=nflip(new_id, self.id_length), id_length=self.id_length + 1)
 *         for node in self:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_Bucket); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_id, __pyx_v_new_id) < 0) __PYX_ERR(0, 2062, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_id_length, __pyx_t_6) < 0) __PYX_ERR(0, 2062, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2062, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_b1 = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "btdht/dht.pyx":2063
 *             new_id = self.id + b"\0"
 *         b1 = Bucket(id=new_id, id_length=self.id_length + 1)
 *         b2 = Bucket(id=nflip(new_id, self.id_length), id_length=self.id_length + 1)             # <<<<<<<<<<<<<<
 *         for node in self:
 *             try:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_Bucket); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2063, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2063, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_nflip); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2063, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2063, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = NULL;
  __pyx_t_9 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_9 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_new_id, __pyx_t_7};
    __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_new_id, __pyx_t_7};
    __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  } else
  #endif
  {
    __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    if (__pyx_t_8) {
      __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL;
    }
    __Pyx_INCREF(__pyx_v_new_id);
    __Pyx_GIVEREF(__pyx_v_new_id);
    PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_v_new_id);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2063, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_id, __pyx_t_3) < 0) __PYX_ERR(0, 2063, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2063, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2063, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_id_length, __pyx_t_4) < 0) __PYX_ERR(0, 2063, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2063, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_b2 = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "btdht/dht.pyx":2064
 *         b1 = Bucket(id=new_id, id_length=self.id_length + 1)
 *         b2 = Bucket(id=nflip(new_id, self.id_length), id_length=self.id_length + 1)
 *         for node in self:             # <<<<<<<<<<<<<<
 *             try:
 *                 if b1.own(node.id):
 */
  if (likely(PyList_CheckExact(__pyx_v_self)) || PyTuple_CheckExact(__pyx_v_self)) {
    __pyx_t_4 = __pyx_v_self; __Pyx_INCREF(__pyx_t_4); __pyx_t_1 = 0;
    __pyx_t_11 = NULL;
  } else {
    __pyx_t_1 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2064, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_11 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2064, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_11)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 2064, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2064, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 2064, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2064, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_11(__pyx_t_4);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2064, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XDECREF_SET(__pyx_v_node, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "btdht/dht.pyx":2065
 *         b2 = Bucket(id=nflip(new_id, self.id_length), id_length=self.id_length + 1)
 *         for node in self:
 *             try:             # <<<<<<<<<<<<<<
 *                 if b1.own(node.id):
 *                     b1.add(dht, node)
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14);
      __Pyx_XGOTREF(__pyx_t_12);
      __Pyx_XGOTREF(__pyx_t_13);
      __Pyx_XGOTREF(__pyx_t_14);
      /*try:*/ {

        /* "btdht/dht.pyx":2066
 *         for node in self:
 *             try:
 *                 if b1.own(node.id):             # <<<<<<<<<<<<<<
 *                     b1.add(dht, node)
 *                 elif b2.own(node.id):
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_b1, __pyx_n_s_own); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2066, __pyx_L7_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2066, __pyx_L7_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_10 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_10)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_10);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
          }
        }
        __pyx_t_2 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_10, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_3);
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2066, __pyx_L7_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2066, __pyx_L7_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (__pyx_t_5) {

          /* "btdht/dht.pyx":2067
 *             try:
 *                 if b1.own(node.id):
 *                     b1.add(dht, node)             # <<<<<<<<<<<<<<
 *                 elif b2.own(node.id):
 *                     b2.add(dht, node)
 */
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_b1, __pyx_n_s_add); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2067, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_3 = NULL;
          __pyx_t_9 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
            __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
            if (likely(__pyx_t_3)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_6, function);
              __pyx_t_9 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_dht, __pyx_v_node};
            __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2067, __pyx_L7_error)
            __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_GOTREF(__pyx_t_2);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_dht, __pyx_v_node};
            __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2067, __pyx_L7_error)
            __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_GOTREF(__pyx_t_2);
          } else
          #endif
          {
            __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2067, __pyx_L7_error)
            __Pyx_GOTREF(__pyx_t_10);
            if (__pyx_t_3) {
              __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3); __pyx_t_3 = NULL;
            }
            __Pyx_INCREF(__pyx_v_dht);
            __Pyx_GIVEREF(__pyx_v_dht);
            PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_v_dht);
            __Pyx_INCREF(__pyx_v_node);
            __Pyx_GIVEREF(__pyx_v_node);
            PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_v_node);
            __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2067, __pyx_L7_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          }
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "btdht/dht.pyx":2066
 *         for node in self:
 *             try:
 *                 if b1.own(node.id):             # <<<<<<<<<<<<<<
 *                     b1.add(dht, node)
 *                 elif b2.own(node.id):
 */
          goto __pyx_L15;
        }

        /* "btdht/dht.pyx":2068
 *                 if b1.own(node.id):
 *                     b1.add(dht, node)
 *                 elif b2.own(node.id):             # <<<<<<<<<<<<<<
 *                     b2.add(dht, node)
 *                 else:
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_b2, __pyx_n_s_own); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2068, __pyx_L7_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_id); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2068, __pyx_L7_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_3 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
          }
        }
        __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_3, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_10);
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2068, __pyx_L7_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2068, __pyx_L7_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (__pyx_t_5) {

          /* "btdht/dht.pyx":2069
 *                     b1.add(dht, node)
 *                 elif b2.own(node.id):
 *                     b2.add(dht, node)             # <<<<<<<<<<<<<<
 *                 else:
 *                     print("%r" % self)
 */
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_b2, __pyx_n_s_add); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2069, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_10 = NULL;
          __pyx_t_9 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
            __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_6);
            if (likely(__pyx_t_10)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
              __Pyx_INCREF(__pyx_t_10);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_6, function);
              __pyx_t_9 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_dht, __pyx_v_node};
            __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2069, __pyx_L7_error)
            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
            __Pyx_GOTREF(__pyx_t_2);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_dht, __pyx_v_node};
            __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2069, __pyx_L7_error)
            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
            __Pyx_GOTREF(__pyx_t_2);
          } else
          #endif
          {
            __pyx_t_3 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2069, __pyx_L7_error)
            __Pyx_GOTREF(__pyx_t_3);
            if (__pyx_t_10) {
              __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_10); __pyx_t_10 = NULL;
            }
            __Pyx_INCREF(__pyx_v_dht);
            __Pyx_GIVEREF(__pyx_v_dht);
            PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_9, __pyx_v_dht);
            __Pyx_INCREF(__pyx_v_node);
            __Pyx_GIVEREF(__pyx_v_node);
            PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_9, __pyx_v_node);
            __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2069, __pyx_L7_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          }
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "btdht/dht.pyx":2068
 *                 if b1.own(node.id):
 *                     b1.add(dht, node)
 *                 elif b2.own(node.id):             # <<<<<<<<<<<<<<
 *                     b2.add(dht, node)
 *                 else:
 */
          goto __pyx_L15;
        }

        /* "btdht/dht.pyx":2071
 *                     b2.add(dht, node)
 *                 else:
 *                     print("%r" % self)             # <<<<<<<<<<<<<<
 *                     raise ValueError("%r %r not in bucket" % (node, node.id))
 *             except BucketFull:
 */
        /*else*/ {
          __pyx_t_2 = __Pyx_PyString_FormatSafe(__pyx_kp_s_r_2, __pyx_v_self); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2071, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_2);
          if (__Pyx_PrintOne(0, __pyx_t_2) < 0) __PYX_ERR(0, 2071, __pyx_L7_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "btdht/dht.pyx":2072
 *                 else:
 *                     print("%r" % self)
 *                     raise ValueError("%r %r not in bucket" % (node, node.id))             # <<<<<<<<<<<<<<
 *             except BucketFull:
 *                 rt.add(dht, node)
 */
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2072, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2072, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_INCREF(__pyx_v_node);
          __Pyx_GIVEREF(__pyx_v_node);
          PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_node);
          __Pyx_GIVEREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_2);
          __pyx_t_2 = 0;
          __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_r_r_not_in_bucket, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2072, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2072, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_Raise(__pyx_t_6, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __PYX_ERR(0, 2072, __pyx_L7_error)
        }
        __pyx_L15:;

        /* "btdht/dht.pyx":2065
 *         b2 = Bucket(id=nflip(new_id, self.id_length), id_length=self.id_length + 1)
 *         for node in self:
 *             try:             # <<<<<<<<<<<<<<
 *                 if b1.own(node.id):
 *                     b1.add(dht, node)
 */
      }
      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
      goto __pyx_L14_try_end;
      __pyx_L7_error:;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "btdht/dht.pyx":2073
 *                     print("%r" % self)
 *                     raise ValueError("%r %r not in bucket" % (node, node.id))
 *             except BucketFull:             # <<<<<<<<<<<<<<
 *                 rt.add(dht, node)
 *         if nbit(b1.id, self.id_length) == 0:
 */
      __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_2, &__pyx_t_3);
      __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_BucketFull); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2073, __pyx_L9_except_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_9 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_6, __pyx_t_10);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_ErrRestore(__pyx_t_6, __pyx_t_2, __pyx_t_3);
      __pyx_t_6 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0;
      if (__pyx_t_9) {
        __Pyx_AddTraceback("btdht.dht.Bucket.split", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_2, &__pyx_t_6) < 0) __PYX_ERR(0, 2073, __pyx_L9_except_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GOTREF(__pyx_t_6);

        /* "btdht/dht.pyx":2074
 *                     raise ValueError("%r %r not in bucket" % (node, node.id))
 *             except BucketFull:
 *                 rt.add(dht, node)             # <<<<<<<<<<<<<<
 *         if nbit(b1.id, self.id_length) == 0:
 *             return (b1, b2)
 */
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_rt, __pyx_n_s_add); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2074, __pyx_L9_except_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = NULL;
        __pyx_t_9 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
            __pyx_t_9 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_7)) {
          PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_dht, __pyx_v_node};
          __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2074, __pyx_L9_except_error)
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_GOTREF(__pyx_t_10);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
          PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_dht, __pyx_v_node};
          __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2074, __pyx_L9_except_error)
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_GOTREF(__pyx_t_10);
        } else
        #endif
        {
          __pyx_t_15 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2074, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_15);
          if (__pyx_t_8) {
            __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_8); __pyx_t_8 = NULL;
          }
          __Pyx_INCREF(__pyx_v_dht);
          __Pyx_GIVEREF(__pyx_v_dht);
          PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_9, __pyx_v_dht);
          __Pyx_INCREF(__pyx_v_node);
          __Pyx_GIVEREF(__pyx_v_node);
          PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_9, __pyx_v_node);
          __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_15, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2074, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        goto __pyx_L8_exception_handled;
      }
      goto __pyx_L9_except_error;
      __pyx_L9_except_error:;

      /* "btdht/dht.pyx":2065
 *         b2 = Bucket(id=nflip(new_id, self.id_length), id_length=self.id_length + 1)
 *         for node in self:
 *             try:             # <<<<<<<<<<<<<<
 *                 if b1.own(node.id):
 *                     b1.add(dht, node)
 */
      __Pyx_XGIVEREF(__pyx_t_12);
      __Pyx_XGIVEREF(__pyx_t_13);
      __Pyx_XGIVEREF(__pyx_t_14);
      __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
      goto __pyx_L1_error;
      __pyx_L8_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_12);
      __Pyx_XGIVEREF(__pyx_t_13);
      __Pyx_XGIVEREF(__pyx_t_14);
      __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
      __pyx_L14_try_end:;
    }

    /* "btdht/dht.pyx":2064
 *         b1 = Bucket(id=new_id, id_length=self.id_length + 1)
 *         b2 = Bucket(id=nflip(new_id, self.id_length), id_length=self.id_length + 1)
 *         for node in self:             # <<<<<<<<<<<<<<
 *             try:
 *                 if b1.own(node.id):
 */
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "btdht/dht.pyx":2075
 *             except BucketFull:
 *                 rt.add(dht, node)
 *         if nbit(b1.id, self.id_length) == 0:             # <<<<<<<<<<<<<<
 *             return (b1, b2)
 *         else:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_nbit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_b1, __pyx_n_s_id); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_10 = NULL;
  __pyx_t_9 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_10)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_10);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
      __pyx_t_9 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_6)) {
    PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_2, __pyx_t_3};
    __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2075, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
    PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_2, __pyx_t_3};
    __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2075, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2075, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__pyx_t_10) {
      __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_10); __pyx_t_10 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_t_3);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2075, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_EqObjC(__pyx_t_4, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 2075, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (__pyx_t_5) {

    /* "btdht/dht.pyx":2076
 *                 rt.add(dht, node)
 *         if nbit(b1.id, self.id_length) == 0:
 *             return (b1, b2)             # <<<<<<<<<<<<<<
 *         else:
 *             return (b2, b1)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2076, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_b1);
    __Pyx_GIVEREF(__pyx_v_b1);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_b1);
    __Pyx_INCREF(__pyx_v_b2);
    __Pyx_GIVEREF(__pyx_v_b2);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_b2);
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L0;

    /* "btdht/dht.pyx":2075
 *             except BucketFull:
 *                 rt.add(dht, node)
 *         if nbit(b1.id, self.id_length) == 0:             # <<<<<<<<<<<<<<
 *             return (b1, b2)
 *         else:
 */
  }

  /* "btdht/dht.pyx":2078
 *             return (b1, b2)
 *         else:
 *             return (b2, b1)             # <<<<<<<<<<<<<<
 * 
 *     def merge(self, bucket):
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2078, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_b2);
    __Pyx_GIVEREF(__pyx_v_b2);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_b2);
    __Pyx_INCREF(__pyx_v_b1);
    __Pyx_GIVEREF(__pyx_v_b1);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_b1);
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":2044
 *             raise BucketFull()
 * 
 *     def split(self, rt, dht):             # <<<<<<<<<<<<<<
 *         """
 *             Split the bucket into two buckets
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("btdht.dht.Bucket.split", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_new_id);
  __Pyx_XDECREF(__pyx_v_b1);
  __Pyx_XDECREF(__pyx_v_b2);
  __Pyx_XDECREF(__pyx_v_node);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2080
 *             return (b2, b1)
 * 
 *     def merge(self, bucket):             # <<<<<<<<<<<<<<
 *         """
 *             Merge the bucket with ``bucket``
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_15merge(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_6Bucket_14merge[] = "\n            Merge the bucket with ``bucket``\n\n            :param Bucket bucket: a bucket to be merged with\n            :return: The merged bucket\n            :rtype: Bucket\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_6Bucket_15merge = {"merge", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_6Bucket_15merge, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_6Bucket_14merge};
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_15merge(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_bucket = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("merge (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_bucket,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bucket)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("merge", 1, 2, 2, 1); __PYX_ERR(0, 2080, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "merge") < 0)) __PYX_ERR(0, 2080, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_self = values[0];
    __pyx_v_bucket = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("merge", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2080, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Bucket.merge", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_6Bucket_14merge(__pyx_self, __pyx_v_self, __pyx_v_bucket);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_6Bucket_14merge(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_bucket) {
  PyObject *__pyx_v_l = NULL;
  PyObject *__pyx_v_n = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("merge", 0);

  /* "btdht/dht.pyx":2088
 *             :rtype: Bucket
 *         """
 *         l = [n for l in zip(self, bucket) for n in l if n.good][:self.max_size]             # <<<<<<<<<<<<<<
 *         return Bucket(id=self.id, id_length=self.id_length - 1, init=l)
 * 
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2088, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2088, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_self);
  __Pyx_GIVEREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self);
  __Pyx_INCREF(__pyx_v_bucket);
  __Pyx_GIVEREF(__pyx_v_bucket);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_bucket);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2088, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2088, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2088, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2088, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2088, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2088, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2088, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_5(__pyx_t_2);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2088, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_3);
    __pyx_t_3 = 0;
    if (likely(PyList_CheckExact(__pyx_v_l)) || PyTuple_CheckExact(__pyx_v_l)) {
      __pyx_t_3 = __pyx_v_l; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0;
      __pyx_t_7 = NULL;
    } else {
      __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_l); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2088, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_7 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2088, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_7)) {
        if (likely(PyList_CheckExact(__pyx_t_3))) {
          if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_8 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 2088, __pyx_L1_error)
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2088, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          #endif
        } else {
          if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 2088, __pyx_L1_error)
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2088, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          #endif
        }
      } else {
        __pyx_t_8 = __pyx_t_7(__pyx_t_3);
        if (unlikely(!__pyx_t_8)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 2088, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_8);
      }
      __Pyx_XDECREF_SET(__pyx_v_n, __pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_n, __pyx_n_s_good); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2088, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 2088, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_9) {
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_v_n))) __PYX_ERR(0, 2088, __pyx_L1_error)
      }
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_max_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2088, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_9 = (__pyx_t_2 == Py_None);
  if (__pyx_t_9) {
    __pyx_t_4 = PY_SSIZE_T_MAX;
  } else {
    __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 2088, __pyx_L1_error)
    __pyx_t_4 = __pyx_t_6;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyList_GetSlice(__pyx_t_1, 0, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2088, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_2);
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":2089
 *         """
 *         l = [n for l in zip(self, bucket) for n in l if n.good][:self.max_size]
 *         return Bucket(id=self.id, id_length=self.id_length - 1, init=l)             # <<<<<<<<<<<<<<
 * 
 *     def __hash__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_Bucket); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2089, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2089, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2089, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_id, __pyx_t_3) < 0) __PYX_ERR(0, 2089, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2089, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2089, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_id_length, __pyx_t_8) < 0) __PYX_ERR(0, 2089, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_init, __pyx_v_l) < 0) __PYX_ERR(0, 2089, __pyx_L1_error)
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2089, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_8;
  __pyx_t_8 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":2080
 *             return (b2, b1)
 * 
 *     def merge(self, bucket):             # <<<<<<<<<<<<<<
 *         """
 *             Merge the bucket with ``bucket``
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("btdht.dht.Bucket.merge", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2091
 *         return Bucket(id=self.id, id_length=self.id_length - 1, init=l)
 * 
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         return hash(utils.id_to_longid(ID.to_bytes(self.id))[:self.id_length])
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_17__hash__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static PyMethodDef __pyx_mdef_5btdht_3dht_6Bucket_17__hash__ = {"__hash__", (PyCFunction)__pyx_pw_5btdht_3dht_6Bucket_17__hash__, METH_O, 0};
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_17__hash__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_6Bucket_16__hash__(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_6Bucket_16__hash__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  Py_hash_t __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__hash__", 0);

  /* "btdht/dht.pyx":2092
 * 
 *     def __hash__(self):
 *         return hash(utils.id_to_longid(ID.to_bytes(self.id))[:self.id_length])             # <<<<<<<<<<<<<<
 * 
 *     def __eq__(self, other):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_utils); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_id_to_longid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_ID); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_to_bytes); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_t_1, 0, 0, NULL, &__pyx_t_3, NULL, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_7 = PyObject_Hash(__pyx_t_2); if (unlikely(__pyx_t_7 == ((Py_hash_t)-1))) __PYX_ERR(0, 2092, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_FromHash_t(__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":2091
 *         return Bucket(id=self.id, id_length=self.id_length - 1, init=l)
 * 
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         return hash(utils.id_to_longid(ID.to_bytes(self.id))[:self.id_length])
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("btdht.dht.Bucket.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2094
 *         return hash(utils.id_to_longid(ID.to_bytes(self.id))[:self.id_length])
 * 
 *     def __eq__(self, other):             # <<<<<<<<<<<<<<
 *         try:
 *             return self.id_length == other.id_length and self.id == other.id
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_19__eq__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5btdht_3dht_6Bucket_19__eq__ = {"__eq__", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_6Bucket_19__eq__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_19__eq__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_other = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__eq__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__eq__", 1, 2, 2, 1); __PYX_ERR(0, 2094, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__eq__") < 0)) __PYX_ERR(0, 2094, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_self = values[0];
    __pyx_v_other = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__eq__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2094, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Bucket.__eq__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_6Bucket_18__eq__(__pyx_self, __pyx_v_self, __pyx_v_other);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_6Bucket_18__eq__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_v_e = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__eq__", 0);

  /* "btdht/dht.pyx":2095
 * 
 *     def __eq__(self, other):
 *         try:             # <<<<<<<<<<<<<<
 *             return self.id_length == other.id_length and self.id == other.id
 *         except AttributeError as e:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "btdht/dht.pyx":2096
 *     def __eq__(self, other):
 *         try:
 *             return self.id_length == other.id_length and self.id == other.id             # <<<<<<<<<<<<<<
 *         except AttributeError as e:
 *             print ("%r" % e)
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2096, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_id_length); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2096, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PyObject_RichCompare(__pyx_t_5, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2096, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2096, __pyx_L3_error)
      if (__pyx_t_8) {
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else {
        __Pyx_INCREF(__pyx_t_7);
        __pyx_t_4 = __pyx_t_7;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        goto __pyx_L9_bool_binop_done;
      }
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2096, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_id); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2096, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = PyObject_RichCompare(__pyx_t_7, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2096, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_INCREF(__pyx_t_5);
      __pyx_t_4 = __pyx_t_5;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_L9_bool_binop_done:;
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L7_try_return;

      /* "btdht/dht.pyx":2095
 * 
 *     def __eq__(self, other):
 *         try:             # <<<<<<<<<<<<<<
 *             return self.id_length == other.id_length and self.id == other.id
 *         except AttributeError as e:
 */
    }
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "btdht/dht.pyx":2097
 *         try:
 *             return self.id_length == other.id_length and self.id == other.id
 *         except AttributeError as e:             # <<<<<<<<<<<<<<
 *             print ("%r" % e)
 *             return False
 */
    __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
    if (__pyx_t_9) {
      __Pyx_AddTraceback("btdht.dht.Bucket.__eq__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6) < 0) __PYX_ERR(0, 2097, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_5);
      __pyx_v_e = __pyx_t_5;

      /* "btdht/dht.pyx":2098
 *             return self.id_length == other.id_length and self.id == other.id
 *         except AttributeError as e:
 *             print ("%r" % e)             # <<<<<<<<<<<<<<
 *             return False
 * 
 */
      __pyx_t_7 = __Pyx_PyString_FormatSafe(__pyx_kp_s_r_2, __pyx_v_e); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2098, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_7);
      if (__Pyx_PrintOne(0, __pyx_t_7) < 0) __PYX_ERR(0, 2098, __pyx_L5_except_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "btdht/dht.pyx":2099
 *         except AttributeError as e:
 *             print ("%r" % e)
 *             return False             # <<<<<<<<<<<<<<
 * 
 *     def __lt__(self, other):
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(Py_False);
      __pyx_r = Py_False;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L6_except_return;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "btdht/dht.pyx":2095
 * 
 *     def __eq__(self, other):
 *         try:             # <<<<<<<<<<<<<<
 *             return self.id_length == other.id_length and self.id == other.id
 *         except AttributeError as e:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L7_try_return:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L0;
    __pyx_L6_except_return:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":2094
 *         return hash(utils.id_to_longid(ID.to_bytes(self.id))[:self.id_length])
 * 
 *     def __eq__(self, other):             # <<<<<<<<<<<<<<
 *         try:
 *             return self.id_length == other.id_length and self.id == other.id
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("btdht.dht.Bucket.__eq__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_e);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2101
 *             return False
 * 
 *     def __lt__(self, other):             # <<<<<<<<<<<<<<
 *         try:
 *             if self.id_length == other.id_length:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_21__lt__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5btdht_3dht_6Bucket_21__lt__ = {"__lt__", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_6Bucket_21__lt__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5btdht_3dht_6Bucket_21__lt__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_other = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__lt__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__lt__", 1, 2, 2, 1); __PYX_ERR(0, 2101, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__lt__") < 0)) __PYX_ERR(0, 2101, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_self = values[0];
    __pyx_v_other = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__lt__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2101, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.Bucket.__lt__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_6Bucket_20__lt__(__pyx_self, __pyx_v_self, __pyx_v_other);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_6Bucket_20__lt__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__lt__", 0);

  /* "btdht/dht.pyx":2102
 * 
 *     def __lt__(self, other):
 *         try:             # <<<<<<<<<<<<<<
 *             if self.id_length == other.id_length:
 *                 return self.id < other.id
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "btdht/dht.pyx":2103
 *     def __lt__(self, other):
 *         try:
 *             if self.id_length == other.id_length:             # <<<<<<<<<<<<<<
 *                 return self.id < other.id
 *             else:
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2103, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_id_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2103, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2103, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 2103, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_7) {

        /* "btdht/dht.pyx":2104
 *         try:
 *             if self.id_length == other.id_length:
 *                 return self.id < other.id             # <<<<<<<<<<<<<<
 *             else:
 *                 return self.id_length < other.id_length
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2104, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_id); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2104, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2104, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_r = __pyx_t_4;
        __pyx_t_4 = 0;
        goto __pyx_L7_try_return;

        /* "btdht/dht.pyx":2103
 *     def __lt__(self, other):
 *         try:
 *             if self.id_length == other.id_length:             # <<<<<<<<<<<<<<
 *                 return self.id < other.id
 *             else:
 */
      }

      /* "btdht/dht.pyx":2106
 *                 return self.id < other.id
 *             else:
 *                 return self.id_length < other.id_length             # <<<<<<<<<<<<<<
 *         except AttributeError:
 *             raise ValueError(
 */
      /*else*/ {
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_id_length); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2106, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_id_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2106, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_LT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2106, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_r = __pyx_t_6;
        __pyx_t_6 = 0;
        goto __pyx_L7_try_return;
      }

      /* "btdht/dht.pyx":2102
 * 
 *     def __lt__(self, other):
 *         try:             # <<<<<<<<<<<<<<
 *             if self.id_length == other.id_length:
 *                 return self.id < other.id
 */
    }
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "btdht/dht.pyx":2107
 *             else:
 *                 return self.id_length < other.id_length
 *         except AttributeError:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "%s not comparable with %s" % (other.__class__.__name__, self.__class__.__name__)
 */
    __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
    if (__pyx_t_8) {
      __Pyx_AddTraceback("btdht.dht.Bucket.__lt__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4) < 0) __PYX_ERR(0, 2107, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_4);

      /* "btdht/dht.pyx":2109
 *         except AttributeError:
 *             raise ValueError(
 *                 "%s not comparable with %s" % (other.__class__.__name__, self.__class__.__name__)             # <<<<<<<<<<<<<<
 *             )
 * 
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_class); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2109, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_name); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2109, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2109, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_name); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2109, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2109, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_11);
      __pyx_t_10 = 0;
      __pyx_t_11 = 0;
      __pyx_t_11 = __Pyx_PyString_Format(__pyx_kp_s_s_not_comparable_with_s, __pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2109, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "btdht/dht.pyx":2108
 *                 return self.id_length < other.id_length
 *         except AttributeError:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "%s not comparable with %s" % (other.__class__.__name__, self.__class__.__name__)
 *             )
 */
      __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2108, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_Raise(__pyx_t_9, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __PYX_ERR(0, 2108, __pyx_L5_except_error)
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "btdht/dht.pyx":2102
 * 
 *     def __lt__(self, other):
 *         try:             # <<<<<<<<<<<<<<
 *             if self.id_length == other.id_length:
 *                 return self.id < other.id
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L7_try_return:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":2101
 *             return False
 * 
 *     def __lt__(self, other):             # <<<<<<<<<<<<<<
 *         try:
 *             if self.id_length == other.id_length:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("btdht.dht.Bucket.__lt__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2169
 *     _lock = None
 * 
 *     def __init__(self, scheduler, debuglvl=0, prefix=""):             # <<<<<<<<<<<<<<
 *         self.debuglvl = debuglvl
 *         self.trie = datrie.Trie(u"01")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_1__init__ = {"__init__", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_1__init__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_scheduler = 0;
  PyObject *__pyx_v_debuglvl = 0;
  PyObject *__pyx_v_prefix = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_scheduler,&__pyx_n_s_debuglvl,&__pyx_n_s_prefix,0};
    PyObject* values[4] = {0,0,0,0};
    values[2] = ((PyObject *)((PyObject *)__pyx_int_0));
    values[3] = ((PyObject *)((PyObject*)__pyx_kp_s__2));
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_scheduler)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 4, 1); __PYX_ERR(0, 2169, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_debuglvl);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_prefix);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 2169, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_self = values[0];
    __pyx_v_scheduler = values[1];
    __pyx_v_debuglvl = values[2];
    __pyx_v_prefix = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2169, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable___init__(__pyx_self, __pyx_v_self, __pyx_v_scheduler, __pyx_v_debuglvl, __pyx_v_prefix);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_scheduler, PyObject *__pyx_v_debuglvl, PyObject *__pyx_v_prefix) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "btdht/dht.pyx":2170
 * 
 *     def __init__(self, scheduler, debuglvl=0, prefix=""):
 *         self.debuglvl = debuglvl             # <<<<<<<<<<<<<<
 *         self.trie = datrie.Trie(u"01")
 *         self.trie[u""]=Bucket()
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_debuglvl, __pyx_v_debuglvl) < 0) __PYX_ERR(0, 2170, __pyx_L1_error)

  /* "btdht/dht.pyx":2171
 *     def __init__(self, scheduler, debuglvl=0, prefix=""):
 *         self.debuglvl = debuglvl
 *         self.trie = datrie.Trie(u"01")             # <<<<<<<<<<<<<<
 *         self.trie[u""]=Bucket()
 *         self._heigth=1
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_datrie); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2171, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Trie); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2171, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_kp_u_01) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_01);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2171, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_trie, __pyx_t_1) < 0) __PYX_ERR(0, 2171, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2172
 *         self.debuglvl = debuglvl
 *         self.trie = datrie.Trie(u"01")
 *         self.trie[u""]=Bucket()             # <<<<<<<<<<<<<<
 *         self._heigth=1
 *         self._split_ids = set()
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_Bucket); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2172, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2172, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2172, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (unlikely(PyObject_SetItem(__pyx_t_3, __pyx_kp_u__2, __pyx_t_1) < 0)) __PYX_ERR(0, 2172, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2173
 *         self.trie = datrie.Trie(u"01")
 *         self.trie[u""]=Bucket()
 *         self._heigth=1             # <<<<<<<<<<<<<<
 *         self._split_ids = set()
 *         self._info_hash = set()
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_heigth_2, __pyx_int_1) < 0) __PYX_ERR(0, 2173, __pyx_L1_error)

  /* "btdht/dht.pyx":2174
 *         self.trie[u""]=Bucket()
 *         self._heigth=1
 *         self._split_ids = set()             # <<<<<<<<<<<<<<
 *         self._info_hash = set()
 *         self._lock = Lock()
 */
  __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2174, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_split_ids, __pyx_t_1) < 0) __PYX_ERR(0, 2174, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2175
 *         self._heigth=1
 *         self._split_ids = set()
 *         self._info_hash = set()             # <<<<<<<<<<<<<<
 *         self._lock = Lock()
 *         self._dhts = set()
 */
  __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2175, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_info_hash_2, __pyx_t_1) < 0) __PYX_ERR(0, 2175, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2176
 *         self._split_ids = set()
 *         self._info_hash = set()
 *         self._lock = Lock()             # <<<<<<<<<<<<<<
 *         self._dhts = set()
 *         self.stoped = True
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_Lock); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2176, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_lock, __pyx_t_1) < 0) __PYX_ERR(0, 2176, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2177
 *         self._info_hash = set()
 *         self._lock = Lock()
 *         self._dhts = set()             # <<<<<<<<<<<<<<
 *         self.stoped = True
 *         self.need_merge = False
 */
  __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2177, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_dhts, __pyx_t_1) < 0) __PYX_ERR(0, 2177, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2178
 *         self._lock = Lock()
 *         self._dhts = set()
 *         self.stoped = True             # <<<<<<<<<<<<<<
 *         self.need_merge = False
 *         self._threads = []
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_stoped, Py_True) < 0) __PYX_ERR(0, 2178, __pyx_L1_error)

  /* "btdht/dht.pyx":2179
 *         self._dhts = set()
 *         self.stoped = True
 *         self.need_merge = False             # <<<<<<<<<<<<<<
 *         self._threads = []
 *         self.threads = []
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_need_merge, Py_False) < 0) __PYX_ERR(0, 2179, __pyx_L1_error)

  /* "btdht/dht.pyx":2180
 *         self.stoped = True
 *         self.need_merge = False
 *         self._threads = []             # <<<<<<<<<<<<<<
 *         self.threads = []
 *         self._to_merge = set()
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2180, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_threads_2, __pyx_t_1) < 0) __PYX_ERR(0, 2180, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2181
 *         self.need_merge = False
 *         self._threads = []
 *         self.threads = []             # <<<<<<<<<<<<<<
 *         self._to_merge = set()
 *         self._threads_zombie= []
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_threads, __pyx_t_1) < 0) __PYX_ERR(0, 2181, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2182
 *         self._threads = []
 *         self.threads = []
 *         self._to_merge = set()             # <<<<<<<<<<<<<<
 *         self._threads_zombie= []
 *         self._last_debug = ""
 */
  __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2182, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_to_merge, __pyx_t_1) < 0) __PYX_ERR(0, 2182, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2183
 *         self.threads = []
 *         self._to_merge = set()
 *         self._threads_zombie= []             # <<<<<<<<<<<<<<
 *         self._last_debug = ""
 *         self._last_debug_time = 0
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2183, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_threads_zombie, __pyx_t_1) < 0) __PYX_ERR(0, 2183, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2184
 *         self._to_merge = set()
 *         self._threads_zombie= []
 *         self._last_debug = ""             # <<<<<<<<<<<<<<
 *         self._last_debug_time = 0
 *         self._scheduler = scheduler
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_last_debug, __pyx_kp_s__2) < 0) __PYX_ERR(0, 2184, __pyx_L1_error)

  /* "btdht/dht.pyx":2185
 *         self._threads_zombie= []
 *         self._last_debug = ""
 *         self._last_debug_time = 0             # <<<<<<<<<<<<<<
 *         self._scheduler = scheduler
 *         self.prefix = prefix
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_last_debug_time, __pyx_int_0) < 0) __PYX_ERR(0, 2185, __pyx_L1_error)

  /* "btdht/dht.pyx":2186
 *         self._last_debug = ""
 *         self._last_debug_time = 0
 *         self._scheduler = scheduler             # <<<<<<<<<<<<<<
 *         self.prefix = prefix
 *         self.to_schedule = [
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_scheduler_2, __pyx_v_scheduler) < 0) __PYX_ERR(0, 2186, __pyx_L1_error)

  /* "btdht/dht.pyx":2187
 *         self._last_debug_time = 0
 *         self._scheduler = scheduler
 *         self.prefix = prefix             # <<<<<<<<<<<<<<
 *         self.to_schedule = [
 *             ("RT%s:merge_loop" % prefix, self._merge_loop),
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_prefix, __pyx_v_prefix) < 0) __PYX_ERR(0, 2187, __pyx_L1_error)

  /* "btdht/dht.pyx":2189
 *         self.prefix = prefix
 *         self.to_schedule = [
 *             ("RT%s:merge_loop" % prefix, self._merge_loop),             # <<<<<<<<<<<<<<
 *             ("RT%s:routine" % prefix, self._routine),
 *         ]
 */
  __pyx_t_1 = __Pyx_PyString_FormatSafe(__pyx_kp_s_RT_s_merge_loop, __pyx_v_prefix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2189, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_merge_loop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2189, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2189, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_3 = 0;

  /* "btdht/dht.pyx":2190
 *         self.to_schedule = [
 *             ("RT%s:merge_loop" % prefix, self._merge_loop),
 *             ("RT%s:routine" % prefix, self._routine),             # <<<<<<<<<<<<<<
 *         ]
 * 
 */
  __pyx_t_3 = __Pyx_PyString_FormatSafe(__pyx_kp_s_RT_s_routine, __pyx_v_prefix); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_routine); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
  __pyx_t_3 = 0;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2188
 *         self._scheduler = scheduler
 *         self.prefix = prefix
 *         self.to_schedule = [             # <<<<<<<<<<<<<<
 *             ("RT%s:merge_loop" % prefix, self._merge_loop),
 *             ("RT%s:routine" % prefix, self._routine),
 */
  __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2188, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_t_4);
  __pyx_t_2 = 0;
  __pyx_t_4 = 0;
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_to_schedule, __pyx_t_1) < 0) __PYX_ERR(0, 2188, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2169
 *     _lock = None
 * 
 *     def __init__(self, scheduler, debuglvl=0, prefix=""):             # <<<<<<<<<<<<<<
 *         self.debuglvl = debuglvl
 *         self.trie = datrie.Trie(u"01")
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2193
 *         ]
 * 
 *     def stop_bg(self):             # <<<<<<<<<<<<<<
 *         """stop the routing table and return immediately"""
 *         if not self.stoped:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_3stop_bg(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_2stop_bg[] = "stop the routing table and return immediately";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_3stop_bg = {"stop_bg", (PyCFunction)__pyx_pw_5btdht_3dht_12RoutingTable_3stop_bg, METH_O, __pyx_doc_5btdht_3dht_12RoutingTable_2stop_bg};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_3stop_bg(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stop_bg (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_2stop_bg(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_2stop_bg(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stop_bg", 0);

  /* "btdht/dht.pyx":2195
 *     def stop_bg(self):
 *         """stop the routing table and return immediately"""
 *         if not self.stoped:             # <<<<<<<<<<<<<<
 *             Thread(target=self.stop).start()
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_stoped); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2195, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2195, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (__pyx_t_3) {

    /* "btdht/dht.pyx":2196
 *         """stop the routing table and return immediately"""
 *         if not self.stoped:
 *             Thread(target=self.stop).start()             # <<<<<<<<<<<<<<
 * 
 *     def stop(self):
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_Thread); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2196, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2196, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_stop); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2196, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_target, __pyx_t_6) < 0) __PYX_ERR(0, 2196, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2196, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_start); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2196, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2196, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":2195
 *     def stop_bg(self):
 *         """stop the routing table and return immediately"""
 *         if not self.stoped:             # <<<<<<<<<<<<<<
 *             Thread(target=self.stop).start()
 * 
 */
  }

  /* "btdht/dht.pyx":2193
 *         ]
 * 
 *     def stop_bg(self):             # <<<<<<<<<<<<<<
 *         """stop the routing table and return immediately"""
 *         if not self.stoped:
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.stop_bg", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2198
 *             Thread(target=self.stop).start()
 * 
 *     def stop(self):             # <<<<<<<<<<<<<<
 *         """stop the routing table and wait for all threads to terminate"""
 *         if self.stoped:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_5stop(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_4stop[] = "stop the routing table and wait for all threads to terminate";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_5stop = {"stop", (PyCFunction)__pyx_pw_5btdht_3dht_12RoutingTable_5stop, METH_O, __pyx_doc_5btdht_3dht_12RoutingTable_4stop};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_5stop(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stop (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_4stop(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_4stop(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_v_s = NULL;
  long __pyx_v_i;
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  long __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stop", 0);

  /* "btdht/dht.pyx":2200
 *     def stop(self):
 *         """stop the routing table and wait for all threads to terminate"""
 *         if self.stoped:             # <<<<<<<<<<<<<<
 *             self.debug(0, "Already stoped or stoping in progress")
 *             return
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_stoped); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2200, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2200, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "btdht/dht.pyx":2201
 *         """stop the routing table and wait for all threads to terminate"""
 *         if self.stoped:
 *             self.debug(0, "Already stoped or stoping in progress")             # <<<<<<<<<<<<<<
 *             return
 *         for s in self.to_schedule:
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2201, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2201, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":2202
 *         if self.stoped:
 *             self.debug(0, "Already stoped or stoping in progress")
 *             return             # <<<<<<<<<<<<<<
 *         for s in self.to_schedule:
 *             self._scheduler.del_thread(s[0])
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "btdht/dht.pyx":2200
 *     def stop(self):
 *         """stop the routing table and wait for all threads to terminate"""
 *         if self.stoped:             # <<<<<<<<<<<<<<
 *             self.debug(0, "Already stoped or stoping in progress")
 *             return
 */
  }

  /* "btdht/dht.pyx":2203
 *             self.debug(0, "Already stoped or stoping in progress")
 *             return
 *         for s in self.to_schedule:             # <<<<<<<<<<<<<<
 *             self._scheduler.del_thread(s[0])
 *         self.stoped = True
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_to_schedule); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2203, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2203, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2203, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2203, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2203, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2203, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2203, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_5(__pyx_t_1);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2203, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_XDECREF_SET(__pyx_v_s, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":2204
 *             return
 *         for s in self.to_schedule:
 *             self._scheduler.del_thread(s[0])             # <<<<<<<<<<<<<<
 *         self.stoped = True
 *         self._threads = [t for t in self._threads[:] if t.is_alive()]
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_scheduler_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_del_thread); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_s, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_3 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "btdht/dht.pyx":2203
 *             self.debug(0, "Already stoped or stoping in progress")
 *             return
 *         for s in self.to_schedule:             # <<<<<<<<<<<<<<
 *             self._scheduler.del_thread(s[0])
 *         self.stoped = True
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2205
 *         for s in self.to_schedule:
 *             self._scheduler.del_thread(s[0])
 *         self.stoped = True             # <<<<<<<<<<<<<<
 *         self._threads = [t for t in self._threads[:] if t.is_alive()]
 *         #self.debug(0, "Trying to terminate thread for 1 minutes")
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_stoped, Py_True) < 0) __PYX_ERR(0, 2205, __pyx_L1_error)

  /* "btdht/dht.pyx":2206
 *             self._scheduler.del_thread(s[0])
 *         self.stoped = True
 *         self._threads = [t for t in self._threads[:] if t.is_alive()]             # <<<<<<<<<<<<<<
 *         #self.debug(0, "Trying to terminate thread for 1 minutes")
 *         for i in range(0, 30):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2206, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2206, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetSlice(__pyx_t_3, 0, 0, NULL, NULL, &__pyx_slice__7, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2206, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
    __pyx_t_3 = __pyx_t_7; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2206, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2206, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_7); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2206, __pyx_L1_error)
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2206, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_7); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2206, __pyx_L1_error)
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2206, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_5(__pyx_t_3);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2206, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_is_alive); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2206, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_7 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2206, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2206, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__pyx_t_2) {
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_v_t))) __PYX_ERR(0, 2206, __pyx_L1_error)
    }
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_threads_2, __pyx_t_1) < 0) __PYX_ERR(0, 2206, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2208
 *         self._threads = [t for t in self._threads[:] if t.is_alive()]
 *         #self.debug(0, "Trying to terminate thread for 1 minutes")
 *         for i in range(0, 30):             # <<<<<<<<<<<<<<
 *             if self._threads:
 *                 if i > 5:
 */
  for (__pyx_t_9 = 0; __pyx_t_9 < 30; __pyx_t_9+=1) {
    __pyx_v_i = __pyx_t_9;

    /* "btdht/dht.pyx":2209
 *         #self.debug(0, "Trying to terminate thread for 1 minutes")
 *         for i in range(0, 30):
 *             if self._threads:             # <<<<<<<<<<<<<<
 *                 if i > 5:
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2209, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2209, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_2) {

      /* "btdht/dht.pyx":2210
 *         for i in range(0, 30):
 *             if self._threads:
 *                 if i > 5:             # <<<<<<<<<<<<<<
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))
 *                 time.sleep(1)
 */
      __pyx_t_2 = ((__pyx_v_i > 5) != 0);
      if (__pyx_t_2) {

        /* "btdht/dht.pyx":2211
 *             if self._threads:
 *                 if i > 5:
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))             # <<<<<<<<<<<<<<
 *                 time.sleep(1)
 *                 self._threads = [t for t in self._threads[:] if t.is_alive()]
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2211, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2211, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_4 = PyObject_Length(__pyx_t_7); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2211, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2211, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_Waiting_for_s_threads_to_termina, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2211, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = NULL;
        __pyx_t_10 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
            __pyx_t_10 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_int_0, __pyx_t_6};
          __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2211, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_int_0, __pyx_t_6};
          __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2211, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        {
          __pyx_t_8 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2211, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          if (__pyx_t_7) {
            __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL;
          }
          __Pyx_INCREF(__pyx_int_0);
          __Pyx_GIVEREF(__pyx_int_0);
          PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_10, __pyx_int_0);
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_10, __pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2211, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "btdht/dht.pyx":2210
 *         for i in range(0, 30):
 *             if self._threads:
 *                 if i > 5:             # <<<<<<<<<<<<<<
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))
 *                 time.sleep(1)
 */
      }

      /* "btdht/dht.pyx":2212
 *                 if i > 5:
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))
 *                 time.sleep(1)             # <<<<<<<<<<<<<<
 *                 self._threads = [t for t in self._threads[:] if t.is_alive()]
 *             else:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2212, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_sleep); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2212, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_3, __pyx_int_1) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_int_1);
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2212, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "btdht/dht.pyx":2213
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))
 *                 time.sleep(1)
 *                 self._threads = [t for t in self._threads[:] if t.is_alive()]             # <<<<<<<<<<<<<<
 *             else:
 *                 break
 */
      __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_t_8, 0, 0, NULL, NULL, &__pyx_slice__7, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2213, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
        __pyx_t_8 = __pyx_t_3; __Pyx_INCREF(__pyx_t_8); __pyx_t_4 = 0;
        __pyx_t_5 = NULL;
      } else {
        __pyx_t_4 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2213, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_5 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2213, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      for (;;) {
        if (likely(!__pyx_t_5)) {
          if (likely(PyList_CheckExact(__pyx_t_8))) {
            if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_8)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2213, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_8, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2213, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          } else {
            if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2213, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_8, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2213, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          }
        } else {
          __pyx_t_3 = __pyx_t_5(__pyx_t_8);
          if (unlikely(!__pyx_t_3)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 2213, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_3);
        }
        __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_3);
        __pyx_t_3 = 0;
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_is_alive); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2213, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
          }
        }
        __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2213, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2213, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_2) {
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_v_t))) __PYX_ERR(0, 2213, __pyx_L1_error)
        }
      }
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_threads_2, __pyx_t_1) < 0) __PYX_ERR(0, 2213, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "btdht/dht.pyx":2209
 *         #self.debug(0, "Trying to terminate thread for 1 minutes")
 *         for i in range(0, 30):
 *             if self._threads:             # <<<<<<<<<<<<<<
 *                 if i > 5:
 *                     self.debug(0, "Waiting for %s threads to terminate" % len(self._threads))
 */
      goto __pyx_L11;
    }

    /* "btdht/dht.pyx":2215
 *                 self._threads = [t for t in self._threads[:] if t.is_alive()]
 *             else:
 *                 break             # <<<<<<<<<<<<<<
 *         if self._threads:
 *             self.debug(
 */
    /*else*/ {
      goto __pyx_L10_break;
    }
    __pyx_L11:;
  }
  __pyx_L10_break:;

  /* "btdht/dht.pyx":2216
 *             else:
 *                 break
 *         if self._threads:             # <<<<<<<<<<<<<<
 *             self.debug(
 *                 0,
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2216, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2216, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "btdht/dht.pyx":2217
 *                 break
 *         if self._threads:
 *             self.debug(             # <<<<<<<<<<<<<<
 *                 0,
 *                 "Unable to stop %s threads, giving up:\n%r" % (len(self._threads), self._threads)
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);

    /* "btdht/dht.pyx":2219
 *             self.debug(
 *                 0,
 *                 "Unable to stop %s threads, giving up:\n%r" % (len(self._threads), self._threads)             # <<<<<<<<<<<<<<
 *             )
 *             self.zombie = True
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2219, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2219, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2219, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2219, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2219, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
    __pyx_t_3 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_Unable_to_stop_s_threads_giving, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2219, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_int_0, __pyx_t_6};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2217, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_int_0, __pyx_t_6};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2217, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    {
      __pyx_t_3 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2217, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__pyx_t_7) {
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7); __pyx_t_7 = NULL;
      }
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_10, __pyx_int_0);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_10, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2217, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":2221
 *                 "Unable to stop %s threads, giving up:\n%r" % (len(self._threads), self._threads)
 *             )
 *             self.zombie = True             # <<<<<<<<<<<<<<
 *             self._threads_zombie.extend(self._threads)
 *             self._threads = []
 */
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_zombie, Py_True) < 0) __PYX_ERR(0, 2221, __pyx_L1_error)

    /* "btdht/dht.pyx":2222
 *             )
 *             self.zombie = True
 *             self._threads_zombie.extend(self._threads)             # <<<<<<<<<<<<<<
 *             self._threads = []
 * 
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads_zombie); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2222, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_extend); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2222, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2222, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_8);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2222, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":2223
 *             self.zombie = True
 *             self._threads_zombie.extend(self._threads)
 *             self._threads = []             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_threads_2, __pyx_t_1) < 0) __PYX_ERR(0, 2223, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":2216
 *             else:
 *                 break
 *         if self._threads:             # <<<<<<<<<<<<<<
 *             self.debug(
 *                 0,
 */
  }

  /* "btdht/dht.pyx":2198
 *             Thread(target=self.stop).start()
 * 
 *     def stop(self):             # <<<<<<<<<<<<<<
 *         """stop the routing table and wait for all threads to terminate"""
 *         if self.stoped:
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.stop", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_s);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2226
 * 
 *     @property
 *     def zombie(self):             # <<<<<<<<<<<<<<
 *         """``True`` if dht is stopped but one thread or more remains alive, ``False`` otherwise"""
 *         return self.stoped and [t for t in self._threads if t.is_alive()]
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_7zombie(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_6zombie[] = "``True`` if dht is stopped but one thread or more remains alive, ``False`` otherwise";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_7zombie = {"zombie", (PyCFunction)__pyx_pw_5btdht_3dht_12RoutingTable_7zombie, METH_O, __pyx_doc_5btdht_3dht_12RoutingTable_6zombie};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_7zombie(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("zombie (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_6zombie(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_6zombie(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("zombie", 0);

  /* "btdht/dht.pyx":2228
 *     def zombie(self):
 *         """``True`` if dht is stopped but one thread or more remains alive, ``False`` otherwise"""
 *         return self.stoped and [t for t in self._threads if t.is_alive()]             # <<<<<<<<<<<<<<
 * 
 *     def start(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_stoped); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2228, __pyx_L1_error)
  if (__pyx_t_3) {
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_1 = __pyx_t_2;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L3_bool_binop_done;
  }
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_5 = __pyx_t_4; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2228, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2228, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_5))) {
        if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 2228, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2228, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 2228, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2228, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_7(__pyx_t_5);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2228, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_is_alive); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2228, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    __pyx_t_4 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_8);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2228, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2228, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_3) {
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_v_t))) __PYX_ERR(0, 2228, __pyx_L1_error)
    }
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_1 = __pyx_t_2;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_L3_bool_binop_done:;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":2226
 * 
 *     @property
 *     def zombie(self):             # <<<<<<<<<<<<<<
 *         """``True`` if dht is stopped but one thread or more remains alive, ``False`` otherwise"""
 *         return self.stoped and [t for t in self._threads if t.is_alive()]
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.zombie", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2230
 *         return self.stoped and [t for t in self._threads if t.is_alive()]
 * 
 *     def start(self):             # <<<<<<<<<<<<<<
 *         """start the routing table"""
 *         with self._lock:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_9start(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_8start[] = "start the routing table";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_9start = {"start", (PyCFunction)__pyx_pw_5btdht_3dht_12RoutingTable_9start, METH_O, __pyx_doc_5btdht_3dht_12RoutingTable_8start};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_9start(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("start (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_8start(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_8start(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_v_name = NULL;
  PyObject *__pyx_v_function = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  Py_ssize_t __pyx_t_12;
  PyObject *(*__pyx_t_13)(PyObject *);
  PyObject *__pyx_t_14 = NULL;
  PyObject *(*__pyx_t_15)(PyObject *);
  int __pyx_t_16;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("start", 0);

  /* "btdht/dht.pyx":2232
 *     def start(self):
 *         """start the routing table"""
 *         with self._lock:             # <<<<<<<<<<<<<<
 *             if not self.stoped:
 *                 self.debug(0, "Already started")
 */
  /*with:*/ {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_lock); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2232, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_LookupSpecial(__pyx_t_1, __pyx_n_s_exit); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2232, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_LookupSpecial(__pyx_t_1, __pyx_n_s_enter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2232, __pyx_L3_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2232, __pyx_L3_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    /*try:*/ {
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
        __Pyx_XGOTREF(__pyx_t_6);
        __Pyx_XGOTREF(__pyx_t_7);
        __Pyx_XGOTREF(__pyx_t_8);
        /*try:*/ {

          /* "btdht/dht.pyx":2233
 *         """start the routing table"""
 *         with self._lock:
 *             if not self.stoped:             # <<<<<<<<<<<<<<
 *                 self.debug(0, "Already started")
 *                 return
 */
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_stoped); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2233, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 2233, __pyx_L7_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_10 = ((!__pyx_t_9) != 0);
          if (__pyx_t_10) {

            /* "btdht/dht.pyx":2234
 *         with self._lock:
 *             if not self.stoped:
 *                 self.debug(0, "Already started")             # <<<<<<<<<<<<<<
 *                 return
 *             if self.zombie:
 */
            __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2234, __pyx_L7_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2234, __pyx_L7_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

            /* "btdht/dht.pyx":2235
 *             if not self.stoped:
 *                 self.debug(0, "Already started")
 *                 return             # <<<<<<<<<<<<<<
 *             if self.zombie:
 *                 self.debug(0, "Zombie threads, unable de start")
 */
            __Pyx_XDECREF(__pyx_r);
            __pyx_r = Py_None; __Pyx_INCREF(Py_None);
            goto __pyx_L11_try_return;

            /* "btdht/dht.pyx":2233
 *         """start the routing table"""
 *         with self._lock:
 *             if not self.stoped:             # <<<<<<<<<<<<<<
 *                 self.debug(0, "Already started")
 *                 return
 */
          }

          /* "btdht/dht.pyx":2236
 *                 self.debug(0, "Already started")
 *                 return
 *             if self.zombie:             # <<<<<<<<<<<<<<
 *                 self.debug(0, "Zombie threads, unable de start")
 *                 return self._threads_zombie
 */
          __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_zombie); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2236, __pyx_L7_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 2236, __pyx_L7_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          if (__pyx_t_10) {

            /* "btdht/dht.pyx":2237
 *                 return
 *             if self.zombie:
 *                 self.debug(0, "Zombie threads, unable de start")             # <<<<<<<<<<<<<<
 *                 return self._threads_zombie
 *             self.stoped = False
 */
            __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2237, __pyx_L7_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2237, __pyx_L7_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

            /* "btdht/dht.pyx":2238
 *             if self.zombie:
 *                 self.debug(0, "Zombie threads, unable de start")
 *                 return self._threads_zombie             # <<<<<<<<<<<<<<
 *             self.stoped = False
 * 
 */
            __Pyx_XDECREF(__pyx_r);
            __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads_zombie); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2238, __pyx_L7_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_r = __pyx_t_1;
            __pyx_t_1 = 0;
            goto __pyx_L11_try_return;

            /* "btdht/dht.pyx":2236
 *                 self.debug(0, "Already started")
 *                 return
 *             if self.zombie:             # <<<<<<<<<<<<<<
 *                 self.debug(0, "Zombie threads, unable de start")
 *                 return self._threads_zombie
 */
          }

          /* "btdht/dht.pyx":2239
 *                 self.debug(0, "Zombie threads, unable de start")
 *                 return self._threads_zombie
 *             self.stoped = False             # <<<<<<<<<<<<<<
 * 
 *         for (name, function) in self.to_schedule:
 */
          if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_stoped, Py_False) < 0) __PYX_ERR(0, 2239, __pyx_L7_error)

          /* "btdht/dht.pyx":2232
 *     def start(self):
 *         """start the routing table"""
 *         with self._lock:             # <<<<<<<<<<<<<<
 *             if not self.stoped:
 *                 self.debug(0, "Already started")
 */
        }
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        goto __pyx_L12_try_end;
        __pyx_L7_error:;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        /*except:*/ {
          __Pyx_AddTraceback("btdht.dht.RoutingTable.start", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_3, &__pyx_t_4) < 0) __PYX_ERR(0, 2232, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_5 = PyTuple_Pack(3, __pyx_t_1, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2232, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2232, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          if (__pyx_t_10 < 0) __PYX_ERR(0, 2232, __pyx_L9_except_error)
          __pyx_t_9 = ((!(__pyx_t_10 != 0)) != 0);
          if (__pyx_t_9) {
            __Pyx_GIVEREF(__pyx_t_1);
            __Pyx_GIVEREF(__pyx_t_3);
            __Pyx_XGIVEREF(__pyx_t_4);
            __Pyx_ErrRestoreWithState(__pyx_t_1, __pyx_t_3, __pyx_t_4);
            __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0; 
            __PYX_ERR(0, 2232, __pyx_L9_except_error)
          }
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          goto __pyx_L8_exception_handled;
        }
        __pyx_L9_except_error:;
        __Pyx_XGIVEREF(__pyx_t_6);
        __Pyx_XGIVEREF(__pyx_t_7);
        __Pyx_XGIVEREF(__pyx_t_8);
        __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
        goto __pyx_L1_error;
        __pyx_L11_try_return:;
        __Pyx_XGIVEREF(__pyx_t_6);
        __Pyx_XGIVEREF(__pyx_t_7);
        __Pyx_XGIVEREF(__pyx_t_8);
        __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
        goto __pyx_L4_return;
        __pyx_L8_exception_handled:;
        __Pyx_XGIVEREF(__pyx_t_6);
        __Pyx_XGIVEREF(__pyx_t_7);
        __Pyx_XGIVEREF(__pyx_t_8);
        __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
        __pyx_L12_try_end:;
      }
    }
    /*finally:*/ {
      /*normal exit:*/{
        if (__pyx_t_2) {
          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__5, NULL);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2232, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        }
        goto __pyx_L6;
      }
      __pyx_L4_return: {
        __pyx_t_8 = __pyx_r;
        __pyx_r = 0;
        if (__pyx_t_2) {
          __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__5, NULL);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2232, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        }
        __pyx_r = __pyx_t_8;
        __pyx_t_8 = 0;
        goto __pyx_L0;
      }
      __pyx_L6:;
    }
    goto __pyx_L18;
    __pyx_L3_error:;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L1_error;
    __pyx_L18:;
  }

  /* "btdht/dht.pyx":2241
 *             self.stoped = False
 * 
 *         for (name, function) in self.to_schedule:             # <<<<<<<<<<<<<<
 *             self._scheduler.add_thread(name, function)
 * 
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_to_schedule); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2241, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_3 = __pyx_t_4; __Pyx_INCREF(__pyx_t_3); __pyx_t_12 = 0;
    __pyx_t_13 = NULL;
  } else {
    __pyx_t_12 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2241, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_13 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2241, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_13)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_12); __Pyx_INCREF(__pyx_t_4); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 2241, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2241, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_12); __Pyx_INCREF(__pyx_t_4); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 2241, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2241, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_13(__pyx_t_3);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2241, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
      PyObject* sequence = __pyx_t_4;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 2241, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_5);
      #else
      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2241, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2241, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_14 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2241, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext;
      index = 0; __pyx_t_1 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_1)) goto __pyx_L21_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_1);
      index = 1; __pyx_t_5 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_5)) goto __pyx_L21_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_5);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) __PYX_ERR(0, 2241, __pyx_L1_error)
      __pyx_t_15 = NULL;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      goto __pyx_L22_unpacking_done;
      __pyx_L21_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_15 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 2241, __pyx_L1_error)
      __pyx_L22_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_function, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "btdht/dht.pyx":2242
 * 
 *         for (name, function) in self.to_schedule:
 *             self._scheduler.add_thread(name, function)             # <<<<<<<<<<<<<<
 * 
 *     def is_alive(self):
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_scheduler_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2242, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_add_thread); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2242, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    __pyx_t_16 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
        __pyx_t_16 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_name, __pyx_v_function};
      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2242, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_name, __pyx_v_function};
      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2242, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else
    #endif
    {
      __pyx_t_14 = PyTuple_New(2+__pyx_t_16); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2242, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_INCREF(__pyx_v_name);
      __Pyx_GIVEREF(__pyx_v_name);
      PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_16, __pyx_v_name);
      __Pyx_INCREF(__pyx_v_function);
      __Pyx_GIVEREF(__pyx_v_function);
      PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_16, __pyx_v_function);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_14, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2242, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "btdht/dht.pyx":2241
 *             self.stoped = False
 * 
 *         for (name, function) in self.to_schedule:             # <<<<<<<<<<<<<<
 *             self._scheduler.add_thread(name, function)
 * 
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "btdht/dht.pyx":2230
 *         return self.stoped and [t for t in self._threads if t.is_alive()]
 * 
 *     def start(self):             # <<<<<<<<<<<<<<
 *         """start the routing table"""
 *         with self._lock:
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.start", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XDECREF(__pyx_v_function);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2244
 *             self._scheduler.add_thread(name, function)
 * 
 *     def is_alive(self):             # <<<<<<<<<<<<<<
 *         """
 *             Test if all routing table threads are alive. If a thread is found dead, stop the
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_11is_alive(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_10is_alive[] = "\n            Test if all routing table threads are alive. If a thread is found dead, stop the\n            routingtable\n\n            :return: ``True`` if all routing table threads are alive, ``False`` otherwise\n            :rtype: bool\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_11is_alive = {"is_alive", (PyCFunction)__pyx_pw_5btdht_3dht_12RoutingTable_11is_alive, METH_O, __pyx_doc_5btdht_3dht_12RoutingTable_10is_alive};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_11is_alive(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_alive (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_10is_alive(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_10is_alive(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_v_weigthless_threads_satus = NULL;
  PyObject *__pyx_v_s = NULL;
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("is_alive", 0);

  /* "btdht/dht.pyx":2252
 *             :rtype: bool
 *         """
 *         weigthless_threads_satus = [             # <<<<<<<<<<<<<<
 *             self._scheduler.thread_alive(s[0]) for s in self.to_schedule
 *         ]
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2252, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "btdht/dht.pyx":2253
 *         """
 *         weigthless_threads_satus = [
 *             self._scheduler.thread_alive(s[0]) for s in self.to_schedule             # <<<<<<<<<<<<<<
 *         ]
 *         if (
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_to_schedule); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2253, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2253, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2253, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2253, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2253, __pyx_L1_error)
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2253, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_5(__pyx_t_3);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2253, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XDECREF_SET(__pyx_v_s, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_scheduler_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_thread_alive); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_s, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_2 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 2252, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_weigthless_threads_satus = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2256
 *         ]
 *         if (
 *             self.threads is not None and             # <<<<<<<<<<<<<<
 *             all([t.is_alive() for t in self.threads]) and
 *             all(weigthless_threads_satus)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2256, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_10 = (__pyx_t_1 != Py_None);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_11 = (__pyx_t_10 != 0);
  if (__pyx_t_11) {
  } else {
    __pyx_t_9 = __pyx_t_11;
    goto __pyx_L6_bool_binop_done;
  }

  /* "btdht/dht.pyx":2257
 *         if (
 *             self.threads is not None and
 *             all([t.is_alive() for t in self.threads]) and             # <<<<<<<<<<<<<<
 *             all(weigthless_threads_satus)
 *         ):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2257, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2257, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2257, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2257, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2257, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2257, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2257, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2257, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_5(__pyx_t_2);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2257, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_is_alive); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2257, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2257, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 2257, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_all, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2257, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2257, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_11) {
  } else {
    __pyx_t_9 = __pyx_t_11;
    goto __pyx_L6_bool_binop_done;
  }

  /* "btdht/dht.pyx":2258
 *             self.threads is not None and
 *             all([t.is_alive() for t in self.threads]) and
 *             all(weigthless_threads_satus)             # <<<<<<<<<<<<<<
 *         ):
 *             return True
 */
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_all, __pyx_v_weigthless_threads_satus); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2258, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2258, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_9 = __pyx_t_11;
  __pyx_L6_bool_binop_done:;

  /* "btdht/dht.pyx":2255
 *             self._scheduler.thread_alive(s[0]) for s in self.to_schedule
 *         ]
 *         if (             # <<<<<<<<<<<<<<
 *             self.threads is not None and
 *             all([t.is_alive() for t in self.threads]) and
 */
  if (__pyx_t_9) {

    /* "btdht/dht.pyx":2260
 *             all(weigthless_threads_satus)
 *         ):
 *             return True             # <<<<<<<<<<<<<<
 *         elif not self._threads and self.stoped and not any(weigthless_threads_satus):
 *             return False
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_True);
    __pyx_r = Py_True;
    goto __pyx_L0;

    /* "btdht/dht.pyx":2255
 *             self._scheduler.thread_alive(s[0]) for s in self.to_schedule
 *         ]
 *         if (             # <<<<<<<<<<<<<<
 *             self.threads is not None and
 *             all([t.is_alive() for t in self.threads]) and
 */
  }

  /* "btdht/dht.pyx":2261
 *         ):
 *             return True
 *         elif not self._threads and self.stoped and not any(weigthless_threads_satus):             # <<<<<<<<<<<<<<
 *             return False
 *         else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_threads_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2261, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2261, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_10 = ((!__pyx_t_11) != 0);
  if (__pyx_t_10) {
  } else {
    __pyx_t_9 = __pyx_t_10;
    goto __pyx_L11_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_stoped); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2261, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 2261, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_10) {
  } else {
    __pyx_t_9 = __pyx_t_10;
    goto __pyx_L11_bool_binop_done;
  }
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_any, __pyx_v_weigthless_threads_satus); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2261, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 2261, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_11 = ((!__pyx_t_10) != 0);
  __pyx_t_9 = __pyx_t_11;
  __pyx_L11_bool_binop_done:;
  if (__pyx_t_9) {

    /* "btdht/dht.pyx":2262
 *             return True
 *         elif not self._threads and self.stoped and not any(weigthless_threads_satus):
 *             return False             # <<<<<<<<<<<<<<
 *         else:
 *             self.debug(0, "One thread died, stopping dht")
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_False);
    __pyx_r = Py_False;
    goto __pyx_L0;

    /* "btdht/dht.pyx":2261
 *         ):
 *             return True
 *         elif not self._threads and self.stoped and not any(weigthless_threads_satus):             # <<<<<<<<<<<<<<
 *             return False
 *         else:
 */
  }

  /* "btdht/dht.pyx":2264
 *             return False
 *         else:
 *             self.debug(0, "One thread died, stopping dht")             # <<<<<<<<<<<<<<
 *             self.stop_bg()
 *             return True
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2264, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2264, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":2265
 *         else:
 *             self.debug(0, "One thread died, stopping dht")
 *             self.stop_bg()             # <<<<<<<<<<<<<<
 *             return True
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_stop_bg); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2265, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2265, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":2266
 *             self.debug(0, "One thread died, stopping dht")
 *             self.stop_bg()
 *             return True             # <<<<<<<<<<<<<<
 * 
 *     def register_torrent(self, id):
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_True);
    __pyx_r = Py_True;
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":2244
 *             self._scheduler.add_thread(name, function)
 * 
 *     def is_alive(self):             # <<<<<<<<<<<<<<
 *         """
 *             Test if all routing table threads are alive. If a thread is found dead, stop the
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.is_alive", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_weigthless_threads_satus);
  __Pyx_XDECREF(__pyx_v_s);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2268
 *             return True
 * 
 *     def register_torrent(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             Register a torrent ``id`` (info_hash) for being tracked by the routing table.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_13register_torrent(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_12register_torrent[] = "\n            Register a torrent ``id`` (info_hash) for being tracked by the routing table.\n            This means that if a node need to be added to the bucket handling ``id``and the\n            bucket is full, then, this bucket will be split into 2 buckets\n\n            :param bytes id: A 160 bits (20 Bytes) torrent identifier\n\n            Note:\n              torrent ids can automaticaly be release by a dht instance after a get_peers.\n              For keeping a torrent registered, use the method :meth:`register_torrent_longterm`\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_13register_torrent = {"register_torrent", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_13register_torrent, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_12RoutingTable_12register_torrent};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_13register_torrent(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_id = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("register_torrent (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_id,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("register_torrent", 1, 2, 2, 1); __PYX_ERR(0, 2268, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "register_torrent") < 0)) __PYX_ERR(0, 2268, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_self = values[0];
    __pyx_v_id = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("register_torrent", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2268, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.register_torrent", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_12register_torrent(__pyx_self, __pyx_v_self, __pyx_v_id);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_12register_torrent(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("register_torrent", 0);

  /* "btdht/dht.pyx":2280
 *               For keeping a torrent registered, use the method :meth:`register_torrent_longterm`
 *         """
 *         self._info_hash.add(id)             # <<<<<<<<<<<<<<
 * 
 *     def release_torrent(self, id):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_info_hash_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_add); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_id);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2268
 *             return True
 * 
 *     def register_torrent(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             Register a torrent ``id`` (info_hash) for being tracked by the routing table.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.register_torrent", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2282
 *         self._info_hash.add(id)
 * 
 *     def release_torrent(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             Release a torrent ``id`` (info_hash) and program the routing table to be merged
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_15release_torrent(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_14release_torrent[] = "\n            Release a torrent ``id`` (info_hash) and program the routing table to be merged\n\n            :param bytes id: A 160 bits (20 Bytes) torrent identifier\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_15release_torrent = {"release_torrent", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_15release_torrent, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_12RoutingTable_14release_torrent};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_15release_torrent(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_id = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("release_torrent (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_id,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("release_torrent", 1, 2, 2, 1); __PYX_ERR(0, 2282, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "release_torrent") < 0)) __PYX_ERR(0, 2282, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_self = values[0];
    __pyx_v_id = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("release_torrent", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2282, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.release_torrent", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_14release_torrent(__pyx_self, __pyx_v_self, __pyx_v_id);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_14release_torrent(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id) {
  CYTHON_UNUSED PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_t_16;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("release_torrent", 0);

  /* "btdht/dht.pyx":2288
 *             :param bytes id: A 160 bits (20 Bytes) torrent identifier
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             self._info_hash.remove(id)
 *             if not id in self._split_ids:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "btdht/dht.pyx":2289
 *         """
 *         try:
 *             self._info_hash.remove(id)             # <<<<<<<<<<<<<<
 *             if not id in self._split_ids:
 *                 try:
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_info_hash_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2289, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_remove); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2289, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_id);
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2289, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "btdht/dht.pyx":2290
 *         try:
 *             self._info_hash.remove(id)
 *             if not id in self._split_ids:             # <<<<<<<<<<<<<<
 *                 try:
 *                     key = self.trie.longest_prefix(utils.id_to_longid(ID.to_bytes(id)))
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_split_ids); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2290, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_v_id, __pyx_t_4, Py_NE)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 2290, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_8 = (__pyx_t_7 != 0);
      if (__pyx_t_8) {

        /* "btdht/dht.pyx":2291
 *             self._info_hash.remove(id)
 *             if not id in self._split_ids:
 *                 try:             # <<<<<<<<<<<<<<
 *                     key = self.trie.longest_prefix(utils.id_to_longid(ID.to_bytes(id)))
 *                     #self._to_merge.add(key)
 */
        {
          __Pyx_PyThreadState_declare
          __Pyx_PyThreadState_assign
          __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
          __Pyx_XGOTREF(__pyx_t_9);
          __Pyx_XGOTREF(__pyx_t_10);
          __Pyx_XGOTREF(__pyx_t_11);
          /*try:*/ {

            /* "btdht/dht.pyx":2292
 *             if not id in self._split_ids:
 *                 try:
 *                     key = self.trie.longest_prefix(utils.id_to_longid(ID.to_bytes(id)))             # <<<<<<<<<<<<<<
 *                     #self._to_merge.add(key)
 *                 except KeyError:
 */
            __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2292, __pyx_L10_error)
            __Pyx_GOTREF(__pyx_t_6);
            __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_longest_prefix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2292, __pyx_L10_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_utils); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2292, __pyx_L10_error)
            __Pyx_GOTREF(__pyx_t_12);
            __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_id_to_longid); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2292, __pyx_L10_error)
            __Pyx_GOTREF(__pyx_t_13);
            __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
            __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_ID); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2292, __pyx_L10_error)
            __Pyx_GOTREF(__pyx_t_14);
            __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_to_bytes); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2292, __pyx_L10_error)
            __Pyx_GOTREF(__pyx_t_15);
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
            __pyx_t_14 = NULL;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_15))) {
              __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_15);
              if (likely(__pyx_t_14)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
                __Pyx_INCREF(__pyx_t_14);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_15, function);
              }
            }
            __pyx_t_12 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_15, __pyx_t_14, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_v_id);
            __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
            if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2292, __pyx_L10_error)
            __Pyx_GOTREF(__pyx_t_12);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            __pyx_t_15 = NULL;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) {
              __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_13);
              if (likely(__pyx_t_15)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
                __Pyx_INCREF(__pyx_t_15);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_13, function);
              }
            }
            __pyx_t_6 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_15, __pyx_t_12) : __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_12);
            __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
            __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
            if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2292, __pyx_L10_error)
            __Pyx_GOTREF(__pyx_t_6);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
            __pyx_t_13 = NULL;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
              __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_5);
              if (likely(__pyx_t_13)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
                __Pyx_INCREF(__pyx_t_13);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_5, function);
              }
            }
            __pyx_t_4 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_13, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6);
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2292, __pyx_L10_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __pyx_v_key = __pyx_t_4;
            __pyx_t_4 = 0;

            /* "btdht/dht.pyx":2291
 *             self._info_hash.remove(id)
 *             if not id in self._split_ids:
 *                 try:             # <<<<<<<<<<<<<<
 *                     key = self.trie.longest_prefix(utils.id_to_longid(ID.to_bytes(id)))
 *                     #self._to_merge.add(key)
 */
          }
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          goto __pyx_L15_try_end;
          __pyx_L10_error:;
          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

          /* "btdht/dht.pyx":2294
 *                     key = self.trie.longest_prefix(utils.id_to_longid(ID.to_bytes(id)))
 *                     #self._to_merge.add(key)
 *                 except KeyError:             # <<<<<<<<<<<<<<
 *                     pass
 *                 if not self.need_merge:
 */
          __pyx_t_16 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
          if (__pyx_t_16) {
            __Pyx_ErrRestore(0,0,0);
            goto __pyx_L11_exception_handled;
          }
          goto __pyx_L12_except_error;
          __pyx_L12_except_error:;

          /* "btdht/dht.pyx":2291
 *             self._info_hash.remove(id)
 *             if not id in self._split_ids:
 *                 try:             # <<<<<<<<<<<<<<
 *                     key = self.trie.longest_prefix(utils.id_to_longid(ID.to_bytes(id)))
 *                     #self._to_merge.add(key)
 */
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_XGIVEREF(__pyx_t_10);
          __Pyx_XGIVEREF(__pyx_t_11);
          __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
          goto __pyx_L3_error;
          __pyx_L11_exception_handled:;
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_XGIVEREF(__pyx_t_10);
          __Pyx_XGIVEREF(__pyx_t_11);
          __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
          __pyx_L15_try_end:;
        }

        /* "btdht/dht.pyx":2296
 *                 except KeyError:
 *                     pass
 *                 if not self.need_merge:             # <<<<<<<<<<<<<<
 *                     self.debug(1, "Programming merge")
 *                     self.need_merge = True
 */
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_need_merge); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2296, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 2296, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_7 = ((!__pyx_t_8) != 0);
        if (__pyx_t_7) {

          /* "btdht/dht.pyx":2297
 *                     pass
 *                 if not self.need_merge:
 *                     self.debug(1, "Programming merge")             # <<<<<<<<<<<<<<
 *                     self.need_merge = True
 *         except KeyError:
 */
          __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2297, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2297, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

          /* "btdht/dht.pyx":2298
 *                 if not self.need_merge:
 *                     self.debug(1, "Programming merge")
 *                     self.need_merge = True             # <<<<<<<<<<<<<<
 *         except KeyError:
 *             pass
 */
          if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_need_merge, Py_True) < 0) __PYX_ERR(0, 2298, __pyx_L3_error)

          /* "btdht/dht.pyx":2296
 *                 except KeyError:
 *                     pass
 *                 if not self.need_merge:             # <<<<<<<<<<<<<<
 *                     self.debug(1, "Programming merge")
 *                     self.need_merge = True
 */
        }

        /* "btdht/dht.pyx":2290
 *         try:
 *             self._info_hash.remove(id)
 *             if not id in self._split_ids:             # <<<<<<<<<<<<<<
 *                 try:
 *                     key = self.trie.longest_prefix(utils.id_to_longid(ID.to_bytes(id)))
 */
      }

      /* "btdht/dht.pyx":2288
 *             :param bytes id: A 160 bits (20 Bytes) torrent identifier
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             self._info_hash.remove(id)
 *             if not id in self._split_ids:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "btdht/dht.pyx":2299
 *                     self.debug(1, "Programming merge")
 *                     self.need_merge = True
 *         except KeyError:             # <<<<<<<<<<<<<<
 *             pass
 * 
 */
    __pyx_t_16 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
    if (__pyx_t_16) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "btdht/dht.pyx":2288
 *             :param bytes id: A 160 bits (20 Bytes) torrent identifier
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             self._info_hash.remove(id)
 *             if not id in self._split_ids:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L4_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    __pyx_L8_try_end:;
  }

  /* "btdht/dht.pyx":2282
 *         self._info_hash.add(id)
 * 
 *     def release_torrent(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             Release a torrent ``id`` (info_hash) and program the routing table to be merged
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.release_torrent", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_18generator3(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "btdht/dht.pyx":2302
 *             pass
 * 
 *     def _merge_loop(self):             # <<<<<<<<<<<<<<
 *         """Weigthless thread handling the merge of the routing table"""
 *         yield 0
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_17_merge_loop(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_16_merge_loop[] = "Weigthless thread handling the merge of the routing table";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_17_merge_loop = {"_merge_loop", (PyCFunction)__pyx_pw_5btdht_3dht_12RoutingTable_17_merge_loop, METH_O, __pyx_doc_5btdht_3dht_12RoutingTable_16_merge_loop};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_17_merge_loop(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_merge_loop (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_16_merge_loop(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_16_merge_loop(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_merge_loop", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct_6__merge_loop(__pyx_ptype_5btdht_3dht___pyx_scope_struct_6__merge_loop, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2302, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5btdht_3dht_12RoutingTable_18generator3, __pyx_codeobj__33, (PyObject *) __pyx_cur_scope, __pyx_n_s_merge_loop, __pyx_n_s_RoutingTable__merge_loop, __pyx_n_s_btdht_dht); if (unlikely(!gen)) __PYX_ERR(0, 2302, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable._merge_loop", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_18generator3(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop *__pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *(*__pyx_t_10)(PyObject *);
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_merge_loop", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L4_resume_from_yield;
    case 2: goto __pyx_L8_resume_from_yield;
    case 3: goto __pyx_L14_resume_from_yield;
    case 4: goto __pyx_L20_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2302, __pyx_L1_error)

  /* "btdht/dht.pyx":2304
 *     def _merge_loop(self):
 *         """Weigthless thread handling the merge of the routing table"""
 *         yield 0             # <<<<<<<<<<<<<<
 *         next_merge = 0
 *         # at most one full merge every 10 minutes
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_r = __pyx_int_0;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  /* return from generator, yielding value */
  __pyx_generator->resume_label = 1;
  return __pyx_r;
  __pyx_L4_resume_from_yield:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2304, __pyx_L1_error)

  /* "btdht/dht.pyx":2305
 *         """Weigthless thread handling the merge of the routing table"""
 *         yield 0
 *         next_merge = 0             # <<<<<<<<<<<<<<
 *         # at most one full merge every 10 minutes
 *         next_full_merge = time.time() + 10 * 60
 */
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __pyx_cur_scope->__pyx_v_next_merge = __pyx_int_0;

  /* "btdht/dht.pyx":2307
 *         next_merge = 0
 *         # at most one full merge every 10 minutes
 *         next_full_merge = time.time() + 10 * 60             # <<<<<<<<<<<<<<
 *         while True:
 *             if self.stoped:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2307, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2307, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2307, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_600, 0x258, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2307, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_cur_scope->__pyx_v_next_full_merge = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "btdht/dht.pyx":2308
 *         # at most one full merge every 10 minutes
 *         next_full_merge = time.time() + 10 * 60
 *         while True:             # <<<<<<<<<<<<<<
 *             if self.stoped:
 *                 return
 */
  while (1) {

    /* "btdht/dht.pyx":2309
 *         next_full_merge = time.time() + 10 * 60
 *         while True:
 *             if self.stoped:             # <<<<<<<<<<<<<<
 *                 return
 *             yield max(next_merge, time.time() + 1)
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_stoped); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2309, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2309, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_4) {

      /* "btdht/dht.pyx":2310
 *         while True:
 *             if self.stoped:
 *                 return             # <<<<<<<<<<<<<<
 *             yield max(next_merge, time.time() + 1)
 *             if self._to_merge:
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_r = NULL;
      goto __pyx_L0;

      /* "btdht/dht.pyx":2309
 *         next_full_merge = time.time() + 10 * 60
 *         while True:
 *             if self.stoped:             # <<<<<<<<<<<<<<
 *                 return
 *             yield max(next_merge, time.time() + 1)
 */
    }

    /* "btdht/dht.pyx":2311
 *             if self.stoped:
 *                 return
 *             yield max(next_merge, time.time() + 1)             # <<<<<<<<<<<<<<
 *             if self._to_merge:
 *                 stack = []
 */
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2311, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2311, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2311, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2311, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_next_merge);
    __pyx_t_3 = __pyx_cur_scope->__pyx_v_next_merge;
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2311, __pyx_L1_error)
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2311, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_4) {
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_1 = __pyx_t_2;
    } else {
      __Pyx_INCREF(__pyx_t_3);
      __pyx_t_1 = __pyx_t_3;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 2;
    return __pyx_r;
    __pyx_L8_resume_from_yield:;
    if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2311, __pyx_L1_error)

    /* "btdht/dht.pyx":2312
 *                 return
 *             yield max(next_merge, time.time() + 1)
 *             if self._to_merge:             # <<<<<<<<<<<<<<
 *                 stack = []
 *                 while self._to_merge:
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_to_merge); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2312, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2312, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_4) {

      /* "btdht/dht.pyx":2313
 *             yield max(next_merge, time.time() + 1)
 *             if self._to_merge:
 *                 stack = []             # <<<<<<<<<<<<<<
 *                 while self._to_merge:
 *                     stack.append(self._to_merge.pop())
 */
      __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2313, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_stack);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_stack, ((PyObject*)__pyx_t_1));
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_t_1 = 0;

      /* "btdht/dht.pyx":2314
 *             if self._to_merge:
 *                 stack = []
 *                 while self._to_merge:             # <<<<<<<<<<<<<<
 *                     stack.append(self._to_merge.pop())
 *                 next_merge = time.time() + 60
 */
      while (1) {
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_to_merge); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2314, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2314, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (!__pyx_t_4) break;

        /* "btdht/dht.pyx":2315
 *                 stack = []
 *                 while self._to_merge:
 *                     stack.append(self._to_merge.pop())             # <<<<<<<<<<<<<<
 *                 next_merge = time.time() + 60
 *                 self.debug(1, "Merging %s buckets" % (len(stack),))
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_to_merge); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2315, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_2 = __Pyx_PyObject_Pop(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2315, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_6 = __Pyx_PyList_Append(__pyx_cur_scope->__pyx_v_stack, __pyx_t_2); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 2315, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }

      /* "btdht/dht.pyx":2316
 *                 while self._to_merge:
 *                     stack.append(self._to_merge.pop())
 *                 next_merge = time.time() + 60             # <<<<<<<<<<<<<<
 *                 self.debug(1, "Merging %s buckets" % (len(stack),))
 *                 # execute merge partially and return regulary hand to the scheduler
 */
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2316, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2316, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2316, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_60, 60, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2316, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_next_merge);
      __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_next_merge, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;

      /* "btdht/dht.pyx":2317
 *                     stack.append(self._to_merge.pop())
 *                 next_merge = time.time() + 60
 *                 self.debug(1, "Merging %s buckets" % (len(stack),))             # <<<<<<<<<<<<<<
 *                 # execute merge partially and return regulary hand to the scheduler
 *                 for i in self._merge(stack):
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2317, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = PyList_GET_SIZE(__pyx_cur_scope->__pyx_v_stack); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2317, __pyx_L1_error)
      __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2317, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2317, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_Merging_s_buckets, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2317, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = NULL;
      __pyx_t_8 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_8 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_1, __pyx_t_1};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2317, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_int_1, __pyx_t_1};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2317, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      {
        __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2317, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (__pyx_t_5) {
          __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_5); __pyx_t_5 = NULL;
        }
        __Pyx_INCREF(__pyx_int_1);
        __Pyx_GIVEREF(__pyx_int_1);
        PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_int_1);
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2317, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "btdht/dht.pyx":2319
 *                 self.debug(1, "Merging %s buckets" % (len(stack),))
 *                 # execute merge partially and return regulary hand to the scheduler
 *                 for i in self._merge(stack):             # <<<<<<<<<<<<<<
 *                     yield i
 * 
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_merge); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2319, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_9 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_9, __pyx_cur_scope->__pyx_v_stack) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_cur_scope->__pyx_v_stack);
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2319, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
        __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_7 = 0;
        __pyx_t_10 = NULL;
      } else {
        __pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2319, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_10 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2319, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      for (;;) {
        if (likely(!__pyx_t_10)) {
          if (likely(PyList_CheckExact(__pyx_t_2))) {
            if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_2)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_3); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 2319, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2319, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          } else {
            if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_3); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 2319, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2319, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          }
        } else {
          __pyx_t_3 = __pyx_t_10(__pyx_t_2);
          if (unlikely(!__pyx_t_3)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 2319, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_3);
        }
        __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i);
        __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_i, __pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_3);
        __pyx_t_3 = 0;

        /* "btdht/dht.pyx":2320
 *                 # execute merge partially and return regulary hand to the scheduler
 *                 for i in self._merge(stack):
 *                     yield i             # <<<<<<<<<<<<<<
 * 
 *             if self.need_merge and time.time() > next_full_merge:
 */
        __Pyx_INCREF(__pyx_cur_scope->__pyx_v_i);
        __pyx_r = __pyx_cur_scope->__pyx_v_i;
        __Pyx_XGIVEREF(__pyx_t_2);
        __pyx_cur_scope->__pyx_t_0 = __pyx_t_2;
        __pyx_cur_scope->__pyx_t_1 = __pyx_t_7;
        __pyx_cur_scope->__pyx_t_2 = __pyx_t_10;
        __Pyx_XGIVEREF(__pyx_r);
        __Pyx_RefNannyFinishContext();
        __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
        /* return from generator, yielding value */
        __pyx_generator->resume_label = 3;
        return __pyx_r;
        __pyx_L14_resume_from_yield:;
        __pyx_t_2 = __pyx_cur_scope->__pyx_t_0;
        __pyx_cur_scope->__pyx_t_0 = 0;
        __Pyx_XGOTREF(__pyx_t_2);
        __pyx_t_7 = __pyx_cur_scope->__pyx_t_1;
        __pyx_t_10 = __pyx_cur_scope->__pyx_t_2;
        if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2320, __pyx_L1_error)

        /* "btdht/dht.pyx":2319
 *                 self.debug(1, "Merging %s buckets" % (len(stack),))
 *                 # execute merge partially and return regulary hand to the scheduler
 *                 for i in self._merge(stack):             # <<<<<<<<<<<<<<
 *                     yield i
 * 
 */
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "btdht/dht.pyx":2312
 *                 return
 *             yield max(next_merge, time.time() + 1)
 *             if self._to_merge:             # <<<<<<<<<<<<<<
 *                 stack = []
 *                 while self._to_merge:
 */
    }

    /* "btdht/dht.pyx":2322
 *                     yield i
 * 
 *             if self.need_merge and time.time() > next_full_merge:             # <<<<<<<<<<<<<<
 *                 self.need_merge = False
 *                 next_merge = time.time() + 60
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_need_merge); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2322, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2322, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_11) {
    } else {
      __pyx_t_4 = __pyx_t_11;
      goto __pyx_L16_bool_binop_done;
    }
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2322, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2322, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_9);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2322, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_RichCompare(__pyx_t_2, __pyx_cur_scope->__pyx_v_next_full_merge, Py_GT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2322, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2322, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_4 = __pyx_t_11;
    __pyx_L16_bool_binop_done:;
    if (__pyx_t_4) {

      /* "btdht/dht.pyx":2323
 * 
 *             if self.need_merge and time.time() > next_full_merge:
 *                 self.need_merge = False             # <<<<<<<<<<<<<<
 *                 next_merge = time.time() + 60
 *                 next_full_merge = time.time() + 10 * 60
 */
      if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_need_merge, Py_False) < 0) __PYX_ERR(0, 2323, __pyx_L1_error)

      /* "btdht/dht.pyx":2324
 *             if self.need_merge and time.time() > next_full_merge:
 *                 self.need_merge = False
 *                 next_merge = time.time() + 60             # <<<<<<<<<<<<<<
 *                 next_full_merge = time.time() + 10 * 60
 *                 # execute merge partially and return regulary hand to the scheduler
 */
      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2324, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2324, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      __pyx_t_9 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2324, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_9, __pyx_int_60, 60, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2324, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_next_merge);
      __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_next_merge, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;

      /* "btdht/dht.pyx":2325
 *                 self.need_merge = False
 *                 next_merge = time.time() + 60
 *                 next_full_merge = time.time() + 10 * 60             # <<<<<<<<<<<<<<
 *                 # execute merge partially and return regulary hand to the scheduler
 *                 for i in self._merge():
 */
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_time); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2325, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2325, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2325, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_600, 0x258, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2325, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_next_full_merge);
      __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_next_full_merge, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;

      /* "btdht/dht.pyx":2327
 *                 next_full_merge = time.time() + 10 * 60
 *                 # execute merge partially and return regulary hand to the scheduler
 *                 for i in self._merge():             # <<<<<<<<<<<<<<
 *                     yield i
 * 
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_merge); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2327, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      __pyx_t_2 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2327, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
        __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0;
        __pyx_t_10 = NULL;
      } else {
        __pyx_t_7 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2327, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2327, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      for (;;) {
        if (likely(!__pyx_t_10)) {
          if (likely(PyList_CheckExact(__pyx_t_3))) {
            if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 2327, __pyx_L1_error)
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2327, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            #endif
          } else {
            if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 2327, __pyx_L1_error)
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2327, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            #endif
          }
        } else {
          __pyx_t_2 = __pyx_t_10(__pyx_t_3);
          if (unlikely(!__pyx_t_2)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 2327, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_2);
        }
        __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i);
        __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_i, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __pyx_t_2 = 0;

        /* "btdht/dht.pyx":2328
 *                 # execute merge partially and return regulary hand to the scheduler
 *                 for i in self._merge():
 *                     yield i             # <<<<<<<<<<<<<<
 * 
 *     def register_torrent_longterm(self, id):
 */
        __Pyx_INCREF(__pyx_cur_scope->__pyx_v_i);
        __pyx_r = __pyx_cur_scope->__pyx_v_i;
        __Pyx_XGIVEREF(__pyx_t_3);
        __pyx_cur_scope->__pyx_t_0 = __pyx_t_3;
        __pyx_cur_scope->__pyx_t_1 = __pyx_t_7;
        __pyx_cur_scope->__pyx_t_2 = __pyx_t_10;
        __Pyx_XGIVEREF(__pyx_r);
        __Pyx_RefNannyFinishContext();
        __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
        /* return from generator, yielding value */
        __pyx_generator->resume_label = 4;
        return __pyx_r;
        __pyx_L20_resume_from_yield:;
        __pyx_t_3 = __pyx_cur_scope->__pyx_t_0;
        __pyx_cur_scope->__pyx_t_0 = 0;
        __Pyx_XGOTREF(__pyx_t_3);
        __pyx_t_7 = __pyx_cur_scope->__pyx_t_1;
        __pyx_t_10 = __pyx_cur_scope->__pyx_t_2;
        if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2328, __pyx_L1_error)

        /* "btdht/dht.pyx":2327
 *                 next_full_merge = time.time() + 10 * 60
 *                 # execute merge partially and return regulary hand to the scheduler
 *                 for i in self._merge():             # <<<<<<<<<<<<<<
 *                     yield i
 * 
 */
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "btdht/dht.pyx":2322
 *                     yield i
 * 
 *             if self.need_merge and time.time() > next_full_merge:             # <<<<<<<<<<<<<<
 *                 self.need_merge = False
 *                 next_merge = time.time() + 60
 */
    }
  }
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* "btdht/dht.pyx":2302
 *             pass
 * 
 *     def _merge_loop(self):             # <<<<<<<<<<<<<<
 *         """Weigthless thread handling the merge of the routing table"""
 *         yield 0
 */

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("_merge_loop", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2330
 *                     yield i
 * 
 *     def register_torrent_longterm(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             Same as :meth:`register_torrent` but garanty that the torrent wont be released
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_20register_torrent_longterm(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_19register_torrent_longterm[] = "\n            Same as :meth:`register_torrent` but garanty that the torrent wont be released\n            automaticaly by the dht.\n\n            :param bytes id: A 160 bits (20 Bytes) torrent identifier\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_20register_torrent_longterm = {"register_torrent_longterm", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_20register_torrent_longterm, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_12RoutingTable_19register_torrent_longterm};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_20register_torrent_longterm(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_id = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("register_torrent_longterm (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_id,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("register_torrent_longterm", 1, 2, 2, 1); __PYX_ERR(0, 2330, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "register_torrent_longterm") < 0)) __PYX_ERR(0, 2330, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_self = values[0];
    __pyx_v_id = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("register_torrent_longterm", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2330, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.register_torrent_longterm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_19register_torrent_longterm(__pyx_self, __pyx_v_self, __pyx_v_id);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_19register_torrent_longterm(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("register_torrent_longterm", 0);

  /* "btdht/dht.pyx":2337
 *             :param bytes id: A 160 bits (20 Bytes) torrent identifier
 *         """
 *         self._split_ids.add(id)             # <<<<<<<<<<<<<<
 * 
 *     def release_torrent_longterm(self, id):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_split_ids); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_add); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_id);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2330
 *                     yield i
 * 
 *     def register_torrent_longterm(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             Same as :meth:`register_torrent` but garanty that the torrent wont be released
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.register_torrent_longterm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2339
 *         self._split_ids.add(id)
 * 
 *     def release_torrent_longterm(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             For releasing torrent registered with the :meth`register_torrent_longterm` method
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_22release_torrent_longterm(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_21release_torrent_longterm[] = "\n            For releasing torrent registered with the :meth`register_torrent_longterm` method\n\n            :param bytes id: A 160 bits (20 Bytes) torrent identifier\n\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_22release_torrent_longterm = {"release_torrent_longterm", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_22release_torrent_longterm, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_12RoutingTable_21release_torrent_longterm};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_22release_torrent_longterm(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_id = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("release_torrent_longterm (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_id,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("release_torrent_longterm", 1, 2, 2, 1); __PYX_ERR(0, 2339, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "release_torrent_longterm") < 0)) __PYX_ERR(0, 2339, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_self = values[0];
    __pyx_v_id = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("release_torrent_longterm", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2339, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.release_torrent_longterm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_21release_torrent_longterm(__pyx_self, __pyx_v_self, __pyx_v_id);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_21release_torrent_longterm(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("release_torrent_longterm", 0);

  /* "btdht/dht.pyx":2346
 * 
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             self._split_ids.remove(id)
 *             if not self.need_merge:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "btdht/dht.pyx":2347
 *         """
 *         try:
 *             self._split_ids.remove(id)             # <<<<<<<<<<<<<<
 *             if not self.need_merge:
 *                 self.debug(1, "Programming merge")
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_split_ids); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2347, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_remove); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2347, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_id);
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2347, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "btdht/dht.pyx":2348
 *         try:
 *             self._split_ids.remove(id)
 *             if not self.need_merge:             # <<<<<<<<<<<<<<
 *                 self.debug(1, "Programming merge")
 *                 self.need_merge = True
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_need_merge); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2348, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 2348, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_8 = ((!__pyx_t_7) != 0);
      if (__pyx_t_8) {

        /* "btdht/dht.pyx":2349
 *             self._split_ids.remove(id)
 *             if not self.need_merge:
 *                 self.debug(1, "Programming merge")             # <<<<<<<<<<<<<<
 *                 self.need_merge = True
 *         except KeyError:
 */
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2349, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2349, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "btdht/dht.pyx":2350
 *             if not self.need_merge:
 *                 self.debug(1, "Programming merge")
 *                 self.need_merge = True             # <<<<<<<<<<<<<<
 *         except KeyError:
 *             pass
 */
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_need_merge, Py_True) < 0) __PYX_ERR(0, 2350, __pyx_L3_error)

        /* "btdht/dht.pyx":2348
 *         try:
 *             self._split_ids.remove(id)
 *             if not self.need_merge:             # <<<<<<<<<<<<<<
 *                 self.debug(1, "Programming merge")
 *                 self.need_merge = True
 */
      }

      /* "btdht/dht.pyx":2346
 * 
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             self._split_ids.remove(id)
 *             if not self.need_merge:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "btdht/dht.pyx":2351
 *                 self.debug(1, "Programming merge")
 *                 self.need_merge = True
 *         except KeyError:             # <<<<<<<<<<<<<<
 *             pass
 * 
 */
    __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
    if (__pyx_t_9) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "btdht/dht.pyx":2346
 * 
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             self._split_ids.remove(id)
 *             if not self.need_merge:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L4_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    __pyx_L8_try_end:;
  }

  /* "btdht/dht.pyx":2339
 *         self._split_ids.add(id)
 * 
 *     def release_torrent_longterm(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             For releasing torrent registered with the :meth`register_torrent_longterm` method
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.release_torrent_longterm", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2354
 *             pass
 * 
 *     def register_dht(self, dht):             # <<<<<<<<<<<<<<
 *         """
 *             Register a ``dht`` instance to the routing table
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_24register_dht(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_23register_dht[] = "\n            Register a ``dht`` instance to the routing table\n\n            :param DHT_BASE dht: A dht instance\n\n            Notes:\n                on start, all dht instances automaticaly register themself to their routing tables\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_24register_dht = {"register_dht", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_24register_dht, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_12RoutingTable_23register_dht};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_24register_dht(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_dht = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("register_dht (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_dht,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dht)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("register_dht", 1, 2, 2, 1); __PYX_ERR(0, 2354, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "register_dht") < 0)) __PYX_ERR(0, 2354, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_self = values[0];
    __pyx_v_dht = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("register_dht", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2354, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.register_dht", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_23register_dht(__pyx_self, __pyx_v_self, __pyx_v_dht);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_23register_dht(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_dht) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("register_dht", 0);

  /* "btdht/dht.pyx":2363
 *                 on start, all dht instances automaticaly register themself to their routing tables
 *         """
 *         self._dhts.add(dht)             # <<<<<<<<<<<<<<
 *         self._split_ids.add(dht.myid.value)
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_dhts); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_add); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_dht) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_dht);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2363, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2364
 *         """
 *         self._dhts.add(dht)
 *         self._split_ids.add(dht.myid.value)             # <<<<<<<<<<<<<<
 * 
 *     def release_dht(self, dht):
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_split_ids); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_add); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dht, __pyx_n_s_myid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2354
 *             pass
 * 
 *     def register_dht(self, dht):             # <<<<<<<<<<<<<<
 *         """
 *             Register a ``dht`` instance to the routing table
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.register_dht", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2366
 *         self._split_ids.add(dht.myid.value)
 * 
 *     def release_dht(self, dht):             # <<<<<<<<<<<<<<
 *         """
 *             Release a ``dht`` instance to the routing table, and shedule the routing table for a
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_26release_dht(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_25release_dht[] = "\n            Release a ``dht`` instance to the routing table, and shedule the routing table for a\n            merge.\n\n            Notes:\n                on stop, dht automatially release itself from the routing table\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_26release_dht = {"release_dht", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_26release_dht, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_12RoutingTable_25release_dht};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_26release_dht(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_dht = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("release_dht (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_dht,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dht)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("release_dht", 1, 2, 2, 1); __PYX_ERR(0, 2366, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "release_dht") < 0)) __PYX_ERR(0, 2366, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_self = values[0];
    __pyx_v_dht = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("release_dht", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2366, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.release_dht", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_25release_dht(__pyx_self, __pyx_v_self, __pyx_v_dht);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_25release_dht(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_dht) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("release_dht", 0);

  /* "btdht/dht.pyx":2374
 *                 on stop, dht automatially release itself from the routing table
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             self._dhts.remove(dht)
 *         except KeyError:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "btdht/dht.pyx":2375
 *         """
 *         try:
 *             self._dhts.remove(dht)             # <<<<<<<<<<<<<<
 *         except KeyError:
 *             pass
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_dhts); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2375, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_remove); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2375, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_v_dht) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_dht);
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2375, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "btdht/dht.pyx":2374
 *                 on stop, dht automatially release itself from the routing table
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             self._dhts.remove(dht)
 *         except KeyError:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "btdht/dht.pyx":2376
 *         try:
 *             self._dhts.remove(dht)
 *         except KeyError:             # <<<<<<<<<<<<<<
 *             pass
 *         try:
 */
    __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
    if (__pyx_t_7) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "btdht/dht.pyx":2374
 *                 on stop, dht automatially release itself from the routing table
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             self._dhts.remove(dht)
 *         except KeyError:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L4_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    __pyx_L8_try_end:;
  }

  /* "btdht/dht.pyx":2378
 *         except KeyError:
 *             pass
 *         try:             # <<<<<<<<<<<<<<
 *             self._split_ids.remove(dht.myid)
 *             if not self.need_merge:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_2, &__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_1);
    /*try:*/ {

      /* "btdht/dht.pyx":2379
 *             pass
 *         try:
 *             self._split_ids.remove(dht.myid)             # <<<<<<<<<<<<<<
 *             if not self.need_merge:
 *                 self.debug(1, "Programming merge")
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_split_ids); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2379, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_remove); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2379, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_dht, __pyx_n_s_myid); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2379, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      __pyx_t_4 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2379, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "btdht/dht.pyx":2380
 *         try:
 *             self._split_ids.remove(dht.myid)
 *             if not self.need_merge:             # <<<<<<<<<<<<<<
 *                 self.debug(1, "Programming merge")
 *                 self.need_merge = True
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_need_merge); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2380, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 2380, __pyx_L9_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_10 = ((!__pyx_t_9) != 0);
      if (__pyx_t_10) {

        /* "btdht/dht.pyx":2381
 *             self._split_ids.remove(dht.myid)
 *             if not self.need_merge:
 *                 self.debug(1, "Programming merge")             # <<<<<<<<<<<<<<
 *                 self.need_merge = True
 *         except KeyError:
 */
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2381, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2381, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "btdht/dht.pyx":2382
 *             if not self.need_merge:
 *                 self.debug(1, "Programming merge")
 *                 self.need_merge = True             # <<<<<<<<<<<<<<
 *         except KeyError:
 *             pass
 */
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_need_merge, Py_True) < 0) __PYX_ERR(0, 2382, __pyx_L9_error)

        /* "btdht/dht.pyx":2380
 *         try:
 *             self._split_ids.remove(dht.myid)
 *             if not self.need_merge:             # <<<<<<<<<<<<<<
 *                 self.debug(1, "Programming merge")
 *                 self.need_merge = True
 */
      }

      /* "btdht/dht.pyx":2378
 *         except KeyError:
 *             pass
 *         try:             # <<<<<<<<<<<<<<
 *             self._split_ids.remove(dht.myid)
 *             if not self.need_merge:
 */
    }
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L14_try_end;
    __pyx_L9_error:;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "btdht/dht.pyx":2383
 *                 self.debug(1, "Programming merge")
 *                 self.need_merge = True
 *         except KeyError:             # <<<<<<<<<<<<<<
 *             pass
 *         if not self._dhts:
 */
    __pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
    if (__pyx_t_7) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L10_exception_handled;
    }
    goto __pyx_L11_except_error;
    __pyx_L11_except_error:;

    /* "btdht/dht.pyx":2378
 *         except KeyError:
 *             pass
 *         try:             # <<<<<<<<<<<<<<
 *             self._split_ids.remove(dht.myid)
 *             if not self.need_merge:
 */
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_2, __pyx_t_1);
    goto __pyx_L1_error;
    __pyx_L10_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_2, __pyx_t_1);
    __pyx_L14_try_end:;
  }

  /* "btdht/dht.pyx":2385
 *         except KeyError:
 *             pass
 *         if not self._dhts:             # <<<<<<<<<<<<<<
 *             self.stop()
 * 
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_dhts); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 2385, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_9 = ((!__pyx_t_10) != 0);
  if (__pyx_t_9) {

    /* "btdht/dht.pyx":2386
 *             pass
 *         if not self._dhts:
 *             self.stop()             # <<<<<<<<<<<<<<
 * 
 *     def debug(self, lvl, msg):
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_stop); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2386, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_5 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2386, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "btdht/dht.pyx":2385
 *         except KeyError:
 *             pass
 *         if not self._dhts:             # <<<<<<<<<<<<<<
 *             self.stop()
 * 
 */
  }

  /* "btdht/dht.pyx":2366
 *         self._split_ids.add(dht.myid.value)
 * 
 *     def release_dht(self, dht):             # <<<<<<<<<<<<<<
 *         """
 *             Release a ``dht`` instance to the routing table, and shedule the routing table for a
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.release_dht", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2388
 *             self.stop()
 * 
 *     def debug(self, lvl, msg):             # <<<<<<<<<<<<<<
 *         """same as :meth:`DHT_BASE.debug`"""
 *         if (
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_28debug(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_27debug[] = "same as :meth:`DHT_BASE.debug`";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_28debug = {"debug", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_28debug, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_12RoutingTable_27debug};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_28debug(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_lvl = 0;
  PyObject *__pyx_v_msg = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("debug (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_lvl,&__pyx_n_s_msg,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_lvl)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("debug", 1, 3, 3, 1); __PYX_ERR(0, 2388, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_msg)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("debug", 1, 3, 3, 2); __PYX_ERR(0, 2388, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "debug") < 0)) __PYX_ERR(0, 2388, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_self = values[0];
    __pyx_v_lvl = values[1];
    __pyx_v_msg = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("debug", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2388, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.debug", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_27debug(__pyx_self, __pyx_v_self, __pyx_v_lvl, __pyx_v_msg);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_27debug(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_lvl, PyObject *__pyx_v_msg) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("debug", 0);

  /* "btdht/dht.pyx":2391
 *         """same as :meth:`DHT_BASE.debug`"""
 *         if (
 *             lvl <= self.debuglvl and             # <<<<<<<<<<<<<<
 *             (msg != self._last_debug or (time.time() - self._last_debug_time) > 5)
 *         ):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_debuglvl); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2391, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_v_lvl, __pyx_t_2, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2391, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2391, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_4) {
  } else {
    __pyx_t_1 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }

  /* "btdht/dht.pyx":2392
 *         if (
 *             lvl <= self.debuglvl and
 *             (msg != self._last_debug or (time.time() - self._last_debug_time) > 5)             # <<<<<<<<<<<<<<
 *         ):
 *             print("RT%s:%s" % (self.prefix, msg))
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_last_debug); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_msg, __pyx_t_3, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!__pyx_t_4) {
  } else {
    __pyx_t_1 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_last_debug_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = PyNumber_Subtract(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_int_5, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2392, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_1 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;

  /* "btdht/dht.pyx":2390
 *     def debug(self, lvl, msg):
 *         """same as :meth:`DHT_BASE.debug`"""
 *         if (             # <<<<<<<<<<<<<<
 *             lvl <= self.debuglvl and
 *             (msg != self._last_debug or (time.time() - self._last_debug_time) > 5)
 */
  if (__pyx_t_1) {

    /* "btdht/dht.pyx":2394
 *             (msg != self._last_debug or (time.time() - self._last_debug_time) > 5)
 *         ):
 *             print("RT%s:%s" % (self.prefix, msg))             # <<<<<<<<<<<<<<
 *             self._last_debug = msg
 *             self._last_debug_time = time.time()
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_prefix); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2394, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2394, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
    __Pyx_INCREF(__pyx_v_msg);
    __Pyx_GIVEREF(__pyx_v_msg);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_msg);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_RT_s_s, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2394, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__Pyx_PrintOne(0, __pyx_t_5) < 0) __PYX_ERR(0, 2394, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "btdht/dht.pyx":2395
 *         ):
 *             print("RT%s:%s" % (self.prefix, msg))
 *             self._last_debug = msg             # <<<<<<<<<<<<<<
 *             self._last_debug_time = time.time()
 * 
 */
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_last_debug, __pyx_v_msg) < 0) __PYX_ERR(0, 2395, __pyx_L1_error)

    /* "btdht/dht.pyx":2396
 *             print("RT%s:%s" % (self.prefix, msg))
 *             self._last_debug = msg
 *             self._last_debug_time = time.time()             # <<<<<<<<<<<<<<
 * 
 *     def _routine(self):
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2396, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2396, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_5 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2396, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_last_debug_time, __pyx_t_5) < 0) __PYX_ERR(0, 2396, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "btdht/dht.pyx":2390
 *     def debug(self, lvl, msg):
 *         """same as :meth:`DHT_BASE.debug`"""
 *         if (             # <<<<<<<<<<<<<<
 *             lvl <= self.debuglvl and
 *             (msg != self._last_debug or (time.time() - self._last_debug_time) > 5)
 */
  }

  /* "btdht/dht.pyx":2388
 *             self.stop()
 * 
 *     def debug(self, lvl, msg):             # <<<<<<<<<<<<<<
 *         """same as :meth:`DHT_BASE.debug`"""
 *         if (
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.debug", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_31generator4(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "btdht/dht.pyx":2398
 *             self._last_debug_time = time.time()
 * 
 *     def _routine(self):             # <<<<<<<<<<<<<<
 *         """
 *             Weigthless thread perfoming routine on the routing table like performing quering to
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_30_routine(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_29_routine[] = "\n            Weigthless thread perfoming routine on the routing table like performing quering to\n            bucket with no activity and pinging questionnable (neither good nor bad) nodes.\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_30_routine = {"_routine", (PyCFunction)__pyx_pw_5btdht_3dht_12RoutingTable_30_routine, METH_O, __pyx_doc_5btdht_3dht_12RoutingTable_29_routine};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_30_routine(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_routine (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_29_routine(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_29_routine(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_routine", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct_7__routine(__pyx_ptype_5btdht_3dht___pyx_scope_struct_7__routine, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2398, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5btdht_3dht_12RoutingTable_31generator4, __pyx_codeobj__34, (PyObject *) __pyx_cur_scope, __pyx_n_s_routine, __pyx_n_s_RoutingTable__routine, __pyx_n_s_btdht_dht); if (unlikely(!gen)) __PYX_ERR(0, 2398, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable._routine", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_31generator4(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine *__pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  int __pyx_t_13;
  PyObject *__pyx_t_14 = NULL;
  Py_ssize_t __pyx_t_15;
  PyObject *(*__pyx_t_16)(PyObject *);
  int __pyx_t_17;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_routine", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L4_resume_from_yield;
    case 2: goto __pyx_L8_resume_from_yield;
    case 3: goto __pyx_L27_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2398, __pyx_L1_error)

  /* "btdht/dht.pyx":2403
 *             bucket with no activity and pinging questionnable (neither good nor bad) nodes.
 *         """
 *         yield 0             # <<<<<<<<<<<<<<
 *         last_explore_tree = time.time()
 *         while True:
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_r = __pyx_int_0;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  /* return from generator, yielding value */
  __pyx_generator->resume_label = 1;
  return __pyx_r;
  __pyx_L4_resume_from_yield:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2403, __pyx_L1_error)

  /* "btdht/dht.pyx":2404
 *         """
 *         yield 0
 *         last_explore_tree = time.time()             # <<<<<<<<<<<<<<
 *         while True:
 *             #self.clean()
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2404, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2404, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2404, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_last_explore_tree = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2405
 *         yield 0
 *         last_explore_tree = time.time()
 *         while True:             # <<<<<<<<<<<<<<
 *             #self.clean()
 *             # exploring the routing table
 */
  while (1) {

    /* "btdht/dht.pyx":2408
 *             #self.clean()
 *             # exploring the routing table
 *             if self.stoped:             # <<<<<<<<<<<<<<
 *                 return
 *             yield (last_explore_tree + 60)
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_stoped); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2408, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2408, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_4) {

      /* "btdht/dht.pyx":2409
 *             # exploring the routing table
 *             if self.stoped:
 *                 return             # <<<<<<<<<<<<<<
 *             yield (last_explore_tree + 60)
 *             if self._dhts:
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_r = NULL;
      goto __pyx_L0;

      /* "btdht/dht.pyx":2408
 *             #self.clean()
 *             # exploring the routing table
 *             if self.stoped:             # <<<<<<<<<<<<<<
 *                 return
 *             yield (last_explore_tree + 60)
 */
    }

    /* "btdht/dht.pyx":2410
 *             if self.stoped:
 *                 return
 *             yield (last_explore_tree + 60)             # <<<<<<<<<<<<<<
 *             if self._dhts:
 *                 dhts = list(self._dhts)
 */
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_cur_scope->__pyx_v_last_explore_tree, __pyx_int_60, 60, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2410, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 2;
    return __pyx_r;
    __pyx_L8_resume_from_yield:;
    if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2410, __pyx_L1_error)

    /* "btdht/dht.pyx":2411
 *                 return
 *             yield (last_explore_tree + 60)
 *             if self._dhts:             # <<<<<<<<<<<<<<
 *                 dhts = list(self._dhts)
 *                 dhts_last_elt = len(dhts) - 1
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_dhts); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2411, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2411, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_4) {

      /* "btdht/dht.pyx":2412
 *             yield (last_explore_tree + 60)
 *             if self._dhts:
 *                 dhts = list(self._dhts)             # <<<<<<<<<<<<<<
 *                 dhts_last_elt = len(dhts) - 1
 *                 shuffle(dhts)
 */
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_dhts); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2412, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2412, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_dhts);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_dhts, ((PyObject*)__pyx_t_3));
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;

      /* "btdht/dht.pyx":2413
 *             if self._dhts:
 *                 dhts = list(self._dhts)
 *                 dhts_last_elt = len(dhts) - 1             # <<<<<<<<<<<<<<
 *                 shuffle(dhts)
 *                 now = time.time()
 */
      __pyx_t_5 = PyList_GET_SIZE(__pyx_cur_scope->__pyx_v_dhts); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2413, __pyx_L1_error)
      __pyx_cur_scope->__pyx_v_dhts_last_elt = (__pyx_t_5 - 1);

      /* "btdht/dht.pyx":2414
 *                 dhts = list(self._dhts)
 *                 dhts_last_elt = len(dhts) - 1
 *                 shuffle(dhts)             # <<<<<<<<<<<<<<
 *                 now = time.time()
 *                 i = 0
 */
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_shuffle); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2414, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
        }
      }
      __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_cur_scope->__pyx_v_dhts) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_cur_scope->__pyx_v_dhts);
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2414, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "btdht/dht.pyx":2415
 *                 dhts_last_elt = len(dhts) - 1
 *                 shuffle(dhts)
 *                 now = time.time()             # <<<<<<<<<<<<<<
 *                 i = 0
 *                 for key, bucket in self.trie.items():
 */
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2415, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2415, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      __pyx_t_3 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2415, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_now);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_now, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;

      /* "btdht/dht.pyx":2416
 *                 shuffle(dhts)
 *                 now = time.time()
 *                 i = 0             # <<<<<<<<<<<<<<
 *                 for key, bucket in self.trie.items():
 *                     if self.stoped:
 */
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_i, __pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);

      /* "btdht/dht.pyx":2417
 *                 now = time.time()
 *                 i = 0
 *                 for key, bucket in self.trie.items():             # <<<<<<<<<<<<<<
 *                     if self.stoped:
 *                         return
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2417, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2417, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
        }
      }
      __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2417, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
        __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
        __pyx_t_6 = NULL;
      } else {
        __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2417, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2417, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      for (;;) {
        if (likely(!__pyx_t_6)) {
          if (likely(PyList_CheckExact(__pyx_t_1))) {
            if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 2417, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2417, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          } else {
            if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 2417, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2417, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          }
        } else {
          __pyx_t_3 = __pyx_t_6(__pyx_t_1);
          if (unlikely(!__pyx_t_3)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 2417, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_3);
        }
        if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
          PyObject* sequence = __pyx_t_3;
          Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
          if (unlikely(size != 2)) {
            if (size > 2) __Pyx_RaiseTooManyValuesError(2);
            else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
            __PYX_ERR(0, 2417, __pyx_L1_error)
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          if (likely(PyTuple_CheckExact(sequence))) {
            __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
            __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_7);
          #else
          __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2417, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2417, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          #endif
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else {
          Py_ssize_t index = -1;
          __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2417, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
          index = 0; __pyx_t_2 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L12_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_2);
          index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L12_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_7);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) __PYX_ERR(0, 2417, __pyx_L1_error)
          __pyx_t_9 = NULL;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          goto __pyx_L13_unpacking_done;
          __pyx_L12_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_9 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          __PYX_ERR(0, 2417, __pyx_L1_error)
          __pyx_L13_unpacking_done:;
        }
        __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key);
        __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_key, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __pyx_t_2 = 0;
        __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_bucket);
        __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_bucket, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_7);
        __pyx_t_7 = 0;

        /* "btdht/dht.pyx":2418
 *                 i = 0
 *                 for key, bucket in self.trie.items():
 *                     if self.stoped:             # <<<<<<<<<<<<<<
 *                         return
 *                     # if trie modifies while looping
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_stoped); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2418, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2418, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_4) {

          /* "btdht/dht.pyx":2419
 *                 for key, bucket in self.trie.items():
 *                     if self.stoped:
 *                         return             # <<<<<<<<<<<<<<
 *                     # if trie modifies while looping
 *                     if not key in self.trie:
 */
          __Pyx_XDECREF(__pyx_r);
          __pyx_r = NULL;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          goto __pyx_L0;

          /* "btdht/dht.pyx":2418
 *                 i = 0
 *                 for key, bucket in self.trie.items():
 *                     if self.stoped:             # <<<<<<<<<<<<<<
 *                         return
 *                     # if trie modifies while looping
 */
        }

        /* "btdht/dht.pyx":2421
 *                         return
 *                     # if trie modifies while looping
 *                     if not key in self.trie:             # <<<<<<<<<<<<<<
 *                         continue
 *                     # If bucket inactif for more than 15min, find_node on a random id in it
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2421, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_cur_scope->__pyx_v_key, __pyx_t_3, Py_NE)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2421, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_10 = (__pyx_t_4 != 0);
        if (__pyx_t_10) {

          /* "btdht/dht.pyx":2422
 *                     # if trie modifies while looping
 *                     if not key in self.trie:
 *                         continue             # <<<<<<<<<<<<<<
 *                     # If bucket inactif for more than 15min, find_node on a random id in it
 *                     if now - bucket.last_changed > 15 * 60:
 */
          goto __pyx_L10_continue;

          /* "btdht/dht.pyx":2421
 *                         return
 *                     # if trie modifies while looping
 *                     if not key in self.trie:             # <<<<<<<<<<<<<<
 *                         continue
 *                     # If bucket inactif for more than 15min, find_node on a random id in it
 */
        }

        /* "btdht/dht.pyx":2424
 *                         continue
 *                     # If bucket inactif for more than 15min, find_node on a random id in it
 *                     if now - bucket.last_changed > 15 * 60:             # <<<<<<<<<<<<<<
 *                         id = bucket.random_id()
 *                         nodes = self.get_closest_nodes(id)
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_bucket, __pyx_n_s_last_changed); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2424, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_7 = PyNumber_Subtract(__pyx_cur_scope->__pyx_v_now, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2424, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = PyObject_RichCompare(__pyx_t_7, __pyx_int_900, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2424, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 2424, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_10) {

          /* "btdht/dht.pyx":2425
 *                     # If bucket inactif for more than 15min, find_node on a random id in it
 *                     if now - bucket.last_changed > 15 * 60:
 *                         id = bucket.random_id()             # <<<<<<<<<<<<<<
 *                         nodes = self.get_closest_nodes(id)
 *                         if nodes:
 */
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_bucket, __pyx_n_s_random_id); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2425, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_2 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
            __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
            if (likely(__pyx_t_2)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
              __Pyx_INCREF(__pyx_t_2);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_7, function);
            }
          }
          __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2425, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_id);
          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_id, __pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_3);
          __pyx_t_3 = 0;

          /* "btdht/dht.pyx":2426
 *                     if now - bucket.last_changed > 15 * 60:
 *                         id = bucket.random_id()
 *                         nodes = self.get_closest_nodes(id)             # <<<<<<<<<<<<<<
 *                         if nodes:
 *                             nodes[0].find_node(dhts[randint(0, dhts_last_elt)], id)
 */
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_get_closest_nodes); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2426, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_2 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
            __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
            if (likely(__pyx_t_2)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
              __Pyx_INCREF(__pyx_t_2);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_7, function);
            }
          }
          __pyx_t_3 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_2, __pyx_cur_scope->__pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_cur_scope->__pyx_v_id);
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2426, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_GIVEREF(__pyx_t_3);
          __pyx_cur_scope->__pyx_v_nodes = __pyx_t_3;
          __pyx_t_3 = 0;

          /* "btdht/dht.pyx":2427
 *                         id = bucket.random_id()
 *                         nodes = self.get_closest_nodes(id)
 *                         if nodes:             # <<<<<<<<<<<<<<
 *                             nodes[0].find_node(dhts[randint(0, dhts_last_elt)], id)
 *                             i += 1
 */
          __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_nodes); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 2427, __pyx_L1_error)
          if (__pyx_t_10) {

            /* "btdht/dht.pyx":2428
 *                         nodes = self.get_closest_nodes(id)
 *                         if nodes:
 *                             nodes[0].find_node(dhts[randint(0, dhts_last_elt)], id)             # <<<<<<<<<<<<<<
 *                             i += 1
 *                         del nodes
 */
            __pyx_t_7 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_nodes, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2428, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_7);
            __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_find_node); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2428, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_randint); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2428, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            __pyx_t_11 = PyInt_FromSsize_t(__pyx_cur_scope->__pyx_v_dhts_last_elt); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2428, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            __pyx_t_12 = NULL;
            __pyx_t_13 = 0;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
              __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_8);
              if (likely(__pyx_t_12)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
                __Pyx_INCREF(__pyx_t_12);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_8, function);
                __pyx_t_13 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_8)) {
              PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_int_0, __pyx_t_11};
              __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2428, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
              __Pyx_GOTREF(__pyx_t_7);
              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
              PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_int_0, __pyx_t_11};
              __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2428, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
              __Pyx_GOTREF(__pyx_t_7);
              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            } else
            #endif
            {
              __pyx_t_14 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2428, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_14);
              if (__pyx_t_12) {
                __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_12); __pyx_t_12 = NULL;
              }
              __Pyx_INCREF(__pyx_int_0);
              __Pyx_GIVEREF(__pyx_int_0);
              PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_13, __pyx_int_0);
              __Pyx_GIVEREF(__pyx_t_11);
              PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_13, __pyx_t_11);
              __pyx_t_11 = 0;
              __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_14, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2428, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_7);
              __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
            }
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_cur_scope->__pyx_v_dhts, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2428, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_8);
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __pyx_t_7 = NULL;
            __pyx_t_13 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
              __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
              if (likely(__pyx_t_7)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
                __Pyx_INCREF(__pyx_t_7);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_2, function);
                __pyx_t_13 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_2)) {
              PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_8, __pyx_cur_scope->__pyx_v_id};
              __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2428, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_GOTREF(__pyx_t_3);
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
              PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_8, __pyx_cur_scope->__pyx_v_id};
              __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2428, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_GOTREF(__pyx_t_3);
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            } else
            #endif
            {
              __pyx_t_14 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2428, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_14);
              if (__pyx_t_7) {
                __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_7); __pyx_t_7 = NULL;
              }
              __Pyx_GIVEREF(__pyx_t_8);
              PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_13, __pyx_t_8);
              __Pyx_INCREF(__pyx_cur_scope->__pyx_v_id);
              __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_id);
              PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_13, __pyx_cur_scope->__pyx_v_id);
              __pyx_t_8 = 0;
              __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_14, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2428, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_3);
              __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
            }
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

            /* "btdht/dht.pyx":2429
 *                         if nodes:
 *                             nodes[0].find_node(dhts[randint(0, dhts_last_elt)], id)
 *                             i += 1             # <<<<<<<<<<<<<<
 *                         del nodes
 *                     # If questionnable nodes, ping one of them
 */
            __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_cur_scope->__pyx_v_i, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2429, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_i);
            __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_i, __pyx_t_3);
            __Pyx_GIVEREF(__pyx_t_3);
            __pyx_t_3 = 0;

            /* "btdht/dht.pyx":2427
 *                         id = bucket.random_id()
 *                         nodes = self.get_closest_nodes(id)
 *                         if nodes:             # <<<<<<<<<<<<<<
 *                             nodes[0].find_node(dhts[randint(0, dhts_last_elt)], id)
 *                             i += 1
 */
          }

          /* "btdht/dht.pyx":2430
 *                             nodes[0].find_node(dhts[randint(0, dhts_last_elt)], id)
 *                             i += 1
 *                         del nodes             # <<<<<<<<<<<<<<
 *                     # If questionnable nodes, ping one of them
 *                     questionable = [node for node in bucket if not node.good and not node.bad]
 */
          __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_nodes);
          __Pyx_DECREF(__pyx_cur_scope->__pyx_v_nodes);
          __pyx_cur_scope->__pyx_v_nodes = NULL;

          /* "btdht/dht.pyx":2424
 *                         continue
 *                     # If bucket inactif for more than 15min, find_node on a random id in it
 *                     if now - bucket.last_changed > 15 * 60:             # <<<<<<<<<<<<<<
 *                         id = bucket.random_id()
 *                         nodes = self.get_closest_nodes(id)
 */
        }

        /* "btdht/dht.pyx":2432
 *                         del nodes
 *                     # If questionnable nodes, ping one of them
 *                     questionable = [node for node in bucket if not node.good and not node.bad]             # <<<<<<<<<<<<<<
 * 
 *                     for dht in dhts:
 */
        __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2432, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v_bucket)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_bucket)) {
          __pyx_t_2 = __pyx_cur_scope->__pyx_v_bucket; __Pyx_INCREF(__pyx_t_2); __pyx_t_15 = 0;
          __pyx_t_16 = NULL;
        } else {
          __pyx_t_15 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_bucket); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2432, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_16 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 2432, __pyx_L1_error)
        }
        for (;;) {
          if (likely(!__pyx_t_16)) {
            if (likely(PyList_CheckExact(__pyx_t_2))) {
              if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_2)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_14 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_15); __Pyx_INCREF(__pyx_t_14); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 2432, __pyx_L1_error)
              #else
              __pyx_t_14 = PySequence_ITEM(__pyx_t_2, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2432, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_14);
              #endif
            } else {
              if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_15); __Pyx_INCREF(__pyx_t_14); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 2432, __pyx_L1_error)
              #else
              __pyx_t_14 = PySequence_ITEM(__pyx_t_2, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2432, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_14);
              #endif
            }
          } else {
            __pyx_t_14 = __pyx_t_16(__pyx_t_2);
            if (unlikely(!__pyx_t_14)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 2432, __pyx_L1_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_14);
          }
          __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_node);
          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_node, __pyx_t_14);
          __Pyx_GIVEREF(__pyx_t_14);
          __pyx_t_14 = 0;
          __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s_good); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2432, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2432, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __pyx_t_17 = ((!__pyx_t_4) != 0);
          if (__pyx_t_17) {
          } else {
            __pyx_t_10 = __pyx_t_17;
            goto __pyx_L21_bool_binop_done;
          }
          __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s_bad); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2432, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 2432, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __pyx_t_4 = ((!__pyx_t_17) != 0);
          __pyx_t_10 = __pyx_t_4;
          __pyx_L21_bool_binop_done:;
          if (__pyx_t_10) {
            if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_cur_scope->__pyx_v_node))) __PYX_ERR(0, 2432, __pyx_L1_error)
          }
        }
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GIVEREF(__pyx_t_3);
        __pyx_cur_scope->__pyx_v_questionable = ((PyObject*)__pyx_t_3);
        __pyx_t_3 = 0;

        /* "btdht/dht.pyx":2434
 *                     questionable = [node for node in bucket if not node.good and not node.bad]
 * 
 *                     for dht in dhts:             # <<<<<<<<<<<<<<
 *                         if not questionable:
 *                             break
 */
        __pyx_t_3 = __pyx_cur_scope->__pyx_v_dhts; __Pyx_INCREF(__pyx_t_3); __pyx_t_15 = 0;
        for (;;) {
          if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_15); __Pyx_INCREF(__pyx_t_2); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 2434, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2434, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
          __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_dht);
          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_dht, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_2);
          __pyx_t_2 = 0;

          /* "btdht/dht.pyx":2435
 * 
 *                     for dht in dhts:
 *                         if not questionable:             # <<<<<<<<<<<<<<
 *                             break
 *                         questionable.pop().ping(dht)
 */
          __pyx_t_10 = (PyList_GET_SIZE(__pyx_cur_scope->__pyx_v_questionable) != 0);
          __pyx_t_4 = ((!__pyx_t_10) != 0);
          if (__pyx_t_4) {

            /* "btdht/dht.pyx":2436
 *                     for dht in dhts:
 *                         if not questionable:
 *                             break             # <<<<<<<<<<<<<<
 *                         questionable.pop().ping(dht)
 *                         i+=1
 */
            goto __pyx_L24_break;

            /* "btdht/dht.pyx":2435
 * 
 *                     for dht in dhts:
 *                         if not questionable:             # <<<<<<<<<<<<<<
 *                             break
 *                         questionable.pop().ping(dht)
 */
          }

          /* "btdht/dht.pyx":2437
 *                         if not questionable:
 *                             break
 *                         questionable.pop().ping(dht)             # <<<<<<<<<<<<<<
 *                         i+=1
 *                     del questionable
 */
          __pyx_t_14 = __Pyx_PyList_Pop(__pyx_cur_scope->__pyx_v_questionable); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2437, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_ping); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2437, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __pyx_t_14 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
            __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_8);
            if (likely(__pyx_t_14)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
              __Pyx_INCREF(__pyx_t_14);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_8, function);
            }
          }
          __pyx_t_2 = (__pyx_t_14) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_14, __pyx_cur_scope->__pyx_v_dht) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_cur_scope->__pyx_v_dht);
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2437, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "btdht/dht.pyx":2438
 *                             break
 *                         questionable.pop().ping(dht)
 *                         i+=1             # <<<<<<<<<<<<<<
 *                     del questionable
 * 
 */
          __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_cur_scope->__pyx_v_i, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2438, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_i);
          __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_i, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_2);
          __pyx_t_2 = 0;

          /* "btdht/dht.pyx":2434
 *                     questionable = [node for node in bucket if not node.good and not node.bad]
 * 
 *                     for dht in dhts:             # <<<<<<<<<<<<<<
 *                         if not questionable:
 *                             break
 */
        }
        __pyx_L24_break:;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "btdht/dht.pyx":2439
 *                         questionable.pop().ping(dht)
 *                         i+=1
 *                     del questionable             # <<<<<<<<<<<<<<
 * 
 *                     # give back the main in case of very big routing table to the scheduler
 */
        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_questionable);
        __Pyx_DECREF(__pyx_cur_scope->__pyx_v_questionable);
        __pyx_cur_scope->__pyx_v_questionable = NULL;

        /* "btdht/dht.pyx":2442
 * 
 *                     # give back the main in case of very big routing table to the scheduler
 *                     if i > 1000:             # <<<<<<<<<<<<<<
 *                         yield 0
 * 
 */
        __pyx_t_3 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_i, __pyx_int_1000, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2442, __pyx_L1_error)
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2442, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_4) {

          /* "btdht/dht.pyx":2443
 *                     # give back the main in case of very big routing table to the scheduler
 *                     if i > 1000:
 *                         yield 0             # <<<<<<<<<<<<<<
 * 
 *             last_explore_tree = time.time()
 */
          __Pyx_INCREF(__pyx_int_0);
          __pyx_r = __pyx_int_0;
          __Pyx_XGIVEREF(__pyx_t_1);
          __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
          __pyx_cur_scope->__pyx_t_1 = __pyx_t_5;
          __pyx_cur_scope->__pyx_t_2 = __pyx_t_6;
          __Pyx_XGIVEREF(__pyx_r);
          __Pyx_RefNannyFinishContext();
          __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
          /* return from generator, yielding value */
          __pyx_generator->resume_label = 3;
          return __pyx_r;
          __pyx_L27_resume_from_yield:;
          __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
          __pyx_cur_scope->__pyx_t_0 = 0;
          __Pyx_XGOTREF(__pyx_t_1);
          __pyx_t_5 = __pyx_cur_scope->__pyx_t_1;
          __pyx_t_6 = __pyx_cur_scope->__pyx_t_2;
          if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2443, __pyx_L1_error)

          /* "btdht/dht.pyx":2442
 * 
 *                     # give back the main in case of very big routing table to the scheduler
 *                     if i > 1000:             # <<<<<<<<<<<<<<
 *                         yield 0
 * 
 */
        }

        /* "btdht/dht.pyx":2417
 *                 now = time.time()
 *                 i = 0
 *                 for key, bucket in self.trie.items():             # <<<<<<<<<<<<<<
 *                     if self.stoped:
 *                         return
 */
        __pyx_L10_continue:;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "btdht/dht.pyx":2411
 *                 return
 *             yield (last_explore_tree + 60)
 *             if self._dhts:             # <<<<<<<<<<<<<<
 *                 dhts = list(self._dhts)
 *                 dhts_last_elt = len(dhts) - 1
 */
    }

    /* "btdht/dht.pyx":2445
 *                         yield 0
 * 
 *             last_explore_tree = time.time()             # <<<<<<<<<<<<<<
 * 
 *     def empty(self):
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2445, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2445, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2445, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_last_explore_tree);
    __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_last_explore_tree, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
  }
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* "btdht/dht.pyx":2398
 *             self._last_debug_time = time.time()
 * 
 *     def _routine(self):             # <<<<<<<<<<<<<<
 *         """
 *             Weigthless thread perfoming routine on the routing table like performing quering to
 */

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_AddTraceback("_routine", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2447
 *             last_explore_tree = time.time()
 * 
 *     def empty(self):             # <<<<<<<<<<<<<<
 *         """Empty the routing table, deleting all buckets"""
 *         self.trie = datrie.Trie("".join(chr(i) for i in range(256)))
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_33empty(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_32empty[] = "Empty the routing table, deleting all buckets";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_33empty = {"empty", (PyCFunction)__pyx_pw_5btdht_3dht_12RoutingTable_33empty, METH_O, __pyx_doc_5btdht_3dht_12RoutingTable_32empty};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_33empty(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("empty (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_32empty(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_5empty_2generator7(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "btdht/dht.pyx":2449
 *     def empty(self):
 *         """Empty the routing table, deleting all buckets"""
 *         self.trie = datrie.Trie("".join(chr(i) for i in range(256)))             # <<<<<<<<<<<<<<
 *         self.trie[u""]=Bucket()
 * 
 */

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_5empty_genexpr(CYTHON_UNUSED PyObject *__pyx_self) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_8_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_8_genexpr *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct_8_genexpr(__pyx_ptype_5btdht_3dht___pyx_scope_struct_8_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_8_genexpr *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2449, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5btdht_3dht_12RoutingTable_5empty_2generator7, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_RoutingTable_empty_locals_genexp, __pyx_n_s_btdht_dht); if (unlikely(!gen)) __PYX_ERR(0, 2449, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.empty.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_5empty_2generator7(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_8_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_8_genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  long __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("genexpr", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L6_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2449, __pyx_L1_error)
  for (__pyx_t_1 = 0; __pyx_t_1 < 0x100; __pyx_t_1+=1) {
    __pyx_cur_scope->__pyx_v_i = __pyx_t_1;
    __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2449, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_chr, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2449, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L6_resume_from_yield:;
    __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
    if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2449, __pyx_L1_error)
  }
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2447
 *             last_explore_tree = time.time()
 * 
 *     def empty(self):             # <<<<<<<<<<<<<<
 *         """Empty the routing table, deleting all buckets"""
 *         self.trie = datrie.Trie("".join(chr(i) for i in range(256)))
 */

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_32empty(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_5empty_2generator7 = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("empty", 0);

  /* "btdht/dht.pyx":2449
 *     def empty(self):
 *         """Empty the routing table, deleting all buckets"""
 *         self.trie = datrie.Trie("".join(chr(i) for i in range(256)))             # <<<<<<<<<<<<<<
 *         self.trie[u""]=Bucket()
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_datrie); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Trie); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __pyx_pf_5btdht_3dht_12RoutingTable_5empty_genexpr(NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyString_Join(__pyx_kp_s__2, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2449, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_trie, __pyx_t_1) < 0) __PYX_ERR(0, 2449, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2450
 *         """Empty the routing table, deleting all buckets"""
 *         self.trie = datrie.Trie("".join(chr(i) for i in range(256)))
 *         self.trie[u""]=Bucket()             # <<<<<<<<<<<<<<
 * 
 *     def stats(self):
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_Bucket); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2450, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2450, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2450, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (unlikely(PyObject_SetItem(__pyx_t_3, __pyx_kp_u__2, __pyx_t_1) < 0)) __PYX_ERR(0, 2450, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2447
 *             last_explore_tree = time.time()
 * 
 *     def empty(self):             # <<<<<<<<<<<<<<
 *         """Empty the routing table, deleting all buckets"""
 *         self.trie = datrie.Trie("".join(chr(i) for i in range(256)))
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.empty", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_gb_5btdht_3dht_12RoutingTable_5empty_2generator7);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2452
 *         self.trie[u""]=Bucket()
 * 
 *     def stats(self):             # <<<<<<<<<<<<<<
 *         """
 *             :return: A triple (number of nodes, number of good nodes, number of bad nodes)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_35stats(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_34stats[] = "\n            :return: A triple (number of nodes, number of good nodes, number of bad nodes)\n            :rtype: tuple\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_35stats = {"stats", (PyCFunction)__pyx_pw_5btdht_3dht_12RoutingTable_35stats, METH_O, __pyx_doc_5btdht_3dht_12RoutingTable_34stats};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_35stats(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stats (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_34stats(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_34stats(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_v_nodes = NULL;
  PyObject *__pyx_v_goods = NULL;
  PyObject *__pyx_v_bads = NULL;
  PyObject *__pyx_v_others = NULL;
  PyObject *__pyx_v_b = NULL;
  PyObject *__pyx_v_n = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  Py_ssize_t __pyx_t_9;
  PyObject *(*__pyx_t_10)(PyObject *);
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stats", 0);

  /* "btdht/dht.pyx":2457
 *             :rtype: tuple
 *         """
 *         nodes = 0             # <<<<<<<<<<<<<<
 *         goods = 0
 *         bads = 0
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_v_nodes = __pyx_int_0;

  /* "btdht/dht.pyx":2458
 *         """
 *         nodes = 0
 *         goods = 0             # <<<<<<<<<<<<<<
 *         bads = 0
 *         others = 0
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_v_goods = __pyx_int_0;

  /* "btdht/dht.pyx":2459
 *         nodes = 0
 *         goods = 0
 *         bads = 0             # <<<<<<<<<<<<<<
 *         others = 0
 *         try:
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_v_bads = __pyx_int_0;

  /* "btdht/dht.pyx":2460
 *         goods = 0
 *         bads = 0
 *         others = 0             # <<<<<<<<<<<<<<
 *         try:
 *             for b in self.trie.values():
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_v_others = __pyx_int_0;

  /* "btdht/dht.pyx":2461
 *         bads = 0
 *         others = 0
 *         try:             # <<<<<<<<<<<<<<
 *             for b in self.trie.values():
 *                 for n in b:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "btdht/dht.pyx":2462
 *         others = 0
 *         try:
 *             for b in self.trie.values():             # <<<<<<<<<<<<<<
 *                 for n in b:
 *                     nodes+=1
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2462, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_values); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2462, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2462, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
        __pyx_t_6 = __pyx_t_4; __Pyx_INCREF(__pyx_t_6); __pyx_t_7 = 0;
        __pyx_t_8 = NULL;
      } else {
        __pyx_t_7 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2462, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_8 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2462, __pyx_L3_error)
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      for (;;) {
        if (likely(!__pyx_t_8)) {
          if (likely(PyList_CheckExact(__pyx_t_6))) {
            if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_6)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_4 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 2462, __pyx_L3_error)
            #else
            __pyx_t_4 = PySequence_ITEM(__pyx_t_6, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2462, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_4);
            #endif
          } else {
            if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 2462, __pyx_L3_error)
            #else
            __pyx_t_4 = PySequence_ITEM(__pyx_t_6, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2462, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_4);
            #endif
          }
        } else {
          __pyx_t_4 = __pyx_t_8(__pyx_t_6);
          if (unlikely(!__pyx_t_4)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 2462, __pyx_L3_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_4);
        }
        __Pyx_XDECREF_SET(__pyx_v_b, __pyx_t_4);
        __pyx_t_4 = 0;

        /* "btdht/dht.pyx":2463
 *         try:
 *             for b in self.trie.values():
 *                 for n in b:             # <<<<<<<<<<<<<<
 *                     nodes+=1
 *                     if n.good:
 */
        if (likely(PyList_CheckExact(__pyx_v_b)) || PyTuple_CheckExact(__pyx_v_b)) {
          __pyx_t_4 = __pyx_v_b; __Pyx_INCREF(__pyx_t_4); __pyx_t_9 = 0;
          __pyx_t_10 = NULL;
        } else {
          __pyx_t_9 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_b); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2463, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_10 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2463, __pyx_L3_error)
        }
        for (;;) {
          if (likely(!__pyx_t_10)) {
            if (likely(PyList_CheckExact(__pyx_t_4))) {
              if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_4)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_9); __Pyx_INCREF(__pyx_t_5); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 2463, __pyx_L3_error)
              #else
              __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2463, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_5);
              #endif
            } else {
              if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_9); __Pyx_INCREF(__pyx_t_5); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 2463, __pyx_L3_error)
              #else
              __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2463, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_5);
              #endif
            }
          } else {
            __pyx_t_5 = __pyx_t_10(__pyx_t_4);
            if (unlikely(!__pyx_t_5)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 2463, __pyx_L3_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_5);
          }
          __Pyx_XDECREF_SET(__pyx_v_n, __pyx_t_5);
          __pyx_t_5 = 0;

          /* "btdht/dht.pyx":2464
 *             for b in self.trie.values():
 *                 for n in b:
 *                     nodes+=1             # <<<<<<<<<<<<<<
 *                     if n.good:
 *                         goods+=1
 */
          __pyx_t_5 = __Pyx_PyInt_AddObjC(__pyx_v_nodes, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2464, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF_SET(__pyx_v_nodes, __pyx_t_5);
          __pyx_t_5 = 0;

          /* "btdht/dht.pyx":2465
 *                 for n in b:
 *                     nodes+=1
 *                     if n.good:             # <<<<<<<<<<<<<<
 *                         goods+=1
 *                     elif n.bad:
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_n, __pyx_n_s_good); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2465, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2465, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (__pyx_t_11) {

            /* "btdht/dht.pyx":2466
 *                     nodes+=1
 *                     if n.good:
 *                         goods+=1             # <<<<<<<<<<<<<<
 *                     elif n.bad:
 *                         bads+=1
 */
            __pyx_t_5 = __Pyx_PyInt_AddObjC(__pyx_v_goods, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2466, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF_SET(__pyx_v_goods, __pyx_t_5);
            __pyx_t_5 = 0;

            /* "btdht/dht.pyx":2465
 *                 for n in b:
 *                     nodes+=1
 *                     if n.good:             # <<<<<<<<<<<<<<
 *                         goods+=1
 *                     elif n.bad:
 */
            goto __pyx_L13;
          }

          /* "btdht/dht.pyx":2467
 *                     if n.good:
 *                         goods+=1
 *                     elif n.bad:             # <<<<<<<<<<<<<<
 *                         bads+=1
 *                     else:
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_n, __pyx_n_s_bad); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2467, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 2467, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (__pyx_t_11) {

            /* "btdht/dht.pyx":2468
 *                         goods+=1
 *                     elif n.bad:
 *                         bads+=1             # <<<<<<<<<<<<<<
 *                     else:
 *                         others+=1
 */
            __pyx_t_5 = __Pyx_PyInt_AddObjC(__pyx_v_bads, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2468, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF_SET(__pyx_v_bads, __pyx_t_5);
            __pyx_t_5 = 0;

            /* "btdht/dht.pyx":2467
 *                     if n.good:
 *                         goods+=1
 *                     elif n.bad:             # <<<<<<<<<<<<<<
 *                         bads+=1
 *                     else:
 */
            goto __pyx_L13;
          }

          /* "btdht/dht.pyx":2470
 *                         bads+=1
 *                     else:
 *                         others+=1             # <<<<<<<<<<<<<<
 *         except (TypeError, AttributeError):
 *             pass
 */
          /*else*/ {
            __pyx_t_5 = __Pyx_PyInt_AddObjC(__pyx_v_others, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2470, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF_SET(__pyx_v_others, __pyx_t_5);
            __pyx_t_5 = 0;
          }
          __pyx_L13:;

          /* "btdht/dht.pyx":2463
 *         try:
 *             for b in self.trie.values():
 *                 for n in b:             # <<<<<<<<<<<<<<
 *                     nodes+=1
 *                     if n.good:
 */
        }
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "btdht/dht.pyx":2462
 *         others = 0
 *         try:
 *             for b in self.trie.values():             # <<<<<<<<<<<<<<
 *                 for n in b:
 *                     nodes+=1
 */
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "btdht/dht.pyx":2461
 *         bads = 0
 *         others = 0
 *         try:             # <<<<<<<<<<<<<<
 *             for b in self.trie.values():
 *                 for n in b:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "btdht/dht.pyx":2471
 *                     else:
 *                         others+=1
 *         except (TypeError, AttributeError):             # <<<<<<<<<<<<<<
 *             pass
 *         return (nodes, goods, bads)
 */
    __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError) || __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
    if (__pyx_t_12) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "btdht/dht.pyx":2461
 *         bads = 0
 *         others = 0
 *         try:             # <<<<<<<<<<<<<<
 *             for b in self.trie.values():
 *                 for n in b:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L4_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    __pyx_L8_try_end:;
  }

  /* "btdht/dht.pyx":2473
 *         except (TypeError, AttributeError):
 *             pass
 *         return (nodes, goods, bads)             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2473, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(__pyx_v_nodes);
  __Pyx_GIVEREF(__pyx_v_nodes);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_nodes);
  __Pyx_INCREF(__pyx_v_goods);
  __Pyx_GIVEREF(__pyx_v_goods);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_goods);
  __Pyx_INCREF(__pyx_v_bads);
  __Pyx_GIVEREF(__pyx_v_bads);
  PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_v_bads);
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":2452
 *         self.trie[u""]=Bucket()
 * 
 *     def stats(self):             # <<<<<<<<<<<<<<
 *         """
 *             :return: A triple (number of nodes, number of good nodes, number of bad nodes)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_nodes);
  __Pyx_XDECREF(__pyx_v_goods);
  __Pyx_XDECREF(__pyx_v_bads);
  __Pyx_XDECREF(__pyx_v_others);
  __Pyx_XDECREF(__pyx_v_b);
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2475
 *         return (nodes, goods, bads)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return iter(self.trie.values())
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_37__iter__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_37__iter__ = {"__iter__", (PyCFunction)__pyx_pw_5btdht_3dht_12RoutingTable_37__iter__, METH_O, 0};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_37__iter__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_36__iter__(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_36__iter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 0);

  /* "btdht/dht.pyx":2476
 * 
 *     def __iter__(self):
 *         return iter(self.trie.values())             # <<<<<<<<<<<<<<
 * 
 *     def get_node(self, id):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2476, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":2475
 *         return (nodes, goods, bads)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return iter(self.trie.values())
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2478
 *         return iter(self.trie.values())
 * 
 *     def get_node(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             :param bytes id: A 160 bits (20 Bytes) identifier
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_39get_node(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_38get_node[] = "\n            :param bytes id: A 160 bits (20 Bytes) identifier\n            :return: A node with id ``id``\n            :rtype: Node\n            :raises NotFound: if no nodes is found\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_39get_node = {"get_node", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_39get_node, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_12RoutingTable_38get_node};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_39get_node(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_id = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_node (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_id,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_node", 1, 2, 2, 1); __PYX_ERR(0, 2478, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_node") < 0)) __PYX_ERR(0, 2478, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_self = values[0];
    __pyx_v_id = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_node", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2478, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.get_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_38get_node(__pyx_self, __pyx_v_self, __pyx_v_id);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_38get_node(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id) {
  PyObject *__pyx_v_b = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_node", 0);

  /* "btdht/dht.pyx":2485
 *             :raises NotFound: if no nodes is found
 *         """
 *         b = self.find(id)             # <<<<<<<<<<<<<<
 *         return b.get_node(id)
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_find); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_id);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2485, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_b = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "btdht/dht.pyx":2486
 *         """
 *         b = self.find(id)
 *         return b.get_node(id)             # <<<<<<<<<<<<<<
 * 
 *     def find(self, id, errno=0):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_get_node); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_id);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":2478
 *         return iter(self.trie.values())
 * 
 *     def get_node(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             :param bytes id: A 160 bits (20 Bytes) identifier
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.get_node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_b);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2488
 *         return b.get_node(id)
 * 
 *     def find(self, id, errno=0):             # <<<<<<<<<<<<<<
 *         """
 *             :param bytes id: A 160 bits (20 Bytes) identifier
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_41find(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_40find[] = "\n            :param bytes id: A 160 bits (20 Bytes) identifier\n            :return: The bucket handling ``id``\n            :rtype: Bucket\n            :raises KeyError: then a racing condition with merging and/or spliting a bucket is met.\n                This should not happen\n\n            Notes:\n                Duging a split or merge of bucket it is possible that the bucket handling ``id``\n                is not found. :meth:`find` will retry at most 20 times to get the bucket.\n                In most case, during those retries, the split and/or merge will end and the bucket\n                handling ``id`` will be returned.\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_41find = {"find", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_41find, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_12RoutingTable_40find};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_41find(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_id = 0;
  PyObject *__pyx_v_errno = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_id,&__pyx_n_s_errno,0};
    PyObject* values[3] = {0,0,0};
    values[2] = ((PyObject *)((PyObject *)__pyx_int_0));
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("find", 0, 2, 3, 1); __PYX_ERR(0, 2488, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_errno);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "find") < 0)) __PYX_ERR(0, 2488, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_self = values[0];
    __pyx_v_id = values[1];
    __pyx_v_errno = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("find", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2488, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.find", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_40find(__pyx_self, __pyx_v_self, __pyx_v_id, __pyx_v_errno);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_40find(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id, PyObject *__pyx_v_errno) {
  PyObject *__pyx_v_e = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("find", 0);

  /* "btdht/dht.pyx":2502
 *                 handling ``id`` will be returned.
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             return self.trie.longest_prefix_value(utils.id_to_longid(ID.to_bytes(id)))
 *         except KeyError as e:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "btdht/dht.pyx":2503
 *         """
 *         try:
 *             return self.trie.longest_prefix_value(utils.id_to_longid(ID.to_bytes(id)))             # <<<<<<<<<<<<<<
 *         except KeyError as e:
 *             if errno > 0:
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2503, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_longest_prefix_value); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2503, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_utils); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2503, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_id_to_longid); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2503, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_ID); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2503, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_to_bytes); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2503, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_10);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_10, function);
        }
      }
      __pyx_t_7 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_9, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_v_id);
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2503, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      __pyx_t_5 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_10, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7);
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2503, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_4 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_8, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2503, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L7_try_return;

      /* "btdht/dht.pyx":2502
 *                 handling ``id`` will be returned.
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             return self.trie.longest_prefix_value(utils.id_to_longid(ID.to_bytes(id)))
 *         except KeyError as e:
 */
    }
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "btdht/dht.pyx":2504
 *         try:
 *             return self.trie.longest_prefix_value(utils.id_to_longid(ID.to_bytes(id)))
 *         except KeyError as e:             # <<<<<<<<<<<<<<
 *             if errno > 0:
 *                 print("%r:%r" % (id,e))
 */
    __pyx_t_11 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
    if (__pyx_t_11) {
      __Pyx_AddTraceback("btdht.dht.RoutingTable.find", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_5) < 0) __PYX_ERR(0, 2504, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __pyx_v_e = __pyx_t_6;

      /* "btdht/dht.pyx":2505
 *             return self.trie.longest_prefix_value(utils.id_to_longid(ID.to_bytes(id)))
 *         except KeyError as e:
 *             if errno > 0:             # <<<<<<<<<<<<<<
 *                 print("%r:%r" % (id,e))
 *             try:
 */
      __pyx_t_8 = PyObject_RichCompare(__pyx_v_errno, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2505, __pyx_L5_except_error)
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2505, __pyx_L5_except_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_12) {

        /* "btdht/dht.pyx":2506
 *         except KeyError as e:
 *             if errno > 0:
 *                 print("%r:%r" % (id,e))             # <<<<<<<<<<<<<<
 *             try:
 *                 return self.trie[u""]
 */
        __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2506, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_v_id);
        __Pyx_GIVEREF(__pyx_v_id);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_id);
        __Pyx_INCREF(__pyx_v_e);
        __Pyx_GIVEREF(__pyx_v_e);
        PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_e);
        __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_r_r, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2506, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (__Pyx_PrintOne(0, __pyx_t_7) < 0) __PYX_ERR(0, 2506, __pyx_L5_except_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "btdht/dht.pyx":2505
 *             return self.trie.longest_prefix_value(utils.id_to_longid(ID.to_bytes(id)))
 *         except KeyError as e:
 *             if errno > 0:             # <<<<<<<<<<<<<<
 *                 print("%r:%r" % (id,e))
 *             try:
 */
      }

      /* "btdht/dht.pyx":2507
 *             if errno > 0:
 *                 print("%r:%r" % (id,e))
 *             try:             # <<<<<<<<<<<<<<
 *                 return self.trie[u""]
 *             except KeyError:
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
        __Pyx_XGOTREF(__pyx_t_13);
        __Pyx_XGOTREF(__pyx_t_14);
        __Pyx_XGOTREF(__pyx_t_15);
        /*try:*/ {

          /* "btdht/dht.pyx":2508
 *                 print("%r:%r" % (id,e))
 *             try:
 *                 return self.trie[u""]             # <<<<<<<<<<<<<<
 *             except KeyError:
 *                 if errno < 20:
 */
          __Pyx_XDECREF(__pyx_r);
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2508, __pyx_L12_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_8 = __Pyx_PyObject_Dict_GetItem(__pyx_t_7, __pyx_kp_u__2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2508, __pyx_L12_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_r = __pyx_t_8;
          __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          goto __pyx_L16_try_return;

          /* "btdht/dht.pyx":2507
 *             if errno > 0:
 *                 print("%r:%r" % (id,e))
 *             try:             # <<<<<<<<<<<<<<
 *                 return self.trie[u""]
 *             except KeyError:
 */
        }
        __pyx_L12_error:;
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "btdht/dht.pyx":2509
 *             try:
 *                 return self.trie[u""]
 *             except KeyError:             # <<<<<<<<<<<<<<
 *                 if errno < 20:
 *                     return self.find(id, errno=errno+1)
 */
        __pyx_t_11 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
        if (__pyx_t_11) {
          __Pyx_AddTraceback("btdht.dht.RoutingTable.find", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_8, &__pyx_t_7, &__pyx_t_10) < 0) __PYX_ERR(0, 2509, __pyx_L14_except_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_GOTREF(__pyx_t_10);

          /* "btdht/dht.pyx":2510
 *                 return self.trie[u""]
 *             except KeyError:
 *                 if errno < 20:             # <<<<<<<<<<<<<<
 *                     return self.find(id, errno=errno+1)
 *                 else:
 */
          __pyx_t_9 = PyObject_RichCompare(__pyx_v_errno, __pyx_int_20, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2510, __pyx_L14_except_error)
          __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2510, __pyx_L14_except_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (likely(__pyx_t_12)) {

            /* "btdht/dht.pyx":2511
 *             except KeyError:
 *                 if errno < 20:
 *                     return self.find(id, errno=errno+1)             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise
 */
            __Pyx_XDECREF(__pyx_r);
            __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_find); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2511, __pyx_L14_except_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_16 = PyTuple_New(1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 2511, __pyx_L14_except_error)
            __Pyx_GOTREF(__pyx_t_16);
            __Pyx_INCREF(__pyx_v_id);
            __Pyx_GIVEREF(__pyx_v_id);
            PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_v_id);
            __pyx_t_17 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2511, __pyx_L14_except_error)
            __Pyx_GOTREF(__pyx_t_17);
            __pyx_t_18 = __Pyx_PyInt_AddObjC(__pyx_v_errno, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 2511, __pyx_L14_except_error)
            __Pyx_GOTREF(__pyx_t_18);
            if (PyDict_SetItem(__pyx_t_17, __pyx_n_s_errno, __pyx_t_18) < 0) __PYX_ERR(0, 2511, __pyx_L14_except_error)
            __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
            __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_16, __pyx_t_17); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 2511, __pyx_L14_except_error)
            __Pyx_GOTREF(__pyx_t_18);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
            __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
            __pyx_r = __pyx_t_18;
            __pyx_t_18 = 0;
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            goto __pyx_L15_except_return;

            /* "btdht/dht.pyx":2510
 *                 return self.trie[u""]
 *             except KeyError:
 *                 if errno < 20:             # <<<<<<<<<<<<<<
 *                     return self.find(id, errno=errno+1)
 *                 else:
 */
          }

          /* "btdht/dht.pyx":2513
 *                     return self.find(id, errno=errno+1)
 *                 else:
 *                     raise             # <<<<<<<<<<<<<<
 * 
 *     def get_closest_nodes(self, id, bad=False, errno=0):
 */
          /*else*/ {
            __Pyx_GIVEREF(__pyx_t_8);
            __Pyx_GIVEREF(__pyx_t_7);
            __Pyx_XGIVEREF(__pyx_t_10);
            __Pyx_ErrRestoreWithState(__pyx_t_8, __pyx_t_7, __pyx_t_10);
            __pyx_t_8 = 0; __pyx_t_7 = 0; __pyx_t_10 = 0; 
            __PYX_ERR(0, 2513, __pyx_L14_except_error)
          }
        }
        goto __pyx_L14_except_error;
        __pyx_L14_except_error:;

        /* "btdht/dht.pyx":2507
 *             if errno > 0:
 *                 print("%r:%r" % (id,e))
 *             try:             # <<<<<<<<<<<<<<
 *                 return self.trie[u""]
 *             except KeyError:
 */
        __Pyx_XGIVEREF(__pyx_t_13);
        __Pyx_XGIVEREF(__pyx_t_14);
        __Pyx_XGIVEREF(__pyx_t_15);
        __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
        goto __pyx_L5_except_error;
        __pyx_L16_try_return:;
        __Pyx_XGIVEREF(__pyx_t_13);
        __Pyx_XGIVEREF(__pyx_t_14);
        __Pyx_XGIVEREF(__pyx_t_15);
        __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
        goto __pyx_L6_except_return;
        __pyx_L15_except_return:;
        __Pyx_XGIVEREF(__pyx_t_13);
        __Pyx_XGIVEREF(__pyx_t_14);
        __Pyx_XGIVEREF(__pyx_t_15);
        __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
        goto __pyx_L6_except_return;
      }
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "btdht/dht.pyx":2502
 *                 handling ``id`` will be returned.
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             return self.trie.longest_prefix_value(utils.id_to_longid(ID.to_bytes(id)))
 *         except KeyError as e:
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L7_try_return:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L0;
    __pyx_L6_except_return:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":2488
 *         return b.get_node(id)
 * 
 *     def find(self, id, errno=0):             # <<<<<<<<<<<<<<
 *         """
 *             :param bytes id: A 160 bits (20 Bytes) identifier
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.find", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_e);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2515
 *                     raise
 * 
 *     def get_closest_nodes(self, id, bad=False, errno=0):             # <<<<<<<<<<<<<<
 *         """
 *             Return the K closest nodes from ``id`` in the routing table
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_43get_closest_nodes(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_42get_closest_nodes[] = "\n            Return the K closest nodes from ``id`` in the routing table\n\n            :param bytes id: A 160 bits (20 Bytes) identifier\n            :param bool bad: Should we return bad nodes ? The default is ``False``\n\n            Notes:\n                If less than K (=8) good nodes is found, bad nodes will be included it solve\n                the case there the connection where temporary lost and all nodes in the routing\n                table marked as bad.\n                In normal operation, we should always find K (=8) good nodes in the routing table.\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_43get_closest_nodes = {"get_closest_nodes", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_43get_closest_nodes, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_12RoutingTable_42get_closest_nodes};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_43get_closest_nodes(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_id = 0;
  PyObject *__pyx_v_bad = 0;
  PyObject *__pyx_v_errno = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_closest_nodes (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_id,&__pyx_n_s_bad,&__pyx_n_s_errno,0};
    PyObject* values[4] = {0,0,0,0};
    values[2] = ((PyObject *)((PyObject *)Py_False));
    values[3] = ((PyObject *)((PyObject *)__pyx_int_0));
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_id)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_closest_nodes", 0, 2, 4, 1); __PYX_ERR(0, 2515, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bad);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_errno);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_closest_nodes") < 0)) __PYX_ERR(0, 2515, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_self = values[0];
    __pyx_v_id = values[1];
    __pyx_v_bad = values[2];
    __pyx_v_errno = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_closest_nodes", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2515, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.get_closest_nodes", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_42get_closest_nodes(__pyx_self, __pyx_v_self, __pyx_v_id, __pyx_v_bad, __pyx_v_errno);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_17get_closest_nodes_2generator8(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "btdht/dht.pyx":2530
 *         try:
 *             id = ID(id)
 *             nodes = set(n for n in self.find(id) if not n.bad)             # <<<<<<<<<<<<<<
 *             try:
 *                 prefix = self.trie.longest_prefix(utils.id_to_longid(id.value))
 */

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_17get_closest_nodes_genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct_10_genexpr(__pyx_ptype_5btdht_3dht___pyx_scope_struct_10_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2530, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *) __pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5btdht_3dht_12RoutingTable_17get_closest_nodes_2generator8, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_RoutingTable_get_closest_nodes_l, __pyx_n_s_btdht_dht); if (unlikely(!gen)) __PYX_ERR(0, 2530, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.get_closest_nodes.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_17get_closest_nodes_2generator8(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("genexpr", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2530, __pyx_L1_error)
  __pyx_r = PySet_New(NULL); if (unlikely(!__pyx_r)) __PYX_ERR(0, 2530, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_r);
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 2530, __pyx_L1_error) }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self, __pyx_n_s_find); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2530, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_id)) { __Pyx_RaiseClosureNameError("id"); __PYX_ERR(0, 2530, __pyx_L1_error) }
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_id);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2530, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2530, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2530, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2530, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2530, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2530, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2530, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_5(__pyx_t_2);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2530, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_n);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_n, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_n, __pyx_n_s_bad); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2530, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 2530, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_7 = ((!__pyx_t_6) != 0);
    if (__pyx_t_7) {
      if (unlikely(PySet_Add(__pyx_r, (PyObject*)__pyx_cur_scope->__pyx_v_n))) __PYX_ERR(0, 2530, __pyx_L1_error)
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_17get_closest_nodes_5generator9(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "btdht/dht.pyx":2538
 *                 prefix = prefix[:-1]
 *                 for suffix in self.trie.suffixes(prefix):
 *                     nodes = nodes.union(n for n in self.trie[prefix + suffix] if bad or not n.bad)             # <<<<<<<<<<<<<<
 *             nodes = list(nodes)
 *             nodes.sort(key=lambda x:id ^ x.id)
 */

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_17get_closest_nodes_3genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct_11_genexpr(__pyx_ptype_5btdht_3dht___pyx_scope_struct_11_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2538, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *) __pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5btdht_3dht_12RoutingTable_17get_closest_nodes_5generator9, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_RoutingTable_get_closest_nodes_l, __pyx_n_s_btdht_dht); if (unlikely(!gen)) __PYX_ERR(0, 2538, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.get_closest_nodes.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_17get_closest_nodes_5generator9(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("genexpr", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L9_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2538, __pyx_L1_error)
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 2538, __pyx_L1_error) }
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2538, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_prefix)) { __Pyx_RaiseClosureNameError("prefix"); __PYX_ERR(0, 2538, __pyx_L1_error) }
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_suffix)) { __Pyx_RaiseClosureNameError("suffix"); __PYX_ERR(0, 2538, __pyx_L1_error) }
  __pyx_t_2 = PyNumber_Add(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_prefix, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_suffix); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2538, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2538, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2538, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2538, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2538, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2538, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2538, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2538, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_5(__pyx_t_2);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2538, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_n);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_n, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_bad)) { __Pyx_RaiseClosureNameError("bad"); __PYX_ERR(0, 2538, __pyx_L1_error) }
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_bad); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 2538, __pyx_L1_error)
    if (!__pyx_t_7) {
    } else {
      __pyx_t_6 = __pyx_t_7;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_n, __pyx_n_s_bad); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2538, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 2538, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_8 = ((!__pyx_t_7) != 0);
    __pyx_t_6 = __pyx_t_8;
    __pyx_L7_bool_binop_done:;
    if (__pyx_t_6) {
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_n);
      __pyx_r = __pyx_cur_scope->__pyx_v_n;
      __Pyx_XGIVEREF(__pyx_t_2);
      __pyx_cur_scope->__pyx_t_0 = __pyx_t_2;
      __pyx_cur_scope->__pyx_t_1 = __pyx_t_4;
      __pyx_cur_scope->__pyx_t_2 = __pyx_t_5;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
      /* return from generator, yielding value */
      __pyx_generator->resume_label = 1;
      return __pyx_r;
      __pyx_L9_resume_from_yield:;
      __pyx_t_2 = __pyx_cur_scope->__pyx_t_0;
      __pyx_cur_scope->__pyx_t_0 = 0;
      __Pyx_XGOTREF(__pyx_t_2);
      __pyx_t_4 = __pyx_cur_scope->__pyx_t_1;
      __pyx_t_5 = __pyx_cur_scope->__pyx_t_2;
      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2538, __pyx_L1_error)
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2540
 *                     nodes = nodes.union(n for n in self.trie[prefix + suffix] if bad or not n.bad)
 *             nodes = list(nodes)
 *             nodes.sort(key=lambda x:id ^ x.id)             # <<<<<<<<<<<<<<
 *             # if found less the k good nodes, retrie including bad nodes
 *             # it solve the case there connection where temporary lost and
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_17get_closest_nodes_6lambda4(PyObject *__pyx_self, PyObject *__pyx_v_x); /*proto*/
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_17get_closest_nodes_6lambda4 = {"lambda4", (PyCFunction)__pyx_pw_5btdht_3dht_12RoutingTable_17get_closest_nodes_6lambda4, METH_O, 0};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_17get_closest_nodes_6lambda4(PyObject *__pyx_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("lambda4 (wrapper)", 0);
  __pyx_r = __pyx_lambda_funcdef_lambda4(__pyx_self, ((PyObject *)__pyx_v_x));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_lambda_funcdef_lambda4(PyObject *__pyx_self, PyObject *__pyx_v_x) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *__pyx_cur_scope;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *__pyx_outer_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("lambda4", 0);
  __pyx_outer_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *) __Pyx_CyFunction_GetClosure(__pyx_self);
  __pyx_cur_scope = __pyx_outer_scope;
  __Pyx_XDECREF(__pyx_r);
  if (unlikely(!__pyx_cur_scope->__pyx_v_id)) { __Pyx_RaiseClosureNameError("id"); __PYX_ERR(0, 2540, __pyx_L1_error) }
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_x, __pyx_n_s_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2540, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyNumber_Xor(__pyx_cur_scope->__pyx_v_id, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2540, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.get_closest_nodes.lambda4", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2515
 *                     raise
 * 
 *     def get_closest_nodes(self, id, bad=False, errno=0):             # <<<<<<<<<<<<<<
 *         """
 *             Return the K closest nodes from ``id`` in the routing table
 */

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_42get_closest_nodes(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id, PyObject *__pyx_v_bad, PyObject *__pyx_v_errno) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *__pyx_cur_scope;
  PyObject *__pyx_v_nodes = NULL;
  PyObject *__pyx_v_e = NULL;
  PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_17get_closest_nodes_2generator8 = 0;
  PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_17get_closest_nodes_5generator9 = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  int __pyx_t_13;
  int __pyx_t_14;
  Py_ssize_t __pyx_t_15;
  int __pyx_t_16;
  PyObject *(*__pyx_t_17)(PyObject *);
  int __pyx_t_18;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_closest_nodes", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes(__pyx_ptype_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2515, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self);
  __pyx_cur_scope->__pyx_v_id = __pyx_v_id;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_id);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_id);
  __pyx_cur_scope->__pyx_v_bad = __pyx_v_bad;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_bad);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_bad);

  /* "btdht/dht.pyx":2528
 *                 In normal operation, we should always find K (=8) good nodes in the routing table.
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             id = ID(id)
 *             nodes = set(n for n in self.find(id) if not n.bad)
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "btdht/dht.pyx":2529
 *         """
 *         try:
 *             id = ID(id)             # <<<<<<<<<<<<<<
 *             nodes = set(n for n in self.find(id) if not n.bad)
 *             try:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_ID); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2529, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_cur_scope->__pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_cur_scope->__pyx_v_id);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2529, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_id);
      __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_id, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __pyx_t_4 = 0;

      /* "btdht/dht.pyx":2530
 *         try:
 *             id = ID(id)
 *             nodes = set(n for n in self.find(id) if not n.bad)             # <<<<<<<<<<<<<<
 *             try:
 *                 prefix = self.trie.longest_prefix(utils.id_to_longid(id.value))
 */
      __pyx_t_4 = __pyx_pf_5btdht_3dht_12RoutingTable_17get_closest_nodes_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2530, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_Generator_Next(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2530, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_v_nodes = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "btdht/dht.pyx":2531
 *             id = ID(id)
 *             nodes = set(n for n in self.find(id) if not n.bad)
 *             try:             # <<<<<<<<<<<<<<
 *                 prefix = self.trie.longest_prefix(utils.id_to_longid(id.value))
 *             except KeyError:
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
        __Pyx_XGOTREF(__pyx_t_7);
        __Pyx_XGOTREF(__pyx_t_8);
        __Pyx_XGOTREF(__pyx_t_9);
        /*try:*/ {

          /* "btdht/dht.pyx":2532
 *             nodes = set(n for n in self.find(id) if not n.bad)
 *             try:
 *                 prefix = self.trie.longest_prefix(utils.id_to_longid(id.value))             # <<<<<<<<<<<<<<
 *             except KeyError:
 *                 prefix = u""
 */
          __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2532, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_longest_prefix); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2532, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GetModuleGlobalName(__pyx_t_10, __pyx_n_s_utils); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2532, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_id_to_longid); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2532, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_id, __pyx_n_s_value); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2532, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_12 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
            __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
            if (likely(__pyx_t_12)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
              __Pyx_INCREF(__pyx_t_12);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_11, function);
            }
          }
          __pyx_t_4 = (__pyx_t_12) ? __Pyx_PyObject_Call2Args(__pyx_t_11, __pyx_t_12, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_10);
          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2532, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __pyx_t_11 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
            __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_6);
            if (likely(__pyx_t_11)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
              __Pyx_INCREF(__pyx_t_11);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_6, function);
            }
          }
          __pyx_t_5 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_11, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4);
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2532, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_GIVEREF(__pyx_t_5);
          __pyx_cur_scope->__pyx_v_prefix = __pyx_t_5;
          __pyx_t_5 = 0;

          /* "btdht/dht.pyx":2531
 *             id = ID(id)
 *             nodes = set(n for n in self.find(id) if not n.bad)
 *             try:             # <<<<<<<<<<<<<<
 *                 prefix = self.trie.longest_prefix(utils.id_to_longid(id.value))
 *             except KeyError:
 */
        }
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L14_try_end;
        __pyx_L9_error:;
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "btdht/dht.pyx":2533
 *             try:
 *                 prefix = self.trie.longest_prefix(utils.id_to_longid(id.value))
 *             except KeyError:             # <<<<<<<<<<<<<<
 *                 prefix = u""
 *             while len(nodes) < Bucket.max_size and prefix:
 */
        __pyx_t_13 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
        if (__pyx_t_13) {
          __Pyx_AddTraceback("btdht.dht.RoutingTable.get_closest_nodes", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_4) < 0) __PYX_ERR(0, 2533, __pyx_L11_except_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_GOTREF(__pyx_t_4);

          /* "btdht/dht.pyx":2534
 *                 prefix = self.trie.longest_prefix(utils.id_to_longid(id.value))
 *             except KeyError:
 *                 prefix = u""             # <<<<<<<<<<<<<<
 *             while len(nodes) < Bucket.max_size and prefix:
 *                 prefix = prefix[:-1]
 */
          __Pyx_INCREF(__pyx_kp_u__2);
          __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_prefix);
          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_prefix, __pyx_kp_u__2);
          __Pyx_GIVEREF(__pyx_kp_u__2);
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          goto __pyx_L10_exception_handled;
        }
        goto __pyx_L11_except_error;
        __pyx_L11_except_error:;

        /* "btdht/dht.pyx":2531
 *             id = ID(id)
 *             nodes = set(n for n in self.find(id) if not n.bad)
 *             try:             # <<<<<<<<<<<<<<
 *                 prefix = self.trie.longest_prefix(utils.id_to_longid(id.value))
 *             except KeyError:
 */
        __Pyx_XGIVEREF(__pyx_t_7);
        __Pyx_XGIVEREF(__pyx_t_8);
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
        goto __pyx_L3_error;
        __pyx_L10_exception_handled:;
        __Pyx_XGIVEREF(__pyx_t_7);
        __Pyx_XGIVEREF(__pyx_t_8);
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
        __pyx_L14_try_end:;
      }

      /* "btdht/dht.pyx":2535
 *             except KeyError:
 *                 prefix = u""
 *             while len(nodes) < Bucket.max_size and prefix:             # <<<<<<<<<<<<<<
 *                 prefix = prefix[:-1]
 *                 for suffix in self.trie.suffixes(prefix):
 */
      while (1) {
        __pyx_t_15 = PyObject_Length(__pyx_v_nodes); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2535, __pyx_L3_error)
        __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2535, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_Bucket); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2535, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_max_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2535, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = PyObject_RichCompare(__pyx_t_4, __pyx_t_5, Py_LT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2535, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 2535, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__pyx_t_16) {
        } else {
          __pyx_t_14 = __pyx_t_16;
          goto __pyx_L19_bool_binop_done;
        }
        __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_prefix); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 2535, __pyx_L3_error)
        __pyx_t_14 = __pyx_t_16;
        __pyx_L19_bool_binop_done:;
        if (!__pyx_t_14) break;

        /* "btdht/dht.pyx":2536
 *                 prefix = u""
 *             while len(nodes) < Bucket.max_size and prefix:
 *                 prefix = prefix[:-1]             # <<<<<<<<<<<<<<
 *                 for suffix in self.trie.suffixes(prefix):
 *                     nodes = nodes.union(n for n in self.trie[prefix + suffix] if bad or not n.bad)
 */
        __pyx_t_6 = __Pyx_PyObject_GetSlice(__pyx_cur_scope->__pyx_v_prefix, 0, -1L, NULL, NULL, &__pyx_slice__35, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2536, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_prefix);
        __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_prefix, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_6);
        __pyx_t_6 = 0;

        /* "btdht/dht.pyx":2537
 *             while len(nodes) < Bucket.max_size and prefix:
 *                 prefix = prefix[:-1]
 *                 for suffix in self.trie.suffixes(prefix):             # <<<<<<<<<<<<<<
 *                     nodes = nodes.union(n for n in self.trie[prefix + suffix] if bad or not n.bad)
 *             nodes = list(nodes)
 */
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2537, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_suffixes); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2537, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_4, function);
          }
        }
        __pyx_t_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_cur_scope->__pyx_v_prefix) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_cur_scope->__pyx_v_prefix);
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2537, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
          __pyx_t_4 = __pyx_t_6; __Pyx_INCREF(__pyx_t_4); __pyx_t_15 = 0;
          __pyx_t_17 = NULL;
        } else {
          __pyx_t_15 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2537, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_17 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 2537, __pyx_L3_error)
        }
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        for (;;) {
          if (likely(!__pyx_t_17)) {
            if (likely(PyList_CheckExact(__pyx_t_4))) {
              if (__pyx_t_15 >= PyList_GET_SIZE(__pyx_t_4)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_15); __Pyx_INCREF(__pyx_t_6); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 2537, __pyx_L3_error)
              #else
              __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2537, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_6);
              #endif
            } else {
              if (__pyx_t_15 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_15); __Pyx_INCREF(__pyx_t_6); __pyx_t_15++; if (unlikely(0 < 0)) __PYX_ERR(0, 2537, __pyx_L3_error)
              #else
              __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2537, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_6);
              #endif
            }
          } else {
            __pyx_t_6 = __pyx_t_17(__pyx_t_4);
            if (unlikely(!__pyx_t_6)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 2537, __pyx_L3_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_6);
          }
          __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_suffix);
          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_suffix, __pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_6);
          __pyx_t_6 = 0;

          /* "btdht/dht.pyx":2538
 *                 prefix = prefix[:-1]
 *                 for suffix in self.trie.suffixes(prefix):
 *                     nodes = nodes.union(n for n in self.trie[prefix + suffix] if bad or not n.bad)             # <<<<<<<<<<<<<<
 *             nodes = list(nodes)
 *             nodes.sort(key=lambda x:id ^ x.id)
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_nodes, __pyx_n_s_union); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2538, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_11 = __pyx_pf_5btdht_3dht_12RoutingTable_17get_closest_nodes_3genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2538, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_10 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_10)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_10);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
            }
          }
          __pyx_t_6 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_10, __pyx_t_11) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_11);
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2538, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF_SET(__pyx_v_nodes, __pyx_t_6);
          __pyx_t_6 = 0;

          /* "btdht/dht.pyx":2537
 *             while len(nodes) < Bucket.max_size and prefix:
 *                 prefix = prefix[:-1]
 *                 for suffix in self.trie.suffixes(prefix):             # <<<<<<<<<<<<<<
 *                     nodes = nodes.union(n for n in self.trie[prefix + suffix] if bad or not n.bad)
 *             nodes = list(nodes)
 */
        }
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }

      /* "btdht/dht.pyx":2539
 *                 for suffix in self.trie.suffixes(prefix):
 *                     nodes = nodes.union(n for n in self.trie[prefix + suffix] if bad or not n.bad)
 *             nodes = list(nodes)             # <<<<<<<<<<<<<<
 *             nodes.sort(key=lambda x:id ^ x.id)
 *             # if found less the k good nodes, retrie including bad nodes
 */
      __pyx_t_4 = PySequence_List(__pyx_v_nodes); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2539, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF_SET(__pyx_v_nodes, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "btdht/dht.pyx":2540
 *                     nodes = nodes.union(n for n in self.trie[prefix + suffix] if bad or not n.bad)
 *             nodes = list(nodes)
 *             nodes.sort(key=lambda x:id ^ x.id)             # <<<<<<<<<<<<<<
 *             # if found less the k good nodes, retrie including bad nodes
 *             # it solve the case there connection where temporary lost and
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_nodes, __pyx_n_s_sort); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2540, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2540, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_17get_closest_nodes_6lambda4, 0, __pyx_n_s_RoutingTable_get_closest_nodes_l_2, ((PyObject*)__pyx_cur_scope), __pyx_n_s_btdht_dht, __pyx_d, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2540, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_key, __pyx_t_5) < 0) __PYX_ERR(0, 2540, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2540, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "btdht/dht.pyx":2544
 *             # it solve the case there connection where temporary lost and
 *             # all nodes in the routing table marked as bad
 *             if len(nodes) < Bucket.max_size and not bad:             # <<<<<<<<<<<<<<
 *                 return self.get_closest_nodes(id, bad=True, errno=errno)
 *             return nodes[0:Bucket.max_size]
 */
      __pyx_t_15 = PyObject_Length(__pyx_v_nodes); if (unlikely(__pyx_t_15 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2544, __pyx_L3_error)
      __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2544, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_Bucket); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2544, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_max_size); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2544, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyObject_RichCompare(__pyx_t_5, __pyx_t_4, Py_LT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2544, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 2544, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_16) {
      } else {
        __pyx_t_14 = __pyx_t_16;
        goto __pyx_L24_bool_binop_done;
      }
      __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_bad); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 2544, __pyx_L3_error)
      __pyx_t_18 = ((!__pyx_t_16) != 0);
      __pyx_t_14 = __pyx_t_18;
      __pyx_L24_bool_binop_done:;
      if (__pyx_t_14) {

        /* "btdht/dht.pyx":2545
 *             # all nodes in the routing table marked as bad
 *             if len(nodes) < Bucket.max_size and not bad:
 *                 return self.get_closest_nodes(id, bad=True, errno=errno)             # <<<<<<<<<<<<<<
 *             return nodes[0:Bucket.max_size]
 *         except KeyError as e:
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_get_closest_nodes); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2545, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2545, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_INCREF(__pyx_cur_scope->__pyx_v_id);
        __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_id);
        PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_cur_scope->__pyx_v_id);
        __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2545, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_bad, Py_True) < 0) __PYX_ERR(0, 2545, __pyx_L3_error)
        if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_errno, __pyx_v_errno) < 0) __PYX_ERR(0, 2545, __pyx_L3_error)
        __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2545, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_r = __pyx_t_11;
        __pyx_t_11 = 0;
        goto __pyx_L7_try_return;

        /* "btdht/dht.pyx":2544
 *             # it solve the case there connection where temporary lost and
 *             # all nodes in the routing table marked as bad
 *             if len(nodes) < Bucket.max_size and not bad:             # <<<<<<<<<<<<<<
 *                 return self.get_closest_nodes(id, bad=True, errno=errno)
 *             return nodes[0:Bucket.max_size]
 */
      }

      /* "btdht/dht.pyx":2546
 *             if len(nodes) < Bucket.max_size and not bad:
 *                 return self.get_closest_nodes(id, bad=True, errno=errno)
 *             return nodes[0:Bucket.max_size]             # <<<<<<<<<<<<<<
 *         except KeyError as e:
 *             if errno>0:
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_Bucket); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2546, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_max_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2546, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_11 = __Pyx_PyObject_GetSlice(__pyx_v_nodes, 0, 0, NULL, &__pyx_t_5, NULL, 1, 0, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 2546, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_r = __pyx_t_11;
      __pyx_t_11 = 0;
      goto __pyx_L7_try_return;

      /* "btdht/dht.pyx":2528
 *                 In normal operation, we should always find K (=8) good nodes in the routing table.
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             id = ID(id)
 *             nodes = set(n for n in self.find(id) if not n.bad)
 */
    }
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "btdht/dht.pyx":2547
 *                 return self.get_closest_nodes(id, bad=True, errno=errno)
 *             return nodes[0:Bucket.max_size]
 *         except KeyError as e:             # <<<<<<<<<<<<<<
 *             if errno>0:
 *                 self.debug(1, "get_closest_nodes:%r" % e)
 */
    __pyx_t_13 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
    if (__pyx_t_13) {
      __Pyx_AddTraceback("btdht.dht.RoutingTable.get_closest_nodes", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_11, &__pyx_t_5, &__pyx_t_4) < 0) __PYX_ERR(0, 2547, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __pyx_v_e = __pyx_t_5;

      /* "btdht/dht.pyx":2548
 *             return nodes[0:Bucket.max_size]
 *         except KeyError as e:
 *             if errno>0:             # <<<<<<<<<<<<<<
 *                 self.debug(1, "get_closest_nodes:%r" % e)
 *             return self.get_closest_nodes(id, bad=bad, errno=errno+1)
 */
      __pyx_t_6 = PyObject_RichCompare(__pyx_v_errno, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2548, __pyx_L5_except_error)
      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 2548, __pyx_L5_except_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_14) {

        /* "btdht/dht.pyx":2549
 *         except KeyError as e:
 *             if errno>0:
 *                 self.debug(1, "get_closest_nodes:%r" % e)             # <<<<<<<<<<<<<<
 *             return self.get_closest_nodes(id, bad=bad, errno=errno+1)
 * 
 */
        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2549, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_12 = __Pyx_PyString_FormatSafe(__pyx_kp_s_get_closest_nodes_r, __pyx_v_e); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2549, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_19 = NULL;
        __pyx_t_13 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) {
          __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_10);
          if (likely(__pyx_t_19)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
            __Pyx_INCREF(__pyx_t_19);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_10, function);
            __pyx_t_13 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_10)) {
          PyObject *__pyx_temp[3] = {__pyx_t_19, __pyx_int_1, __pyx_t_12};
          __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2549, __pyx_L5_except_error)
          __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
          PyObject *__pyx_temp[3] = {__pyx_t_19, __pyx_int_1, __pyx_t_12};
          __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2549, __pyx_L5_except_error)
          __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        } else
        #endif
        {
          __pyx_t_20 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2549, __pyx_L5_except_error)
          __Pyx_GOTREF(__pyx_t_20);
          if (__pyx_t_19) {
            __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_19); __pyx_t_19 = NULL;
          }
          __Pyx_INCREF(__pyx_int_1);
          __Pyx_GIVEREF(__pyx_int_1);
          PyTuple_SET_ITEM(__pyx_t_20, 0+__pyx_t_13, __pyx_int_1);
          __Pyx_GIVEREF(__pyx_t_12);
          PyTuple_SET_ITEM(__pyx_t_20, 1+__pyx_t_13, __pyx_t_12);
          __pyx_t_12 = 0;
          __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_20, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2549, __pyx_L5_except_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        }
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "btdht/dht.pyx":2548
 *             return nodes[0:Bucket.max_size]
 *         except KeyError as e:
 *             if errno>0:             # <<<<<<<<<<<<<<
 *                 self.debug(1, "get_closest_nodes:%r" % e)
 *             return self.get_closest_nodes(id, bad=bad, errno=errno+1)
 */
      }

      /* "btdht/dht.pyx":2550
 *             if errno>0:
 *                 self.debug(1, "get_closest_nodes:%r" % e)
 *             return self.get_closest_nodes(id, bad=bad, errno=errno+1)             # <<<<<<<<<<<<<<
 * 
 *     def add(self, dht, node):
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_get_closest_nodes); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2550, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 2550, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_id);
      __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_id);
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_cur_scope->__pyx_v_id);
      __pyx_t_20 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 2550, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_20);
      if (PyDict_SetItem(__pyx_t_20, __pyx_n_s_bad, __pyx_cur_scope->__pyx_v_bad) < 0) __PYX_ERR(0, 2550, __pyx_L5_except_error)
      __pyx_t_12 = __Pyx_PyInt_AddObjC(__pyx_v_errno, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2550, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_12);
      if (PyDict_SetItem(__pyx_t_20, __pyx_n_s_errno, __pyx_t_12) < 0) __PYX_ERR(0, 2550, __pyx_L5_except_error)
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_10, __pyx_t_20); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 2550, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __pyx_r = __pyx_t_12;
      __pyx_t_12 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      goto __pyx_L6_except_return;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "btdht/dht.pyx":2528
 *                 In normal operation, we should always find K (=8) good nodes in the routing table.
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             id = ID(id)
 *             nodes = set(n for n in self.find(id) if not n.bad)
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L7_try_return:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L0;
    __pyx_L6_except_return:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L0;
  }

  /* "btdht/dht.pyx":2515
 *                     raise
 * 
 *     def get_closest_nodes(self, id, bad=False, errno=0):             # <<<<<<<<<<<<<<
 *         """
 *             Return the K closest nodes from ``id`` in the routing table
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.get_closest_nodes", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_nodes);
  __Pyx_XDECREF(__pyx_v_e);
  __Pyx_XDECREF(__pyx_gb_5btdht_3dht_12RoutingTable_17get_closest_nodes_2generator8);
  __Pyx_XDECREF(__pyx_gb_5btdht_3dht_12RoutingTable_17get_closest_nodes_5generator9);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2552
 *             return self.get_closest_nodes(id, bad=bad, errno=errno+1)
 * 
 *     def add(self, dht, node):             # <<<<<<<<<<<<<<
 *         """
 *             Add a node the the routing table
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_45add(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_44add[] = "\n            Add a node the the routing table\n\n            :param DHT_BASE dht: The dht instance ``node``is from\n            :param Node node: The node to add to the routing table\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_45add = {"add", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_45add, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_12RoutingTable_44add};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_45add(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_dht = 0;
  PyObject *__pyx_v_node = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("add (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_dht,&__pyx_n_s_node,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dht)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("add", 1, 3, 3, 1); __PYX_ERR(0, 2552, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_node)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("add", 1, 3, 3, 2); __PYX_ERR(0, 2552, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add") < 0)) __PYX_ERR(0, 2552, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_self = values[0];
    __pyx_v_dht = values[1];
    __pyx_v_node = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("add", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2552, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.add", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_44add(__pyx_self, __pyx_v_self, __pyx_v_dht, __pyx_v_node);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_44add(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_dht, PyObject *__pyx_v_node) {
  PyObject *__pyx_v_b = NULL;
  PyObject *__pyx_v_id = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  Py_ssize_t __pyx_t_13;
  PyObject *(*__pyx_t_14)(PyObject *);
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("add", 0);

  /* "btdht/dht.pyx":2559
 *             :param Node node: The node to add to the routing table
 *         """
 *         if node.ip in dht.ignored_ip:             # <<<<<<<<<<<<<<
 *             return
 *         if utils.ip_in_nets(node.ip, dht.ignored_net):
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_ip); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2559, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_dht, __pyx_n_s_ignored_ip); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2559, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 2559, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {

    /* "btdht/dht.pyx":2560
 *         """
 *         if node.ip in dht.ignored_ip:
 *             return             # <<<<<<<<<<<<<<
 *         if utils.ip_in_nets(node.ip, dht.ignored_net):
 *             return
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "btdht/dht.pyx":2559
 *             :param Node node: The node to add to the routing table
 *         """
 *         if node.ip in dht.ignored_ip:             # <<<<<<<<<<<<<<
 *             return
 *         if utils.ip_in_nets(node.ip, dht.ignored_net):
 */
  }

  /* "btdht/dht.pyx":2561
 *         if node.ip in dht.ignored_ip:
 *             return
 *         if utils.ip_in_nets(node.ip, dht.ignored_net):             # <<<<<<<<<<<<<<
 *             return
 *         b = self.find(node.id)
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_utils); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_ip_in_nets); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_ip); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_dht, __pyx_n_s_ignored_net); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = NULL;
  __pyx_t_8 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
      __pyx_t_8 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_1, __pyx_t_6};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2561, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_1, __pyx_t_6};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2561, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  } else
  #endif
  {
    __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2561, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    if (__pyx_t_7) {
      __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_6);
    __pyx_t_1 = 0;
    __pyx_t_6 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2561, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2561, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_4) {

    /* "btdht/dht.pyx":2562
 *             return
 *         if utils.ip_in_nets(node.ip, dht.ignored_net):
 *             return             # <<<<<<<<<<<<<<
 *         b = self.find(node.id)
 *         try:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "btdht/dht.pyx":2561
 *         if node.ip in dht.ignored_ip:
 *             return
 *         if utils.ip_in_nets(node.ip, dht.ignored_net):             # <<<<<<<<<<<<<<
 *             return
 *         b = self.find(node.id)
 */
  }

  /* "btdht/dht.pyx":2563
 *         if utils.ip_in_nets(node.ip, dht.ignored_net):
 *             return
 *         b = self.find(node.id)             # <<<<<<<<<<<<<<
 *         try:
 *             b.add(dht, node)
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_find); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2563, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_id); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2563, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_9);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2563, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_b = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "btdht/dht.pyx":2564
 *             return
 *         b = self.find(node.id)
 *         try:             # <<<<<<<<<<<<<<
 *             b.add(dht, node)
 *         except BucketFull:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
    __Pyx_XGOTREF(__pyx_t_10);
    __Pyx_XGOTREF(__pyx_t_11);
    __Pyx_XGOTREF(__pyx_t_12);
    /*try:*/ {

      /* "btdht/dht.pyx":2565
 *         b = self.find(node.id)
 *         try:
 *             b.add(dht, node)             # <<<<<<<<<<<<<<
 *         except BucketFull:
 *             # If bucket is full, try to split
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_add); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2565, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_9 = NULL;
      __pyx_t_8 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_8 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_v_dht, __pyx_v_node};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2565, __pyx_L5_error)
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_v_dht, __pyx_v_node};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2565, __pyx_L5_error)
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else
      #endif
      {
        __pyx_t_6 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2565, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (__pyx_t_9) {
          __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_9); __pyx_t_9 = NULL;
        }
        __Pyx_INCREF(__pyx_v_dht);
        __Pyx_GIVEREF(__pyx_v_dht);
        PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_8, __pyx_v_dht);
        __Pyx_INCREF(__pyx_v_node);
        __Pyx_GIVEREF(__pyx_v_node);
        PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_8, __pyx_v_node);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2565, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "btdht/dht.pyx":2564
 *             return
 *         b = self.find(node.id)
 *         try:             # <<<<<<<<<<<<<<
 *             b.add(dht, node)
 *         except BucketFull:
 */
    }
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
    goto __pyx_L10_try_end;
    __pyx_L5_error:;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "btdht/dht.pyx":2566
 *         try:
 *             b.add(dht, node)
 *         except BucketFull:             # <<<<<<<<<<<<<<
 *             # If bucket is full, try to split
 *             if b.id_length < 160:
 */
    __Pyx_ErrFetch(&__pyx_t_2, &__pyx_t_5, &__pyx_t_6);
    __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_BucketFull); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2566, __pyx_L7_except_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_8 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_2, __pyx_t_9);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_ErrRestore(__pyx_t_2, __pyx_t_5, __pyx_t_6);
    __pyx_t_2 = 0; __pyx_t_5 = 0; __pyx_t_6 = 0;
    if (__pyx_t_8) {
      __Pyx_AddTraceback("btdht.dht.RoutingTable.add", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_5, &__pyx_t_2) < 0) __PYX_ERR(0, 2566, __pyx_L7_except_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_2);

      /* "btdht/dht.pyx":2568
 *         except BucketFull:
 *             # If bucket is full, try to split
 *             if b.id_length < 160:             # <<<<<<<<<<<<<<
 *                 for id in self._split_ids | self._info_hash:
 *                     if b.own(id):
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_id_length); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2568, __pyx_L7_except_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_1 = PyObject_RichCompare(__pyx_t_9, __pyx_int_160, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2568, __pyx_L7_except_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2568, __pyx_L7_except_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_4) {

        /* "btdht/dht.pyx":2569
 *             # If bucket is full, try to split
 *             if b.id_length < 160:
 *                 for id in self._split_ids | self._info_hash:             # <<<<<<<<<<<<<<
 *                     if b.own(id):
 *                         self.split(dht, b)
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_split_ids); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2569, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_info_hash_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2569, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_7 = PyNumber_Or(__pyx_t_1, __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2569, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
          __pyx_t_9 = __pyx_t_7; __Pyx_INCREF(__pyx_t_9); __pyx_t_13 = 0;
          __pyx_t_14 = NULL;
        } else {
          __pyx_t_13 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2569, __pyx_L7_except_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_14 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2569, __pyx_L7_except_error)
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        for (;;) {
          if (likely(!__pyx_t_14)) {
            if (likely(PyList_CheckExact(__pyx_t_9))) {
              if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_9)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_7 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_13); __Pyx_INCREF(__pyx_t_7); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 2569, __pyx_L7_except_error)
              #else
              __pyx_t_7 = PySequence_ITEM(__pyx_t_9, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2569, __pyx_L7_except_error)
              __Pyx_GOTREF(__pyx_t_7);
              #endif
            } else {
              if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_13); __Pyx_INCREF(__pyx_t_7); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 2569, __pyx_L7_except_error)
              #else
              __pyx_t_7 = PySequence_ITEM(__pyx_t_9, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2569, __pyx_L7_except_error)
              __Pyx_GOTREF(__pyx_t_7);
              #endif
            }
          } else {
            __pyx_t_7 = __pyx_t_14(__pyx_t_9);
            if (unlikely(!__pyx_t_7)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 2569, __pyx_L7_except_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_7);
          }
          __Pyx_XDECREF_SET(__pyx_v_id, __pyx_t_7);
          __pyx_t_7 = 0;

          /* "btdht/dht.pyx":2570
 *             if b.id_length < 160:
 *                 for id in self._split_ids | self._info_hash:
 *                     if b.own(id):             # <<<<<<<<<<<<<<
 *                         self.split(dht, b)
 *                         self.add(dht, node)
 */
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_own); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2570, __pyx_L7_except_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_15 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_1);
            if (likely(__pyx_t_15)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
              __Pyx_INCREF(__pyx_t_15);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_1, function);
            }
          }
          __pyx_t_7 = (__pyx_t_15) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_15, __pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_id);
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2570, __pyx_L7_except_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 2570, __pyx_L7_except_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (__pyx_t_4) {

            /* "btdht/dht.pyx":2571
 *                 for id in self._split_ids | self._info_hash:
 *                     if b.own(id):
 *                         self.split(dht, b)             # <<<<<<<<<<<<<<
 *                         self.add(dht, node)
 *                         return
 */
            __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_split); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2571, __pyx_L7_except_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_15 = NULL;
            __pyx_t_8 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
              __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_1);
              if (likely(__pyx_t_15)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
                __Pyx_INCREF(__pyx_t_15);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_1, function);
                __pyx_t_8 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_v_dht, __pyx_v_b};
              __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2571, __pyx_L7_except_error)
              __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
              __Pyx_GOTREF(__pyx_t_7);
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_v_dht, __pyx_v_b};
              __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2571, __pyx_L7_except_error)
              __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
              __Pyx_GOTREF(__pyx_t_7);
            } else
            #endif
            {
              __pyx_t_16 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 2571, __pyx_L7_except_error)
              __Pyx_GOTREF(__pyx_t_16);
              if (__pyx_t_15) {
                __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_15); __pyx_t_15 = NULL;
              }
              __Pyx_INCREF(__pyx_v_dht);
              __Pyx_GIVEREF(__pyx_v_dht);
              PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_8, __pyx_v_dht);
              __Pyx_INCREF(__pyx_v_b);
              __Pyx_GIVEREF(__pyx_v_b);
              PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_8, __pyx_v_b);
              __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_16, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2571, __pyx_L7_except_error)
              __Pyx_GOTREF(__pyx_t_7);
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
            }
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

            /* "btdht/dht.pyx":2572
 *                     if b.own(id):
 *                         self.split(dht, b)
 *                         self.add(dht, node)             # <<<<<<<<<<<<<<
 *                         return
 *             else:
 */
            __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_add); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2572, __pyx_L7_except_error)
            __Pyx_GOTREF(__pyx_t_1);
            __pyx_t_16 = NULL;
            __pyx_t_8 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
              __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_1);
              if (likely(__pyx_t_16)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
                __Pyx_INCREF(__pyx_t_16);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_1, function);
                __pyx_t_8 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_v_dht, __pyx_v_node};
              __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2572, __pyx_L7_except_error)
              __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
              __Pyx_GOTREF(__pyx_t_7);
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_v_dht, __pyx_v_node};
              __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2572, __pyx_L7_except_error)
              __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
              __Pyx_GOTREF(__pyx_t_7);
            } else
            #endif
            {
              __pyx_t_15 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2572, __pyx_L7_except_error)
              __Pyx_GOTREF(__pyx_t_15);
              if (__pyx_t_16) {
                __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_16); __pyx_t_16 = NULL;
              }
              __Pyx_INCREF(__pyx_v_dht);
              __Pyx_GIVEREF(__pyx_v_dht);
              PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_8, __pyx_v_dht);
              __Pyx_INCREF(__pyx_v_node);
              __Pyx_GIVEREF(__pyx_v_node);
              PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_8, __pyx_v_node);
              __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_15, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2572, __pyx_L7_except_error)
              __Pyx_GOTREF(__pyx_t_7);
              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
            }
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

            /* "btdht/dht.pyx":2573
 *                         self.split(dht, b)
 *                         self.add(dht, node)
 *                         return             # <<<<<<<<<<<<<<
 *             else:
 *                 print("%r" % b)
 */
            __Pyx_XDECREF(__pyx_r);
            __pyx_r = Py_None; __Pyx_INCREF(Py_None);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            goto __pyx_L8_except_return;

            /* "btdht/dht.pyx":2570
 *             if b.id_length < 160:
 *                 for id in self._split_ids | self._info_hash:
 *                     if b.own(id):             # <<<<<<<<<<<<<<
 *                         self.split(dht, b)
 *                         self.add(dht, node)
 */
          }

          /* "btdht/dht.pyx":2569
 *             # If bucket is full, try to split
 *             if b.id_length < 160:
 *                 for id in self._split_ids | self._info_hash:             # <<<<<<<<<<<<<<
 *                     if b.own(id):
 *                         self.split(dht, b)
 */
        }
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "btdht/dht.pyx":2568
 *         except BucketFull:
 *             # If bucket is full, try to split
 *             if b.id_length < 160:             # <<<<<<<<<<<<<<
 *                 for id in self._split_ids | self._info_hash:
 *                     if b.own(id):
 */
        goto __pyx_L13;
      }

      /* "btdht/dht.pyx":2575
 *                         return
 *             else:
 *                 print("%r" % b)             # <<<<<<<<<<<<<<
 * 
 *     def heigth(self):
 */
      /*else*/ {
        __pyx_t_9 = __Pyx_PyString_FormatSafe(__pyx_kp_s_r_2, __pyx_v_b); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2575, __pyx_L7_except_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (__Pyx_PrintOne(0, __pyx_t_9) < 0) __PYX_ERR(0, 2575, __pyx_L7_except_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __pyx_L13:;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      goto __pyx_L6_exception_handled;
    }
    goto __pyx_L7_except_error;
    __pyx_L7_except_error:;

    /* "btdht/dht.pyx":2564
 *             return
 *         b = self.find(node.id)
 *         try:             # <<<<<<<<<<<<<<
 *             b.add(dht, node)
 *         except BucketFull:
 */
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_XGIVEREF(__pyx_t_11);
    __Pyx_XGIVEREF(__pyx_t_12);
    __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
    goto __pyx_L1_error;
    __pyx_L8_except_return:;
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_XGIVEREF(__pyx_t_11);
    __Pyx_XGIVEREF(__pyx_t_12);
    __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
    goto __pyx_L0;
    __pyx_L6_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_10);
    __Pyx_XGIVEREF(__pyx_t_11);
    __Pyx_XGIVEREF(__pyx_t_12);
    __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
    __pyx_L10_try_end:;
  }

  /* "btdht/dht.pyx":2552
 *             return self.get_closest_nodes(id, bad=bad, errno=errno+1)
 * 
 *     def add(self, dht, node):             # <<<<<<<<<<<<<<
 *         """
 *             Add a node the the routing table
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.add", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_b);
  __Pyx_XDECREF(__pyx_v_id);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2577
 *                 print("%r" % b)
 * 
 *     def heigth(self):             # <<<<<<<<<<<<<<
 *         """
 *             :return: the height of the tree of the routing table
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_47heigth(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_46heigth[] = "\n            :return: the height of the tree of the routing table\n            :rtype: int\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_47heigth = {"heigth", (PyCFunction)__pyx_pw_5btdht_3dht_12RoutingTable_47heigth, METH_O, __pyx_doc_5btdht_3dht_12RoutingTable_46heigth};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_47heigth(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("heigth (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_46heigth(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_46heigth(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("heigth", 0);

  /* "btdht/dht.pyx":2582
 *             :rtype: int
 *         """
 *         return self._heigth             # <<<<<<<<<<<<<<
 * 
 *     def split(self, dht, bucket):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_heigth_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2582, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "btdht/dht.pyx":2577
 *                 print("%r" % b)
 * 
 *     def heigth(self):             # <<<<<<<<<<<<<<
 *         """
 *             :return: the height of the tree of the routing table
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.heigth", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2584
 *         return self._heigth
 * 
 *     def split(self, dht, bucket):             # <<<<<<<<<<<<<<
 *         """
 *             Split ``bucket`` in two
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_49split(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_48split[] = "\n            Split ``bucket`` in two\n\n            :param DHT_BASE dht: A dht instance\n            :param Bucket bucket: A bucket from the routing table to split\n\n            Notes:\n                the routing table cover the entire 160bits space\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_49split = {"split", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_49split, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_12RoutingTable_48split};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_49split(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_dht = 0;
  PyObject *__pyx_v_bucket = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("split (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_dht,&__pyx_n_s_bucket,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dht)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("split", 1, 3, 3, 1); __PYX_ERR(0, 2584, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bucket)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("split", 1, 3, 3, 2); __PYX_ERR(0, 2584, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "split") < 0)) __PYX_ERR(0, 2584, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_self = values[0];
    __pyx_v_dht = values[1];
    __pyx_v_bucket = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("split", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2584, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.split", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_48split(__pyx_self, __pyx_v_self, __pyx_v_dht, __pyx_v_bucket);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_48split(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_dht, PyObject *__pyx_v_bucket) {
  PyObject *__pyx_v_prefix = NULL;
  PyObject *__pyx_v_zero_b = NULL;
  PyObject *__pyx_v_one_b = NULL;
  PyObject *__pyx_v_e = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *(*__pyx_t_9)(PyObject *);
  Py_ssize_t __pyx_t_10;
  Py_ssize_t __pyx_t_11;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("split", 0);

  /* "btdht/dht.pyx":2594
 *                 the routing table cover the entire 160bits space
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             prefix = utils.id_to_longid(bucket.id)[:bucket.id_length]
 *             (zero_b, one_b) = self.trie[prefix].split(self, dht)
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "btdht/dht.pyx":2595
 *         """
 *         try:
 *             prefix = utils.id_to_longid(bucket.id)[:bucket.id_length]             # <<<<<<<<<<<<<<
 *             (zero_b, one_b) = self.trie[prefix].split(self, dht)
 *             (zero_b, one_b) = self.trie[prefix].split(self, dht)
 */
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_utils); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2595, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_id_to_longid); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2595, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_bucket, __pyx_n_s_id); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2595, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      __pyx_t_4 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_7, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5);
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2595, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_bucket, __pyx_n_s_id_length); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2595, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = __Pyx_PyObject_GetSlice(__pyx_t_4, 0, 0, NULL, &__pyx_t_6, NULL, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2595, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_prefix = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "btdht/dht.pyx":2596
 *         try:
 *             prefix = utils.id_to_longid(bucket.id)[:bucket.id_length]
 *             (zero_b, one_b) = self.trie[prefix].split(self, dht)             # <<<<<<<<<<<<<<
 *             (zero_b, one_b) = self.trie[prefix].split(self, dht)
 *             self.trie[prefix + u"1"] = one_b
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2596, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_t_6, __pyx_v_prefix); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2596, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_split); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2596, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = NULL;
      __pyx_t_8 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
          __pyx_t_8 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_self, __pyx_v_dht};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2596, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_self, __pyx_v_dht};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2596, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      {
        __pyx_t_7 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2596, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        if (__pyx_t_4) {
          __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL;
        }
        __Pyx_INCREF(__pyx_v_self);
        __Pyx_GIVEREF(__pyx_v_self);
        PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_8, __pyx_v_self);
        __Pyx_INCREF(__pyx_v_dht);
        __Pyx_GIVEREF(__pyx_v_dht);
        PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_8, __pyx_v_dht);
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2596, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
        PyObject* sequence = __pyx_t_5;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 2596, __pyx_L3_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        #else
        __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2596, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2596, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_4 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2596, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext;
        index = 0; __pyx_t_6 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_6);
        index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_7)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_7);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_4), 2) < 0) __PYX_ERR(0, 2596, __pyx_L3_error)
        __pyx_t_9 = NULL;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        goto __pyx_L10_unpacking_done;
        __pyx_L9_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_9 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 2596, __pyx_L3_error)
        __pyx_L10_unpacking_done:;
      }
      __pyx_v_zero_b = __pyx_t_6;
      __pyx_t_6 = 0;
      __pyx_v_one_b = __pyx_t_7;
      __pyx_t_7 = 0;

      /* "btdht/dht.pyx":2597
 *             prefix = utils.id_to_longid(bucket.id)[:bucket.id_length]
 *             (zero_b, one_b) = self.trie[prefix].split(self, dht)
 *             (zero_b, one_b) = self.trie[prefix].split(self, dht)             # <<<<<<<<<<<<<<
 *             self.trie[prefix + u"1"] = one_b
 *             self.trie[prefix + u"0"] = zero_b
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2597, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_7, __pyx_v_prefix); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2597, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_split); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2597, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      __pyx_t_8 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
          __pyx_t_8 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_self, __pyx_v_dht};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2597, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_self, __pyx_v_dht};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2597, __pyx_L3_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      {
        __pyx_t_4 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2597, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        if (__pyx_t_6) {
          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL;
        }
        __Pyx_INCREF(__pyx_v_self);
        __Pyx_GIVEREF(__pyx_v_self);
        PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_8, __pyx_v_self);
        __Pyx_INCREF(__pyx_v_dht);
        __Pyx_GIVEREF(__pyx_v_dht);
        PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_8, __pyx_v_dht);
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2597, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
        PyObject* sequence = __pyx_t_5;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 2597, __pyx_L3_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_4);
        #else
        __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2597, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2597, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_6 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2597, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_9 = Py_TYPE(__pyx_t_6)->tp_iternext;
        index = 0; __pyx_t_7 = __pyx_t_9(__pyx_t_6); if (unlikely(!__pyx_t_7)) goto __pyx_L11_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_7);
        index = 1; __pyx_t_4 = __pyx_t_9(__pyx_t_6); if (unlikely(!__pyx_t_4)) goto __pyx_L11_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_4);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_6), 2) < 0) __PYX_ERR(0, 2597, __pyx_L3_error)
        __pyx_t_9 = NULL;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        goto __pyx_L12_unpacking_done;
        __pyx_L11_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_9 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 2597, __pyx_L3_error)
        __pyx_L12_unpacking_done:;
      }
      __Pyx_DECREF_SET(__pyx_v_zero_b, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_DECREF_SET(__pyx_v_one_b, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "btdht/dht.pyx":2598
 *             (zero_b, one_b) = self.trie[prefix].split(self, dht)
 *             (zero_b, one_b) = self.trie[prefix].split(self, dht)
 *             self.trie[prefix + u"1"] = one_b             # <<<<<<<<<<<<<<
 *             self.trie[prefix + u"0"] = zero_b
 *             self._heigth = max(self._heigth, len(prefix) + 2)
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2598, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = PyNumber_Add(__pyx_v_prefix, __pyx_kp_u_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2598, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (unlikely(PyObject_SetItem(__pyx_t_5, __pyx_t_4, __pyx_v_one_b) < 0)) __PYX_ERR(0, 2598, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "btdht/dht.pyx":2599
 *             (zero_b, one_b) = self.trie[prefix].split(self, dht)
 *             self.trie[prefix + u"1"] = one_b
 *             self.trie[prefix + u"0"] = zero_b             # <<<<<<<<<<<<<<
 *             self._heigth = max(self._heigth, len(prefix) + 2)
 *             del self.trie[prefix]
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2599, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = PyNumber_Add(__pyx_v_prefix, __pyx_kp_u_0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2599, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (unlikely(PyObject_SetItem(__pyx_t_4, __pyx_t_5, __pyx_v_zero_b) < 0)) __PYX_ERR(0, 2599, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "btdht/dht.pyx":2600
 *             self.trie[prefix + u"1"] = one_b
 *             self.trie[prefix + u"0"] = zero_b
 *             self._heigth = max(self._heigth, len(prefix) + 2)             # <<<<<<<<<<<<<<
 *             del self.trie[prefix]
 *         except KeyError:
 */
      __pyx_t_10 = PyObject_Length(__pyx_v_prefix); if (unlikely(__pyx_t_10 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2600, __pyx_L3_error)
      __pyx_t_11 = (__pyx_t_10 + 2);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_heigth_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2600, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2600, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = PyObject_RichCompare(__pyx_t_7, __pyx_t_5, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2600, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 2600, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_12) {
        __pyx_t_6 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2600, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_4 = __pyx_t_6;
        __pyx_t_6 = 0;
      } else {
        __Pyx_INCREF(__pyx_t_5);
        __pyx_t_4 = __pyx_t_5;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __pyx_t_4;
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_heigth_2, __pyx_t_5) < 0) __PYX_ERR(0, 2600, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "btdht/dht.pyx":2601
 *             self.trie[prefix + u"0"] = zero_b
 *             self._heigth = max(self._heigth, len(prefix) + 2)
 *             del self.trie[prefix]             # <<<<<<<<<<<<<<
 *         except KeyError:
 *             self.debug(2, "trie changed while splitting")
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2601, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (unlikely(PyObject_DelItem(__pyx_t_5, __pyx_v_prefix) < 0)) __PYX_ERR(0, 2601, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "btdht/dht.pyx":2594
 *                 the routing table cover the entire 160bits space
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             prefix = utils.id_to_longid(bucket.id)[:bucket.id_length]
 *             (zero_b, one_b) = self.trie[prefix].split(self, dht)
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "btdht/dht.pyx":2602
 *             self._heigth = max(self._heigth, len(prefix) + 2)
 *             del self.trie[prefix]
 *         except KeyError:             # <<<<<<<<<<<<<<
 *             self.debug(2, "trie changed while splitting")
 *         except BucketNotFull as e:
 */
    __pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
    if (__pyx_t_8) {
      __Pyx_AddTraceback("btdht.dht.RoutingTable.split", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_4, &__pyx_t_6) < 0) __PYX_ERR(0, 2602, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_t_6);

      /* "btdht/dht.pyx":2603
 *             del self.trie[prefix]
 *         except KeyError:
 *             self.debug(2, "trie changed while splitting")             # <<<<<<<<<<<<<<
 *         except BucketNotFull as e:
 *             self.debug(1, "%r" % e)
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2603, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2603, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L4_exception_handled;
    }

    /* "btdht/dht.pyx":2604
 *         except KeyError:
 *             self.debug(2, "trie changed while splitting")
 *         except BucketNotFull as e:             # <<<<<<<<<<<<<<
 *             self.debug(1, "%r" % e)
 * 
 */
    __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_4, &__pyx_t_5);
    __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_BucketNotFull); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2604, __pyx_L5_except_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_8 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_6, __pyx_t_13);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_ErrRestore(__pyx_t_6, __pyx_t_4, __pyx_t_5);
    __pyx_t_6 = 0; __pyx_t_4 = 0; __pyx_t_5 = 0;
    if (__pyx_t_8) {
      __Pyx_AddTraceback("btdht.dht.RoutingTable.split", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_4, &__pyx_t_6) < 0) __PYX_ERR(0, 2604, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_4);
      __pyx_v_e = __pyx_t_4;

      /* "btdht/dht.pyx":2605
 *             self.debug(2, "trie changed while splitting")
 *         except BucketNotFull as e:
 *             self.debug(1, "%r" % e)             # <<<<<<<<<<<<<<
 * 
 *     def merge(self):
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2605, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_14 = __Pyx_PyString_FormatSafe(__pyx_kp_s_r_2, __pyx_v_e); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 2605, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_15 = NULL;
      __pyx_t_8 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_15)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_15);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
          __pyx_t_8 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_int_1, __pyx_t_14};
        __pyx_t_13 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2605, __pyx_L5_except_error)
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_int_1, __pyx_t_14};
        __pyx_t_13 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2605, __pyx_L5_except_error)
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      } else
      #endif
      {
        __pyx_t_16 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 2605, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_16);
        if (__pyx_t_15) {
          __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_15); __pyx_t_15 = NULL;
        }
        __Pyx_INCREF(__pyx_int_1);
        __Pyx_GIVEREF(__pyx_int_1);
        PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_8, __pyx_int_1);
        __Pyx_GIVEREF(__pyx_t_14);
        PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_8, __pyx_t_14);
        __pyx_t_14 = 0;
        __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_16, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 2605, __pyx_L5_except_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "btdht/dht.pyx":2594
 *                 the routing table cover the entire 160bits space
 *         """
 *         try:             # <<<<<<<<<<<<<<
 *             prefix = utils.id_to_longid(bucket.id)[:bucket.id_length]
 *             (zero_b, one_b) = self.trie[prefix].split(self, dht)
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L4_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    __pyx_L8_try_end:;
  }

  /* "btdht/dht.pyx":2584
 *         return self._heigth
 * 
 *     def split(self, dht, bucket):             # <<<<<<<<<<<<<<
 *         """
 *             Split ``bucket`` in two
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("btdht.dht.RoutingTable.split", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_prefix);
  __Pyx_XDECREF(__pyx_v_zero_b);
  __Pyx_XDECREF(__pyx_v_one_b);
  __Pyx_XDECREF(__pyx_v_e);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2607
 *             self.debug(1, "%r" % e)
 * 
 *     def merge(self):             # <<<<<<<<<<<<<<
 *         """Request a merge to be perform"""
 *         self.need_merge = True
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_51merge(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_50merge[] = "Request a merge to be perform";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_51merge = {"merge", (PyCFunction)__pyx_pw_5btdht_3dht_12RoutingTable_51merge, METH_O, __pyx_doc_5btdht_3dht_12RoutingTable_50merge};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_51merge(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("merge (wrapper)", 0);
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_50merge(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_50merge(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("merge", 0);

  /* "btdht/dht.pyx":2609
 *     def merge(self):
 *         """Request a merge to be perform"""
 *         self.need_merge = True             # <<<<<<<<<<<<<<
 * 
 *     def _merge(self, stack=None):
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_need_merge, Py_True) < 0) __PYX_ERR(0, 2609, __pyx_L1_error)

  /* "btdht/dht.pyx":2607
 *             self.debug(1, "%r" % e)
 * 
 *     def merge(self):             # <<<<<<<<<<<<<<
 *         """Request a merge to be perform"""
 *         self.need_merge = True
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable.merge", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_54generator5(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "btdht/dht.pyx":2611
 *         self.need_merge = True
 * 
 *     def _merge(self, stack=None):             # <<<<<<<<<<<<<<
 *         """
 *             Perform a merge of the routing table. If ``stack`` is provided, only a partial merge
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_53_merge(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5btdht_3dht_12RoutingTable_52_merge[] = "\n            Perform a merge of the routing table. If ``stack`` is provided, only a partial merge\n            on buckets identified by ``stack`` is perform. Otherwise, a full merge of the\n            routing table is done.\n\n            :param list stack: An optional list of keys of :attr:`trie` to merge.\n        ";
static PyMethodDef __pyx_mdef_5btdht_3dht_12RoutingTable_53_merge = {"_merge", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_12RoutingTable_53_merge, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_12RoutingTable_52_merge};
static PyObject *__pyx_pw_5btdht_3dht_12RoutingTable_53_merge(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_stack = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_merge (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_stack,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)((PyObject *)Py_None));
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stack);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_merge") < 0)) __PYX_ERR(0, 2611, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_self = values[0];
    __pyx_v_stack = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_merge", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 2611, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable._merge", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_12RoutingTable_52_merge(__pyx_self, __pyx_v_self, __pyx_v_stack);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_6_merge_2generator10(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */

/* "btdht/dht.pyx":2677
 * 
 *         if full_merge:
 *             self._heigth = max(len(k) for k in self.trie.keys()) + 1             # <<<<<<<<<<<<<<
 *             self.debug(
 *                 1,
 */

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_6_merge_genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct_13_genexpr(__pyx_ptype_5btdht_3dht___pyx_scope_struct_13_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2677, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge *) __pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5btdht_3dht_12RoutingTable_6_merge_2generator10, NULL, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_RoutingTable__merge_locals_genex, __pyx_n_s_btdht_dht); if (unlikely(!gen)) __PYX_ERR(0, 2677, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable._merge.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_6_merge_2generator10(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("genexpr", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L6_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2677, __pyx_L1_error)
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); __PYX_ERR(0, 2677, __pyx_L1_error) }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_keys); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2677, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2677, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2677, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2677, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2677, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 2677, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2677, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_5(__pyx_t_3);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 2677, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_k);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_k, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_6 = PyObject_Length(__pyx_cur_scope->__pyx_v_k); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2677, __pyx_L1_error)
    __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2677, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    __Pyx_XGIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_3;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_4;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_5;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L6_resume_from_yield:;
    __pyx_t_3 = __pyx_cur_scope->__pyx_t_0;
    __pyx_cur_scope->__pyx_t_0 = 0;
    __Pyx_XGOTREF(__pyx_t_3);
    __pyx_t_4 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_5 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2677, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "btdht/dht.pyx":2611
 *         self.need_merge = True
 * 
 *     def _merge(self, stack=None):             # <<<<<<<<<<<<<<
 *         """
 *             Perform a merge of the routing table. If ``stack`` is provided, only a partial merge
 */

static PyObject *__pyx_pf_5btdht_3dht_12RoutingTable_52_merge(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_stack) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge *__pyx_cur_scope;
  PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_6_merge_2generator10 = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_merge", 0);
  __pyx_cur_scope = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge *)__pyx_tp_new_5btdht_3dht___pyx_scope_struct_12__merge(__pyx_ptype_5btdht_3dht___pyx_scope_struct_12__merge, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge *)Py_None);
    __Pyx_INCREF(Py_None);
    __PYX_ERR(0, 2611, __pyx_L1_error)
  } else {
    __Pyx_GOTREF(__pyx_cur_scope);
  }
  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self);
  __pyx_cur_scope->__pyx_v_stack = __pyx_v_stack;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_stack);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_stack);
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5btdht_3dht_12RoutingTable_54generator5, __pyx_codeobj__37, (PyObject *) __pyx_cur_scope, __pyx_n_s_merge, __pyx_n_s_RoutingTable__merge, __pyx_n_s_btdht_dht); if (unlikely(!gen)) __PYX_ERR(0, 2611, __pyx_L1_error)
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("btdht.dht.RoutingTable._merge", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XDECREF(__pyx_gb_5btdht_3dht_12RoutingTable_6_merge_2generator10);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5btdht_3dht_12RoutingTable_54generator5(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge *__pyx_cur_scope = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  int __pyx_t_13;
  int __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_merge", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L15_resume_from_yield;
    case 2: goto __pyx_L30_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2611, __pyx_L1_error)

  /* "btdht/dht.pyx":2619
 *             :param list stack: An optional list of keys of :attr:`trie` to merge.
 *         """
 *         if stack is None:             # <<<<<<<<<<<<<<
 *             stack = self.trie.keys()
 *             full_merge = True
 */
  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_stack == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "btdht/dht.pyx":2620
 *         """
 *         if stack is None:
 *             stack = self.trie.keys()             # <<<<<<<<<<<<<<
 *             full_merge = True
 *         else:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2620, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_keys); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2620, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2620, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_stack);
    __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_stack, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":2621
 *         if stack is None:
 *             stack = self.trie.keys()
 *             full_merge = True             # <<<<<<<<<<<<<<
 *         else:
 *             full_merge = False
 */
    __pyx_cur_scope->__pyx_v_full_merge = 1;

    /* "btdht/dht.pyx":2619
 *             :param list stack: An optional list of keys of :attr:`trie` to merge.
 *         """
 *         if stack is None:             # <<<<<<<<<<<<<<
 *             stack = self.trie.keys()
 *             full_merge = True
 */
    goto __pyx_L4;
  }

  /* "btdht/dht.pyx":2623
 *             full_merge = True
 *         else:
 *             full_merge = False             # <<<<<<<<<<<<<<
 *         if full_merge:
 *             nodes_before = self.stats()[0]
 */
  /*else*/ {
    __pyx_cur_scope->__pyx_v_full_merge = 0;
  }
  __pyx_L4:;

  /* "btdht/dht.pyx":2624
 *         else:
 *             full_merge = False
 *         if full_merge:             # <<<<<<<<<<<<<<
 *             nodes_before = self.stats()[0]
 *             if nodes_before < 1000:
 */
  __pyx_t_2 = (__pyx_cur_scope->__pyx_v_full_merge != 0);
  if (__pyx_t_2) {

    /* "btdht/dht.pyx":2625
 *             full_merge = False
 *         if full_merge:
 *             nodes_before = self.stats()[0]             # <<<<<<<<<<<<<<
 *             if nodes_before < 1000:
 *                 self.debug(1, "Less than 1000 nodes, no merge")
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_stats); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2625, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2625, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2625, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_cur_scope->__pyx_v_nodes_before = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "btdht/dht.pyx":2626
 *         if full_merge:
 *             nodes_before = self.stats()[0]
 *             if nodes_before < 1000:             # <<<<<<<<<<<<<<
 *                 self.debug(1, "Less than 1000 nodes, no merge")
 *                 return
 */
    __pyx_t_5 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_nodes_before, __pyx_int_1000, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2626, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2626, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_2) {

      /* "btdht/dht.pyx":2627
 *             nodes_before = self.stats()[0]
 *             if nodes_before < 1000:
 *                 self.debug(1, "Less than 1000 nodes, no merge")             # <<<<<<<<<<<<<<
 *                 return
 *             started = time.time()
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2627, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2627, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "btdht/dht.pyx":2628
 *             if nodes_before < 1000:
 *                 self.debug(1, "Less than 1000 nodes, no merge")
 *                 return             # <<<<<<<<<<<<<<
 *             started = time.time()
 *         i = 0
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_r = NULL;
      goto __pyx_L0;

      /* "btdht/dht.pyx":2626
 *         if full_merge:
 *             nodes_before = self.stats()[0]
 *             if nodes_before < 1000:             # <<<<<<<<<<<<<<
 *                 self.debug(1, "Less than 1000 nodes, no merge")
 *                 return
 */
    }

    /* "btdht/dht.pyx":2629
 *                 self.debug(1, "Less than 1000 nodes, no merge")
 *                 return
 *             started = time.time()             # <<<<<<<<<<<<<<
 *         i = 0
 *         j = 0
 */
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2629, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2629, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2629, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_v_started = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":2624
 *         else:
 *             full_merge = False
 *         if full_merge:             # <<<<<<<<<<<<<<
 *             nodes_before = self.stats()[0]
 *             if nodes_before < 1000:
 */
  }

  /* "btdht/dht.pyx":2630
 *                 return
 *             started = time.time()
 *         i = 0             # <<<<<<<<<<<<<<
 *         j = 0
 *         while stack:
 */
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __pyx_cur_scope->__pyx_v_i = __pyx_int_0;

  /* "btdht/dht.pyx":2631
 *             started = time.time()
 *         i = 0
 *         j = 0             # <<<<<<<<<<<<<<
 *         while stack:
 *             if self.stoped:
 */
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __pyx_cur_scope->__pyx_v_j = __pyx_int_0;

  /* "btdht/dht.pyx":2632
 *         i = 0
 *         j = 0
 *         while stack:             # <<<<<<<<<<<<<<
 *             if self.stoped:
 *                 return
 */
  while (1) {
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_stack); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2632, __pyx_L1_error)
    if (!__pyx_t_2) break;

    /* "btdht/dht.pyx":2633
 *         j = 0
 *         while stack:
 *             if self.stoped:             # <<<<<<<<<<<<<<
 *                 return
 *             key = stack.pop()
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_stoped); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2633, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_2) {

      /* "btdht/dht.pyx":2634
 *         while stack:
 *             if self.stoped:
 *                 return             # <<<<<<<<<<<<<<
 *             key = stack.pop()
 *             if not key:
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_r = NULL;
      goto __pyx_L0;

      /* "btdht/dht.pyx":2633
 *         j = 0
 *         while stack:
 *             if self.stoped:             # <<<<<<<<<<<<<<
 *                 return
 *             key = stack.pop()
 */
    }

    /* "btdht/dht.pyx":2635
 *             if self.stoped:
 *                 return
 *             key = stack.pop()             # <<<<<<<<<<<<<<
 *             if not key:
 *                 continue
 */
    __pyx_t_3 = __Pyx_PyObject_Pop(__pyx_cur_scope->__pyx_v_stack); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2635, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_key, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":2636
 *                 return
 *             key = stack.pop()
 *             if not key:             # <<<<<<<<<<<<<<
 *                 continue
 *             to_merge =  True
 */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_key); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2636, __pyx_L1_error)
    __pyx_t_1 = ((!__pyx_t_2) != 0);
    if (__pyx_t_1) {

      /* "btdht/dht.pyx":2637
 *             key = stack.pop()
 *             if not key:
 *                 continue             # <<<<<<<<<<<<<<
 *             to_merge =  True
 *             for id in self._split_ids | self._info_hash:
 */
      goto __pyx_L7_continue;

      /* "btdht/dht.pyx":2636
 *                 return
 *             key = stack.pop()
 *             if not key:             # <<<<<<<<<<<<<<
 *                 continue
 *             to_merge =  True
 */
    }

    /* "btdht/dht.pyx":2638
 *             if not key:
 *                 continue
 *             to_merge =  True             # <<<<<<<<<<<<<<
 *             for id in self._split_ids | self._info_hash:
 *                 if utils.id_to_longid(id).startswith(key[:-1]):
 */
    __pyx_cur_scope->__pyx_v_to_merge = 1;

    /* "btdht/dht.pyx":2639
 *                 continue
 *             to_merge =  True
 *             for id in self._split_ids | self._info_hash:             # <<<<<<<<<<<<<<
 *                 if utils.id_to_longid(id).startswith(key[:-1]):
 *                     to_merge = False
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_split_ids); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_info_hash_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyNumber_Or(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2639, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) {
      __pyx_t_4 = __pyx_t_5; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = 0;
      __pyx_t_7 = NULL;
    } else {
      __pyx_t_6 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2639, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2639, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    for (;;) {
      if (likely(!__pyx_t_7)) {
        if (likely(PyList_CheckExact(__pyx_t_4))) {
          if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 2639, __pyx_L1_error)
          #else
          __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2639, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          #endif
        } else {
          if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 2639, __pyx_L1_error)
          #else
          __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2639, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          #endif
        }
      } else {
        __pyx_t_5 = __pyx_t_7(__pyx_t_4);
        if (unlikely(!__pyx_t_5)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 2639, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_5);
      }
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_id);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_id, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_5 = 0;

      /* "btdht/dht.pyx":2640
 *             to_merge =  True
 *             for id in self._split_ids | self._info_hash:
 *                 if utils.id_to_longid(id).startswith(key[:-1]):             # <<<<<<<<<<<<<<
 *                     to_merge = False
 *                     break
 */
      __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_utils); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2640, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_id_to_longid); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2640, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
        }
      }
      __pyx_t_3 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_cur_scope->__pyx_v_id) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_cur_scope->__pyx_v_id);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2640, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_startswith); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2640, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_cur_scope->__pyx_v_key, 0, -1L, NULL, NULL, &__pyx_slice__35, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2640, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
        }
      }
      __pyx_t_5 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_3);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2640, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2640, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_1) {

        /* "btdht/dht.pyx":2641
 *             for id in self._split_ids | self._info_hash:
 *                 if utils.id_to_longid(id).startswith(key[:-1]):
 *                     to_merge = False             # <<<<<<<<<<<<<<
 *                     break
 *             j += 1
 */
        __pyx_cur_scope->__pyx_v_to_merge = 0;

        /* "btdht/dht.pyx":2642
 *                 if utils.id_to_longid(id).startswith(key[:-1]):
 *                     to_merge = False
 *                     break             # <<<<<<<<<<<<<<
 *             j += 1
 *             # give back control to the scheduler every 100,000 keys
 */
        goto __pyx_L12_break;

        /* "btdht/dht.pyx":2640
 *             to_merge =  True
 *             for id in self._split_ids | self._info_hash:
 *                 if utils.id_to_longid(id).startswith(key[:-1]):             # <<<<<<<<<<<<<<
 *                     to_merge = False
 *                     break
 */
      }

      /* "btdht/dht.pyx":2639
 *                 continue
 *             to_merge =  True
 *             for id in self._split_ids | self._info_hash:             # <<<<<<<<<<<<<<
 *                 if utils.id_to_longid(id).startswith(key[:-1]):
 *                     to_merge = False
 */
    }
    __pyx_L12_break:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "btdht/dht.pyx":2643
 *                     to_merge = False
 *                     break
 *             j += 1             # <<<<<<<<<<<<<<
 *             # give back control to the scheduler every 100,000 keys
 *             if j >= 100000:
 */
    __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_cur_scope->__pyx_v_j, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2643, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_j);
    __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_j, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;

    /* "btdht/dht.pyx":2645
 *             j += 1
 *             # give back control to the scheduler every 100,000 keys
 *             if j >= 100000:             # <<<<<<<<<<<<<<
 *                 yield 0
 *             if to_merge:
 */
    __pyx_t_4 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_j, __pyx_int_100000, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2645, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2645, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_1) {

      /* "btdht/dht.pyx":2646
 *             # give back control to the scheduler every 100,000 keys
 *             if j >= 100000:
 *                 yield 0             # <<<<<<<<<<<<<<
 *             if to_merge:
 *                 try:
 */
      __Pyx_INCREF(__pyx_int_0);
      __pyx_r = __pyx_int_0;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
      /* return from generator, yielding value */
      __pyx_generator->resume_label = 1;
      return __pyx_r;
      __pyx_L15_resume_from_yield:;
      if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2646, __pyx_L1_error)

      /* "btdht/dht.pyx":2645
 *             j += 1
 *             # give back control to the scheduler every 100,000 keys
 *             if j >= 100000:             # <<<<<<<<<<<<<<
 *                 yield 0
 *             if to_merge:
 */
    }

    /* "btdht/dht.pyx":2647
 *             if j >= 100000:
 *                 yield 0
 *             if to_merge:             # <<<<<<<<<<<<<<
 *                 try:
 *                     if key not in self.trie:
 */
    __pyx_t_1 = (__pyx_cur_scope->__pyx_v_to_merge != 0);
    if (__pyx_t_1) {

      /* "btdht/dht.pyx":2648
 *                 yield 0
 *             if to_merge:
 *                 try:             # <<<<<<<<<<<<<<
 *                     if key not in self.trie:
 *                         self.debug(2, "%s gone away while merging" % key)
 */
      {
        __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
        __Pyx_XGOTREF(__pyx_t_10);
        __Pyx_XGOTREF(__pyx_t_11);
        __Pyx_XGOTREF(__pyx_t_12);
        /*try:*/ {

          /* "btdht/dht.pyx":2649
 *             if to_merge:
 *                 try:
 *                     if key not in self.trie:             # <<<<<<<<<<<<<<
 *                         self.debug(2, "%s gone away while merging" % key)
 *                         continue
 */
          __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2649, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_cur_scope->__pyx_v_key, __pyx_t_4, Py_NE)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2649, __pyx_L17_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_t_2 = (__pyx_t_1 != 0);
          if (__pyx_t_2) {

            /* "btdht/dht.pyx":2650
 *                 try:
 *                     if key not in self.trie:
 *                         self.debug(2, "%s gone away while merging" % key)             # <<<<<<<<<<<<<<
 *                         continue
 *                     prefix0 = key
 */
            __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2650, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_9 = __Pyx_PyString_FormatSafe(__pyx_kp_s_s_gone_away_while_merging, __pyx_cur_scope->__pyx_v_key); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2650, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_3 = NULL;
            __pyx_t_13 = 0;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
              if (likely(__pyx_t_3)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
                __Pyx_INCREF(__pyx_t_3);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_5, function);
                __pyx_t_13 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_5)) {
              PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_2, __pyx_t_9};
              __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2650, __pyx_L17_error)
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_GOTREF(__pyx_t_4);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
              PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_int_2, __pyx_t_9};
              __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2650, __pyx_L17_error)
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_GOTREF(__pyx_t_4);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            } else
            #endif
            {
              __pyx_t_8 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2650, __pyx_L17_error)
              __Pyx_GOTREF(__pyx_t_8);
              if (__pyx_t_3) {
                __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3); __pyx_t_3 = NULL;
              }
              __Pyx_INCREF(__pyx_int_2);
              __Pyx_GIVEREF(__pyx_int_2);
              PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_13, __pyx_int_2);
              __Pyx_GIVEREF(__pyx_t_9);
              PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_13, __pyx_t_9);
              __pyx_t_9 = 0;
              __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2650, __pyx_L17_error)
              __Pyx_GOTREF(__pyx_t_4);
              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            }
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

            /* "btdht/dht.pyx":2651
 *                     if key not in self.trie:
 *                         self.debug(2, "%s gone away while merging" % key)
 *                         continue             # <<<<<<<<<<<<<<
 *                     prefix0 = key
 *                     prefix1 = key[:-1] + six.text_type(int(key[-1]) ^ 1)
 */
            goto __pyx_L23_try_continue;

            /* "btdht/dht.pyx":2649
 *             if to_merge:
 *                 try:
 *                     if key not in self.trie:             # <<<<<<<<<<<<<<
 *                         self.debug(2, "%s gone away while merging" % key)
 *                         continue
 */
          }

          /* "btdht/dht.pyx":2652
 *                         self.debug(2, "%s gone away while merging" % key)
 *                         continue
 *                     prefix0 = key             # <<<<<<<<<<<<<<
 *                     prefix1 = key[:-1] + six.text_type(int(key[-1]) ^ 1)
 *                     bucket0 = self.trie[prefix0]
 */
          __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key);
          __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_prefix0);
          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_prefix0, __pyx_cur_scope->__pyx_v_key);
          __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key);

          /* "btdht/dht.pyx":2653
 *                         continue
 *                     prefix0 = key
 *                     prefix1 = key[:-1] + six.text_type(int(key[-1]) ^ 1)             # <<<<<<<<<<<<<<
 *                     bucket0 = self.trie[prefix0]
 *                     if prefix1 in self.trie:
 */
          __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_cur_scope->__pyx_v_key, 0, -1L, NULL, NULL, &__pyx_slice__35, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2653, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_six); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2653, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_text_type); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2653, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_key, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2653, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2653, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = __Pyx_PyInt_XorObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2653, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_3 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
            __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_9);
            if (likely(__pyx_t_3)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_9, function);
            }
          }
          __pyx_t_5 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_3, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8);
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2653, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = PyNumber_Add(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2653, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_prefix1);
          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_prefix1, __pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_9);
          __pyx_t_9 = 0;

          /* "btdht/dht.pyx":2654
 *                     prefix0 = key
 *                     prefix1 = key[:-1] + six.text_type(int(key[-1]) ^ 1)
 *                     bucket0 = self.trie[prefix0]             # <<<<<<<<<<<<<<
 *                     if prefix1 in self.trie:
 *                         bucket1 = self.trie[prefix1]
 */
          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2654, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_t_9, __pyx_cur_scope->__pyx_v_prefix0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2654, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_bucket0);
          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_bucket0, __pyx_t_5);
          __Pyx_GIVEREF(__pyx_t_5);
          __pyx_t_5 = 0;

          /* "btdht/dht.pyx":2655
 *                     prefix1 = key[:-1] + six.text_type(int(key[-1]) ^ 1)
 *                     bucket0 = self.trie[prefix0]
 *                     if prefix1 in self.trie:             # <<<<<<<<<<<<<<
 *                         bucket1 = self.trie[prefix1]
 *                         bucket = bucket0.merge(bucket1)
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2655, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_cur_scope->__pyx_v_prefix1, __pyx_t_5, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 2655, __pyx_L17_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_1 = (__pyx_t_2 != 0);
          if (__pyx_t_1) {

            /* "btdht/dht.pyx":2656
 *                     bucket0 = self.trie[prefix0]
 *                     if prefix1 in self.trie:
 *                         bucket1 = self.trie[prefix1]             # <<<<<<<<<<<<<<
 *                         bucket = bucket0.merge(bucket1)
 *                         self.trie[key[:-1]] = bucket
 */
            __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2656, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_t_5, __pyx_cur_scope->__pyx_v_prefix1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2656, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_bucket1);
            __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_bucket1, __pyx_t_9);
            __Pyx_GIVEREF(__pyx_t_9);
            __pyx_t_9 = 0;

            /* "btdht/dht.pyx":2657
 *                     if prefix1 in self.trie:
 *                         bucket1 = self.trie[prefix1]
 *                         bucket = bucket0.merge(bucket1)             # <<<<<<<<<<<<<<
 *                         self.trie[key[:-1]] = bucket
 *                         del self.trie[prefix1]
 */
            __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_bucket0, __pyx_n_s_merge_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2657, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_4 = NULL;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
              __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
              if (likely(__pyx_t_4)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
                __Pyx_INCREF(__pyx_t_4);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_5, function);
              }
            }
            __pyx_t_9 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_4, __pyx_cur_scope->__pyx_v_bucket1) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_cur_scope->__pyx_v_bucket1);
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2657, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_bucket);
            __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_bucket, __pyx_t_9);
            __Pyx_GIVEREF(__pyx_t_9);
            __pyx_t_9 = 0;

            /* "btdht/dht.pyx":2658
 *                         bucket1 = self.trie[prefix1]
 *                         bucket = bucket0.merge(bucket1)
 *                         self.trie[key[:-1]] = bucket             # <<<<<<<<<<<<<<
 *                         del self.trie[prefix1]
 *                     else:
 */
            __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2658, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_5 = __Pyx_PyObject_GetSlice(__pyx_cur_scope->__pyx_v_key, 0, -1L, NULL, NULL, &__pyx_slice__35, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2658, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_5);
            if (unlikely(PyObject_SetItem(__pyx_t_9, __pyx_t_5, __pyx_cur_scope->__pyx_v_bucket) < 0)) __PYX_ERR(0, 2658, __pyx_L17_error)
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

            /* "btdht/dht.pyx":2659
 *                         bucket = bucket0.merge(bucket1)
 *                         self.trie[key[:-1]] = bucket
 *                         del self.trie[prefix1]             # <<<<<<<<<<<<<<
 *                     else:
 *                         self.trie[key[:-1]] = Bucket(
 */
            __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2659, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_5);
            if (unlikely(PyObject_DelItem(__pyx_t_5, __pyx_cur_scope->__pyx_v_prefix1) < 0)) __PYX_ERR(0, 2659, __pyx_L17_error)
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

            /* "btdht/dht.pyx":2655
 *                     prefix1 = key[:-1] + six.text_type(int(key[-1]) ^ 1)
 *                     bucket0 = self.trie[prefix0]
 *                     if prefix1 in self.trie:             # <<<<<<<<<<<<<<
 *                         bucket1 = self.trie[prefix1]
 *                         bucket = bucket0.merge(bucket1)
 */
            goto __pyx_L26;
          }

          /* "btdht/dht.pyx":2661
 *                         del self.trie[prefix1]
 *                     else:
 *                         self.trie[key[:-1]] = Bucket(             # <<<<<<<<<<<<<<
 *                             id=bucket0.id,
 *                             id_length=len(key[:-1]),
 */
          /*else*/ {
            __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_Bucket); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2661, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_5);

            /* "btdht/dht.pyx":2662
 *                     else:
 *                         self.trie[key[:-1]] = Bucket(
 *                             id=bucket0.id,             # <<<<<<<<<<<<<<
 *                             id_length=len(key[:-1]),
 *                             init=bucket0
 */
            __pyx_t_9 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2662, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_bucket0, __pyx_n_s_id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2662, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_4);
            if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_id, __pyx_t_4) < 0) __PYX_ERR(0, 2662, __pyx_L17_error)
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

            /* "btdht/dht.pyx":2663
 *                         self.trie[key[:-1]] = Bucket(
 *                             id=bucket0.id,
 *                             id_length=len(key[:-1]),             # <<<<<<<<<<<<<<
 *                             init=bucket0
 *                         )
 */
            __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_cur_scope->__pyx_v_key, 0, -1L, NULL, NULL, &__pyx_slice__35, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2663, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_6 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2663, __pyx_L17_error)
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2663, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_4);
            if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_id_length, __pyx_t_4) < 0) __PYX_ERR(0, 2662, __pyx_L17_error)
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

            /* "btdht/dht.pyx":2664
 *                             id=bucket0.id,
 *                             id_length=len(key[:-1]),
 *                             init=bucket0             # <<<<<<<<<<<<<<
 *                         )
 *                     del self.trie[prefix0]
 */
            if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_init, __pyx_cur_scope->__pyx_v_bucket0) < 0) __PYX_ERR(0, 2662, __pyx_L17_error)

            /* "btdht/dht.pyx":2661
 *                         del self.trie[prefix1]
 *                     else:
 *                         self.trie[key[:-1]] = Bucket(             # <<<<<<<<<<<<<<
 *                             id=bucket0.id,
 *                             id_length=len(key[:-1]),
 */
            __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2661, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2661, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_5 = __Pyx_PyObject_GetSlice(__pyx_cur_scope->__pyx_v_key, 0, -1L, NULL, NULL, &__pyx_slice__35, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2661, __pyx_L17_error)
            __Pyx_GOTREF(__pyx_t_5);
            if (unlikely(PyObject_SetItem(__pyx_t_9, __pyx_t_5, __pyx_t_4) < 0)) __PYX_ERR(0, 2661, __pyx_L17_error)
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          }
          __pyx_L26:;

          /* "btdht/dht.pyx":2666
 *                             init=bucket0
 *                         )
 *                     del self.trie[prefix0]             # <<<<<<<<<<<<<<
 *                     stack.append(key[:-1])
 *                 except KeyError:
 */
          __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_trie); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2666, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_4);
          if (unlikely(PyObject_DelItem(__pyx_t_4, __pyx_cur_scope->__pyx_v_prefix0) < 0)) __PYX_ERR(0, 2666, __pyx_L17_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

          /* "btdht/dht.pyx":2667
 *                         )
 *                     del self.trie[prefix0]
 *                     stack.append(key[:-1])             # <<<<<<<<<<<<<<
 *                 except KeyError:
 *                     self.debug(0, "trie changed while merging")
 */
          __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_cur_scope->__pyx_v_key, 0, -1L, NULL, NULL, &__pyx_slice__35, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2667, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_14 = __Pyx_PyObject_Append(__pyx_cur_scope->__pyx_v_stack, __pyx_t_4); if (unlikely(__pyx_t_14 == ((int)-1))) __PYX_ERR(0, 2667, __pyx_L17_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

          /* "btdht/dht.pyx":2648
 *                 yield 0
 *             if to_merge:
 *                 try:             # <<<<<<<<<<<<<<
 *                     if key not in self.trie:
 *                         self.debug(2, "%s gone away while merging" % key)
 */
        }
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        goto __pyx_L24_try_end;
        __pyx_L17_error:;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "btdht/dht.pyx":2668
 *                     del self.trie[prefix0]
 *                     stack.append(key[:-1])
 *                 except KeyError:             # <<<<<<<<<<<<<<
 *                     self.debug(0, "trie changed while merging")
 * 
 */
        __pyx_t_13 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
        if (__pyx_t_13) {
          __Pyx_AddTraceback("btdht.dht.RoutingTable._merge", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_5, &__pyx_t_9) < 0) __PYX_ERR(0, 2668, __pyx_L19_except_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_GOTREF(__pyx_t_9);

          /* "btdht/dht.pyx":2669
 *                     stack.append(key[:-1])
 *                 except KeyError:
 *                     self.debug(0, "trie changed while merging")             # <<<<<<<<<<<<<<
 * 
 *                 i += 1
 */
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2669, __pyx_L19_except_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2669, __pyx_L19_except_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          goto __pyx_L18_exception_handled;
        }
        goto __pyx_L19_except_error;
        __pyx_L19_except_error:;

        /* "btdht/dht.pyx":2648
 *                 yield 0
 *             if to_merge:
 *                 try:             # <<<<<<<<<<<<<<
 *                     if key not in self.trie:
 *                         self.debug(2, "%s gone away while merging" % key)
 */
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_XGIVEREF(__pyx_t_12);
        __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
        goto __pyx_L1_error;
        __pyx_L23_try_continue:;
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_XGIVEREF(__pyx_t_12);
        __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
        goto __pyx_L7_continue;
        __pyx_L18_exception_handled:;
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_XGIVEREF(__pyx_t_12);
        __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
        __pyx_L24_try_end:;
      }

      /* "btdht/dht.pyx":2671
 *                     self.debug(0, "trie changed while merging")
 * 
 *                 i += 1             # <<<<<<<<<<<<<<
 *                 # give back control to the scheduler every 1000 buckets merged
 *                 if i >= 1000:
 */
      __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_cur_scope->__pyx_v_i, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2671, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_i);
      __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_i, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_9);
      __pyx_t_9 = 0;

      /* "btdht/dht.pyx":2673
 *                 i += 1
 *                 # give back control to the scheduler every 1000 buckets merged
 *                 if i >= 1000:             # <<<<<<<<<<<<<<
 *                     yield 0
 * 
 */
      __pyx_t_9 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_i, __pyx_int_1000, Py_GE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2673, __pyx_L1_error)
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 2673, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_1) {

        /* "btdht/dht.pyx":2674
 *                 # give back control to the scheduler every 1000 buckets merged
 *                 if i >= 1000:
 *                     yield 0             # <<<<<<<<<<<<<<
 * 
 *         if full_merge:
 */
        __Pyx_INCREF(__pyx_int_0);
        __pyx_r = __pyx_int_0;
        __Pyx_XGIVEREF(__pyx_r);
        __Pyx_RefNannyFinishContext();
        __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
        /* return from generator, yielding value */
        __pyx_generator->resume_label = 2;
        return __pyx_r;
        __pyx_L30_resume_from_yield:;
        if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 2674, __pyx_L1_error)

        /* "btdht/dht.pyx":2673
 *                 i += 1
 *                 # give back control to the scheduler every 1000 buckets merged
 *                 if i >= 1000:             # <<<<<<<<<<<<<<
 *                     yield 0
 * 
 */
      }

      /* "btdht/dht.pyx":2647
 *             if j >= 100000:
 *                 yield 0
 *             if to_merge:             # <<<<<<<<<<<<<<
 *                 try:
 *                     if key not in self.trie:
 */
    }
    __pyx_L7_continue:;
  }

  /* "btdht/dht.pyx":2676
 *                     yield 0
 * 
 *         if full_merge:             # <<<<<<<<<<<<<<
 *             self._heigth = max(len(k) for k in self.trie.keys()) + 1
 *             self.debug(
 */
  __pyx_t_1 = (__pyx_cur_scope->__pyx_v_full_merge != 0);
  if (__pyx_t_1) {

    /* "btdht/dht.pyx":2677
 * 
 *         if full_merge:
 *             self._heigth = max(len(k) for k in self.trie.keys()) + 1             # <<<<<<<<<<<<<<
 *             self.debug(
 *                 1,
 */
    __pyx_t_9 = __pyx_pf_5btdht_3dht_12RoutingTable_6_merge_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2677, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_max, __pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2677, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_t_5, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2677, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_heigth_2, __pyx_t_9) < 0) __PYX_ERR(0, 2677, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "btdht/dht.pyx":2678
 *         if full_merge:
 *             self._heigth = max(len(k) for k in self.trie.keys()) + 1
 *             self.debug(             # <<<<<<<<<<<<<<
 *                 1,
 *                 "%s nodes merged in %ss" % (
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_debug); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2678, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);

    /* "btdht/dht.pyx":2681
 *                 1,
 *                 "%s nodes merged in %ss" % (
 *                     nodes_before - self.stats()[0], int(time.time() - started)             # <<<<<<<<<<<<<<
 *                 )
 *             )
 */
    if (unlikely(!__pyx_cur_scope->__pyx_v_nodes_before)) { __Pyx_RaiseUnboundLocalError("nodes_before"); __PYX_ERR(0, 2681, __pyx_L1_error) }
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_stats); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_4 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Subtract(__pyx_cur_scope->__pyx_v_nodes_before, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_time); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_15))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_15);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_15, function);
      }
    }
    __pyx_t_3 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_15);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    if (unlikely(!__pyx_cur_scope->__pyx_v_started)) { __Pyx_RaiseUnboundLocalError("started"); __PYX_ERR(0, 2681, __pyx_L1_error) }
    __pyx_t_15 = PyNumber_Subtract(__pyx_t_3, __pyx_cur_scope->__pyx_v_started); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 2681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_3);
    __pyx_t_4 = 0;
    __pyx_t_3 = 0;

    /* "btdht/dht.pyx":2680
 *             self.debug(
 *                 1,
 *                 "%s nodes merged in %ss" % (             # <<<<<<<<<<<<<<
 *                     nodes_before - self.stats()[0], int(time.time() - started)
 *                 )
 */
    __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_s_nodes_merged_in_ss, __pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2680, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = NULL;
    __pyx_t_13 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_15)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_15);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
        __pyx_t_13 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_int_1, __pyx_t_3};
      __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2678, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_15, __pyx_int_1, __pyx_t_3};
      __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2678, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2678, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__pyx_t_15) {
        __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_15); __pyx_t_15 = NULL;
      }
      __Pyx_INCREF(__pyx_int_1);
      __Pyx_GIVEREF(__pyx_int_1);
      PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_13, __pyx_int_1);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_13, __pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2678, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "btdht/dht.pyx":2676
 *                     yield 0
 * 
 *         if full_merge:             # <<<<<<<<<<<<<<
 *             self._heigth = max(len(k) for k in self.trie.keys()) + 1
 *             self.debug(
 */
  }
  CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

  /* "btdht/dht.pyx":2611
 *         self.need_merge = True
 * 
 *     def _merge(self, stack=None):             # <<<<<<<<<<<<<<
 *         """
 *             Perform a merge of the routing table. If ``stack`` is provided, only a partial merge
 */

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("_merge", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  #if !CYTHON_USE_EXC_INFO_STACK
  __Pyx_Coroutine_ResetAndClearException(__pyx_generator);
  #endif
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __pyx_unpickle_DHT_BASE(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_1__pyx_unpickle_DHT_BASE(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5btdht_3dht_1__pyx_unpickle_DHT_BASE = {"__pyx_unpickle_DHT_BASE", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_1__pyx_unpickle_DHT_BASE, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5btdht_3dht_1__pyx_unpickle_DHT_BASE(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v___pyx_type = 0;
  long __pyx_v___pyx_checksum;
  PyObject *__pyx_v___pyx_state = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__pyx_unpickle_DHT_BASE (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_DHT_BASE", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_DHT_BASE", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_DHT_BASE") < 0)) __PYX_ERR(1, 1, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v___pyx_type = values[0];
    __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error)
    __pyx_v___pyx_state = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_DHT_BASE", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.__pyx_unpickle_DHT_BASE", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht___pyx_unpickle_DHT_BASE(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht___pyx_unpickle_DHT_BASE(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_v___pyx_PickleError = 0;
  PyObject *__pyx_v___pyx_result = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_unpickle_DHT_BASE", 0);

  /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0x4d4fbc6, 0xd7ddd24, 0xf626de7):             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0x4d4fbc6, 0xd7ddd24, 0xf626de7) = (_myid))" % __pyx_checksum)
 */
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, __pyx_tuple__40, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "(tree fragment)":5
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0x4d4fbc6, 0xd7ddd24, 0xf626de7):
 *         from pickle import PickleError as __pyx_PickleError             # <<<<<<<<<<<<<<
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0x4d4fbc6, 0xd7ddd24, 0xf626de7) = (_myid))" % __pyx_checksum)
 *     __pyx_result = DHT_BASE.__new__(__pyx_type)
 */
    __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_n_s_PickleError);
    __Pyx_GIVEREF(__pyx_n_s_PickleError);
    PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_PickleError);
    __pyx_t_4 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_1, -1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_1);
    __pyx_v___pyx_PickleError = __pyx_t_1;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "(tree fragment)":6
 *     if __pyx_checksum not in (0x4d4fbc6, 0xd7ddd24, 0xf626de7):
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0x4d4fbc6, 0xd7ddd24, 0xf626de7) = (_myid))" % __pyx_checksum)             # <<<<<<<<<<<<<<
 *     __pyx_result = DHT_BASE.__new__(__pyx_type)
 *     if __pyx_state is not None:
 */
    __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_0x_x_vs_0, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_v___pyx_PickleError);
    __pyx_t_1 = __pyx_v___pyx_PickleError; __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(1, 6, __pyx_L1_error)

    /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0x4d4fbc6, 0xd7ddd24, 0xf626de7):             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0x4d4fbc6, 0xd7ddd24, 0xf626de7) = (_myid))" % __pyx_checksum)
 */
  }

  /* "(tree fragment)":7
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0x4d4fbc6, 0xd7ddd24, 0xf626de7) = (_myid))" % __pyx_checksum)
 *     __pyx_result = DHT_BASE.__new__(__pyx_type)             # <<<<<<<<<<<<<<
 *     if __pyx_state is not None:
 *         __pyx_unpickle_DHT_BASE__set_state(<DHT_BASE> __pyx_result, __pyx_state)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE), __pyx_n_s_new); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_5, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v___pyx_type);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "(tree fragment)":8
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0x4d4fbc6, 0xd7ddd24, 0xf626de7) = (_myid))" % __pyx_checksum)
 *     __pyx_result = DHT_BASE.__new__(__pyx_type)
 *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
 *         __pyx_unpickle_DHT_BASE__set_state(<DHT_BASE> __pyx_result, __pyx_state)
 *     return __pyx_result
 */
  __pyx_t_3 = (__pyx_v___pyx_state != Py_None);
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "(tree fragment)":9
 *     __pyx_result = DHT_BASE.__new__(__pyx_type)
 *     if __pyx_state is not None:
 *         __pyx_unpickle_DHT_BASE__set_state(<DHT_BASE> __pyx_result, __pyx_state)             # <<<<<<<<<<<<<<
 *     return __pyx_result
 * cdef __pyx_unpickle_DHT_BASE__set_state(DHT_BASE __pyx_result, tuple __pyx_state):
 */
    if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 9, __pyx_L1_error)
    __pyx_t_4 = __pyx_f_5btdht_3dht___pyx_unpickle_DHT_BASE__set_state(((struct __pyx_obj_5btdht_3dht_DHT_BASE *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 9, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "(tree fragment)":8
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0x4d4fbc6, 0xd7ddd24, 0xf626de7) = (_myid))" % __pyx_checksum)
 *     __pyx_result = DHT_BASE.__new__(__pyx_type)
 *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
 *         __pyx_unpickle_DHT_BASE__set_state(<DHT_BASE> __pyx_result, __pyx_state)
 *     return __pyx_result
 */
  }

  /* "(tree fragment)":10
 *     if __pyx_state is not None:
 *         __pyx_unpickle_DHT_BASE__set_state(<DHT_BASE> __pyx_result, __pyx_state)
 *     return __pyx_result             # <<<<<<<<<<<<<<
 * cdef __pyx_unpickle_DHT_BASE__set_state(DHT_BASE __pyx_result, tuple __pyx_state):
 *     __pyx_result._myid = __pyx_state[0]
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v___pyx_result);
  __pyx_r = __pyx_v___pyx_result;
  goto __pyx_L0;

  /* "(tree fragment)":1
 * def __pyx_unpickle_DHT_BASE(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("btdht.dht.__pyx_unpickle_DHT_BASE", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v___pyx_PickleError);
  __Pyx_XDECREF(__pyx_v___pyx_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":11
 *         __pyx_unpickle_DHT_BASE__set_state(<DHT_BASE> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_DHT_BASE__set_state(DHT_BASE __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result._myid = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 */

static PyObject *__pyx_f_5btdht_3dht___pyx_unpickle_DHT_BASE__set_state(struct __pyx_obj_5btdht_3dht_DHT_BASE *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char __pyx_t_2[20];
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_unpickle_DHT_BASE__set_state", 0);

  /* "(tree fragment)":12
 *     return __pyx_result
 * cdef __pyx_unpickle_DHT_BASE__set_state(DHT_BASE __pyx_result, tuple __pyx_state):
 *     __pyx_result._myid = __pyx_state[0]             # <<<<<<<<<<<<<<
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 *         __pyx_result.__dict__.update(__pyx_state[1])
 */
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(__Pyx_carray_from_py_char(__pyx_t_1, __pyx_t_2, 20) < 0)) __PYX_ERR(1, 12, __pyx_L1_error)
  memcpy(&(__pyx_v___pyx_result->_myid[0]), __pyx_t_2, sizeof(__pyx_v___pyx_result->_myid[0]) * (20));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "(tree fragment)":13
 * cdef __pyx_unpickle_DHT_BASE__set_state(DHT_BASE __pyx_result, tuple __pyx_state):
 *     __pyx_result._myid = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
 *         __pyx_result.__dict__.update(__pyx_state[1])
 */
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(1, 13, __pyx_L1_error)
  }
  __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
  __pyx_t_5 = ((__pyx_t_4 > 1) != 0);
  if (__pyx_t_5) {
  } else {
    __pyx_t_3 = __pyx_t_5;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
  __pyx_t_6 = (__pyx_t_5 != 0);
  __pyx_t_3 = __pyx_t_6;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_3) {

    /* "(tree fragment)":14
 *     __pyx_result._myid = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 *         __pyx_result.__dict__.update(__pyx_state[1])             # <<<<<<<<<<<<<<
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__pyx_v___pyx_state == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(1, 14, __pyx_L1_error)
    }
    __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "(tree fragment)":13
 * cdef __pyx_unpickle_DHT_BASE__set_state(DHT_BASE __pyx_result, tuple __pyx_state):
 *     __pyx_result._myid = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
 *         __pyx_result.__dict__.update(__pyx_state[1])
 */
  }

  /* "(tree fragment)":11
 *         __pyx_unpickle_DHT_BASE__set_state(<DHT_BASE> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_DHT_BASE__set_state(DHT_BASE __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result._myid = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("btdht.dht.__pyx_unpickle_DHT_BASE__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __pyx_unpickle_Node(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */

/* Python wrapper */
static PyObject *__pyx_pw_5btdht_3dht_3__pyx_unpickle_Node(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_5btdht_3dht_3__pyx_unpickle_Node = {"__pyx_unpickle_Node", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_3__pyx_unpickle_Node, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_5btdht_3dht_3__pyx_unpickle_Node(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v___pyx_type = 0;
  long __pyx_v___pyx_checksum;
  PyObject *__pyx_v___pyx_state = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__pyx_unpickle_Node (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_type)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_checksum)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Node", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pyx_state)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Node", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pyx_unpickle_Node") < 0)) __PYX_ERR(1, 1, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v___pyx_type = values[0];
    __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error)
    __pyx_v___pyx_state = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_Node", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 1, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("btdht.dht.__pyx_unpickle_Node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5btdht_3dht_2__pyx_unpickle_Node(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5btdht_3dht_2__pyx_unpickle_Node(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_v___pyx_PickleError = 0;
  PyObject *__pyx_v___pyx_result = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_unpickle_Node", 0);

  /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0xe3db725, 0x0eaf894, 0xd0728b2):             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xe3db725, 0x0eaf894, 0xd0728b2) = (_failed, _id, _ip, _last_query, _last_response, _port))" % __pyx_checksum)
 */
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, __pyx_tuple__41, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "(tree fragment)":5
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0xe3db725, 0x0eaf894, 0xd0728b2):
 *         from pickle import PickleError as __pyx_PickleError             # <<<<<<<<<<<<<<
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xe3db725, 0x0eaf894, 0xd0728b2) = (_failed, _id, _ip, _last_query, _last_response, _port))" % __pyx_checksum)
 *     __pyx_result = Node.__new__(__pyx_type)
 */
    __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_n_s_PickleError);
    __Pyx_GIVEREF(__pyx_n_s_PickleError);
    PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_PickleError);
    __pyx_t_4 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_1, -1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_1);
    __pyx_v___pyx_PickleError = __pyx_t_1;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "(tree fragment)":6
 *     if __pyx_checksum not in (0xe3db725, 0x0eaf894, 0xd0728b2):
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xe3db725, 0x0eaf894, 0xd0728b2) = (_failed, _id, _ip, _last_query, _last_response, _port))" % __pyx_checksum)             # <<<<<<<<<<<<<<
 *     __pyx_result = Node.__new__(__pyx_type)
 *     if __pyx_state is not None:
 */
    __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_0x_x_vs_0_2, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_v___pyx_PickleError);
    __pyx_t_1 = __pyx_v___pyx_PickleError; __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    __pyx_t_4 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(1, 6, __pyx_L1_error)

    /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0xe3db725, 0x0eaf894, 0xd0728b2):             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xe3db725, 0x0eaf894, 0xd0728b2) = (_failed, _id, _ip, _last_query, _last_response, _port))" % __pyx_checksum)
 */
  }

  /* "(tree fragment)":7
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xe3db725, 0x0eaf894, 0xd0728b2) = (_failed, _id, _ip, _last_query, _last_response, _port))" % __pyx_checksum)
 *     __pyx_result = Node.__new__(__pyx_type)             # <<<<<<<<<<<<<<
 *     if __pyx_state is not None:
 *         __pyx_unpickle_Node__set_state(<Node> __pyx_result, __pyx_state)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5btdht_3dht_Node), __pyx_n_s_new); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_5, __pyx_v___pyx_type) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v___pyx_type);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "(tree fragment)":8
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xe3db725, 0x0eaf894, 0xd0728b2) = (_failed, _id, _ip, _last_query, _last_response, _port))" % __pyx_checksum)
 *     __pyx_result = Node.__new__(__pyx_type)
 *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
 *         __pyx_unpickle_Node__set_state(<Node> __pyx_result, __pyx_state)
 *     return __pyx_result
 */
  __pyx_t_3 = (__pyx_v___pyx_state != Py_None);
  __pyx_t_2 = (__pyx_t_3 != 0);
  if (__pyx_t_2) {

    /* "(tree fragment)":9
 *     __pyx_result = Node.__new__(__pyx_type)
 *     if __pyx_state is not None:
 *         __pyx_unpickle_Node__set_state(<Node> __pyx_result, __pyx_state)             # <<<<<<<<<<<<<<
 *     return __pyx_result
 * cdef __pyx_unpickle_Node__set_state(Node __pyx_result, tuple __pyx_state):
 */
    if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 9, __pyx_L1_error)
    __pyx_t_4 = __pyx_f_5btdht_3dht___pyx_unpickle_Node__set_state(((struct __pyx_obj_5btdht_3dht_Node *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 9, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "(tree fragment)":8
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0xe3db725, 0x0eaf894, 0xd0728b2) = (_failed, _id, _ip, _last_query, _last_response, _port))" % __pyx_checksum)
 *     __pyx_result = Node.__new__(__pyx_type)
 *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
 *         __pyx_unpickle_Node__set_state(<Node> __pyx_result, __pyx_state)
 *     return __pyx_result
 */
  }

  /* "(tree fragment)":10
 *     if __pyx_state is not None:
 *         __pyx_unpickle_Node__set_state(<Node> __pyx_result, __pyx_state)
 *     return __pyx_result             # <<<<<<<<<<<<<<
 * cdef __pyx_unpickle_Node__set_state(Node __pyx_result, tuple __pyx_state):
 *     __pyx_result._failed = __pyx_state[0]; __pyx_result._id = __pyx_state[1]; __pyx_result._ip = __pyx_state[2]; __pyx_result._last_query = __pyx_state[3]; __pyx_result._last_response = __pyx_state[4]; __pyx_result._port = __pyx_state[5]
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v___pyx_result);
  __pyx_r = __pyx_v___pyx_result;
  goto __pyx_L0;

  /* "(tree fragment)":1
 * def __pyx_unpickle_Node(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("btdht.dht.__pyx_unpickle_Node", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v___pyx_PickleError);
  __Pyx_XDECREF(__pyx_v___pyx_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":11
 *         __pyx_unpickle_Node__set_state(<Node> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_Node__set_state(Node __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result._failed = __pyx_state[0]; __pyx_result._id = __pyx_state[1]; __pyx_result._ip = __pyx_state[2]; __pyx_result._last_query = __pyx_state[3]; __pyx_result._last_response = __pyx_state[4]; __pyx_result._port = __pyx_state[5]
 *     if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'):
 */

static PyObject *__pyx_f_5btdht_3dht___pyx_unpickle_Node__set_state(struct __pyx_obj_5btdht_3dht_Node *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  char __pyx_t_3[20];
  char __pyx_t_4[4];
  int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_unpickle_Node__set_state", 0);

  /* "(tree fragment)":12
 *     return __pyx_result
 * cdef __pyx_unpickle_Node__set_state(Node __pyx_result, tuple __pyx_state):
 *     __pyx_result._failed = __pyx_state[0]; __pyx_result._id = __pyx_state[1]; __pyx_result._ip = __pyx_state[2]; __pyx_result._last_query = __pyx_state[3]; __pyx_result._last_response = __pyx_state[4]; __pyx_result._port = __pyx_state[5]             # <<<<<<<<<<<<<<
 *     if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'):
 *         __pyx_result.__dict__.update(__pyx_state[6])
 */
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_failed = __pyx_t_2;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(__Pyx_carray_from_py_char(__pyx_t_1, __pyx_t_3, 20) < 0)) __PYX_ERR(1, 12, __pyx_L1_error)
  memcpy(&(__pyx_v___pyx_result->_id[0]), __pyx_t_3, sizeof(__pyx_v___pyx_result->_id[0]) * (20));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(__Pyx_carray_from_py_char(__pyx_t_1, __pyx_t_4, 4) < 0)) __PYX_ERR(1, 12, __pyx_L1_error)
  memcpy(&(__pyx_v___pyx_result->_ip[0]), __pyx_t_4, sizeof(__pyx_v___pyx_result->_ip[0]) * (4));
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_last_query = __pyx_t_2;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_last_response = __pyx_t_2;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(1, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_port = __pyx_t_2;

  /* "(tree fragment)":13
 * cdef __pyx_unpickle_Node__set_state(Node __pyx_result, tuple __pyx_state):
 *     __pyx_result._failed = __pyx_state[0]; __pyx_result._id = __pyx_state[1]; __pyx_result._ip = __pyx_state[2]; __pyx_result._last_query = __pyx_state[3]; __pyx_result._last_response = __pyx_state[4]; __pyx_result._port = __pyx_state[5]
 *     if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
 *         __pyx_result.__dict__.update(__pyx_state[6])
 */
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(1, 13, __pyx_L1_error)
  }
  __pyx_t_6 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
  __pyx_t_7 = ((__pyx_t_6 > 6) != 0);
  if (__pyx_t_7) {
  } else {
    __pyx_t_5 = __pyx_t_7;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_7 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
  __pyx_t_8 = (__pyx_t_7 != 0);
  __pyx_t_5 = __pyx_t_8;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_5) {

    /* "(tree fragment)":14
 *     __pyx_result._failed = __pyx_state[0]; __pyx_result._id = __pyx_state[1]; __pyx_result._ip = __pyx_state[2]; __pyx_result._last_query = __pyx_state[3]; __pyx_result._last_response = __pyx_state[4]; __pyx_result._port = __pyx_state[5]
 *     if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'):
 *         __pyx_result.__dict__.update(__pyx_state[6])             # <<<<<<<<<<<<<<
 */
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_update); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(__pyx_v___pyx_state == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(1, 14, __pyx_L1_error)
    }
    __pyx_t_9 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 6, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_11 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) {
      __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10);
      if (likely(__pyx_t_11)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_10, function);
      }
    }
    __pyx_t_1 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_11, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_9);
    __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "(tree fragment)":13
 * cdef __pyx_unpickle_Node__set_state(Node __pyx_result, tuple __pyx_state):
 *     __pyx_result._failed = __pyx_state[0]; __pyx_result._id = __pyx_state[1]; __pyx_result._ip = __pyx_state[2]; __pyx_result._last_query = __pyx_state[3]; __pyx_result._last_response = __pyx_state[4]; __pyx_result._port = __pyx_state[5]
 *     if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
 *         __pyx_result.__dict__.update(__pyx_state[6])
 */
  }

  /* "(tree fragment)":11
 *         __pyx_unpickle_Node__set_state(<Node> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_Node__set_state(Node __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result._failed = __pyx_state[0]; __pyx_result._id = __pyx_state[1]; __pyx_result._ip = __pyx_state[2]; __pyx_result._last_query = __pyx_state[3]; __pyx_result._last_response = __pyx_state[4]; __pyx_result._port = __pyx_state[5]
 *     if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'):
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("btdht.dht.__pyx_unpickle_Node__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "carray.from_py":77
 * 
 * @cname("__Pyx_carray_from_py_char")
 * cdef int __Pyx_carray_from_py_char(object o, base_type *v, Py_ssize_t length) except -1:             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t i = length
 *     try:
 */

static int __Pyx_carray_from_py_char(PyObject *__pyx_v_o, char *__pyx_v_v, Py_ssize_t __pyx_v_length) {
  Py_ssize_t __pyx_v_i;
  PyObject *__pyx_v_item = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  Py_ssize_t __pyx_t_8;
  PyObject *(*__pyx_t_9)(PyObject *);
  PyObject *__pyx_t_10 = NULL;
  char __pyx_t_11;
  char const *__pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_carray_from_py_char", 0);

  /* "carray.from_py":78
 * @cname("__Pyx_carray_from_py_char")
 * cdef int __Pyx_carray_from_py_char(object o, base_type *v, Py_ssize_t length) except -1:
 *     cdef Py_ssize_t i = length             # <<<<<<<<<<<<<<
 *     try:
 *         i = len(o)
 */
  __pyx_v_i = __pyx_v_length;

  /* "carray.from_py":79
 * cdef int __Pyx_carray_from_py_char(object o, base_type *v, Py_ssize_t length) except -1:
 *     cdef Py_ssize_t i = length
 *     try:             # <<<<<<<<<<<<<<
 *         i = len(o)
 *     except (TypeError, OverflowError):
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "carray.from_py":80
 *     cdef Py_ssize_t i = length
 *     try:
 *         i = len(o)             # <<<<<<<<<<<<<<
 *     except (TypeError, OverflowError):
 *         pass
 */
      __pyx_t_4 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 80, __pyx_L3_error)
      __pyx_v_i = __pyx_t_4;

      /* "carray.from_py":79
 * cdef int __Pyx_carray_from_py_char(object o, base_type *v, Py_ssize_t length) except -1:
 *     cdef Py_ssize_t i = length
 *     try:             # <<<<<<<<<<<<<<
 *         i = len(o)
 *     except (TypeError, OverflowError):
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;

    /* "carray.from_py":81
 *     try:
 *         i = len(o)
 *     except (TypeError, OverflowError):             # <<<<<<<<<<<<<<
 *         pass
 *     if i == length:
 */
    __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError) || __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
    if (__pyx_t_5) {
      __Pyx_ErrRestore(0,0,0);
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "carray.from_py":79
 * cdef int __Pyx_carray_from_py_char(object o, base_type *v, Py_ssize_t length) except -1:
 *     cdef Py_ssize_t i = length
 *     try:             # <<<<<<<<<<<<<<
 *         i = len(o)
 *     except (TypeError, OverflowError):
 */
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L4_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    __pyx_L8_try_end:;
  }

  /* "carray.from_py":83
 *     except (TypeError, OverflowError):
 *         pass
 *     if i == length:             # <<<<<<<<<<<<<<
 *         for i, item in enumerate(o):
 *             if i >= length:
 */
  __pyx_t_6 = ((__pyx_v_i == __pyx_v_length) != 0);
  if (__pyx_t_6) {

    /* "carray.from_py":84
 *         pass
 *     if i == length:
 *         for i, item in enumerate(o):             # <<<<<<<<<<<<<<
 *             if i >= length:
 *                 break
 */
    __pyx_t_4 = 0;
    if (likely(PyList_CheckExact(__pyx_v_o)) || PyTuple_CheckExact(__pyx_v_o)) {
      __pyx_t_7 = __pyx_v_o; __Pyx_INCREF(__pyx_t_7); __pyx_t_8 = 0;
      __pyx_t_9 = NULL;
    } else {
      __pyx_t_8 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 84, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 84, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_9)) {
        if (likely(PyList_CheckExact(__pyx_t_7))) {
          if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_10 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_10); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(1, 84, __pyx_L1_error)
          #else
          __pyx_t_10 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 84, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          #endif
        } else {
          if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_10); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(1, 84, __pyx_L1_error)
          #else
          __pyx_t_10 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 84, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          #endif
        }
      } else {
        __pyx_t_10 = __pyx_t_9(__pyx_t_7);
        if (unlikely(!__pyx_t_10)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(1, 84, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_10);
      }
      __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_10);
      __pyx_t_10 = 0;
      __pyx_v_i = __pyx_t_4;
      __pyx_t_4 = (__pyx_t_4 + 1);

      /* "carray.from_py":85
 *     if i == length:
 *         for i, item in enumerate(o):
 *             if i >= length:             # <<<<<<<<<<<<<<
 *                 break
 *             v[i] = item
 */
      __pyx_t_6 = ((__pyx_v_i >= __pyx_v_length) != 0);
      if (__pyx_t_6) {

        /* "carray.from_py":86
 *         for i, item in enumerate(o):
 *             if i >= length:
 *                 break             # <<<<<<<<<<<<<<
 *             v[i] = item
 *         else:
 */
        goto __pyx_L11_break;

        /* "carray.from_py":85
 *     if i == length:
 *         for i, item in enumerate(o):
 *             if i >= length:             # <<<<<<<<<<<<<<
 *                 break
 *             v[i] = item
 */
      }

      /* "carray.from_py":87
 *             if i >= length:
 *                 break
 *             v[i] = item             # <<<<<<<<<<<<<<
 *         else:
 *             i += 1  # convert index to length
 */
      __pyx_t_11 = __Pyx_PyInt_As_char(__pyx_v_item); if (unlikely((__pyx_t_11 == (char)-1) && PyErr_Occurred())) __PYX_ERR(1, 87, __pyx_L1_error)
      (__pyx_v_v[__pyx_v_i]) = __pyx_t_11;

      /* "carray.from_py":84
 *         pass
 *     if i == length:
 *         for i, item in enumerate(o):             # <<<<<<<<<<<<<<
 *             if i >= length:
 *                 break
 */
    }
    /*else*/ {

      /* "carray.from_py":89
 *             v[i] = item
 *         else:
 *             i += 1  # convert index to length             # <<<<<<<<<<<<<<
 *             if i == length:
 *                 return 0
 */
      __pyx_v_i = (__pyx_v_i + 1);

      /* "carray.from_py":90
 *         else:
 *             i += 1  # convert index to length
 *             if i == length:             # <<<<<<<<<<<<<<
 *                 return 0
 * 
 */
      __pyx_t_6 = ((__pyx_v_i == __pyx_v_length) != 0);
      if (__pyx_t_6) {

        /* "carray.from_py":91
 *             i += 1  # convert index to length
 *             if i == length:
 *                 return 0             # <<<<<<<<<<<<<<
 * 
 *     PyErr_Format(
 */
        __pyx_r = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        goto __pyx_L0;

        /* "carray.from_py":90
 *         else:
 *             i += 1  # convert index to length
 *             if i == length:             # <<<<<<<<<<<<<<
 *                 return 0
 * 
 */
      }
    }

    /* "carray.from_py":84
 *         pass
 *     if i == length:
 *         for i, item in enumerate(o):             # <<<<<<<<<<<<<<
 *             if i >= length:
 *                 break
 */
    __pyx_L11_break:;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "carray.from_py":83
 *     except (TypeError, OverflowError):
 *         pass
 *     if i == length:             # <<<<<<<<<<<<<<
 *         for i, item in enumerate(o):
 *             if i >= length:
 */
  }

  /* "carray.from_py":96
 *         IndexError,
 *         ("too many values found during array assignment, expected %zd"
 *          if i >= length else             # <<<<<<<<<<<<<<
 *          "not enough values found during array assignment, expected %zd, got %zd"),
 *         length, i)
 */
  if (((__pyx_v_i >= __pyx_v_length) != 0)) {
    __pyx_t_12 = ((char const *)"too many values found during array assignment, expected %zd");
  } else {
    __pyx_t_12 = ((char const *)"not enough values found during array assignment, expected %zd, got %zd");
  }

  /* "carray.from_py":93
 *                 return 0
 * 
 *     PyErr_Format(             # <<<<<<<<<<<<<<
 *         IndexError,
 *         ("too many values found during array assignment, expected %zd"
 */
  __pyx_t_7 = PyErr_Format(__pyx_builtin_IndexError, __pyx_t_12, __pyx_v_length, __pyx_v_i); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 93, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "carray.from_py":77
 * 
 * @cname("__Pyx_carray_from_py_char")
 * cdef int __Pyx_carray_from_py_char(object o, base_type *v, Py_ssize_t length) except -1:             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t i = length
 *     try:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("carray.from_py.__Pyx_carray_from_py_char", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_item);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static struct __pyx_vtabstruct_5btdht_3dht_DHT_BASE __pyx_vtable_5btdht_3dht_DHT_BASE;

static PyObject *__pyx_tp_new_5btdht_3dht_DHT_BASE(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5btdht_3dht_DHT_BASE *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5btdht_3dht_DHT_BASE *)o);
  p->__pyx_vtab = __pyx_vtabptr_5btdht_3dht_DHT_BASE;
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht_DHT_BASE(PyObject *o) {
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_5btdht_3dht_8DHT_BASE_zombie(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5btdht_3dht_8DHT_BASE_6zombie_1__get__(o);
}

static PyMethodDef __pyx_methods_5btdht_3dht_DHT_BASE[] = {
  {"save", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_3save, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_2save},
  {"load", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_5load, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_4load},
  {"stop_bg", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_7stop_bg, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_6stop_bg},
  {"stop", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_9stop, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_8stop},
  {"start", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_11start, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_10start},
  {"is_alive", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_13is_alive, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_12is_alive},
  {"debug", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_15debug, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_14debug},
  {"_socket_stats", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_17_socket_stats, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_16_socket_stats},
  {"init_socket", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_19init_socket, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_18init_socket},
  {"sleep", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_21sleep, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_20sleep},
  {"announce_peer", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_23announce_peer, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_22announce_peer},
  {"_add_peer", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_25_add_peer, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_24_add_peer},
  {"_add_peer_queried", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_27_add_peer_queried, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_26_add_peer_queried},
  {"get_peers", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_29get_peers, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_28get_peers},
  {"_get_peers_closest_loop", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_31_get_peers_closest_loop, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_30_get_peers_closest_loop},
  {"_get_peers", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_34_get_peers, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_33_get_peers},
  {"get_closest_nodes", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_36get_closest_nodes, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_35get_closest_nodes},
  {"bootstarp", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_38bootstarp, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_37bootstarp},
  {"_update_node", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_40_update_node, METH_O, __pyx_doc_5btdht_3dht_8DHT_BASE_39_update_node},
  {"sendto", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_42sendto, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_41sendto},
  {"_process_outgoing_message", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_44_process_outgoing_message, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_43_process_outgoing_message},
  {"_process_incoming_message", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_46_process_incoming_message, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_45_process_incoming_message},
  {"_get_token", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_48_get_token, METH_O, __pyx_doc_5btdht_3dht_8DHT_BASE_47_get_token},
  {"_get_valid_token", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_50_get_valid_token, METH_O, __pyx_doc_5btdht_3dht_8DHT_BASE_49_get_valid_token},
  {"clean", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_52clean, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_51clean},
  {"clean_long", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_54clean_long, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_53clean_long},
  {"_clean", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_56_clean, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_55_clean},
  {"build_table", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_58build_table, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_57build_table},
  {"_routine", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_60_routine, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_59_routine},
  {"register_message", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_63register_message, METH_O, __pyx_doc_5btdht_3dht_8DHT_BASE_62register_message},
  {"on_error", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_65on_error, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_64on_error},
  {"on_ping_response", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_67on_ping_response, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_66on_ping_response},
  {"on_find_node_response", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_69on_find_node_response, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_68on_find_node_response},
  {"on_get_peers_response", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_71on_get_peers_response, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_70on_get_peers_response},
  {"on_announce_peer_response", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_73on_announce_peer_response, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_72on_announce_peer_response},
  {"on_ping_query", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_75on_ping_query, METH_O, __pyx_doc_5btdht_3dht_8DHT_BASE_74on_ping_query},
  {"on_find_node_query", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_77on_find_node_query, METH_O, __pyx_doc_5btdht_3dht_8DHT_BASE_76on_find_node_query},
  {"on_get_peers_query", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_79on_get_peers_query, METH_O, __pyx_doc_5btdht_3dht_8DHT_BASE_78on_get_peers_query},
  {"on_announce_peer_query", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_81on_announce_peer_query, METH_O, __pyx_doc_5btdht_3dht_8DHT_BASE_80on_announce_peer_query},
  {"_on_ping_response", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_83_on_ping_response, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_82_on_ping_response},
  {"_on_find_node_response", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_85_on_find_node_response, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_84_on_find_node_response},
  {"_on_get_peers_response", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_87_on_get_peers_response, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_86_on_get_peers_response},
  {"_on_announce_peer_response", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_89_on_announce_peer_response, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_88_on_announce_peer_response},
  {"_on_ping_query", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_91_on_ping_query, METH_O, __pyx_doc_5btdht_3dht_8DHT_BASE_90_on_ping_query},
  {"_on_find_node_query", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_93_on_find_node_query, METH_O, __pyx_doc_5btdht_3dht_8DHT_BASE_92_on_find_node_query},
  {"_on_get_peers_query", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_95_on_get_peers_query, METH_O, __pyx_doc_5btdht_3dht_8DHT_BASE_94_on_get_peers_query},
  {"_on_announce_peer_query", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_97_on_announce_peer_query, METH_O, __pyx_doc_5btdht_3dht_8DHT_BASE_96_on_announce_peer_query},
  {"_process_error", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_99_process_error, METH_VARARGS|METH_KEYWORDS, 0},
  {"_process_response", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_101_process_response, METH_VARARGS|METH_KEYWORDS, 0},
  {"_process_query", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_103_process_query, METH_O, 0},
  {"_process_loop", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_105_process_loop, METH_NOARGS, __pyx_doc_5btdht_3dht_8DHT_BASE_104_process_loop},
  {"_decode", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_8DHT_BASE_108_decode, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_8DHT_BASE_107_decode},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_110__reduce_cython__, METH_NOARGS, 0},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5btdht_3dht_8DHT_BASE_112__setstate_cython__, METH_O, 0},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5btdht_3dht_DHT_BASE[] = {
  {(char *)"zombie", __pyx_getprop_5btdht_3dht_8DHT_BASE_zombie, 0, (char *)"``True`` if dht is stopped but one thread or more remains alive, ``False`` otherwise", 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5btdht_3dht_DHT_BASE = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.DHT_BASE", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht_DHT_BASE), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht_DHT_BASE, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  "\n    The DHT base class\n\n    :param RoutingTable routing_table: An optional routing table, possibly shared between several\n        dht instances. If not specified, a new routing table is instanciated.\n    :param int bind_port: And optional udp port to use for the dht instance. If not specified, the\n        hosting system will choose an available port.\n    :param str bind_ip: The interface to listen to. The default is ``\"0.0.0.0\"``.\n    :param bytes id: An optional 160 bits long (20 Bytes) id. If not specified, a random one is\n        generated.\n    :param set ignored_ip: A set of ip address in dotted (``\"1.2.3.4\"``) notation to ignore.\n        The default is the empty set.\n    :param int debuglvl: Level of verbosity, default to ``0``.\n    :param str prefix: A prefix to use in logged messages. The default is ``\"\"``.\n    :param int process_queue_size: Size of the queue of messages waiting to be processed by user\n        defines functions (on_`msg`_(query|response)). see the\n        :meth:`register_message<DHT_BASE.register_message>` method. The default to ``500``.\n    :param list ignored_net: An list of ip networks in cidr notation (``\"1.2.3.4/5\"``) to ignore.\n        The default is the value of the attribute :attr:`ignored_net`.\n    :param btdht.utils.Scheduler scheduler: A optional :class:`Scheduler<btdht.utils.Scheduler>`\n        instance. If not specified, a new :class:`Scheduler<btdht.utils.Scheduler>` is instanciated.\n\n    Note:\n        try to use same ``id`` and ``bind_port`` over dht restart to increase\n        the probability to remain in other nodes routing table\n\n    ", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5btdht_3dht_DHT_BASE, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5btdht_3dht_DHT_BASE, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_5btdht_3dht_8DHT_BASE_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht_DHT_BASE, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static PyObject *__pyx_tp_new_5btdht_3dht_Node(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht_Node(PyObject *o) {
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_5btdht_3dht_4Node_port(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5btdht_3dht_4Node_4port_1__get__(o);
}

static int __pyx_setprop_5btdht_3dht_4Node_port(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5btdht_3dht_4Node_4port_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5btdht_3dht_4Node_last_response(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5btdht_3dht_4Node_13last_response_1__get__(o);
}

static int __pyx_setprop_5btdht_3dht_4Node_last_response(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5btdht_3dht_4Node_13last_response_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5btdht_3dht_4Node_last_query(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5btdht_3dht_4Node_10last_query_1__get__(o);
}

static int __pyx_setprop_5btdht_3dht_4Node_last_query(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5btdht_3dht_4Node_10last_query_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5btdht_3dht_4Node_failed(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5btdht_3dht_4Node_6failed_1__get__(o);
}

static int __pyx_setprop_5btdht_3dht_4Node_failed(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5btdht_3dht_4Node_6failed_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5btdht_3dht_4Node_id(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5btdht_3dht_4Node_2id_1__get__(o);
}

static PyObject *__pyx_getprop_5btdht_3dht_4Node_good(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5btdht_3dht_4Node_4good_1__get__(o);
}

static PyObject *__pyx_getprop_5btdht_3dht_4Node_bad(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5btdht_3dht_4Node_3bad_1__get__(o);
}

static PyObject *__pyx_getprop_5btdht_3dht_4Node_ip(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5btdht_3dht_4Node_2ip_1__get__(o);
}

static int __pyx_setprop_5btdht_3dht_4Node_ip(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5btdht_3dht_4Node_2ip_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_5btdht_3dht_Node[] = {
  {"compact_info", (PyCFunction)__pyx_pw_5btdht_3dht_4Node_7compact_info, METH_NOARGS, __pyx_doc_5btdht_3dht_4Node_6compact_info},
  {"from_compact_infos", (PyCFunction)__pyx_pw_5btdht_3dht_4Node_9from_compact_infos, METH_O, __pyx_doc_5btdht_3dht_4Node_8from_compact_infos},
  {"from_compact_info", (PyCFunction)__pyx_pw_5btdht_3dht_4Node_11from_compact_info, METH_O, __pyx_doc_5btdht_3dht_4Node_10from_compact_info},
  {"ping", (PyCFunction)__pyx_pw_5btdht_3dht_4Node_17ping, METH_O, __pyx_doc_5btdht_3dht_4Node_16ping},
  {"find_node", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_4Node_19find_node, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_4Node_18find_node},
  {"get_peers", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_4Node_21get_peers, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_4Node_20get_peers},
  {"announce_peer", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5btdht_3dht_4Node_23announce_peer, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5btdht_3dht_4Node_22announce_peer},
  {"__reduce_cython__", (PyCFunction)__pyx_pw_5btdht_3dht_4Node_25__reduce_cython__, METH_NOARGS, 0},
  {"__setstate_cython__", (PyCFunction)__pyx_pw_5btdht_3dht_4Node_27__setstate_cython__, METH_O, 0},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5btdht_3dht_Node[] = {
  {(char *)"port", __pyx_getprop_5btdht_3dht_4Node_port, __pyx_setprop_5btdht_3dht_4Node_port, (char *)0, 0},
  {(char *)"last_response", __pyx_getprop_5btdht_3dht_4Node_last_response, __pyx_setprop_5btdht_3dht_4Node_last_response, (char *)0, 0},
  {(char *)"last_query", __pyx_getprop_5btdht_3dht_4Node_last_query, __pyx_setprop_5btdht_3dht_4Node_last_query, (char *)0, 0},
  {(char *)"failed", __pyx_getprop_5btdht_3dht_4Node_failed, __pyx_setprop_5btdht_3dht_4Node_failed, (char *)0, 0},
  {(char *)"id", __pyx_getprop_5btdht_3dht_4Node_id, 0, (char *)0, 0},
  {(char *)"good", __pyx_getprop_5btdht_3dht_4Node_good, 0, (char *)0, 0},
  {(char *)"bad", __pyx_getprop_5btdht_3dht_4Node_bad, 0, (char *)0, 0},
  {(char *)"ip", __pyx_getprop_5btdht_3dht_4Node_ip, __pyx_setprop_5btdht_3dht_4Node_ip, (char *)0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5btdht_3dht_Node = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.Node", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht_Node), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht_Node, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  __pyx_pw_5btdht_3dht_4Node_13__cmp__, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  __pyx_pw_5btdht_3dht_4Node_5__repr__, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  __pyx_pw_5btdht_3dht_4Node_15__hash__, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  "\n        A node of the dht in the routing table\n\n        :param bytes id: The 160 bits (20 Bytes) long identifier of the node\n        :param str ip: The ip, in dotted notation of the node\n        :param int port: The udp dht port of the node\n        :param int last_response: Unix timestamp of the last received response from this node\n        :param int last_query: Unix timestamp of the last received query from this node\n        :param int failed: Number of consecutive queries sended to the node without responses\n\n        Note:\n          A good node is a node has responded to one of our queries within the last\n          15 minutes. A node is also good if it has ever responded to one of our\n          queries and has sent us a query within the last 15 minutes. After 15 minutes\n          of inactivity, a node becomes questionable. Nodes become bad when they fail\n          to respond to multiple queries in a row (3 query in a row in this implementation).\n    ", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  __pyx_pw_5btdht_3dht_4Node_3__richcmp__, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5btdht_3dht_Node, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5btdht_3dht_Node, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_5btdht_3dht_4Node_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht_Node, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *__pyx_freelist_5btdht_3dht___pyx_scope_struct__announce_peer[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct__announce_peer = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct__announce_peer(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct__announce_peer > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct__announce_peer[--__pyx_freecount_5btdht_3dht___pyx_scope_struct__announce_peer];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct__announce_peer(PyObject *o) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_info_hash);
  Py_CLEAR(p->__pyx_v_port);
  Py_CLEAR(p->__pyx_v_self);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct__announce_peer < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct__announce_peer[__pyx_freecount_5btdht_3dht___pyx_scope_struct__announce_peer++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct__announce_peer(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *)o;
  if (p->__pyx_v_info_hash) {
    e = (*v)(p->__pyx_v_info_hash, a); if (e) return e;
  }
  if (p->__pyx_v_port) {
    e = (*v)(p->__pyx_v_port, a); if (e) return e;
  }
  if (p->__pyx_v_self) {
    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5btdht_3dht___pyx_scope_struct__announce_peer(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer *)o;
  tmp = ((PyObject*)p->__pyx_v_info_hash);
  p->__pyx_v_info_hash = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_port);
  p->__pyx_v_port = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_self);
  p->__pyx_v_self = ((struct __pyx_obj_5btdht_3dht_DHT_BASE *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct__announce_peer = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct__announce_peer", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct__announce_peer), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct__announce_peer, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct__announce_peer, /*tp_traverse*/
  __pyx_tp_clear_5btdht_3dht___pyx_scope_struct__announce_peer, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct__announce_peer, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *__pyx_freelist_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop[--__pyx_freecount_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop(PyObject *o) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v___closest);
  Py_CLEAR(p->__pyx_v__closest);
  Py_CLEAR(p->__pyx_v_callback);
  Py_CLEAR(p->__pyx_v_closest);
  Py_CLEAR(p->__pyx_v_hash);
  Py_CLEAR(p->__pyx_v_limit);
  Py_CLEAR(p->__pyx_v_node);
  Py_CLEAR(p->__pyx_v_nodes);
  Py_CLEAR(p->__pyx_v_on_stop);
  Py_CLEAR(p->__pyx_v_self);
  Py_CLEAR(p->__pyx_v_stop);
  Py_CLEAR(p->__pyx_v_tosleep);
  Py_CLEAR(p->__pyx_v_tried_nodes);
  Py_CLEAR(p->__pyx_v_ts);
  Py_CLEAR(p->__pyx_v_typ);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop[__pyx_freecount_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop *)o;
  if (p->__pyx_v___closest) {
    e = (*v)(p->__pyx_v___closest, a); if (e) return e;
  }
  if (p->__pyx_v__closest) {
    e = (*v)(p->__pyx_v__closest, a); if (e) return e;
  }
  if (p->__pyx_v_callback) {
    e = (*v)(p->__pyx_v_callback, a); if (e) return e;
  }
  if (p->__pyx_v_closest) {
    e = (*v)(p->__pyx_v_closest, a); if (e) return e;
  }
  if (p->__pyx_v_hash) {
    e = (*v)(p->__pyx_v_hash, a); if (e) return e;
  }
  if (p->__pyx_v_limit) {
    e = (*v)(p->__pyx_v_limit, a); if (e) return e;
  }
  if (p->__pyx_v_node) {
    e = (*v)(p->__pyx_v_node, a); if (e) return e;
  }
  if (p->__pyx_v_nodes) {
    e = (*v)(p->__pyx_v_nodes, a); if (e) return e;
  }
  if (p->__pyx_v_on_stop) {
    e = (*v)(p->__pyx_v_on_stop, a); if (e) return e;
  }
  if (p->__pyx_v_self) {
    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
  }
  if (p->__pyx_v_stop) {
    e = (*v)(p->__pyx_v_stop, a); if (e) return e;
  }
  if (p->__pyx_v_tosleep) {
    e = (*v)(p->__pyx_v_tosleep, a); if (e) return e;
  }
  if (p->__pyx_v_tried_nodes) {
    e = (*v)(p->__pyx_v_tried_nodes, a); if (e) return e;
  }
  if (p->__pyx_v_ts) {
    e = (*v)(p->__pyx_v_ts, a); if (e) return e;
  }
  if (p->__pyx_v_typ) {
    e = (*v)(p->__pyx_v_typ, a); if (e) return e;
  }
  return 0;
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct_1__get_peers_closest_loop", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes *__pyx_freelist_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes[--__pyx_freecount_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes(PyObject *o) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_l);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes[__pyx_freecount_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes *)o;
  if (p->__pyx_v_l) {
    e = (*v)(p->__pyx_v_l, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes *)o;
  tmp = ((PyObject*)p->__pyx_v_l);
  p->__pyx_v_l = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct_2_get_closest_nodes", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes, /*tp_traverse*/
  __pyx_tp_clear_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr *__pyx_freelist_5btdht_3dht___pyx_scope_struct_3_genexpr[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct_3_genexpr = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_3_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct_3_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct_3_genexpr[--__pyx_freecount_5btdht_3dht___pyx_scope_struct_3_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_3_genexpr(PyObject *o) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_outer_scope);
  Py_CLEAR(p->__pyx_v_n);
  Py_CLEAR(p->__pyx_t_0);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct_3_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct_3_genexpr[__pyx_freecount_5btdht_3dht___pyx_scope_struct_3_genexpr++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_3_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr *)o;
  if (p->__pyx_outer_scope) {
    e = (*v)(((PyObject *)p->__pyx_outer_scope), a); if (e) return e;
  }
  if (p->__pyx_v_n) {
    e = (*v)(p->__pyx_v_n, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct_3_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct_3_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_3_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_3_genexpr, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_3_genexpr, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct_3_genexpr, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine *__pyx_freelist_5btdht_3dht___pyx_scope_struct_4__routine[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct_4__routine = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_4__routine(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct_4__routine > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct_4__routine[--__pyx_freecount_5btdht_3dht___pyx_scope_struct_4__routine];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_4__routine(PyObject *o) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_bads);
  Py_CLEAR(p->__pyx_v_delta);
  Py_CLEAR(p->__pyx_v_goods);
  Py_CLEAR(p->__pyx_v_in_s);
  Py_CLEAR(p->__pyx_v_next_routine);
  Py_CLEAR(p->__pyx_v_nodes);
  Py_CLEAR(p->__pyx_v_now);
  Py_CLEAR(p->__pyx_v_out_s);
  Py_CLEAR(p->__pyx_v_self);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct_4__routine < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct_4__routine[__pyx_freecount_5btdht_3dht___pyx_scope_struct_4__routine++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_4__routine(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine *)o;
  if (p->__pyx_v_bads) {
    e = (*v)(p->__pyx_v_bads, a); if (e) return e;
  }
  if (p->__pyx_v_delta) {
    e = (*v)(p->__pyx_v_delta, a); if (e) return e;
  }
  if (p->__pyx_v_goods) {
    e = (*v)(p->__pyx_v_goods, a); if (e) return e;
  }
  if (p->__pyx_v_in_s) {
    e = (*v)(p->__pyx_v_in_s, a); if (e) return e;
  }
  if (p->__pyx_v_next_routine) {
    e = (*v)(p->__pyx_v_next_routine, a); if (e) return e;
  }
  if (p->__pyx_v_nodes) {
    e = (*v)(p->__pyx_v_nodes, a); if (e) return e;
  }
  if (p->__pyx_v_now) {
    e = (*v)(p->__pyx_v_now, a); if (e) return e;
  }
  if (p->__pyx_v_out_s) {
    e = (*v)(p->__pyx_v_out_s, a); if (e) return e;
  }
  if (p->__pyx_v_self) {
    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
  }
  return 0;
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct_4__routine = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct_4__routine", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_4__routine), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_4__routine, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_4__routine, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct_4__routine, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop *__pyx_freelist_5btdht_3dht___pyx_scope_struct_5__process_loop[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct_5__process_loop = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_5__process_loop(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct_5__process_loop > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct_5__process_loop[--__pyx_freecount_5btdht_3dht___pyx_scope_struct_5__process_loop];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_5__process_loop(PyObject *o) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_query);
  Py_CLEAR(p->__pyx_v_response);
  Py_CLEAR(p->__pyx_v_self);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct_5__process_loop < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct_5__process_loop[__pyx_freecount_5btdht_3dht___pyx_scope_struct_5__process_loop++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_5__process_loop(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop *)o;
  if (p->__pyx_v_query) {
    e = (*v)(p->__pyx_v_query, a); if (e) return e;
  }
  if (p->__pyx_v_response) {
    e = (*v)(p->__pyx_v_response, a); if (e) return e;
  }
  if (p->__pyx_v_self) {
    e = (*v)(((PyObject *)p->__pyx_v_self), a); if (e) return e;
  }
  return 0;
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct_5__process_loop = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct_5__process_loop", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_5__process_loop), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_5__process_loop, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_5__process_loop, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct_5__process_loop, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop *__pyx_freelist_5btdht_3dht___pyx_scope_struct_6__merge_loop[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct_6__merge_loop = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_6__merge_loop(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct_6__merge_loop > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct_6__merge_loop[--__pyx_freecount_5btdht_3dht___pyx_scope_struct_6__merge_loop];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_6__merge_loop(PyObject *o) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_i);
  Py_CLEAR(p->__pyx_v_next_full_merge);
  Py_CLEAR(p->__pyx_v_next_merge);
  Py_CLEAR(p->__pyx_v_self);
  Py_CLEAR(p->__pyx_v_stack);
  Py_CLEAR(p->__pyx_t_0);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct_6__merge_loop < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct_6__merge_loop[__pyx_freecount_5btdht_3dht___pyx_scope_struct_6__merge_loop++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_6__merge_loop(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop *)o;
  if (p->__pyx_v_i) {
    e = (*v)(p->__pyx_v_i, a); if (e) return e;
  }
  if (p->__pyx_v_next_full_merge) {
    e = (*v)(p->__pyx_v_next_full_merge, a); if (e) return e;
  }
  if (p->__pyx_v_next_merge) {
    e = (*v)(p->__pyx_v_next_merge, a); if (e) return e;
  }
  if (p->__pyx_v_self) {
    e = (*v)(p->__pyx_v_self, a); if (e) return e;
  }
  if (p->__pyx_v_stack) {
    e = (*v)(p->__pyx_v_stack, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct_6__merge_loop = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct_6__merge_loop", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_6__merge_loop), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_6__merge_loop, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_6__merge_loop, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct_6__merge_loop, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine *__pyx_freelist_5btdht_3dht___pyx_scope_struct_7__routine[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct_7__routine = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_7__routine(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct_7__routine > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct_7__routine[--__pyx_freecount_5btdht_3dht___pyx_scope_struct_7__routine];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_7__routine(PyObject *o) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_bucket);
  Py_CLEAR(p->__pyx_v_dht);
  Py_CLEAR(p->__pyx_v_dhts);
  Py_CLEAR(p->__pyx_v_i);
  Py_CLEAR(p->__pyx_v_id);
  Py_CLEAR(p->__pyx_v_key);
  Py_CLEAR(p->__pyx_v_last_explore_tree);
  Py_CLEAR(p->__pyx_v_node);
  Py_CLEAR(p->__pyx_v_nodes);
  Py_CLEAR(p->__pyx_v_now);
  Py_CLEAR(p->__pyx_v_questionable);
  Py_CLEAR(p->__pyx_v_self);
  Py_CLEAR(p->__pyx_t_0);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct_7__routine < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct_7__routine[__pyx_freecount_5btdht_3dht___pyx_scope_struct_7__routine++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_7__routine(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine *)o;
  if (p->__pyx_v_bucket) {
    e = (*v)(p->__pyx_v_bucket, a); if (e) return e;
  }
  if (p->__pyx_v_dht) {
    e = (*v)(p->__pyx_v_dht, a); if (e) return e;
  }
  if (p->__pyx_v_dhts) {
    e = (*v)(p->__pyx_v_dhts, a); if (e) return e;
  }
  if (p->__pyx_v_i) {
    e = (*v)(p->__pyx_v_i, a); if (e) return e;
  }
  if (p->__pyx_v_id) {
    e = (*v)(p->__pyx_v_id, a); if (e) return e;
  }
  if (p->__pyx_v_key) {
    e = (*v)(p->__pyx_v_key, a); if (e) return e;
  }
  if (p->__pyx_v_last_explore_tree) {
    e = (*v)(p->__pyx_v_last_explore_tree, a); if (e) return e;
  }
  if (p->__pyx_v_node) {
    e = (*v)(p->__pyx_v_node, a); if (e) return e;
  }
  if (p->__pyx_v_nodes) {
    e = (*v)(p->__pyx_v_nodes, a); if (e) return e;
  }
  if (p->__pyx_v_now) {
    e = (*v)(p->__pyx_v_now, a); if (e) return e;
  }
  if (p->__pyx_v_questionable) {
    e = (*v)(p->__pyx_v_questionable, a); if (e) return e;
  }
  if (p->__pyx_v_self) {
    e = (*v)(p->__pyx_v_self, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct_7__routine = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct_7__routine", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_7__routine), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_7__routine, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_7__routine, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct_7__routine, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct_8_genexpr *__pyx_freelist_5btdht_3dht___pyx_scope_struct_8_genexpr[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct_8_genexpr = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_8_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct_8_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_8_genexpr)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct_8_genexpr[--__pyx_freecount_5btdht_3dht___pyx_scope_struct_8_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_8_genexpr));
    (void) PyObject_INIT(o, t);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_8_genexpr(PyObject *o) {
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct_8_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_8_genexpr)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct_8_genexpr[__pyx_freecount_5btdht_3dht___pyx_scope_struct_8_genexpr++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_8_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct_8_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct_8_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_8_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_8_genexpr, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  0, /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct_8_genexpr, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *__pyx_freelist_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes[--__pyx_freecount_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes(PyObject *o) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_bad);
  Py_CLEAR(p->__pyx_v_id);
  Py_CLEAR(p->__pyx_v_prefix);
  Py_CLEAR(p->__pyx_v_self);
  Py_CLEAR(p->__pyx_v_suffix);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes[__pyx_freecount_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *)o;
  if (p->__pyx_v_bad) {
    e = (*v)(p->__pyx_v_bad, a); if (e) return e;
  }
  if (p->__pyx_v_id) {
    e = (*v)(p->__pyx_v_id, a); if (e) return e;
  }
  if (p->__pyx_v_prefix) {
    e = (*v)(p->__pyx_v_prefix, a); if (e) return e;
  }
  if (p->__pyx_v_self) {
    e = (*v)(p->__pyx_v_self, a); if (e) return e;
  }
  if (p->__pyx_v_suffix) {
    e = (*v)(p->__pyx_v_suffix, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes *)o;
  tmp = ((PyObject*)p->__pyx_v_bad);
  p->__pyx_v_bad = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_id);
  p->__pyx_v_id = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_prefix);
  p->__pyx_v_prefix = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_self);
  p->__pyx_v_self = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_suffix);
  p->__pyx_v_suffix = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct_9_get_closest_nodes", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes, /*tp_traverse*/
  __pyx_tp_clear_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr *__pyx_freelist_5btdht_3dht___pyx_scope_struct_10_genexpr[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct_10_genexpr = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_10_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct_10_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct_10_genexpr[--__pyx_freecount_5btdht_3dht___pyx_scope_struct_10_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_10_genexpr(PyObject *o) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_outer_scope);
  Py_CLEAR(p->__pyx_v_n);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct_10_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct_10_genexpr[__pyx_freecount_5btdht_3dht___pyx_scope_struct_10_genexpr++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_10_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr *)o;
  if (p->__pyx_outer_scope) {
    e = (*v)(((PyObject *)p->__pyx_outer_scope), a); if (e) return e;
  }
  if (p->__pyx_v_n) {
    e = (*v)(p->__pyx_v_n, a); if (e) return e;
  }
  return 0;
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct_10_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct_10_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_10_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_10_genexpr, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_10_genexpr, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct_10_genexpr, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr *__pyx_freelist_5btdht_3dht___pyx_scope_struct_11_genexpr[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct_11_genexpr = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_11_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct_11_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct_11_genexpr[--__pyx_freecount_5btdht_3dht___pyx_scope_struct_11_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_11_genexpr(PyObject *o) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_outer_scope);
  Py_CLEAR(p->__pyx_v_n);
  Py_CLEAR(p->__pyx_t_0);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct_11_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct_11_genexpr[__pyx_freecount_5btdht_3dht___pyx_scope_struct_11_genexpr++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_11_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr *)o;
  if (p->__pyx_outer_scope) {
    e = (*v)(((PyObject *)p->__pyx_outer_scope), a); if (e) return e;
  }
  if (p->__pyx_v_n) {
    e = (*v)(p->__pyx_v_n, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct_11_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct_11_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_11_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_11_genexpr, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_11_genexpr, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct_11_genexpr, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge *__pyx_freelist_5btdht_3dht___pyx_scope_struct_12__merge[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct_12__merge = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_12__merge(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct_12__merge > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct_12__merge[--__pyx_freecount_5btdht_3dht___pyx_scope_struct_12__merge];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_12__merge(PyObject *o) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_bucket);
  Py_CLEAR(p->__pyx_v_bucket0);
  Py_CLEAR(p->__pyx_v_bucket1);
  Py_CLEAR(p->__pyx_v_genexpr);
  Py_CLEAR(p->__pyx_v_i);
  Py_CLEAR(p->__pyx_v_id);
  Py_CLEAR(p->__pyx_v_j);
  Py_CLEAR(p->__pyx_v_key);
  Py_CLEAR(p->__pyx_v_nodes_before);
  Py_CLEAR(p->__pyx_v_prefix0);
  Py_CLEAR(p->__pyx_v_prefix1);
  Py_CLEAR(p->__pyx_v_self);
  Py_CLEAR(p->__pyx_v_stack);
  Py_CLEAR(p->__pyx_v_started);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct_12__merge < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct_12__merge[__pyx_freecount_5btdht_3dht___pyx_scope_struct_12__merge++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_12__merge(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge *)o;
  if (p->__pyx_v_bucket) {
    e = (*v)(p->__pyx_v_bucket, a); if (e) return e;
  }
  if (p->__pyx_v_bucket0) {
    e = (*v)(p->__pyx_v_bucket0, a); if (e) return e;
  }
  if (p->__pyx_v_bucket1) {
    e = (*v)(p->__pyx_v_bucket1, a); if (e) return e;
  }
  if (p->__pyx_v_genexpr) {
    e = (*v)(p->__pyx_v_genexpr, a); if (e) return e;
  }
  if (p->__pyx_v_i) {
    e = (*v)(p->__pyx_v_i, a); if (e) return e;
  }
  if (p->__pyx_v_id) {
    e = (*v)(p->__pyx_v_id, a); if (e) return e;
  }
  if (p->__pyx_v_j) {
    e = (*v)(p->__pyx_v_j, a); if (e) return e;
  }
  if (p->__pyx_v_key) {
    e = (*v)(p->__pyx_v_key, a); if (e) return e;
  }
  if (p->__pyx_v_nodes_before) {
    e = (*v)(p->__pyx_v_nodes_before, a); if (e) return e;
  }
  if (p->__pyx_v_prefix0) {
    e = (*v)(p->__pyx_v_prefix0, a); if (e) return e;
  }
  if (p->__pyx_v_prefix1) {
    e = (*v)(p->__pyx_v_prefix1, a); if (e) return e;
  }
  if (p->__pyx_v_self) {
    e = (*v)(p->__pyx_v_self, a); if (e) return e;
  }
  if (p->__pyx_v_stack) {
    e = (*v)(p->__pyx_v_stack, a); if (e) return e;
  }
  if (p->__pyx_v_started) {
    e = (*v)(p->__pyx_v_started, a); if (e) return e;
  }
  return 0;
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct_12__merge = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct_12__merge", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_12__merge), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_12__merge, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_12__merge, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct_12__merge, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr *__pyx_freelist_5btdht_3dht___pyx_scope_struct_13_genexpr[8];
static int __pyx_freecount_5btdht_3dht___pyx_scope_struct_13_genexpr = 0;

static PyObject *__pyx_tp_new_5btdht_3dht___pyx_scope_struct_13_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5btdht_3dht___pyx_scope_struct_13_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr)))) {
    o = (PyObject*)__pyx_freelist_5btdht_3dht___pyx_scope_struct_13_genexpr[--__pyx_freecount_5btdht_3dht___pyx_scope_struct_13_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_13_genexpr(PyObject *o) {
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_outer_scope);
  Py_CLEAR(p->__pyx_v_k);
  Py_CLEAR(p->__pyx_t_0);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5btdht_3dht___pyx_scope_struct_13_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr)))) {
    __pyx_freelist_5btdht_3dht___pyx_scope_struct_13_genexpr[__pyx_freecount_5btdht_3dht___pyx_scope_struct_13_genexpr++] = ((struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_13_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr *p = (struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr *)o;
  if (p->__pyx_outer_scope) {
    e = (*v)(((PyObject *)p->__pyx_outer_scope), a); if (e) return e;
  }
  if (p->__pyx_v_k) {
    e = (*v)(p->__pyx_v_k, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static PyTypeObject __pyx_type_5btdht_3dht___pyx_scope_struct_13_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "btdht.dht.__pyx_scope_struct_13_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_5btdht_3dht___pyx_scope_struct_13_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5btdht_3dht___pyx_scope_struct_13_genexpr, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5btdht_3dht___pyx_scope_struct_13_genexpr, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5btdht_3dht___pyx_scope_struct_13_genexpr, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  0, /*tp_print*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
  0, /*tp_pypy_flags*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
#if CYTHON_PEP489_MULTI_PHASE_INIT
static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
static int __pyx_pymod_exec_dht(PyObject* module); /*proto*/
static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  {Py_mod_create, (void*)__pyx_pymod_create},
  {Py_mod_exec, (void*)__pyx_pymod_exec_dht},
  {0, NULL}
};
#endif

static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    "dht",
    0, /* m_doc */
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    0, /* m_size */
  #else
    -1, /* m_size */
  #endif
    __pyx_methods /* m_methods */,
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    __pyx_moduledef_slots, /* m_slots */
  #else
    NULL, /* m_reload */
  #endif
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif
#ifndef CYTHON_SMALL_CODE
#if defined(__clang__)
    #define CYTHON_SMALL_CODE
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
    #define CYTHON_SMALL_CODE __attribute__((cold))
#else
    #define CYTHON_SMALL_CODE
#endif
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_0, __pyx_k_0, sizeof(__pyx_k_0), 0, 0, 1, 0},
  {&__pyx_kp_u_0, __pyx_k_0, sizeof(__pyx_k_0), 0, 1, 0, 0},
  {&__pyx_kp_u_01, __pyx_k_01, sizeof(__pyx_k_01), 0, 1, 0, 0},
  {&__pyx_kp_s_0_0_0_0, __pyx_k_0_0_0_0, sizeof(__pyx_k_0_0_0_0), 0, 0, 1, 0},
  {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_u_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 1, 0, 0},
  {&__pyx_kp_s_20s4sH, __pyx_k_20s4sH, sizeof(__pyx_k_20s4sH), 0, 0, 1, 0},
  {&__pyx_kp_s_4sH, __pyx_k_4sH, sizeof(__pyx_k_4sH), 0, 0, 1, 0},
  {&__pyx_n_s_AF_INET, __pyx_k_AF_INET, sizeof(__pyx_k_AF_INET), 0, 0, 1, 1},
  {&__pyx_kp_s_A_DHT_class_ready_for_instancia, __pyx_k_A_DHT_class_ready_for_instancia, sizeof(__pyx_k_A_DHT_class_ready_for_instancia), 0, 0, 1, 0},
  {&__pyx_kp_s_A_bucket_of_nodes_in_the_routin, __pyx_k_A_bucket_of_nodes_in_the_routin, sizeof(__pyx_k_A_bucket_of_nodes_in_the_routin), 0, 0, 1, 0},
  {&__pyx_kp_s_A_routing_table_for_one_or_more, __pyx_k_A_routing_table_for_one_or_more, sizeof(__pyx_k_A_routing_table_for_one_or_more), 0, 0, 1, 0},
  {&__pyx_kp_s_Already_started, __pyx_k_Already_started, sizeof(__pyx_k_Already_started), 0, 0, 1, 0},
  {&__pyx_kp_s_Already_stoped_or_stoping_in_pro, __pyx_k_Already_stoped_or_stoping_in_pro, sizeof(__pyx_k_Already_stoped_or_stoping_in_pro), 0, 0, 1, 0},
  {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1},
  {&__pyx_kp_s_AttributeError_r_in__on_find_nod, __pyx_k_AttributeError_r_in__on_find_nod, sizeof(__pyx_k_AttributeError_r_in__on_find_nod), 0, 0, 1, 0},
  {&__pyx_n_s_BError, __pyx_k_BError, sizeof(__pyx_k_BError), 0, 0, 1, 1},
  {&__pyx_n_s_Bootstraping, __pyx_k_Bootstraping, sizeof(__pyx_k_Bootstraping), 0, 0, 1, 1},
  {&__pyx_n_s_Bucket, __pyx_k_Bucket, sizeof(__pyx_k_Bucket), 0, 0, 1, 1},
  {&__pyx_n_s_BucketFull, __pyx_k_BucketFull, sizeof(__pyx_k_BucketFull), 0, 0, 1, 1},
  {&__pyx_n_s_BucketNotFull, __pyx_k_BucketNotFull, sizeof(__pyx_k_BucketNotFull), 0, 0, 1, 1},
  {&__pyx_n_s_Bucket___eq, __pyx_k_Bucket___eq, sizeof(__pyx_k_Bucket___eq), 0, 0, 1, 1},
  {&__pyx_n_s_Bucket___hash, __pyx_k_Bucket___hash, sizeof(__pyx_k_Bucket___hash), 0, 0, 1, 1},
  {&__pyx_n_s_Bucket___init, __pyx_k_Bucket___init, sizeof(__pyx_k_Bucket___init), 0, 0, 1, 1},
  {&__pyx_n_s_Bucket___lt, __pyx_k_Bucket___lt, sizeof(__pyx_k_Bucket___lt), 0, 0, 1, 1},
  {&__pyx_n_s_Bucket_add, __pyx_k_Bucket_add, sizeof(__pyx_k_Bucket_add), 0, 0, 1, 1},
  {&__pyx_n_s_Bucket_get_node, __pyx_k_Bucket_get_node, sizeof(__pyx_k_Bucket_get_node), 0, 0, 1, 1},
  {&__pyx_n_s_Bucket_merge, __pyx_k_Bucket_merge, sizeof(__pyx_k_Bucket_merge), 0, 0, 1, 1},
  {&__pyx_kp_s_Bucket_not_Full_r, __pyx_k_Bucket_not_Full_r, sizeof(__pyx_k_Bucket_not_Full_r), 0, 0, 1, 0},
  {&__pyx_n_s_Bucket_own, __pyx_k_Bucket_own, sizeof(__pyx_k_Bucket_own), 0, 0, 1, 1},
  {&__pyx_n_s_Bucket_random_id, __pyx_k_Bucket_random_id, sizeof(__pyx_k_Bucket_random_id), 0, 0, 1, 1},
  {&__pyx_n_s_Bucket_split, __pyx_k_Bucket_split, sizeof(__pyx_k_Bucket_split), 0, 0, 1, 1},
  {&__pyx_n_s_Bucket_to_refresh, __pyx_k_Bucket_to_refresh, sizeof(__pyx_k_Bucket_to_refresh), 0, 0, 1, 1},
  {&__pyx_n_s_DHT, __pyx_k_DHT, sizeof(__pyx_k_DHT), 0, 0, 1, 1},
  {&__pyx_n_s_DHT_BASE, __pyx_k_DHT_BASE, sizeof(__pyx_k_DHT_BASE), 0, 0, 1, 1},
  {&__pyx_n_s_DHT_BASE__get_peers_closest_loop, __pyx_k_DHT_BASE__get_peers_closest_loop, sizeof(__pyx_k_DHT_BASE__get_peers_closest_loop), 0, 0, 1, 1},
  {&__pyx_n_s_DHT_BASE__process_loop, __pyx_k_DHT_BASE__process_loop, sizeof(__pyx_k_DHT_BASE__process_loop), 0, 0, 1, 1},
  {&__pyx_n_s_DHT_BASE__routine, __pyx_k_DHT_BASE__routine, sizeof(__pyx_k_DHT_BASE__routine), 0, 0, 1, 1},
  {&__pyx_kp_s_DHT_BASE_cannot_be_directly_inst, __pyx_k_DHT_BASE_cannot_be_directly_inst, sizeof(__pyx_k_DHT_BASE_cannot_be_directly_inst), 0, 0, 1, 0},
  {&__pyx_n_s_DecodeError, __pyx_k_DecodeError, sizeof(__pyx_k_DecodeError), 0, 0, 1, 1},
  {&__pyx_kp_s_ERROR_201_s_pour_r, __pyx_k_ERROR_201_s_pour_r, sizeof(__pyx_k_ERROR_201_s_pour_r), 0, 0, 1, 0},
  {&__pyx_kp_s_ERROR_202_s_pour_r, __pyx_k_ERROR_202_s_pour_r, sizeof(__pyx_k_ERROR_202_s_pour_r), 0, 0, 1, 0},
  {&__pyx_kp_s_ERROR_203_s_pour_r, __pyx_k_ERROR_203_s_pour_r, sizeof(__pyx_k_ERROR_203_s_pour_r), 0, 0, 1, 0},
  {&__pyx_kp_s_ERROR_204_s_pour_r, __pyx_k_ERROR_204_s_pour_r, sizeof(__pyx_k_ERROR_204_s_pour_r), 0, 0, 1, 0},
  {&__pyx_kp_s_ERROR_s_s_pour_r, __pyx_k_ERROR_s_s_pour_r, sizeof(__pyx_k_ERROR_s_s_pour_r), 0, 0, 1, 0},
  {&__pyx_n_s_Empty, __pyx_k_Empty, sizeof(__pyx_k_Empty), 0, 0, 1, 1},
  {&__pyx_n_s_EnvironmentError, __pyx_k_EnvironmentError, sizeof(__pyx_k_EnvironmentError), 0, 0, 1, 1},
  {&__pyx_kp_b_Error_code_s_unknown, __pyx_k_Error_code_s_unknown, sizeof(__pyx_k_Error_code_s_unknown), 0, 0, 0, 0},
  {&__pyx_n_s_FailToStop, __pyx_k_FailToStop, sizeof(__pyx_k_FailToStop), 0, 0, 1, 1},
  {&__pyx_kp_s_Fetching_my_own_id, __pyx_k_Fetching_my_own_id, sizeof(__pyx_k_Fetching_my_own_id), 0, 0, 1, 0},
  {&__pyx_n_s_Full, __pyx_k_Full, sizeof(__pyx_k_Full), 0, 0, 1, 1},
  {&__pyx_n_s_GenericError, __pyx_k_GenericError, sizeof(__pyx_k_GenericError), 0, 0, 1, 1},
  {&__pyx_kp_s_Hash_s_find_nodes, __pyx_k_Hash_s_find_nodes, sizeof(__pyx_k_Hash_s_find_nodes), 0, 0, 1, 0},
  {&__pyx_kp_s_Hash_s_find_peers, __pyx_k_Hash_s_find_peers, sizeof(__pyx_k_Hash_s_find_peers), 0, 0, 1, 0},
  {&__pyx_kp_s_Hash_s_no_peers_or_nodes_found, __pyx_k_Hash_s_no_peers_or_nodes_found, sizeof(__pyx_k_Hash_s_no_peers_or_nodes_found), 0, 0, 1, 0},
  {&__pyx_n_s_ID, __pyx_k_ID, sizeof(__pyx_k_ID), 0, 0, 1, 1},
  {&__pyx_n_s_IN, __pyx_k_IN, sizeof(__pyx_k_IN), 0, 0, 1, 1},
  {&__pyx_n_s_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 0, 0, 1, 1},
  {&__pyx_n_s_IPNetwork, __pyx_k_IPNetwork, sizeof(__pyx_k_IPNetwork), 0, 0, 1, 1},
  {&__pyx_n_s_IPPROTO_IP, __pyx_k_IPPROTO_IP, sizeof(__pyx_k_IPPROTO_IP), 0, 0, 1, 1},
  {&__pyx_n_s_IP_MTU_DISCOVER, __pyx_k_IP_MTU_DISCOVER, sizeof(__pyx_k_IP_MTU_DISCOVER), 0, 0, 1, 1},
  {&__pyx_n_s_IP_PMTUDISC_DO, __pyx_k_IP_PMTUDISC_DO, sizeof(__pyx_k_IP_PMTUDISC_DO), 0, 0, 1, 1},
  {&__pyx_kp_s_IP_start_with_0___r_r, __pyx_k_IP_start_with_0___r_r, sizeof(__pyx_k_IP_start_with_0___r_r), 0, 0, 1, 0},
  {&__pyx_n_s_ImportError, __pyx_k_ImportError, sizeof(__pyx_k_ImportError), 0, 0, 1, 1},
  {&__pyx_kp_s_Incompatible_checksums_0x_x_vs_0, __pyx_k_Incompatible_checksums_0x_x_vs_0, sizeof(__pyx_k_Incompatible_checksums_0x_x_vs_0), 0, 0, 1, 0},
  {&__pyx_kp_s_Incompatible_checksums_0x_x_vs_0_2, __pyx_k_Incompatible_checksums_0x_x_vs_0_2, sizeof(__pyx_k_Incompatible_checksums_0x_x_vs_0_2), 0, 0, 1, 0},
  {&__pyx_n_s_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 0, 0, 1, 1},
  {&__pyx_kp_s_Invalid_port_number_on_announce, __pyx_k_Invalid_port_number_on_announce, sizeof(__pyx_k_Invalid_port_number_on_announce), 0, 0, 1, 0},
  {&__pyx_kp_s_Invalid_port_number_s_sould_be_w, __pyx_k_Invalid_port_number_s_sould_be_w, sizeof(__pyx_k_Invalid_port_number_s_sould_be_w), 0, 0, 1, 0},
  {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1},
  {&__pyx_kp_s_Less_than_1000_nodes_no_merge, __pyx_k_Less_than_1000_nodes_no_merge, sizeof(__pyx_k_Less_than_1000_nodes_no_merge), 0, 0, 1, 0},
  {&__pyx_n_s_Lock, __pyx_k_Lock, sizeof(__pyx_k_Lock), 0, 0, 1, 1},
  {&__pyx_kp_s_Merging_s_buckets, __pyx_k_Merging_s_buckets, sizeof(__pyx_k_Merging_s_buckets), 0, 0, 1, 0},
  {&__pyx_kp_b_Message_malformed, __pyx_k_Message_malformed, sizeof(__pyx_k_Message_malformed), 0, 0, 0, 0},
  {&__pyx_kp_b_Message_malformed_s_key_is_missi, __pyx_k_Message_malformed_s_key_is_missi, sizeof(__pyx_k_Message_malformed_s_key_is_missi), 0, 0, 0, 0},
  {&__pyx_n_s_MethodUnknownError, __pyx_k_MethodUnknownError, sizeof(__pyx_k_MethodUnknownError), 0, 0, 1, 1},
  {&__pyx_n_s_MissingT, __pyx_k_MissingT, sizeof(__pyx_k_MissingT), 0, 0, 1, 1},
  {&__pyx_n_s_NoTokenError, __pyx_k_NoTokenError, sizeof(__pyx_k_NoTokenError), 0, 0, 1, 1},
  {&__pyx_kp_s_No_msg_response_since_more_than, __pyx_k_No_msg_response_since_more_than, sizeof(__pyx_k_No_msg_response_since_more_than), 0, 0, 1, 0},
  {&__pyx_kp_s_No_msg_since_more_than_2_minutes, __pyx_k_No_msg_since_more_than_2_minutes, sizeof(__pyx_k_No_msg_since_more_than_2_minutes), 0, 0, 1, 0},
  {&__pyx_kp_s_No_token_to_announce_on_node_s, __pyx_k_No_token_to_announce_on_node_s, sizeof(__pyx_k_No_token_to_announce_on_node_s), 0, 0, 1, 0},
  {&__pyx_n_s_Node, __pyx_k_Node, sizeof(__pyx_k_Node), 0, 0, 1, 1},
  {&__pyx_kp_s_Node_s_s, __pyx_k_Node_s_s, sizeof(__pyx_k_Node_s_s), 0, 0, 1, 0},
  {&__pyx_n_s_NotFound, __pyx_k_NotFound, sizeof(__pyx_k_NotFound), 0, 0, 1, 1},
  {&__pyx_kp_s_One_thread_died_stopping_dht, __pyx_k_One_thread_died_stopping_dht, sizeof(__pyx_k_One_thread_died_stopping_dht), 0, 0, 1, 0},
  {&__pyx_n_s_OrderedDict, __pyx_k_OrderedDict, sizeof(__pyx_k_OrderedDict), 0, 0, 1, 1},
  {&__pyx_n_s_OverflowError, __pyx_k_OverflowError, sizeof(__pyx_k_OverflowError), 0, 0, 1, 1},
  {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1},
  {&__pyx_n_s_PollableQueue, __pyx_k_PollableQueue, sizeof(__pyx_k_PollableQueue), 0, 0, 1, 1},
  {&__pyx_kp_s_Port_should_be_whithin_1_and_655, __pyx_k_Port_should_be_whithin_1_and_655, sizeof(__pyx_k_Port_should_be_whithin_1_and_655), 0, 0, 1, 0},
  {&__pyx_kp_s_Programming_merge, __pyx_k_Programming_merge, sizeof(__pyx_k_Programming_merge), 0, 0, 1, 0},
  {&__pyx_n_s_ProtocolError, __pyx_k_ProtocolError, sizeof(__pyx_k_ProtocolError), 0, 0, 1, 1},
  {&__pyx_n_s_Queue, __pyx_k_Queue, sizeof(__pyx_k_Queue), 0, 0, 1, 1},
  {&__pyx_kp_s_RT_s_merge_loop, __pyx_k_RT_s_merge_loop, sizeof(__pyx_k_RT_s_merge_loop), 0, 0, 1, 0},
  {&__pyx_kp_s_RT_s_routine, __pyx_k_RT_s_routine, sizeof(__pyx_k_RT_s_routine), 0, 0, 1, 0},
  {&__pyx_kp_s_RT_s_s, __pyx_k_RT_s_s, sizeof(__pyx_k_RT_s_s), 0, 0, 1, 0},
  {&__pyx_n_s_RoutingTable, __pyx_k_RoutingTable, sizeof(__pyx_k_RoutingTable), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable___init, __pyx_k_RoutingTable___init, sizeof(__pyx_k_RoutingTable___init), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable___iter, __pyx_k_RoutingTable___iter, sizeof(__pyx_k_RoutingTable___iter), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable__merge, __pyx_k_RoutingTable__merge, sizeof(__pyx_k_RoutingTable__merge), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable__merge_locals_genex, __pyx_k_RoutingTable__merge_locals_genex, sizeof(__pyx_k_RoutingTable__merge_locals_genex), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable__merge_loop, __pyx_k_RoutingTable__merge_loop, sizeof(__pyx_k_RoutingTable__merge_loop), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable__routine, __pyx_k_RoutingTable__routine, sizeof(__pyx_k_RoutingTable__routine), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_add, __pyx_k_RoutingTable_add, sizeof(__pyx_k_RoutingTable_add), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_debug, __pyx_k_RoutingTable_debug, sizeof(__pyx_k_RoutingTable_debug), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_empty, __pyx_k_RoutingTable_empty, sizeof(__pyx_k_RoutingTable_empty), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_empty_locals_genexp, __pyx_k_RoutingTable_empty_locals_genexp, sizeof(__pyx_k_RoutingTable_empty_locals_genexp), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_find, __pyx_k_RoutingTable_find, sizeof(__pyx_k_RoutingTable_find), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_get_closest_nodes, __pyx_k_RoutingTable_get_closest_nodes, sizeof(__pyx_k_RoutingTable_get_closest_nodes), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_get_closest_nodes_l, __pyx_k_RoutingTable_get_closest_nodes_l, sizeof(__pyx_k_RoutingTable_get_closest_nodes_l), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_get_closest_nodes_l_2, __pyx_k_RoutingTable_get_closest_nodes_l_2, sizeof(__pyx_k_RoutingTable_get_closest_nodes_l_2), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_get_node, __pyx_k_RoutingTable_get_node, sizeof(__pyx_k_RoutingTable_get_node), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_heigth, __pyx_k_RoutingTable_heigth, sizeof(__pyx_k_RoutingTable_heigth), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_is_alive, __pyx_k_RoutingTable_is_alive, sizeof(__pyx_k_RoutingTable_is_alive), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_merge, __pyx_k_RoutingTable_merge, sizeof(__pyx_k_RoutingTable_merge), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_register_dht, __pyx_k_RoutingTable_register_dht, sizeof(__pyx_k_RoutingTable_register_dht), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_register_torrent, __pyx_k_RoutingTable_register_torrent, sizeof(__pyx_k_RoutingTable_register_torrent), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_register_torrent_lo, __pyx_k_RoutingTable_register_torrent_lo, sizeof(__pyx_k_RoutingTable_register_torrent_lo), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_release_dht, __pyx_k_RoutingTable_release_dht, sizeof(__pyx_k_RoutingTable_release_dht), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_release_torrent, __pyx_k_RoutingTable_release_torrent, sizeof(__pyx_k_RoutingTable_release_torrent), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_release_torrent_lon, __pyx_k_RoutingTable_release_torrent_lon, sizeof(__pyx_k_RoutingTable_release_torrent_lon), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_split, __pyx_k_RoutingTable_split, sizeof(__pyx_k_RoutingTable_split), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_start, __pyx_k_RoutingTable_start, sizeof(__pyx_k_RoutingTable_start), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_stats, __pyx_k_RoutingTable_stats, sizeof(__pyx_k_RoutingTable_stats), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_stop, __pyx_k_RoutingTable_stop, sizeof(__pyx_k_RoutingTable_stop), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_stop_bg, __pyx_k_RoutingTable_stop_bg, sizeof(__pyx_k_RoutingTable_stop_bg), 0, 0, 1, 1},
  {&__pyx_n_s_RoutingTable_zombie, __pyx_k_RoutingTable_zombie, sizeof(__pyx_k_RoutingTable_zombie), 0, 0, 1, 1},
  {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1},
  {&__pyx_n_s_SOCK_DGRAM, __pyx_k_SOCK_DGRAM, sizeof(__pyx_k_SOCK_DGRAM), 0, 0, 1, 1},
  {&__pyx_n_s_Scheduler, __pyx_k_Scheduler, sizeof(__pyx_k_Scheduler), 0, 0, 1, 1},
  {&__pyx_n_s_ServerError, __pyx_k_ServerError, sizeof(__pyx_k_ServerError), 0, 0, 1, 1},
  {&__pyx_n_s_Thread, __pyx_k_Thread, sizeof(__pyx_k_Thread), 0, 0, 1, 1},
  {&__pyx_n_s_TransactionIdUnknown, __pyx_k_TransactionIdUnknown, sizeof(__pyx_k_TransactionIdUnknown), 0, 0, 1, 1},
  {&__pyx_n_s_Trie, __pyx_k_Trie, sizeof(__pyx_k_Trie), 0, 0, 1, 1},
  {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
  {&__pyx_kp_s_TypeError_r_in__recv_loop, __pyx_k_TypeError_r_in__recv_loop, sizeof(__pyx_k_TypeError_r_in__recv_loop), 0, 0, 1, 0},
  {&__pyx_kp_s_UNKNOWN_MSG_r_decoded_as_r_from, __pyx_k_UNKNOWN_MSG_r_decoded_as_r_from, sizeof(__pyx_k_UNKNOWN_MSG_r_decoded_as_r_from), 0, 0, 1, 0},
  {&__pyx_kp_s_Unable_to_queue_msg_to_be_proces, __pyx_k_Unable_to_queue_msg_to_be_proces, sizeof(__pyx_k_Unable_to_queue_msg_to_be_proces), 0, 0, 1, 0},
  {&__pyx_kp_s_Unable_to_stop_s_threads_giving, __pyx_k_Unable_to_stop_s_threads_giving, sizeof(__pyx_k_Unable_to_stop_s_threads_giving), 0, 0, 1, 0},
  {&__pyx_n_s_UnboundLocalError, __pyx_k_UnboundLocalError, sizeof(__pyx_k_UnboundLocalError), 0, 0, 1, 1},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_kp_s_Waiting_for_s_threads_to_termina, __pyx_k_Waiting_for_s_threads_to_termina, sizeof(__pyx_k_Waiting_for_s_threads_to_termina), 0, 0, 1, 0},
  {&__pyx_kp_s_Wrong_Bucket, __pyx_k_Wrong_Bucket, sizeof(__pyx_k_Wrong_Bucket), 0, 0, 1, 0},
  {&__pyx_kp_s_Zombie_threads_unable_de_start, __pyx_k_Zombie_threads_unable_de_start, sizeof(__pyx_k_Zombie_threads_unable_de_start), 0, 0, 1, 0},
  {&__pyx_n_s__15, __pyx_k__15, sizeof(__pyx_k__15), 0, 0, 1, 1},
  {&__pyx_kp_b__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 0, 0},
  {&__pyx_kp_s__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 1, 0},
  {&__pyx_kp_u__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 1, 0, 0},
  {&__pyx_kp_b__27, __pyx_k__27, sizeof(__pyx_k__27), 0, 0, 0, 0},
  {&__pyx_kp_b__28, __pyx_k__28, sizeof(__pyx_k__28), 0, 0, 0, 0},
  {&__pyx_kp_b__30, __pyx_k__30, sizeof(__pyx_k__30), 0, 0, 0, 0},
  {&__pyx_kp_s__70, __pyx_k__70, sizeof(__pyx_k__70), 0, 0, 1, 0},
  {&__pyx_n_s_add, __pyx_k_add, sizeof(__pyx_k_add), 0, 0, 1, 1},
  {&__pyx_n_s_add_dht, __pyx_k_add_dht, sizeof(__pyx_k_add_dht), 0, 0, 1, 1},
  {&__pyx_n_s_add_peer, __pyx_k_add_peer, sizeof(__pyx_k_add_peer), 0, 0, 1, 1},
  {&__pyx_n_s_add_peer_queried, __pyx_k_add_peer_queried, sizeof(__pyx_k_add_peer_queried), 0, 0, 1, 1},
  {&__pyx_n_s_add_thread, __pyx_k_add_thread, sizeof(__pyx_k_add_thread), 0, 0, 1, 1},
  {&__pyx_n_s_addr, __pyx_k_addr, sizeof(__pyx_k_addr), 0, 0, 1, 1},
  {&__pyx_n_s_addresses, __pyx_k_addresses, sizeof(__pyx_k_addresses), 0, 0, 1, 1},
  {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1},
  {&__pyx_n_b_announce_peer, __pyx_k_announce_peer, sizeof(__pyx_k_announce_peer), 0, 0, 0, 1},
  {&__pyx_n_s_announce_peer, __pyx_k_announce_peer, sizeof(__pyx_k_announce_peer), 0, 0, 1, 1},
  {&__pyx_n_s_announce_peer_locals_callback, __pyx_k_announce_peer_locals_callback, sizeof(__pyx_k_announce_peer_locals_callback), 0, 0, 1, 1},
  {&__pyx_n_s_any, __pyx_k_any, sizeof(__pyx_k_any), 0, 0, 1, 1},
  {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1},
  {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
  {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1},
  {&__pyx_n_s_b1, __pyx_k_b1, sizeof(__pyx_k_b1), 0, 0, 1, 1},
  {&__pyx_n_s_b2, __pyx_k_b2, sizeof(__pyx_k_b2), 0, 0, 1, 1},
  {&__pyx_n_s_b2a_hex, __pyx_k_b2a_hex, sizeof(__pyx_k_b2a_hex), 0, 0, 1, 1},
  {&__pyx_n_s_bad, __pyx_k_bad, sizeof(__pyx_k_bad), 0, 0, 1, 1},
  {&__pyx_n_s_bads, __pyx_k_bads, sizeof(__pyx_k_bads), 0, 0, 1, 1},
  {&__pyx_n_s_binascii, __pyx_k_binascii, sizeof(__pyx_k_binascii), 0, 0, 1, 1},
  {&__pyx_n_s_bind, __pyx_k_bind, sizeof(__pyx_k_bind), 0, 0, 1, 1},
  {&__pyx_n_s_bind_ip, __pyx_k_bind_ip, sizeof(__pyx_k_bind_ip), 0, 0, 1, 1},
  {&__pyx_n_s_bind_port, __pyx_k_bind_port, sizeof(__pyx_k_bind_port), 0, 0, 1, 1},
  {&__pyx_n_s_block, __pyx_k_block, sizeof(__pyx_k_block), 0, 0, 1, 1},
  {&__pyx_n_s_bootstarp, __pyx_k_bootstarp, sizeof(__pyx_k_bootstarp), 0, 0, 1, 1},
  {&__pyx_n_s_btdht_dht, __pyx_k_btdht_dht, sizeof(__pyx_k_btdht_dht), 0, 0, 1, 1},
  {&__pyx_kp_s_btdht_dht_pyx, __pyx_k_btdht_dht_pyx, sizeof(__pyx_k_btdht_dht_pyx), 0, 0, 1, 0},
  {&__pyx_n_s_bucket, __pyx_k_bucket, sizeof(__pyx_k_bucket), 0, 0, 1, 1},
  {&__pyx_n_s_bucket0, __pyx_k_bucket0, sizeof(__pyx_k_bucket0), 0, 0, 1, 1},
  {&__pyx_n_s_bucket1, __pyx_k_bucket1, sizeof(__pyx_k_bucket1), 0, 0, 1, 1},
  {&__pyx_n_s_build_table, __pyx_k_build_table, sizeof(__pyx_k_build_table), 0, 0, 1, 1},
  {&__pyx_n_s_callback, __pyx_k_callback, sizeof(__pyx_k_callback), 0, 0, 1, 1},
  {&__pyx_n_s_char, __pyx_k_char, sizeof(__pyx_k_char), 0, 0, 1, 1},
  {&__pyx_n_s_chr, __pyx_k_chr, sizeof(__pyx_k_chr), 0, 0, 1, 1},
  {&__pyx_n_s_class, __pyx_k_class, sizeof(__pyx_k_class), 0, 0, 1, 1},
  {&__pyx_n_s_clean, __pyx_k_clean, sizeof(__pyx_k_clean), 0, 0, 1, 1},
  {&__pyx_n_s_clean_2, __pyx_k_clean_2, sizeof(__pyx_k_clean_2), 0, 0, 1, 1},
  {&__pyx_n_s_clean_long, __pyx_k_clean_long, sizeof(__pyx_k_clean_long), 0, 0, 1, 1},
  {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
  {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
  {&__pyx_n_s_closest, __pyx_k_closest, sizeof(__pyx_k_closest), 0, 0, 1, 1},
  {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1},
  {&__pyx_n_s_compact, __pyx_k_compact, sizeof(__pyx_k_compact), 0, 0, 1, 1},
  {&__pyx_n_s_compact_info, __pyx_k_compact_info, sizeof(__pyx_k_compact_info), 0, 0, 1, 1},
  {&__pyx_kp_s_compact_node_info_should_be_26_c, __pyx_k_compact_node_info_should_be_26_c, sizeof(__pyx_k_compact_node_info_should_be_26_c), 0, 0, 1, 0},
  {&__pyx_kp_s_d_nodes_d_goods_d_bads_in_s_out, __pyx_k_d_nodes_d_goods_d_bads_in_s_out, sizeof(__pyx_k_d_nodes_d_goods_d_bads_in_s_out), 0, 0, 1, 0},
  {&__pyx_n_s_daemon, __pyx_k_daemon, sizeof(__pyx_k_daemon), 0, 0, 1, 1},
  {&__pyx_n_s_datrie, __pyx_k_datrie, sizeof(__pyx_k_datrie), 0, 0, 1, 1},
  {&__pyx_n_s_debug, __pyx_k_debug, sizeof(__pyx_k_debug), 0, 0, 1, 1},
  {&__pyx_n_s_debuglvl, __pyx_k_debuglvl, sizeof(__pyx_k_debuglvl), 0, 0, 1, 1},
  {&__pyx_n_s_decode, __pyx_k_decode, sizeof(__pyx_k_decode), 0, 0, 1, 1},
  {&__pyx_n_s_decode_2, __pyx_k_decode_2, sizeof(__pyx_k_decode_2), 0, 0, 1, 1},
  {&__pyx_n_s_defaultdict, __pyx_k_defaultdict, sizeof(__pyx_k_defaultdict), 0, 0, 1, 1},
  {&__pyx_n_s_del_dht, __pyx_k_del_dht, sizeof(__pyx_k_del_dht), 0, 0, 1, 1},
  {&__pyx_n_s_del_thread, __pyx_k_del_thread, sizeof(__pyx_k_del_thread), 0, 0, 1, 1},
  {&__pyx_n_s_delay, __pyx_k_delay, sizeof(__pyx_k_delay), 0, 0, 1, 1},
  {&__pyx_n_s_dht, __pyx_k_dht, sizeof(__pyx_k_dht), 0, 0, 1, 1},
  {&__pyx_kp_s_dht__s_status, __pyx_k_dht__s_status, sizeof(__pyx_k_dht__s_status), 0, 0, 1, 0},
  {&__pyx_kp_s_dht_transmissionbt_com, __pyx_k_dht_transmissionbt_com, sizeof(__pyx_k_dht_transmissionbt_com), 0, 0, 1, 0},
  {&__pyx_n_s_dhts, __pyx_k_dhts, sizeof(__pyx_k_dhts), 0, 0, 1, 1},
  {&__pyx_n_s_dhts_2, __pyx_k_dhts_2, sizeof(__pyx_k_dhts_2), 0, 0, 1, 1},
  {&__pyx_n_s_dhts_last_elt, __pyx_k_dhts_last_elt, sizeof(__pyx_k_dhts_last_elt), 0, 0, 1, 1},
  {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1},
  {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1},
  {&__pyx_n_b_e, __pyx_k_e, sizeof(__pyx_k_e), 0, 0, 0, 1},
  {&__pyx_n_s_e, __pyx_k_e, sizeof(__pyx_k_e), 0, 0, 1, 1},
  {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1},
  {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1},
  {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1},
  {&__pyx_n_s_enter, __pyx_k_enter, sizeof(__pyx_k_enter), 0, 0, 1, 1},
  {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
  {&__pyx_n_s_eq, __pyx_k_eq, sizeof(__pyx_k_eq), 0, 0, 1, 1},
  {&__pyx_n_s_errmsg, __pyx_k_errmsg, sizeof(__pyx_k_errmsg), 0, 0, 1, 1},
  {&__pyx_n_s_errno, __pyx_k_errno, sizeof(__pyx_k_errno), 0, 0, 1, 1},
  {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1},
  {&__pyx_kp_s_error_r, __pyx_k_error_r, sizeof(__pyx_k_error_r), 0, 0, 1, 0},
  {&__pyx_n_s_exceptions, __pyx_k_exceptions, sizeof(__pyx_k_exceptions), 0, 0, 1, 1},
  {&__pyx_n_s_exit, __pyx_k_exit, sizeof(__pyx_k_exit), 0, 0, 1, 1},
  {&__pyx_n_s_exit_2, __pyx_k_exit_2, sizeof(__pyx_k_exit_2), 0, 0, 1, 1},
  {&__pyx_n_s_extend, __pyx_k_extend, sizeof(__pyx_k_extend), 0, 0, 1, 1},
  {&__pyx_kp_s_fail_to_bind_to_port_s, __pyx_k_fail_to_bind_to_port_s, sizeof(__pyx_k_fail_to_bind_to_port_s), 0, 0, 1, 0},
  {&__pyx_n_s_failed, __pyx_k_failed, sizeof(__pyx_k_failed), 0, 0, 1, 1},
  {&__pyx_n_s_file, __pyx_k_file, sizeof(__pyx_k_file), 0, 0, 1, 1},
  {&__pyx_n_s_filename, __pyx_k_filename, sizeof(__pyx_k_filename), 0, 0, 1, 1},
  {&__pyx_n_s_find, __pyx_k_find, sizeof(__pyx_k_find), 0, 0, 1, 1},
  {&__pyx_n_b_find_node, __pyx_k_find_node, sizeof(__pyx_k_find_node), 0, 0, 0, 1},
  {&__pyx_n_s_find_node, __pyx_k_find_node, sizeof(__pyx_k_find_node), 0, 0, 1, 1},
  {&__pyx_n_s_from_compact_info, __pyx_k_from_compact_info, sizeof(__pyx_k_from_compact_info), 0, 0, 1, 1},
  {&__pyx_n_s_from_compact_infos, __pyx_k_from_compact_infos, sizeof(__pyx_k_from_compact_infos), 0, 0, 1, 1},
  {&__pyx_n_s_fstop, __pyx_k_fstop, sizeof(__pyx_k_fstop), 0, 0, 1, 1},
  {&__pyx_n_s_full_merge, __pyx_k_full_merge, sizeof(__pyx_k_full_merge), 0, 0, 1, 1},
  {&__pyx_n_s_function, __pyx_k_function, sizeof(__pyx_k_function), 0, 0, 1, 1},
  {&__pyx_n_s_functools, __pyx_k_functools, sizeof(__pyx_k_functools), 0, 0, 1, 1},
  {&__pyx_n_s_gaierror, __pyx_k_gaierror, sizeof(__pyx_k_gaierror), 0, 0, 1, 1},
  {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 0, 0, 1, 1},
  {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1},
  {&__pyx_kp_s_get_closest_hash_s, __pyx_k_get_closest_hash_s, sizeof(__pyx_k_get_closest_hash_s), 0, 0, 1, 0},
  {&__pyx_n_s_get_closest_loop_lock, __pyx_k_get_closest_loop_lock, sizeof(__pyx_k_get_closest_loop_lock), 0, 0, 1, 1},
  {&__pyx_n_s_get_closest_nodes, __pyx_k_get_closest_nodes, sizeof(__pyx_k_get_closest_nodes), 0, 0, 1, 1},
  {&__pyx_n_s_get_closest_nodes_locals_genexpr, __pyx_k_get_closest_nodes_locals_genexpr, sizeof(__pyx_k_get_closest_nodes_locals_genexpr), 0, 0, 1, 1},
  {&__pyx_kp_s_get_closest_nodes_r, __pyx_k_get_closest_nodes_r, sizeof(__pyx_k_get_closest_nodes_r), 0, 0, 1, 0},
  {&__pyx_n_s_get_node, __pyx_k_get_node, sizeof(__pyx_k_get_node), 0, 0, 1, 1},
  {&__pyx_n_s_get_nowait, __pyx_k_get_nowait, sizeof(__pyx_k_get_nowait), 0, 0, 1, 1},
  {&__pyx_n_s_get_peer_loop_list, __pyx_k_get_peer_loop_list, sizeof(__pyx_k_get_peer_loop_list), 0, 0, 1, 1},
  {&__pyx_n_s_get_peer_loop_lock, __pyx_k_get_peer_loop_lock, sizeof(__pyx_k_get_peer_loop_lock), 0, 0, 1, 1},
  {&__pyx_n_b_get_peers, __pyx_k_get_peers, sizeof(__pyx_k_get_peers), 0, 0, 0, 1},
  {&__pyx_n_s_get_peers, __pyx_k_get_peers, sizeof(__pyx_k_get_peers), 0, 0, 1, 1},
  {&__pyx_n_s_get_peers_2, __pyx_k_get_peers_2, sizeof(__pyx_k_get_peers_2), 0, 0, 1, 1},
  {&__pyx_n_s_get_peers_closest_loop, __pyx_k_get_peers_closest_loop, sizeof(__pyx_k_get_peers_closest_loop), 0, 0, 1, 1},
  {&__pyx_n_s_get_peers_closest_loop_locals_o, __pyx_k_get_peers_closest_loop_locals_o, sizeof(__pyx_k_get_peers_closest_loop_locals_o), 0, 0, 1, 1},
  {&__pyx_n_s_get_peers_closest_loop_locals_s, __pyx_k_get_peers_closest_loop_locals_s, sizeof(__pyx_k_get_peers_closest_loop_locals_s), 0, 0, 1, 1},
  {&__pyx_kp_s_get_peers_hash_s, __pyx_k_get_peers_hash_s, sizeof(__pyx_k_get_peers_hash_s), 0, 0, 1, 0},
  {&__pyx_n_s_getsockname, __pyx_k_getsockname, sizeof(__pyx_k_getsockname), 0, 0, 1, 1},
  {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1},
  {&__pyx_n_s_good, __pyx_k_good, sizeof(__pyx_k_good), 0, 0, 1, 1},
  {&__pyx_n_s_goods, __pyx_k_goods, sizeof(__pyx_k_goods), 0, 0, 1, 1},
  {&__pyx_n_s_got_peers, __pyx_k_got_peers, sizeof(__pyx_k_got_peers), 0, 0, 1, 1},
  {&__pyx_kp_s_grenade_genua_fr, __pyx_k_grenade_genua_fr, sizeof(__pyx_k_grenade_genua_fr), 0, 0, 1, 0},
  {&__pyx_n_s_hash, __pyx_k_hash, sizeof(__pyx_k_hash), 0, 0, 1, 1},
  {&__pyx_n_s_hash_2, __pyx_k_hash_2, sizeof(__pyx_k_hash_2), 0, 0, 1, 1},
  {&__pyx_n_s_heappop, __pyx_k_heappop, sizeof(__pyx_k_heappop), 0, 0, 1, 1},
  {&__pyx_n_s_heappush, __pyx_k_heappush, sizeof(__pyx_k_heappush), 0, 0, 1, 1},
  {&__pyx_n_s_heapq, __pyx_k_heapq, sizeof(__pyx_k_heapq), 0, 0, 1, 1},
  {&__pyx_n_s_heigth, __pyx_k_heigth, sizeof(__pyx_k_heigth), 0, 0, 1, 1},
  {&__pyx_n_s_heigth_2, __pyx_k_heigth_2, sizeof(__pyx_k_heigth_2), 0, 0, 1, 1},
  {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
  {&__pyx_n_b_id, __pyx_k_id, sizeof(__pyx_k_id), 0, 0, 0, 1},
  {&__pyx_n_s_id, __pyx_k_id, sizeof(__pyx_k_id), 0, 0, 1, 1},
  {&__pyx_n_s_id_end, __pyx_k_id_end, sizeof(__pyx_k_id_end), 0, 0, 1, 1},
  {&__pyx_n_s_id_length, __pyx_k_id_length, sizeof(__pyx_k_id_length), 0, 0, 1, 1},
  {&__pyx_kp_s_id_must_be_20_char_long, __pyx_k_id_must_be_20_char_long, sizeof(__pyx_k_id_must_be_20_char_long), 0, 0, 1, 0},
  {&__pyx_n_s_id_start, __pyx_k_id_start, sizeof(__pyx_k_id_start), 0, 0, 1, 1},
  {&__pyx_n_s_id_to_longid, __pyx_k_id_to_longid, sizeof(__pyx_k_id_to_longid), 0, 0, 1, 1},
  {&__pyx_n_s_ignored_ip, __pyx_k_ignored_ip, sizeof(__pyx_k_ignored_ip), 0, 0, 1, 1},
  {&__pyx_n_s_ignored_net, __pyx_k_ignored_net, sizeof(__pyx_k_ignored_net), 0, 0, 1, 1},
  {&__pyx_n_b_implied_port, __pyx_k_implied_port, sizeof(__pyx_k_implied_port), 0, 0, 0, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_inet_aton, __pyx_k_inet_aton, sizeof(__pyx_k_inet_aton), 0, 0, 1, 1},
  {&__pyx_n_s_inet_ntoa, __pyx_k_inet_ntoa, sizeof(__pyx_k_inet_ntoa), 0, 0, 1, 1},
  {&__pyx_n_b_info_hash, __pyx_k_info_hash, sizeof(__pyx_k_info_hash), 0, 0, 0, 1},
  {&__pyx_n_s_info_hash, __pyx_k_info_hash, sizeof(__pyx_k_info_hash), 0, 0, 1, 1},
  {&__pyx_n_s_info_hash_2, __pyx_k_info_hash_2, sizeof(__pyx_k_info_hash_2), 0, 0, 1, 1},
  {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1},
  {&__pyx_n_s_init_2, __pyx_k_init_2, sizeof(__pyx_k_init_2), 0, 0, 1, 1},
  {&__pyx_n_s_init_socket, __pyx_k_init_socket, sizeof(__pyx_k_init_socket), 0, 0, 1, 1},
  {&__pyx_kp_s_init_socket_for_s, __pyx_k_init_socket_for_s, sizeof(__pyx_k_init_socket_for_s), 0, 0, 1, 0},
  {&__pyx_n_s_ip, __pyx_k_ip, sizeof(__pyx_k_ip), 0, 0, 1, 1},
  {&__pyx_n_s_ip_in_nets, __pyx_k_ip_in_nets, sizeof(__pyx_k_ip_in_nets), 0, 0, 1, 1},
  {&__pyx_n_s_is_alive, __pyx_k_is_alive, sizeof(__pyx_k_is_alive), 0, 0, 1, 1},
  {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1},
  {&__pyx_n_s_iter, __pyx_k_iter, sizeof(__pyx_k_iter), 0, 0, 1, 1},
  {&__pyx_n_s_iteritems, __pyx_k_iteritems, sizeof(__pyx_k_iteritems), 0, 0, 1, 1},
  {&__pyx_n_s_j, __pyx_k_j, sizeof(__pyx_k_j), 0, 0, 1, 1},
  {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1},
  {&__pyx_n_s_key, __pyx_k_key, sizeof(__pyx_k_key), 0, 0, 1, 1},
  {&__pyx_n_s_keys, __pyx_k_keys, sizeof(__pyx_k_keys), 0, 0, 1, 1},
  {&__pyx_n_s_krcp, __pyx_k_krcp, sizeof(__pyx_k_krcp), 0, 0, 1, 1},
  {&__pyx_n_s_l, __pyx_k_l, sizeof(__pyx_k_l), 0, 0, 1, 1},
  {&__pyx_n_s_last_changed, __pyx_k_last_changed, sizeof(__pyx_k_last_changed), 0, 0, 1, 1},
  {&__pyx_n_s_last_debug, __pyx_k_last_debug, sizeof(__pyx_k_last_debug), 0, 0, 1, 1},
  {&__pyx_n_s_last_debug_time, __pyx_k_last_debug_time, sizeof(__pyx_k_last_debug_time), 0, 0, 1, 1},
  {&__pyx_n_s_last_explore_tree, __pyx_k_last_explore_tree, sizeof(__pyx_k_last_explore_tree), 0, 0, 1, 1},
  {&__pyx_n_s_last_msg, __pyx_k_last_msg, sizeof(__pyx_k_last_msg), 0, 0, 1, 1},
  {&__pyx_n_s_last_msg_rep, __pyx_k_last_msg_rep, sizeof(__pyx_k_last_msg_rep), 0, 0, 1, 1},
  {&__pyx_n_s_last_query, __pyx_k_last_query, sizeof(__pyx_k_last_query), 0, 0, 1, 1},
  {&__pyx_n_s_last_response, __pyx_k_last_response, sizeof(__pyx_k_last_response), 0, 0, 1, 1},
  {&__pyx_n_s_last_socket_stats, __pyx_k_last_socket_stats, sizeof(__pyx_k_last_socket_stats), 0, 0, 1, 1},
  {&__pyx_n_s_limit, __pyx_k_limit, sizeof(__pyx_k_limit), 0, 0, 1, 1},
  {&__pyx_n_s_lock, __pyx_k_lock, sizeof(__pyx_k_lock), 0, 0, 1, 1},
  {&__pyx_n_s_long_clean, __pyx_k_long_clean, sizeof(__pyx_k_long_clean), 0, 0, 1, 1},
  {&__pyx_n_s_longest_prefix, __pyx_k_longest_prefix, sizeof(__pyx_k_longest_prefix), 0, 0, 1, 1},
  {&__pyx_n_s_longest_prefix_value, __pyx_k_longest_prefix_value, sizeof(__pyx_k_longest_prefix_value), 0, 0, 1, 1},
  {&__pyx_n_s_lt, __pyx_k_lt, sizeof(__pyx_k_lt), 0, 0, 1, 1},
  {&__pyx_n_s_lvl, __pyx_k_lvl, sizeof(__pyx_k_lvl), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1},
  {&__pyx_n_s_max_node, __pyx_k_max_node, sizeof(__pyx_k_max_node), 0, 0, 1, 1},
  {&__pyx_n_s_max_size, __pyx_k_max_size, sizeof(__pyx_k_max_size), 0, 0, 1, 1},
  {&__pyx_n_s_maxsize, __pyx_k_maxsize, sizeof(__pyx_k_maxsize), 0, 0, 1, 1},
  {&__pyx_n_s_merge, __pyx_k_merge, sizeof(__pyx_k_merge), 0, 0, 1, 1},
  {&__pyx_n_s_merge_2, __pyx_k_merge_2, sizeof(__pyx_k_merge_2), 0, 0, 1, 1},
  {&__pyx_n_s_merge_loop, __pyx_k_merge_loop, sizeof(__pyx_k_merge_loop), 0, 0, 1, 1},
  {&__pyx_n_s_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 0, 1, 1},
  {&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1},
  {&__pyx_n_s_msg, __pyx_k_msg, sizeof(__pyx_k_msg), 0, 0, 1, 1},
  {&__pyx_n_s_myid, __pyx_k_myid, sizeof(__pyx_k_myid), 0, 0, 1, 1},
  {&__pyx_n_s_mytoken, __pyx_k_mytoken, sizeof(__pyx_k_mytoken), 0, 0, 1, 1},
  {&__pyx_n_s_n, __pyx_k_n, sizeof(__pyx_k_n), 0, 0, 1, 1},
  {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
  {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1},
  {&__pyx_n_s_nbit, __pyx_k_nbit, sizeof(__pyx_k_nbit), 0, 0, 1, 1},
  {&__pyx_n_s_need_merge, __pyx_k_need_merge, sizeof(__pyx_k_need_merge), 0, 0, 1, 1},
  {&__pyx_n_s_netaddr, __pyx_k_netaddr, sizeof(__pyx_k_netaddr), 0, 0, 1, 1},
  {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1},
  {&__pyx_n_s_new_id, __pyx_k_new_id, sizeof(__pyx_k_new_id), 0, 0, 1, 1},
  {&__pyx_n_s_next_full_merge, __pyx_k_next_full_merge, sizeof(__pyx_k_next_full_merge), 0, 0, 1, 1},
  {&__pyx_n_s_next_merge, __pyx_k_next_merge, sizeof(__pyx_k_next_merge), 0, 0, 1, 1},
  {&__pyx_n_s_nflip, __pyx_k_nflip, sizeof(__pyx_k_nflip), 0, 0, 1, 1},
  {&__pyx_n_s_node, __pyx_k_node, sizeof(__pyx_k_node), 0, 0, 1, 1},
  {&__pyx_n_b_nodes, __pyx_k_nodes, sizeof(__pyx_k_nodes), 0, 0, 0, 1},
  {&__pyx_n_s_nodes, __pyx_k_nodes, sizeof(__pyx_k_nodes), 0, 0, 1, 1},
  {&__pyx_n_s_nodes_before, __pyx_k_nodes_before, sizeof(__pyx_k_nodes_before), 0, 0, 1, 1},
  {&__pyx_kp_b_nodes_length_should_be_a_multipl, __pyx_k_nodes_length_should_be_a_multipl, sizeof(__pyx_k_nodes_length_should_be_a_multipl), 0, 0, 0, 0},
  {&__pyx_n_s_now, __pyx_k_now, sizeof(__pyx_k_now), 0, 0, 1, 1},
  {&__pyx_n_s_nset, __pyx_k_nset, sizeof(__pyx_k_nset), 0, 0, 1, 1},
  {&__pyx_n_s_obj, __pyx_k_obj, sizeof(__pyx_k_obj), 0, 0, 1, 1},
  {&__pyx_kp_s_obj_of_type_r, __pyx_k_obj_of_type_r, sizeof(__pyx_k_obj_of_type_r), 0, 0, 1, 0},
  {&__pyx_kp_s_obj_without_id_no_node_update, __pyx_k_obj_without_id_no_node_update, sizeof(__pyx_k_obj_without_id_no_node_update), 0, 0, 1, 0},
  {&__pyx_n_s_object, __pyx_k_object, sizeof(__pyx_k_object), 0, 0, 1, 1},
  {&__pyx_n_s_old_node, __pyx_k_old_node, sizeof(__pyx_k_old_node), 0, 0, 1, 1},
  {&__pyx_kp_s_on__s_query, __pyx_k_on__s_query, sizeof(__pyx_k_on__s_query), 0, 0, 1, 0},
  {&__pyx_kp_s_on__s_query_2, __pyx_k_on__s_query_2, sizeof(__pyx_k_on__s_query_2), 0, 0, 1, 0},
  {&__pyx_kp_s_on__s_response, __pyx_k_on__s_response, sizeof(__pyx_k_on__s_response), 0, 0, 1, 0},
  {&__pyx_kp_s_on__s_response_2, __pyx_k_on__s_response_2, sizeof(__pyx_k_on__s_response_2), 0, 0, 1, 0},
  {&__pyx_n_s_on_error, __pyx_k_on_error, sizeof(__pyx_k_on_error), 0, 0, 1, 1},
  {&__pyx_n_s_on_stop, __pyx_k_on_stop, sizeof(__pyx_k_on_stop), 0, 0, 1, 1},
  {&__pyx_n_s_one_b, __pyx_k_one_b, sizeof(__pyx_k_one_b), 0, 0, 1, 1},
  {&__pyx_n_s_open, __pyx_k_open, sizeof(__pyx_k_open), 0, 0, 1, 1},
  {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1},
  {&__pyx_n_s_other, __pyx_k_other, sizeof(__pyx_k_other), 0, 0, 1, 1},
  {&__pyx_n_s_others, __pyx_k_others, sizeof(__pyx_k_others), 0, 0, 1, 1},
  {&__pyx_n_s_own, __pyx_k_own, sizeof(__pyx_k_own), 0, 0, 1, 1},
  {&__pyx_n_s_pack, __pyx_k_pack, sizeof(__pyx_k_pack), 0, 0, 1, 1},
  {&__pyx_n_s_peers, __pyx_k_peers, sizeof(__pyx_k_peers), 0, 0, 1, 1},
  {&__pyx_n_s_peers_2, __pyx_k_peers_2, sizeof(__pyx_k_peers_2), 0, 0, 1, 1},
  {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1},
  {&__pyx_n_b_ping, __pyx_k_ping, sizeof(__pyx_k_ping), 0, 0, 0, 1},
  {&__pyx_n_s_ping, __pyx_k_ping, sizeof(__pyx_k_ping), 0, 0, 1, 1},
  {&__pyx_n_s_pop, __pyx_k_pop, sizeof(__pyx_k_pop), 0, 0, 1, 1},
  {&__pyx_n_s_popitem, __pyx_k_popitem, sizeof(__pyx_k_popitem), 0, 0, 1, 1},
  {&__pyx_n_b_port, __pyx_k_port, sizeof(__pyx_k_port), 0, 0, 0, 1},
  {&__pyx_n_s_port, __pyx_k_port, sizeof(__pyx_k_port), 0, 0, 1, 1},
  {&__pyx_n_s_prefix, __pyx_k_prefix, sizeof(__pyx_k_prefix), 0, 0, 1, 1},
  {&__pyx_n_s_prefix0, __pyx_k_prefix0, sizeof(__pyx_k_prefix0), 0, 0, 1, 1},
  {&__pyx_n_s_prefix1, __pyx_k_prefix1, sizeof(__pyx_k_prefix1), 0, 0, 1, 1},
  {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1},
  {&__pyx_n_s_print, __pyx_k_print, sizeof(__pyx_k_print), 0, 0, 1, 1},
  {&__pyx_n_s_print_exc, __pyx_k_print_exc, sizeof(__pyx_k_print_exc), 0, 0, 1, 1},
  {&__pyx_n_s_process_error, __pyx_k_process_error, sizeof(__pyx_k_process_error), 0, 0, 1, 1},
  {&__pyx_n_s_process_loop, __pyx_k_process_loop, sizeof(__pyx_k_process_loop), 0, 0, 1, 1},
  {&__pyx_n_s_process_query, __pyx_k_process_query, sizeof(__pyx_k_process_query), 0, 0, 1, 1},
  {&__pyx_n_s_process_queue_size, __pyx_k_process_queue_size, sizeof(__pyx_k_process_queue_size), 0, 0, 1, 1},
  {&__pyx_n_s_process_response, __pyx_k_process_response, sizeof(__pyx_k_process_response), 0, 0, 1, 1},
  {&__pyx_n_s_property, __pyx_k_property, sizeof(__pyx_k_property), 0, 0, 1, 1},
  {&__pyx_n_s_put, __pyx_k_put, sizeof(__pyx_k_put), 0, 0, 1, 1},
  {&__pyx_n_s_put_nowait, __pyx_k_put_nowait, sizeof(__pyx_k_put_nowait), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_unpickle_DHT_BASE, __pyx_k_pyx_unpickle_DHT_BASE, sizeof(__pyx_k_pyx_unpickle_DHT_BASE), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_unpickle_Node, __pyx_k_pyx_unpickle_Node, sizeof(__pyx_k_pyx_unpickle_Node), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  {&__pyx_n_b_q, __pyx_k_q, sizeof(__pyx_k_q), 0, 0, 0, 1},
  {&__pyx_n_s_q, __pyx_k_q, sizeof(__pyx_k_q), 0, 0, 1, 1},
  {&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1},
  {&__pyx_n_s_query, __pyx_k_query, sizeof(__pyx_k_query), 0, 0, 1, 1},
  {&__pyx_n_s_questionable, __pyx_k_questionable, sizeof(__pyx_k_questionable), 0, 0, 1, 1},
  {&__pyx_n_s_queue, __pyx_k_queue, sizeof(__pyx_k_queue), 0, 0, 1, 1},
  {&__pyx_n_b_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 0, 1},
  {&__pyx_kp_s_r_2, __pyx_k_r_2, sizeof(__pyx_k_r_2), 0, 0, 1, 0},
  {&__pyx_kp_s_r_i_s_selfid_s_s_r_nodeid_d_r_r, __pyx_k_r_i_s_selfid_s_s_r_nodeid_d_r_r, sizeof(__pyx_k_r_i_s_selfid_s_s_r_nodeid_d_r_r), 0, 0, 1, 0},
  {&__pyx_kp_s_r_r, __pyx_k_r_r, sizeof(__pyx_k_r_r), 0, 0, 1, 0},
  {&__pyx_kp_s_r_r_not_in_bucket, __pyx_k_r_r_not_in_bucket, sizeof(__pyx_k_r_r_not_in_bucket), 0, 0, 1, 0},
  {&__pyx_n_s_randint, __pyx_k_randint, sizeof(__pyx_k_randint), 0, 0, 1, 1},
  {&__pyx_n_s_random, __pyx_k_random, sizeof(__pyx_k_random), 0, 0, 1, 1},
  {&__pyx_n_s_random_id, __pyx_k_random_id, sizeof(__pyx_k_random_id), 0, 0, 1, 1},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_rb, __pyx_k_rb, sizeof(__pyx_k_rb), 0, 0, 1, 1},
  {&__pyx_n_s_read, __pyx_k_read, sizeof(__pyx_k_read), 0, 0, 1, 1},
  {&__pyx_kp_s_recv_r, __pyx_k_recv_r, sizeof(__pyx_k_recv_r), 0, 0, 1, 0},
  {&__pyx_kp_s_recv_r_r_r, __pyx_k_recv_r_r_r, sizeof(__pyx_k_recv_r_r_r), 0, 0, 1, 0},
  {&__pyx_n_s_recvfrom, __pyx_k_recvfrom, sizeof(__pyx_k_recvfrom), 0, 0, 1, 1},
  {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1},
  {&__pyx_n_s_reduce_2, __pyx_k_reduce_2, sizeof(__pyx_k_reduce_2), 0, 0, 1, 1},
  {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1},
  {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1},
  {&__pyx_n_s_register_dht, __pyx_k_register_dht, sizeof(__pyx_k_register_dht), 0, 0, 1, 1},
  {&__pyx_n_s_register_torrent, __pyx_k_register_torrent, sizeof(__pyx_k_register_torrent), 0, 0, 1, 1},
  {&__pyx_n_s_register_torrent_longterm, __pyx_k_register_torrent_longterm, sizeof(__pyx_k_register_torrent_longterm), 0, 0, 1, 1},
  {&__pyx_n_s_release_dht, __pyx_k_release_dht, sizeof(__pyx_k_release_dht), 0, 0, 1, 1},
  {&__pyx_n_s_release_torrent, __pyx_k_release_torrent, sizeof(__pyx_k_release_torrent), 0, 0, 1, 1},
  {&__pyx_n_s_release_torrent_longterm, __pyx_k_release_torrent_longterm, sizeof(__pyx_k_release_torrent_longterm), 0, 0, 1, 1},
  {&__pyx_n_s_remove, __pyx_k_remove, sizeof(__pyx_k_remove), 0, 0, 1, 1},
  {&__pyx_n_s_response, __pyx_k_response, sizeof(__pyx_k_response), 0, 0, 1, 1},
  {&__pyx_n_s_richcmp, __pyx_k_richcmp, sizeof(__pyx_k_richcmp), 0, 0, 1, 1},
  {&__pyx_n_s_root, __pyx_k_root, sizeof(__pyx_k_root), 0, 0, 1, 1},
  {&__pyx_n_s_root_heigth, __pyx_k_root_heigth, sizeof(__pyx_k_root_heigth), 0, 0, 1, 1},
  {&__pyx_kp_s_router_bittorrent_com, __pyx_k_router_bittorrent_com, sizeof(__pyx_k_router_bittorrent_com), 0, 0, 1, 0},
  {&__pyx_kp_s_router_utorrent_com, __pyx_k_router_utorrent_com, sizeof(__pyx_k_router_utorrent_com), 0, 0, 1, 0},
  {&__pyx_n_s_routine, __pyx_k_routine, sizeof(__pyx_k_routine), 0, 0, 1, 1},
  {&__pyx_n_s_routing_table, __pyx_k_routing_table, sizeof(__pyx_k_routing_table), 0, 0, 1, 1},
  {&__pyx_n_s_rt, __pyx_k_rt, sizeof(__pyx_k_rt), 0, 0, 1, 1},
  {&__pyx_n_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 1},
  {&__pyx_kp_s_s_gone_away_while_merging, __pyx_k_s_gone_away_while_merging, sizeof(__pyx_k_s_gone_away_while_merging), 0, 0, 1, 0},
  {&__pyx_kp_s_s_nodes_added_to_routing_table, __pyx_k_s_nodes_added_to_routing_table, sizeof(__pyx_k_s_nodes_added_to_routing_table), 0, 0, 1, 0},
  {&__pyx_kp_s_s_nodes_merged_in_ss, __pyx_k_s_nodes_merged_in_ss, sizeof(__pyx_k_s_nodes_merged_in_ss), 0, 0, 1, 0},
  {&__pyx_kp_s_s_not_comparable_with_s, __pyx_k_s_not_comparable_with_s, sizeof(__pyx_k_s_not_comparable_with_s), 0, 0, 1, 0},
  {&__pyx_n_s_scheduler, __pyx_k_scheduler, sizeof(__pyx_k_scheduler), 0, 0, 1, 1},
  {&__pyx_n_s_scheduler_2, __pyx_k_scheduler_2, sizeof(__pyx_k_scheduler_2), 0, 0, 1, 1},
  {&__pyx_n_s_select, __pyx_k_select, sizeof(__pyx_k_select), 0, 0, 1, 1},
  {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1},
  {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1},
  {&__pyx_kp_s_send_r_r, __pyx_k_send_r_r, sizeof(__pyx_k_send_r_r), 0, 0, 1, 0},
  {&__pyx_kp_s_send_r_r_r, __pyx_k_send_r_r_r, sizeof(__pyx_k_send_r_r_r), 0, 0, 1, 0},
  {&__pyx_n_s_sendto, __pyx_k_sendto, sizeof(__pyx_k_sendto), 0, 0, 1, 1},
  {&__pyx_n_s_setblocking, __pyx_k_setblocking, sizeof(__pyx_k_setblocking), 0, 0, 1, 1},
  {&__pyx_n_s_setsockopt, __pyx_k_setsockopt, sizeof(__pyx_k_setsockopt), 0, 0, 1, 1},
  {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1},
  {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1},
  {&__pyx_kp_s_sget_peers_closest_loop, __pyx_k_sget_peers_closest_loop, sizeof(__pyx_k_sget_peers_closest_loop), 0, 0, 1, 0},
  {&__pyx_n_s_shuffle, __pyx_k_shuffle, sizeof(__pyx_k_shuffle), 0, 0, 1, 1},
  {&__pyx_n_s_six, __pyx_k_six, sizeof(__pyx_k_six), 0, 0, 1, 1},
  {&__pyx_n_s_sleep, __pyx_k_sleep, sizeof(__pyx_k_sleep), 0, 0, 1, 1},
  {&__pyx_n_s_slot, __pyx_k_slot, sizeof(__pyx_k_slot), 0, 0, 1, 1},
  {&__pyx_n_s_sock, __pyx_k_sock, sizeof(__pyx_k_sock), 0, 0, 1, 1},
  {&__pyx_n_s_socket, __pyx_k_socket, sizeof(__pyx_k_socket), 0, 0, 1, 1},
  {&__pyx_n_s_socket_in, __pyx_k_socket_in, sizeof(__pyx_k_socket_in), 0, 0, 1, 1},
  {&__pyx_n_s_socket_out, __pyx_k_socket_out, sizeof(__pyx_k_socket_out), 0, 0, 1, 1},
  {&__pyx_n_s_socket_stats, __pyx_k_socket_stats, sizeof(__pyx_k_socket_stats), 0, 0, 1, 1},
  {&__pyx_n_s_sort, __pyx_k_sort, sizeof(__pyx_k_sort), 0, 0, 1, 1},
  {&__pyx_n_s_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1},
  {&__pyx_n_s_split_ids, __pyx_k_split_ids, sizeof(__pyx_k_split_ids), 0, 0, 1, 1},
  {&__pyx_kp_s_sprocess_loop, __pyx_k_sprocess_loop, sizeof(__pyx_k_sprocess_loop), 0, 0, 1, 0},
  {&__pyx_kp_s_sroutine, __pyx_k_sroutine, sizeof(__pyx_k_sroutine), 0, 0, 1, 0},
  {&__pyx_n_s_stack, __pyx_k_stack, sizeof(__pyx_k_stack), 0, 0, 1, 1},
  {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
  {&__pyx_n_s_start_routing_table, __pyx_k_start_routing_table, sizeof(__pyx_k_start_routing_table), 0, 0, 1, 1},
  {&__pyx_n_s_start_scheduler, __pyx_k_start_scheduler, sizeof(__pyx_k_start_scheduler), 0, 0, 1, 1},
  {&__pyx_n_s_started, __pyx_k_started, sizeof(__pyx_k_started), 0, 0, 1, 1},
  {&__pyx_n_s_startswith, __pyx_k_startswith, sizeof(__pyx_k_startswith), 0, 0, 1, 1},
  {&__pyx_n_s_stats, __pyx_k_stats, sizeof(__pyx_k_stats), 0, 0, 1, 1},
  {&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1},
  {&__pyx_n_s_stop_bg, __pyx_k_stop_bg, sizeof(__pyx_k_stop_bg), 0, 0, 1, 1},
  {&__pyx_n_s_stoped, __pyx_k_stoped, sizeof(__pyx_k_stoped), 0, 0, 1, 1},
  {&__pyx_n_s_stoped_2, __pyx_k_stoped_2, sizeof(__pyx_k_stoped_2), 0, 0, 1, 1},
  {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0},
  {&__pyx_n_s_struct, __pyx_k_struct, sizeof(__pyx_k_struct), 0, 0, 1, 1},
  {&__pyx_n_s_suffix, __pyx_k_suffix, sizeof(__pyx_k_suffix), 0, 0, 1, 1},
  {&__pyx_n_s_suffixes, __pyx_k_suffixes, sizeof(__pyx_k_suffixes), 0, 0, 1, 1},
  {&__pyx_n_s_super, __pyx_k_super, sizeof(__pyx_k_super), 0, 0, 1, 1},
  {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1},
  {&__pyx_n_s_t, __pyx_k_t, sizeof(__pyx_k_t), 0, 0, 1, 1},
  {&__pyx_n_b_target, __pyx_k_target, sizeof(__pyx_k_target), 0, 0, 0, 1},
  {&__pyx_n_s_target, __pyx_k_target, sizeof(__pyx_k_target), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_text_type, __pyx_k_text_type, sizeof(__pyx_k_text_type), 0, 0, 1, 1},
  {&__pyx_n_s_thread_alive, __pyx_k_thread_alive, sizeof(__pyx_k_thread_alive), 0, 0, 1, 1},
  {&__pyx_n_s_threading, __pyx_k_threading, sizeof(__pyx_k_threading), 0, 0, 1, 1},
  {&__pyx_n_s_threads, __pyx_k_threads, sizeof(__pyx_k_threads), 0, 0, 1, 1},
  {&__pyx_n_s_threads_2, __pyx_k_threads_2, sizeof(__pyx_k_threads_2), 0, 0, 1, 1},
  {&__pyx_n_s_threads_zombie, __pyx_k_threads_zombie, sizeof(__pyx_k_threads_zombie), 0, 0, 1, 1},
  {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1},
  {&__pyx_n_s_time, __pyx_k_time, sizeof(__pyx_k_time), 0, 0, 1, 1},
  {&__pyx_n_s_tmp, __pyx_k_tmp, sizeof(__pyx_k_tmp), 0, 0, 1, 1},
  {&__pyx_n_s_to_bytes, __pyx_k_to_bytes, sizeof(__pyx_k_to_bytes), 0, 0, 1, 1},
  {&__pyx_n_s_to_merge, __pyx_k_to_merge, sizeof(__pyx_k_to_merge), 0, 0, 1, 1},
  {&__pyx_n_s_to_merge_2, __pyx_k_to_merge_2, sizeof(__pyx_k_to_merge_2), 0, 0, 1, 1},
  {&__pyx_n_s_to_process, __pyx_k_to_process, sizeof(__pyx_k_to_process), 0, 0, 1, 1},
  {&__pyx_n_s_to_process_registered, __pyx_k_to_process_registered, sizeof(__pyx_k_to_process_registered), 0, 0, 1, 1},
  {&__pyx_n_s_to_refresh, __pyx_k_to_refresh, sizeof(__pyx_k_to_refresh), 0, 0, 1, 1},
  {&__pyx_n_s_to_schedule, __pyx_k_to_schedule, sizeof(__pyx_k_to_schedule), 0, 0, 1, 1},
  {&__pyx_n_s_to_send, __pyx_k_to_send, sizeof(__pyx_k_to_send), 0, 0, 1, 1},
  {&__pyx_n_b_token, __pyx_k_token, sizeof(__pyx_k_token), 0, 0, 0, 1},
  {&__pyx_n_s_token, __pyx_k_token, sizeof(__pyx_k_token), 0, 0, 1, 1},
  {&__pyx_n_s_total_ordering, __pyx_k_total_ordering, sizeof(__pyx_k_total_ordering), 0, 0, 1, 1},
  {&__pyx_n_s_traceback, __pyx_k_traceback, sizeof(__pyx_k_traceback), 0, 0, 1, 1},
  {&__pyx_n_s_transaction_type, __pyx_k_transaction_type, sizeof(__pyx_k_transaction_type), 0, 0, 1, 1},
  {&__pyx_n_s_trie, __pyx_k_trie, sizeof(__pyx_k_trie), 0, 0, 1, 1},
  {&__pyx_kp_s_trie_changed_while_merging, __pyx_k_trie_changed_while_merging, sizeof(__pyx_k_trie_changed_while_merging), 0, 0, 1, 0},
  {&__pyx_kp_s_trie_changed_while_splitting, __pyx_k_trie_changed_while_splitting, sizeof(__pyx_k_trie_changed_while_splitting), 0, 0, 1, 0},
  {&__pyx_n_s_typ, __pyx_k_typ, sizeof(__pyx_k_typ), 0, 0, 1, 1},
  {&__pyx_kp_s_typ_should_not_be_s, __pyx_k_typ_should_not_be_s, sizeof(__pyx_k_typ_should_not_be_s), 0, 0, 1, 0},
  {&__pyx_n_s_union, __pyx_k_union, sizeof(__pyx_k_union), 0, 0, 1, 1},
  {&__pyx_n_s_unpack, __pyx_k_unpack, sizeof(__pyx_k_unpack), 0, 0, 1, 1},
  {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1},
  {&__pyx_n_s_update_node, __pyx_k_update_node, sizeof(__pyx_k_update_node), 0, 0, 1, 1},
  {&__pyx_n_s_urandom, __pyx_k_urandom, sizeof(__pyx_k_urandom), 0, 0, 1, 1},
  {&__pyx_n_s_utils, __pyx_k_utils, sizeof(__pyx_k_utils), 0, 0, 1, 1},
  {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1},
  {&__pyx_n_b_values, __pyx_k_values, sizeof(__pyx_k_values), 0, 0, 0, 1},
  {&__pyx_n_s_values, __pyx_k_values, sizeof(__pyx_k_values), 0, 0, 1, 1},
  {&__pyx_n_s_wb, __pyx_k_wb, sizeof(__pyx_k_wb), 0, 0, 1, 1},
  {&__pyx_n_s_weigthless_threads_satus, __pyx_k_weigthless_threads_satus, sizeof(__pyx_k_weigthless_threads_satus), 0, 0, 1, 1},
  {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1},
  {&__pyx_n_s_y, __pyx_k_y, sizeof(__pyx_k_y), 0, 0, 1, 1},
  {&__pyx_n_s_zero_b, __pyx_k_zero_b, sizeof(__pyx_k_zero_b), 0, 0, 1, 1},
  {&__pyx_n_s_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1},
  {&__pyx_n_s_zombie, __pyx_k_zombie, sizeof(__pyx_k_zombie), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(0, 30, __pyx_L1_error)
  __pyx_builtin_property = __Pyx_GetBuiltinName(__pyx_n_s_property); if (!__pyx_builtin_property) __PYX_ERR(0, 1920, __pyx_L1_error)
  __pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) __PYX_ERR(0, 2124, __pyx_L1_error)
  __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(0, 174, __pyx_L1_error)
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 181, __pyx_L1_error)
  __pyx_builtin_open = __Pyx_GetBuiltinName(__pyx_n_s_open); if (!__pyx_builtin_open) __PYX_ERR(0, 252, __pyx_L1_error)
  __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 285, __pyx_L1_error)
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 313, __pyx_L1_error)
  __pyx_builtin_all = __Pyx_GetBuiltinName(__pyx_n_s_all); if (!__pyx_builtin_all) __PYX_ERR(0, 394, __pyx_L1_error)
  __pyx_builtin_any = __Pyx_GetBuiltinName(__pyx_n_s_any); if (!__pyx_builtin_any) __PYX_ERR(0, 398, __pyx_L1_error)
  __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 455, __pyx_L1_error)
  __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 633, __pyx_L1_error)
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 934, __pyx_L1_error)
  __pyx_builtin_UnboundLocalError = __Pyx_GetBuiltinName(__pyx_n_s_UnboundLocalError); if (!__pyx_builtin_UnboundLocalError) __PYX_ERR(0, 979, __pyx_L1_error)
  __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(0, 1557, __pyx_L1_error)
  __pyx_builtin_EnvironmentError = __Pyx_GetBuiltinName(__pyx_n_s_EnvironmentError); if (!__pyx_builtin_EnvironmentError) __PYX_ERR(0, 1794, __pyx_L1_error)
  __pyx_builtin_super = __Pyx_GetBuiltinName(__pyx_n_s_super); if (!__pyx_builtin_super) __PYX_ERR(0, 1956, __pyx_L1_error)
  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 2088, __pyx_L1_error)
  __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) __PYX_ERR(0, 2449, __pyx_L1_error)
  __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_n_s_max); if (!__pyx_builtin_max) __PYX_ERR(0, 2677, __pyx_L1_error)
  __pyx_builtin_OverflowError = __Pyx_GetBuiltinName(__pyx_n_s_OverflowError); if (!__pyx_builtin_OverflowError) __PYX_ERR(1, 81, __pyx_L1_error)
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(1, 84, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "btdht/dht.pyx":174
 *     ):
 *         if self.__class__ == DHT_BASE:
 *             raise RuntimeError(             # <<<<<<<<<<<<<<
 *                 "DHT_BASE cannot be directly instantiated, use DHT instead or any subclass that"
 *                 " may have be defined"
 */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_DHT_BASE_cannot_be_directly_inst); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 174, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);

  /* "btdht/dht.pyx":181
 *         if id is not None:
 *             if len(id) != 20:
 *                 raise ValueError("id must be 20 char long")             # <<<<<<<<<<<<<<
 *             id = ID.to_bytes(id)
 *         else:
 */
  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_id_must_be_20_char_long); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);

  /* "btdht/dht.pyx":252
 *             myid = binascii.b2a_hex(self.myid.value)
 *             filename = "dht_%s.status" % myid
 *         with open(filename, 'wb') as f:             # <<<<<<<<<<<<<<
 *             for bucket in self.root.trie.values():
 *                 for node in bucket:
 */
  __pyx_tuple__5 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 252, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);

  /* "btdht/dht.pyx":306
 *         """
 *         if self.stoped:
 *             self.debug(0, "Already stoped or stoping in progress")             # <<<<<<<<<<<<<<
 *             return
 *         self._scheduler.del_dht(self)
 */
  __pyx_tuple__6 = PyTuple_Pack(2, __pyx_int_0, __pyx_kp_s_Already_stoped_or_stoping_in_pro); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 306, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);

  /* "btdht/dht.pyx":311
 *         self.root.release_dht(self)
 *         self.stoped = True
 *         self._threads = [t for t in self._threads[:] if t.is_alive()]             # <<<<<<<<<<<<<<
 *         #self.debug(0, "Trying to terminate thread for 1 minutes")
 *         for i in range(0, 30):
 */
  __pyx_slice__7 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__7)) __PYX_ERR(0, 311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__7);
  __Pyx_GIVEREF(__pyx_slice__7);

  /* "btdht/dht.pyx":357
 *         """
 *         if not self.stoped:
 *             self.debug(0, "Already started")             # <<<<<<<<<<<<<<
 *             return
 *         if self.zombie:
 */
  __pyx_tuple__8 = PyTuple_Pack(2, __pyx_int_0, __pyx_kp_s_Already_started); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);

  /* "btdht/dht.pyx":360
 *             return
 *         if self.zombie:
 *             self.debug(0, "Zombie threads, unable de start")             # <<<<<<<<<<<<<<
 *             return self._threads_zombie
 * 
 */
  __pyx_tuple__9 = PyTuple_Pack(2, __pyx_int_0, __pyx_kp_s_Zombie_threads_unable_de_start); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 360, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__9);
  __Pyx_GIVEREF(__pyx_tuple__9);

  /* "btdht/dht.pyx":401
 *             return False
 *         else:
 *             self.debug(0, "One thread died, stopping dht")             # <<<<<<<<<<<<<<
 *             self.stop_bg()
 *             return False
 */
  __pyx_tuple__10 = PyTuple_Pack(2, __pyx_int_0, __pyx_kp_s_One_thread_died_stopping_dht); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 401, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "btdht/dht.pyx":505
 *                 closest nodes. Otherwise, return immediately.
 *         """
 *         def callback(nodes):             # <<<<<<<<<<<<<<
 *             for node in nodes:
 *                 try:
 */
  __pyx_tuple__11 = PyTuple_Pack(2, __pyx_n_s_nodes, __pyx_n_s_node); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 505, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);
  __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_callback, 505, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 505, __pyx_L1_error)

  /* "btdht/dht.pyx":629
 *         """
 *         yield 0
 *         def on_stop(hash, typ):             # <<<<<<<<<<<<<<
 *             self.root.release_torrent(hash)
 *             if typ == "peers":
 */
  __pyx_tuple__13 = PyTuple_Pack(2, __pyx_n_s_hash, __pyx_n_s_typ); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 629, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__13);
  __Pyx_GIVEREF(__pyx_tuple__13);
  __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_on_stop, 629, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 629, __pyx_L1_error)

  /* "btdht/dht.pyx":638
 *                 except KeyError: pass
 * 
 *         def stop():             # <<<<<<<<<<<<<<
 *             while self._get_peer_loop_list:
 *                 (_, hash, _, _, typ, _, _) = heapq.heappop(self._get_peer_loop_list)
 */
  __pyx_tuple__16 = PyTuple_Pack(3, __pyx_n_s__15, __pyx_n_s_hash, __pyx_n_s_typ); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 638, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);
  __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__16, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_stop, 638, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(0, 638, __pyx_L1_error)

  /* "btdht/dht.pyx":828
 *                     * grenade.genua.fr:6880
 *         """
 *         self.debug(0,"Bootstraping")             # <<<<<<<<<<<<<<
 *         for addr in addresses:
 *             msg = BMessage()
 */
  __pyx_tuple__19 = PyTuple_Pack(2, __pyx_int_0, __pyx_n_s_Bootstraping); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 828, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__19);
  __Pyx_GIVEREF(__pyx_tuple__19);

  /* "btdht/dht.pyx":864
 *                     node.failed = 0
 *             else:
 *                 self.debug(1, "obj without id, no node update")             # <<<<<<<<<<<<<<
 *         else:
 *             self.debug(2, "obj of type %r" % obj.y)
 */
  __pyx_tuple__20 = PyTuple_Pack(2, __pyx_int_1, __pyx_kp_s_obj_without_id_no_node_update); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 864, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);

  /* "btdht/dht.pyx":1186
 *             # Searching its own id while the Routing table is growing
 *             if self._root_heigth != self.root.heigth():
 *                 self.debug(1, "Fetching my own id")             # <<<<<<<<<<<<<<
 *                 if self.build_table():
 *                     self._root_heigth = self.root.heigth()
 */
  __pyx_tuple__21 = PyTuple_Pack(2, __pyx_int_1, __pyx_kp_s_Fetching_my_own_id); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 1186, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);

  /* "btdht/dht.pyx":1355
 *             :param krcp.BMessage response: the received response object
 *         """
 *         nodes = Node.from_compact_infos(response.get(b"nodes", b""))             # <<<<<<<<<<<<<<
 *         for node in nodes:
 *             try:
 */
  __pyx_tuple__22 = PyTuple_Pack(2, __pyx_n_b_nodes, __pyx_kp_b__2); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 1355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);

  /* "btdht/dht.pyx":1374
 *         if token:
 *             self.mytoken[response[b"id"]]=(token, time.time())
 *         for node in Node.from_compact_infos(response.get(b"nodes", "")):             # <<<<<<<<<<<<<<
 *             self.root.add(self, node)
 *         for ipport in response.get(b"values", []):
 */
  __pyx_tuple__23 = PyTuple_Pack(2, __pyx_n_b_nodes, __pyx_kp_s__2); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 1374, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);

  /* "btdht/dht.pyx":1422
 *         """
 *         try:
 *             if query.get(b"implied_port", 0) != 0:             # <<<<<<<<<<<<<<
 *                 if query.addr[1] > 0 and query.addr[1] < 65536:
 *                     self._add_peer(
 */
  __pyx_tuple__24 = PyTuple_Pack(2, __pyx_n_b_implied_port, __pyx_int_0); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 1422, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);

  /* "btdht/dht.pyx":1458
 *                 self._to_process.put_nowait((query, obj))
 *             except Queue.Full:
 *                 self.debug(0, "Unable to queue msg to be processed, QueueFull")             # <<<<<<<<<<<<<<
 * 
 *     def _process_response(self, obj, query):
 */
  __pyx_tuple__25 = PyTuple_Pack(2, __pyx_int_0, __pyx_kp_s_Unable_to_queue_msg_to_be_proces); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 1458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__25);
  __Pyx_GIVEREF(__pyx_tuple__25);

  /* "btdht/dht.pyx":1762
 *         length = len(infos)
 *         if length//26*26 != length:
 *             raise ValueError(b"nodes length should be a multiple of 26")             # <<<<<<<<<<<<<<
 *         i=0
 *         while i < length:
 */
  __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_b_nodes_length_should_be_a_multipl); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 1762, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);

  /* "btdht/dht.pyx":1794
 *         """
 *         if len(info) != 26:
 *             raise EnvironmentError("compact node info should be 26 chars long")             # <<<<<<<<<<<<<<
 *         (id, ip, port) = struct.unpack("!20s4sH", info)
 *         ip = socket.inet_ntoa(ip)
 */
  __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_compact_node_info_should_be_26_c); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 1794, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);

  /* "btdht/dht.pyx":2015
 *         """
 *         if not self.own(node.id):
 *             raise ValueError("Wrong Bucket")             # <<<<<<<<<<<<<<
 *         elif node in self:
 *             try:
 */
  __pyx_tuple__31 = PyTuple_Pack(1, __pyx_kp_s_Wrong_Bucket); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 2015, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__31);
  __Pyx_GIVEREF(__pyx_tuple__31);

  /* "btdht/dht.pyx":2297
 *                     pass
 *                 if not self.need_merge:
 *                     self.debug(1, "Programming merge")             # <<<<<<<<<<<<<<
 *                     self.need_merge = True
 *         except KeyError:
 */
  __pyx_tuple__32 = PyTuple_Pack(2, __pyx_int_1, __pyx_kp_s_Programming_merge); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 2297, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);

  /* "btdht/dht.pyx":2536
 *                 prefix = u""
 *             while len(nodes) < Bucket.max_size and prefix:
 *                 prefix = prefix[:-1]             # <<<<<<<<<<<<<<
 *                 for suffix in self.trie.suffixes(prefix):
 *                     nodes = nodes.union(n for n in self.trie[prefix + suffix] if bad or not n.bad)
 */
  __pyx_slice__35 = PySlice_New(Py_None, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__35)) __PYX_ERR(0, 2536, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__35);
  __Pyx_GIVEREF(__pyx_slice__35);

  /* "btdht/dht.pyx":2603
 *             del self.trie[prefix]
 *         except KeyError:
 *             self.debug(2, "trie changed while splitting")             # <<<<<<<<<<<<<<
 *         except BucketNotFull as e:
 *             self.debug(1, "%r" % e)
 */
  __pyx_tuple__36 = PyTuple_Pack(2, __pyx_int_2, __pyx_kp_s_trie_changed_while_splitting); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 2603, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);

  /* "btdht/dht.pyx":2627
 *             nodes_before = self.stats()[0]
 *             if nodes_before < 1000:
 *                 self.debug(1, "Less than 1000 nodes, no merge")             # <<<<<<<<<<<<<<
 *                 return
 *             started = time.time()
 */
  __pyx_tuple__38 = PyTuple_Pack(2, __pyx_int_1, __pyx_kp_s_Less_than_1000_nodes_no_merge); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 2627, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__38);
  __Pyx_GIVEREF(__pyx_tuple__38);

  /* "btdht/dht.pyx":2669
 *                     stack.append(key[:-1])
 *                 except KeyError:
 *                     self.debug(0, "trie changed while merging")             # <<<<<<<<<<<<<<
 * 
 *                 i += 1
 */
  __pyx_tuple__39 = PyTuple_Pack(2, __pyx_int_0, __pyx_kp_s_trie_changed_while_merging); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 2669, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);

  /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0x4d4fbc6, 0xd7ddd24, 0xf626de7):             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError("Incompatible checksums (0x%x vs (0x4d4fbc6, 0xd7ddd24, 0xf626de7) = (_myid))" % __pyx_checksum)
 */
  __pyx_tuple__40 = PyTuple_Pack(3, __pyx_int_81066950, __pyx_int_226352420, __pyx_int_258108903); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__40);
  __Pyx_GIVEREF(__pyx_tuple__40);
  __pyx_tuple__41 = PyTuple_Pack(3, __pyx_int_238925605, __pyx_int_15399060, __pyx_int_218572978); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(1, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);

  /* "btdht/dht.pyx":812
 *         self,
 *         addresses=[
 *             ("router.utorrent.com", 6881),             # <<<<<<<<<<<<<<
 *             ("router.bittorrent.com", 6881),
 *             ("grenade.genua.fr", 6880),
 */
  __pyx_tuple__42 = PyTuple_Pack(2, __pyx_kp_s_router_utorrent_com, __pyx_int_6881); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 812, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);

  /* "btdht/dht.pyx":813
 *         addresses=[
 *             ("router.utorrent.com", 6881),
 *             ("router.bittorrent.com", 6881),             # <<<<<<<<<<<<<<
 *             ("grenade.genua.fr", 6880),
 *             ("dht.transmissionbt.com", 6881)
 */
  __pyx_tuple__43 = PyTuple_Pack(2, __pyx_kp_s_router_bittorrent_com, __pyx_int_6881); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__43);
  __Pyx_GIVEREF(__pyx_tuple__43);

  /* "btdht/dht.pyx":814
 *             ("router.utorrent.com", 6881),
 *             ("router.bittorrent.com", 6881),
 *             ("grenade.genua.fr", 6880),             # <<<<<<<<<<<<<<
 *             ("dht.transmissionbt.com", 6881)
 *         ]
 */
  __pyx_tuple__44 = PyTuple_Pack(2, __pyx_kp_s_grenade_genua_fr, __pyx_int_6880); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 814, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);

  /* "btdht/dht.pyx":815
 *             ("router.bittorrent.com", 6881),
 *             ("grenade.genua.fr", 6880),
 *             ("dht.transmissionbt.com", 6881)             # <<<<<<<<<<<<<<
 *         ]
 *     ):
 */
  __pyx_tuple__45 = PyTuple_Pack(2, __pyx_kp_s_dht_transmissionbt_com, __pyx_int_6881); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 815, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__45);
  __Pyx_GIVEREF(__pyx_tuple__45);

  /* "btdht/dht.pyx":1921
 * 
 *     @property
 *     def to_refresh(self):             # <<<<<<<<<<<<<<
 *         """``True`` if the bucket need refreshing"""
 *         return time.time() - self.last_changed > 15 * 60
 */
  __pyx_tuple__46 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(0, 1921, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__46);
  __Pyx_GIVEREF(__pyx_tuple__46);
  __pyx_codeobj__47 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__46, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_to_refresh, 1921, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__47)) __PYX_ERR(0, 1921, __pyx_L1_error)

  /* "btdht/dht.pyx":1925
 *         return time.time() - self.last_changed > 15 * 60
 * 
 *     __slot__ = ("id", "id_length")             # <<<<<<<<<<<<<<
 * 
 *     def own(self, id):
 */
  __pyx_tuple__48 = PyTuple_Pack(2, __pyx_n_s_id, __pyx_n_s_id_length); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 1925, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__48);
  __Pyx_GIVEREF(__pyx_tuple__48);

  /* "btdht/dht.pyx":1927
 *     __slot__ = ("id", "id_length")
 * 
 *     def own(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             :param bytes id: A 60bit (20 Bytes) identifier
 */
  __pyx_tuple__49 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_id, __pyx_n_s_i, __pyx_n_s_e); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 1927, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__49);
  __Pyx_GIVEREF(__pyx_tuple__49);
  __pyx_codeobj__50 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__49, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_own, 1927, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__50)) __PYX_ERR(0, 1927, __pyx_L1_error)

  /* "btdht/dht.pyx":1952
 *             return False
 * 
 *     def __init__(self, id=b"", id_length=0, init=None):             # <<<<<<<<<<<<<<
 *         self.id = id
 *         self.id_length = id_length # en bit
 */
  __pyx_tuple__51 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_id, __pyx_n_s_id_length, __pyx_n_s_init); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 1952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__51);
  __Pyx_GIVEREF(__pyx_tuple__51);
  __pyx_codeobj__52 = (PyObject*)__Pyx_PyCode_New(4, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__51, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_init_2, 1952, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__52)) __PYX_ERR(0, 1952, __pyx_L1_error)
  __pyx_tuple__53 = PyTuple_Pack(3, ((PyObject*)__pyx_kp_b__2), ((PyObject *)__pyx_int_0), ((PyObject *)Py_None)); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 1952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__53);
  __Pyx_GIVEREF(__pyx_tuple__53);

  /* "btdht/dht.pyx":1958
 *             super(Bucket, self).__init__(init)
 * 
 *     def random_id(self):             # <<<<<<<<<<<<<<
 *         """
 *             :return: A random id handle by the bucket
 */
  __pyx_tuple__54 = PyTuple_Pack(8, __pyx_n_s_self, __pyx_n_s_id, __pyx_n_s_id_length, __pyx_n_s_id_end, __pyx_n_s_tmp, __pyx_n_s_id_start, __pyx_n_s_i, __pyx_n_s_char); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(0, 1958, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__54);
  __Pyx_GIVEREF(__pyx_tuple__54);
  __pyx_codeobj__55 = (PyObject*)__Pyx_PyCode_New(1, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__54, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_random_id, 1958, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__55)) __PYX_ERR(0, 1958, __pyx_L1_error)

  /* "btdht/dht.pyx":1985
 *         return ID(self.id[0:id_length//8] + char + id[id_length//8+1:])
 * 
 *     def get_node(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             :return: A :class:`Node` with :attr:`Node.id` equal to ``id``
 */
  __pyx_tuple__56 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_id, __pyx_n_s_n); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(0, 1985, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__56);
  __Pyx_GIVEREF(__pyx_tuple__56);
  __pyx_codeobj__57 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__56, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_get_node, 1985, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__57)) __PYX_ERR(0, 1985, __pyx_L1_error)

  /* "btdht/dht.pyx":1996
 *         raise NotFound()
 * 
 *     def add(self, dht, node):             # <<<<<<<<<<<<<<
 *         """
 *             Try to add a node to the bucket.
 */
  __pyx_tuple__58 = PyTuple_Pack(6, __pyx_n_s_self, __pyx_n_s_dht, __pyx_n_s_node, __pyx_n_s_old_node, __pyx_n_s_n, __pyx_n_s_l); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(0, 1996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__58);
  __Pyx_GIVEREF(__pyx_tuple__58);
  __pyx_codeobj__59 = (PyObject*)__Pyx_PyCode_New(3, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__58, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_add, 1996, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__59)) __PYX_ERR(0, 1996, __pyx_L1_error)

  /* "btdht/dht.pyx":2044
 *             raise BucketFull()
 * 
 *     def split(self, rt, dht):             # <<<<<<<<<<<<<<
 *         """
 *             Split the bucket into two buckets
 */
  __pyx_tuple__60 = PyTuple_Pack(7, __pyx_n_s_self, __pyx_n_s_rt, __pyx_n_s_dht, __pyx_n_s_new_id, __pyx_n_s_b1, __pyx_n_s_b2, __pyx_n_s_node); if (unlikely(!__pyx_tuple__60)) __PYX_ERR(0, 2044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__60);
  __Pyx_GIVEREF(__pyx_tuple__60);
  __pyx_codeobj__61 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__60, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_split, 2044, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__61)) __PYX_ERR(0, 2044, __pyx_L1_error)

  /* "btdht/dht.pyx":2080
 *             return (b2, b1)
 * 
 *     def merge(self, bucket):             # <<<<<<<<<<<<<<
 *         """
 *             Merge the bucket with ``bucket``
 */
  __pyx_tuple__62 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_bucket, __pyx_n_s_l, __pyx_n_s_n); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(0, 2080, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__62);
  __Pyx_GIVEREF(__pyx_tuple__62);
  __pyx_codeobj__63 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__62, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_merge_2, 2080, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__63)) __PYX_ERR(0, 2080, __pyx_L1_error)

  /* "btdht/dht.pyx":2091
 *         return Bucket(id=self.id, id_length=self.id_length - 1, init=l)
 * 
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         return hash(utils.id_to_longid(ID.to_bytes(self.id))[:self.id_length])
 * 
 */
  __pyx_tuple__64 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(0, 2091, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__64);
  __Pyx_GIVEREF(__pyx_tuple__64);
  __pyx_codeobj__65 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__64, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_hash_2, 2091, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__65)) __PYX_ERR(0, 2091, __pyx_L1_error)

  /* "btdht/dht.pyx":2094
 *         return hash(utils.id_to_longid(ID.to_bytes(self.id))[:self.id_length])
 * 
 *     def __eq__(self, other):             # <<<<<<<<<<<<<<
 *         try:
 *             return self.id_length == other.id_length and self.id == other.id
 */
  __pyx_tuple__66 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_other, __pyx_n_s_e); if (unlikely(!__pyx_tuple__66)) __PYX_ERR(0, 2094, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__66);
  __Pyx_GIVEREF(__pyx_tuple__66);
  __pyx_codeobj__67 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__66, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_eq, 2094, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__67)) __PYX_ERR(0, 2094, __pyx_L1_error)

  /* "btdht/dht.pyx":2101
 *             return False
 * 
 *     def __lt__(self, other):             # <<<<<<<<<<<<<<
 *         try:
 *             if self.id_length == other.id_length:
 */
  __pyx_tuple__68 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__68)) __PYX_ERR(0, 2101, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__68);
  __Pyx_GIVEREF(__pyx_tuple__68);
  __pyx_codeobj__69 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__68, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_lt, 2101, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__69)) __PYX_ERR(0, 2101, __pyx_L1_error)

  /* "btdht/dht.pyx":2118
 *     {
 *         '__doc__': "\n    A DHT class ready for instanciation\n%s" % (
 *             "\n".join(DHT_BASE.__doc__.split('\n')[2:]),             # <<<<<<<<<<<<<<
 *         )
 *     }
 */
  __pyx_tuple__71 = PyTuple_Pack(1, __pyx_kp_s__70); if (unlikely(!__pyx_tuple__71)) __PYX_ERR(0, 2118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__71);
  __Pyx_GIVEREF(__pyx_tuple__71);
  __pyx_slice__72 = PySlice_New(__pyx_int_2, Py_None, Py_None); if (unlikely(!__pyx_slice__72)) __PYX_ERR(0, 2118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__72);
  __Pyx_GIVEREF(__pyx_slice__72);

  /* "btdht/dht.pyx":2124
 * 
 * 
 * class RoutingTable(object):             # <<<<<<<<<<<<<<
 *     """
 *         A routing table for one or more :class:`DHT_BASE` instances
 */
  __pyx_tuple__73 = PyTuple_Pack(1, __pyx_builtin_object); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(0, 2124, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__73);
  __Pyx_GIVEREF(__pyx_tuple__73);

  /* "btdht/dht.pyx":2169
 *     _lock = None
 * 
 *     def __init__(self, scheduler, debuglvl=0, prefix=""):             # <<<<<<<<<<<<<<
 *         self.debuglvl = debuglvl
 *         self.trie = datrie.Trie(u"01")
 */
  __pyx_tuple__74 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_scheduler, __pyx_n_s_debuglvl, __pyx_n_s_prefix); if (unlikely(!__pyx_tuple__74)) __PYX_ERR(0, 2169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__74);
  __Pyx_GIVEREF(__pyx_tuple__74);
  __pyx_codeobj__75 = (PyObject*)__Pyx_PyCode_New(4, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__74, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_init_2, 2169, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__75)) __PYX_ERR(0, 2169, __pyx_L1_error)
  __pyx_tuple__76 = PyTuple_Pack(2, ((PyObject *)__pyx_int_0), ((PyObject*)__pyx_kp_s__2)); if (unlikely(!__pyx_tuple__76)) __PYX_ERR(0, 2169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__76);
  __Pyx_GIVEREF(__pyx_tuple__76);

  /* "btdht/dht.pyx":2193
 *         ]
 * 
 *     def stop_bg(self):             # <<<<<<<<<<<<<<
 *         """stop the routing table and return immediately"""
 *         if not self.stoped:
 */
  __pyx_tuple__77 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__77)) __PYX_ERR(0, 2193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__77);
  __Pyx_GIVEREF(__pyx_tuple__77);
  __pyx_codeobj__78 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__77, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_stop_bg, 2193, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__78)) __PYX_ERR(0, 2193, __pyx_L1_error)

  /* "btdht/dht.pyx":2198
 *             Thread(target=self.stop).start()
 * 
 *     def stop(self):             # <<<<<<<<<<<<<<
 *         """stop the routing table and wait for all threads to terminate"""
 *         if self.stoped:
 */
  __pyx_tuple__79 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_s, __pyx_n_s_i, __pyx_n_s_t); if (unlikely(!__pyx_tuple__79)) __PYX_ERR(0, 2198, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__79);
  __Pyx_GIVEREF(__pyx_tuple__79);
  __pyx_codeobj__80 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__79, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_stop, 2198, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__80)) __PYX_ERR(0, 2198, __pyx_L1_error)

  /* "btdht/dht.pyx":2226
 * 
 *     @property
 *     def zombie(self):             # <<<<<<<<<<<<<<
 *         """``True`` if dht is stopped but one thread or more remains alive, ``False`` otherwise"""
 *         return self.stoped and [t for t in self._threads if t.is_alive()]
 */
  __pyx_tuple__81 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_t); if (unlikely(!__pyx_tuple__81)) __PYX_ERR(0, 2226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__81);
  __Pyx_GIVEREF(__pyx_tuple__81);
  __pyx_codeobj__82 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__81, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_zombie, 2226, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__82)) __PYX_ERR(0, 2226, __pyx_L1_error)

  /* "btdht/dht.pyx":2230
 *         return self.stoped and [t for t in self._threads if t.is_alive()]
 * 
 *     def start(self):             # <<<<<<<<<<<<<<
 *         """start the routing table"""
 *         with self._lock:
 */
  __pyx_tuple__83 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_name_2, __pyx_n_s_function); if (unlikely(!__pyx_tuple__83)) __PYX_ERR(0, 2230, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__83);
  __Pyx_GIVEREF(__pyx_tuple__83);
  __pyx_codeobj__84 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__83, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_start, 2230, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__84)) __PYX_ERR(0, 2230, __pyx_L1_error)

  /* "btdht/dht.pyx":2244
 *             self._scheduler.add_thread(name, function)
 * 
 *     def is_alive(self):             # <<<<<<<<<<<<<<
 *         """
 *             Test if all routing table threads are alive. If a thread is found dead, stop the
 */
  __pyx_tuple__85 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_weigthless_threads_satus, __pyx_n_s_s, __pyx_n_s_t); if (unlikely(!__pyx_tuple__85)) __PYX_ERR(0, 2244, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__85);
  __Pyx_GIVEREF(__pyx_tuple__85);
  __pyx_codeobj__86 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__85, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_is_alive, 2244, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__86)) __PYX_ERR(0, 2244, __pyx_L1_error)

  /* "btdht/dht.pyx":2268
 *             return True
 * 
 *     def register_torrent(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             Register a torrent ``id`` (info_hash) for being tracked by the routing table.
 */
  __pyx_tuple__87 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_id); if (unlikely(!__pyx_tuple__87)) __PYX_ERR(0, 2268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__87);
  __Pyx_GIVEREF(__pyx_tuple__87);
  __pyx_codeobj__88 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__87, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_register_torrent, 2268, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__88)) __PYX_ERR(0, 2268, __pyx_L1_error)

  /* "btdht/dht.pyx":2282
 *         self._info_hash.add(id)
 * 
 *     def release_torrent(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             Release a torrent ``id`` (info_hash) and program the routing table to be merged
 */
  __pyx_tuple__89 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_id, __pyx_n_s_key); if (unlikely(!__pyx_tuple__89)) __PYX_ERR(0, 2282, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__89);
  __Pyx_GIVEREF(__pyx_tuple__89);
  __pyx_codeobj__90 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__89, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_release_torrent, 2282, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__90)) __PYX_ERR(0, 2282, __pyx_L1_error)

  /* "btdht/dht.pyx":2302
 *             pass
 * 
 *     def _merge_loop(self):             # <<<<<<<<<<<<<<
 *         """Weigthless thread handling the merge of the routing table"""
 *         yield 0
 */
  __pyx_tuple__91 = PyTuple_Pack(5, __pyx_n_s_self, __pyx_n_s_next_merge, __pyx_n_s_next_full_merge, __pyx_n_s_stack, __pyx_n_s_i); if (unlikely(!__pyx_tuple__91)) __PYX_ERR(0, 2302, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__91);
  __Pyx_GIVEREF(__pyx_tuple__91);
  __pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__91, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_merge_loop, 2302, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(0, 2302, __pyx_L1_error)

  /* "btdht/dht.pyx":2330
 *                     yield i
 * 
 *     def register_torrent_longterm(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             Same as :meth:`register_torrent` but garanty that the torrent wont be released
 */
  __pyx_tuple__92 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_id); if (unlikely(!__pyx_tuple__92)) __PYX_ERR(0, 2330, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__92);
  __Pyx_GIVEREF(__pyx_tuple__92);
  __pyx_codeobj__93 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__92, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_register_torrent_longterm, 2330, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__93)) __PYX_ERR(0, 2330, __pyx_L1_error)

  /* "btdht/dht.pyx":2339
 *         self._split_ids.add(id)
 * 
 *     def release_torrent_longterm(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             For releasing torrent registered with the :meth`register_torrent_longterm` method
 */
  __pyx_tuple__94 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_id); if (unlikely(!__pyx_tuple__94)) __PYX_ERR(0, 2339, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__94);
  __Pyx_GIVEREF(__pyx_tuple__94);
  __pyx_codeobj__95 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__94, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_release_torrent_longterm, 2339, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__95)) __PYX_ERR(0, 2339, __pyx_L1_error)

  /* "btdht/dht.pyx":2354
 *             pass
 * 
 *     def register_dht(self, dht):             # <<<<<<<<<<<<<<
 *         """
 *             Register a ``dht`` instance to the routing table
 */
  __pyx_tuple__96 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_dht); if (unlikely(!__pyx_tuple__96)) __PYX_ERR(0, 2354, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__96);
  __Pyx_GIVEREF(__pyx_tuple__96);
  __pyx_codeobj__97 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__96, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_register_dht, 2354, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__97)) __PYX_ERR(0, 2354, __pyx_L1_error)

  /* "btdht/dht.pyx":2366
 *         self._split_ids.add(dht.myid.value)
 * 
 *     def release_dht(self, dht):             # <<<<<<<<<<<<<<
 *         """
 *             Release a ``dht`` instance to the routing table, and shedule the routing table for a
 */
  __pyx_tuple__98 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_dht); if (unlikely(!__pyx_tuple__98)) __PYX_ERR(0, 2366, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__98);
  __Pyx_GIVEREF(__pyx_tuple__98);
  __pyx_codeobj__99 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__98, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_release_dht, 2366, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__99)) __PYX_ERR(0, 2366, __pyx_L1_error)

  /* "btdht/dht.pyx":2388
 *             self.stop()
 * 
 *     def debug(self, lvl, msg):             # <<<<<<<<<<<<<<
 *         """same as :meth:`DHT_BASE.debug`"""
 *         if (
 */
  __pyx_tuple__100 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_lvl, __pyx_n_s_msg); if (unlikely(!__pyx_tuple__100)) __PYX_ERR(0, 2388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__100);
  __Pyx_GIVEREF(__pyx_tuple__100);
  __pyx_codeobj__101 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__100, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_debug, 2388, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__101)) __PYX_ERR(0, 2388, __pyx_L1_error)

  /* "btdht/dht.pyx":2398
 *             self._last_debug_time = time.time()
 * 
 *     def _routine(self):             # <<<<<<<<<<<<<<
 *         """
 *             Weigthless thread perfoming routine on the routing table like performing quering to
 */
  __pyx_tuple__102 = PyTuple_Pack(13, __pyx_n_s_self, __pyx_n_s_last_explore_tree, __pyx_n_s_dhts_2, __pyx_n_s_dhts_last_elt, __pyx_n_s_now, __pyx_n_s_i, __pyx_n_s_key, __pyx_n_s_bucket, __pyx_n_s_id, __pyx_n_s_nodes, __pyx_n_s_questionable, __pyx_n_s_dht, __pyx_n_s_node); if (unlikely(!__pyx_tuple__102)) __PYX_ERR(0, 2398, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__102);
  __Pyx_GIVEREF(__pyx_tuple__102);
  __pyx_codeobj__34 = (PyObject*)__Pyx_PyCode_New(1, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__102, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_routine, 2398, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__34)) __PYX_ERR(0, 2398, __pyx_L1_error)

  /* "btdht/dht.pyx":2447
 *             last_explore_tree = time.time()
 * 
 *     def empty(self):             # <<<<<<<<<<<<<<
 *         """Empty the routing table, deleting all buckets"""
 *         self.trie = datrie.Trie("".join(chr(i) for i in range(256)))
 */
  __pyx_tuple__103 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_genexpr, __pyx_n_s_genexpr); if (unlikely(!__pyx_tuple__103)) __PYX_ERR(0, 2447, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__103);
  __Pyx_GIVEREF(__pyx_tuple__103);
  __pyx_codeobj__104 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__103, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_empty, 2447, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__104)) __PYX_ERR(0, 2447, __pyx_L1_error)

  /* "btdht/dht.pyx":2452
 *         self.trie[u""]=Bucket()
 * 
 *     def stats(self):             # <<<<<<<<<<<<<<
 *         """
 *             :return: A triple (number of nodes, number of good nodes, number of bad nodes)
 */
  __pyx_tuple__105 = PyTuple_Pack(7, __pyx_n_s_self, __pyx_n_s_nodes, __pyx_n_s_goods, __pyx_n_s_bads, __pyx_n_s_others, __pyx_n_s_b, __pyx_n_s_n); if (unlikely(!__pyx_tuple__105)) __PYX_ERR(0, 2452, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__105);
  __Pyx_GIVEREF(__pyx_tuple__105);
  __pyx_codeobj__106 = (PyObject*)__Pyx_PyCode_New(1, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__105, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_stats, 2452, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__106)) __PYX_ERR(0, 2452, __pyx_L1_error)

  /* "btdht/dht.pyx":2475
 *         return (nodes, goods, bads)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return iter(self.trie.values())
 * 
 */
  __pyx_tuple__107 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__107)) __PYX_ERR(0, 2475, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__107);
  __Pyx_GIVEREF(__pyx_tuple__107);
  __pyx_codeobj__108 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__107, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_iter, 2475, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__108)) __PYX_ERR(0, 2475, __pyx_L1_error)

  /* "btdht/dht.pyx":2478
 *         return iter(self.trie.values())
 * 
 *     def get_node(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             :param bytes id: A 160 bits (20 Bytes) identifier
 */
  __pyx_tuple__109 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_id, __pyx_n_s_b); if (unlikely(!__pyx_tuple__109)) __PYX_ERR(0, 2478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__109);
  __Pyx_GIVEREF(__pyx_tuple__109);
  __pyx_codeobj__110 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__109, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_get_node, 2478, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__110)) __PYX_ERR(0, 2478, __pyx_L1_error)

  /* "btdht/dht.pyx":2488
 *         return b.get_node(id)
 * 
 *     def find(self, id, errno=0):             # <<<<<<<<<<<<<<
 *         """
 *             :param bytes id: A 160 bits (20 Bytes) identifier
 */
  __pyx_tuple__111 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_id, __pyx_n_s_errno, __pyx_n_s_e); if (unlikely(!__pyx_tuple__111)) __PYX_ERR(0, 2488, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__111);
  __Pyx_GIVEREF(__pyx_tuple__111);
  __pyx_codeobj__112 = (PyObject*)__Pyx_PyCode_New(3, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__111, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_find, 2488, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__112)) __PYX_ERR(0, 2488, __pyx_L1_error)
  __pyx_tuple__113 = PyTuple_Pack(1, ((PyObject *)__pyx_int_0)); if (unlikely(!__pyx_tuple__113)) __PYX_ERR(0, 2488, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__113);
  __Pyx_GIVEREF(__pyx_tuple__113);

  /* "btdht/dht.pyx":2515
 *                     raise
 * 
 *     def get_closest_nodes(self, id, bad=False, errno=0):             # <<<<<<<<<<<<<<
 *         """
 *             Return the K closest nodes from ``id`` in the routing table
 */
  __pyx_tuple__114 = PyTuple_Pack(11, __pyx_n_s_self, __pyx_n_s_id, __pyx_n_s_bad, __pyx_n_s_errno, __pyx_n_s_nodes, __pyx_n_s_prefix, __pyx_n_s_suffix, __pyx_n_s_e, __pyx_n_s_genexpr, __pyx_n_s_genexpr, __pyx_n_s_genexpr); if (unlikely(!__pyx_tuple__114)) __PYX_ERR(0, 2515, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__114);
  __Pyx_GIVEREF(__pyx_tuple__114);
  __pyx_codeobj__115 = (PyObject*)__Pyx_PyCode_New(4, 0, 11, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__114, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_get_closest_nodes, 2515, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__115)) __PYX_ERR(0, 2515, __pyx_L1_error)
  __pyx_tuple__116 = PyTuple_Pack(2, ((PyObject *)Py_False), ((PyObject *)__pyx_int_0)); if (unlikely(!__pyx_tuple__116)) __PYX_ERR(0, 2515, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__116);
  __Pyx_GIVEREF(__pyx_tuple__116);

  /* "btdht/dht.pyx":2552
 *             return self.get_closest_nodes(id, bad=bad, errno=errno+1)
 * 
 *     def add(self, dht, node):             # <<<<<<<<<<<<<<
 *         """
 *             Add a node the the routing table
 */
  __pyx_tuple__117 = PyTuple_Pack(5, __pyx_n_s_self, __pyx_n_s_dht, __pyx_n_s_node, __pyx_n_s_b, __pyx_n_s_id); if (unlikely(!__pyx_tuple__117)) __PYX_ERR(0, 2552, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__117);
  __Pyx_GIVEREF(__pyx_tuple__117);
  __pyx_codeobj__118 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__117, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_add, 2552, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__118)) __PYX_ERR(0, 2552, __pyx_L1_error)

  /* "btdht/dht.pyx":2577
 *                 print("%r" % b)
 * 
 *     def heigth(self):             # <<<<<<<<<<<<<<
 *         """
 *             :return: the height of the tree of the routing table
 */
  __pyx_tuple__119 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__119)) __PYX_ERR(0, 2577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__119);
  __Pyx_GIVEREF(__pyx_tuple__119);
  __pyx_codeobj__120 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__119, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_heigth, 2577, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__120)) __PYX_ERR(0, 2577, __pyx_L1_error)

  /* "btdht/dht.pyx":2584
 *         return self._heigth
 * 
 *     def split(self, dht, bucket):             # <<<<<<<<<<<<<<
 *         """
 *             Split ``bucket`` in two
 */
  __pyx_tuple__121 = PyTuple_Pack(7, __pyx_n_s_self, __pyx_n_s_dht, __pyx_n_s_bucket, __pyx_n_s_prefix, __pyx_n_s_zero_b, __pyx_n_s_one_b, __pyx_n_s_e); if (unlikely(!__pyx_tuple__121)) __PYX_ERR(0, 2584, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__121);
  __Pyx_GIVEREF(__pyx_tuple__121);
  __pyx_codeobj__122 = (PyObject*)__Pyx_PyCode_New(3, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__121, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_split, 2584, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__122)) __PYX_ERR(0, 2584, __pyx_L1_error)

  /* "btdht/dht.pyx":2607
 *             self.debug(1, "%r" % e)
 * 
 *     def merge(self):             # <<<<<<<<<<<<<<
 *         """Request a merge to be perform"""
 *         self.need_merge = True
 */
  __pyx_tuple__123 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__123)) __PYX_ERR(0, 2607, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__123);
  __Pyx_GIVEREF(__pyx_tuple__123);
  __pyx_codeobj__124 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__123, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_merge_2, 2607, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__124)) __PYX_ERR(0, 2607, __pyx_L1_error)

  /* "btdht/dht.pyx":2611
 *         self.need_merge = True
 * 
 *     def _merge(self, stack=None):             # <<<<<<<<<<<<<<
 *         """
 *             Perform a merge of the routing table. If ``stack`` is provided, only a partial merge
 */
  __pyx_tuple__125 = PyTuple_Pack(17, __pyx_n_s_self, __pyx_n_s_stack, __pyx_n_s_full_merge, __pyx_n_s_nodes_before, __pyx_n_s_started, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_key, __pyx_n_s_to_merge_2, __pyx_n_s_id, __pyx_n_s_prefix0, __pyx_n_s_prefix1, __pyx_n_s_bucket0, __pyx_n_s_bucket1, __pyx_n_s_bucket, __pyx_n_s_genexpr, __pyx_n_s_genexpr); if (unlikely(!__pyx_tuple__125)) __PYX_ERR(0, 2611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__125);
  __Pyx_GIVEREF(__pyx_tuple__125);
  __pyx_codeobj__37 = (PyObject*)__Pyx_PyCode_New(2, 0, 17, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__125, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_btdht_dht_pyx, __pyx_n_s_merge, 2611, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__37)) __PYX_ERR(0, 2611, __pyx_L1_error)
  __pyx_tuple__126 = PyTuple_Pack(1, ((PyObject *)Py_None)); if (unlikely(!__pyx_tuple__126)) __PYX_ERR(0, 2611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__126);
  __Pyx_GIVEREF(__pyx_tuple__126);

  /* "(tree fragment)":1
 * def __pyx_unpickle_DHT_BASE(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */
  __pyx_tuple__127 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__127)) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__127);
  __Pyx_GIVEREF(__pyx_tuple__127);
  __pyx_codeobj__128 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__127, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_DHT_BASE, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__128)) __PYX_ERR(1, 1, __pyx_L1_error)
  __pyx_tuple__129 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__129)) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__129);
  __Pyx_GIVEREF(__pyx_tuple__129);
  __pyx_codeobj__130 = (PyObject*)__Pyx_PyCode_New(3, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__129, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_Node, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__130)) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
  __pyx_umethod_PyList_Type_pop.type = (PyObject*)&PyList_Type;
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  __pyx_float_0_1 = PyFloat_FromDouble(0.1); if (unlikely(!__pyx_float_0_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_10 = PyInt_FromLong(10); if (unlikely(!__pyx_int_10)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_11 = PyInt_FromLong(11); if (unlikely(!__pyx_int_11)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_13 = PyInt_FromLong(13); if (unlikely(!__pyx_int_13)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_20 = PyInt_FromLong(20); if (unlikely(!__pyx_int_20)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_24 = PyInt_FromLong(24); if (unlikely(!__pyx_int_24)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_26 = PyInt_FromLong(26); if (unlikely(!__pyx_int_26)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_30 = PyInt_FromLong(30); if (unlikely(!__pyx_int_30)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_60 = PyInt_FromLong(60); if (unlikely(!__pyx_int_60)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_90 = PyInt_FromLong(90); if (unlikely(!__pyx_int_90)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_120 = PyInt_FromLong(120); if (unlikely(!__pyx_int_120)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_160 = PyInt_FromLong(160); if (unlikely(!__pyx_int_160)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_201 = PyInt_FromLong(201); if (unlikely(!__pyx_int_201)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_202 = PyInt_FromLong(202); if (unlikely(!__pyx_int_202)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_203 = PyInt_FromLong(203); if (unlikely(!__pyx_int_203)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_204 = PyInt_FromLong(204); if (unlikely(!__pyx_int_204)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_300 = PyInt_FromLong(300); if (unlikely(!__pyx_int_300)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_500 = PyInt_FromLong(500); if (unlikely(!__pyx_int_500)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_600 = PyInt_FromLong(600); if (unlikely(!__pyx_int_600)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_900 = PyInt_FromLong(900); if (unlikely(!__pyx_int_900)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1000 = PyInt_FromLong(1000); if (unlikely(!__pyx_int_1000)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1800 = PyInt_FromLong(1800); if (unlikely(!__pyx_int_1800)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_2600 = PyInt_FromLong(2600); if (unlikely(!__pyx_int_2600)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_4048 = PyInt_FromLong(4048); if (unlikely(!__pyx_int_4048)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_6880 = PyInt_FromLong(6880); if (unlikely(!__pyx_int_6880)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_6881 = PyInt_FromLong(6881); if (unlikely(!__pyx_int_6881)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_10013 = PyInt_FromLong(10013L); if (unlikely(!__pyx_int_10013)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_10035 = PyInt_FromLong(10035L); if (unlikely(!__pyx_int_10035)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_10040 = PyInt_FromLong(10040L); if (unlikely(!__pyx_int_10040)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_65535 = PyInt_FromLong(65535L); if (unlikely(!__pyx_int_65535)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_65536 = PyInt_FromLong(65536L); if (unlikely(!__pyx_int_65536)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_100000 = PyInt_FromLong(100000L); if (unlikely(!__pyx_int_100000)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_15399060 = PyInt_FromLong(15399060L); if (unlikely(!__pyx_int_15399060)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_81066950 = PyInt_FromLong(81066950L); if (unlikely(!__pyx_int_81066950)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_218572978 = PyInt_FromLong(218572978L); if (unlikely(!__pyx_int_218572978)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_226352420 = PyInt_FromLong(226352420L); if (unlikely(!__pyx_int_226352420)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_238925605 = PyInt_FromLong(238925605L); if (unlikely(!__pyx_int_238925605)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_258108903 = PyInt_FromLong(258108903L); if (unlikely(!__pyx_int_258108903)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_10 = PyInt_FromLong(-10); if (unlikely(!__pyx_int_neg_10)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/

static int __Pyx_modinit_global_init_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
  /*--- Global init code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_variable_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  /*--- Variable export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
  /*--- Function export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_type_init_code(void) {
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  /*--- Type init code ---*/
  __pyx_vtabptr_5btdht_3dht_DHT_BASE = &__pyx_vtable_5btdht_3dht_DHT_BASE;
  __pyx_vtable_5btdht_3dht_DHT_BASE._set_transaction_id = (void (*)(struct __pyx_obj_5btdht_3dht_DHT_BASE *, struct __pyx_obj_5btdht_4krcp_BMessage *, struct __pyx_opt_args_5btdht_3dht_8DHT_BASE__set_transaction_id *__pyx_optional_args))__pyx_f_5btdht_3dht_8DHT_BASE__set_transaction_id;
  if (PyType_Ready(&__pyx_type_5btdht_3dht_DHT_BASE) < 0) __PYX_ERR(0, 53, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht_DHT_BASE.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht_DHT_BASE.tp_dictoffset && __pyx_type_5btdht_3dht_DHT_BASE.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht_DHT_BASE.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (__Pyx_SetVtable(__pyx_type_5btdht_3dht_DHT_BASE.tp_dict, __pyx_vtabptr_5btdht_3dht_DHT_BASE) < 0) __PYX_ERR(0, 53, __pyx_L1_error)
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_DHT_BASE, (PyObject *)&__pyx_type_5btdht_3dht_DHT_BASE) < 0) __PYX_ERR(0, 53, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5btdht_3dht_DHT_BASE) < 0) __PYX_ERR(0, 53, __pyx_L1_error)
  __pyx_ptype_5btdht_3dht_DHT_BASE = &__pyx_type_5btdht_3dht_DHT_BASE;
  if (PyType_Ready(&__pyx_type_5btdht_3dht_Node) < 0) __PYX_ERR(0, 1561, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht_Node.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht_Node.tp_dictoffset && __pyx_type_5btdht_3dht_Node.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht_Node.tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_Node, (PyObject *)&__pyx_type_5btdht_3dht_Node) < 0) __PYX_ERR(0, 1561, __pyx_L1_error)
  if (__Pyx_setup_reduce((PyObject*)&__pyx_type_5btdht_3dht_Node) < 0) __PYX_ERR(0, 1561, __pyx_L1_error)
  __pyx_ptype_5btdht_3dht_Node = &__pyx_type_5btdht_3dht_Node;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct__announce_peer) < 0) __PYX_ERR(0, 493, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct__announce_peer.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct__announce_peer.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct__announce_peer.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct__announce_peer.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct__announce_peer = &__pyx_type_5btdht_3dht___pyx_scope_struct__announce_peer;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop) < 0) __PYX_ERR(0, 623, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop = &__pyx_type_5btdht_3dht___pyx_scope_struct_1__get_peers_closest_loop;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes) < 0) __PYX_ERR(0, 781, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes = &__pyx_type_5btdht_3dht___pyx_scope_struct_2_get_closest_nodes;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct_3_genexpr) < 0) __PYX_ERR(0, 805, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct_3_genexpr.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct_3_genexpr.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct_3_genexpr.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct_3_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct_3_genexpr = &__pyx_type_5btdht_3dht___pyx_scope_struct_3_genexpr;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct_4__routine) < 0) __PYX_ERR(0, 1167, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct_4__routine.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct_4__routine.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct_4__routine.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct_4__routine.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct_4__routine = &__pyx_type_5btdht_3dht___pyx_scope_struct_4__routine;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct_5__process_loop) < 0) __PYX_ERR(0, 1478, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct_5__process_loop.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct_5__process_loop.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct_5__process_loop.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct_5__process_loop.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct_5__process_loop = &__pyx_type_5btdht_3dht___pyx_scope_struct_5__process_loop;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct_6__merge_loop) < 0) __PYX_ERR(0, 2302, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct_6__merge_loop.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct_6__merge_loop.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct_6__merge_loop.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct_6__merge_loop.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct_6__merge_loop = &__pyx_type_5btdht_3dht___pyx_scope_struct_6__merge_loop;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct_7__routine) < 0) __PYX_ERR(0, 2398, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct_7__routine.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct_7__routine.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct_7__routine.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct_7__routine.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct_7__routine = &__pyx_type_5btdht_3dht___pyx_scope_struct_7__routine;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct_8_genexpr) < 0) __PYX_ERR(0, 2449, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct_8_genexpr.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct_8_genexpr.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct_8_genexpr.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct_8_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct_8_genexpr = &__pyx_type_5btdht_3dht___pyx_scope_struct_8_genexpr;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes) < 0) __PYX_ERR(0, 2515, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes = &__pyx_type_5btdht_3dht___pyx_scope_struct_9_get_closest_nodes;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct_10_genexpr) < 0) __PYX_ERR(0, 2530, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct_10_genexpr.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct_10_genexpr.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct_10_genexpr.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct_10_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct_10_genexpr = &__pyx_type_5btdht_3dht___pyx_scope_struct_10_genexpr;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct_11_genexpr) < 0) __PYX_ERR(0, 2538, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct_11_genexpr.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct_11_genexpr.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct_11_genexpr.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct_11_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct_11_genexpr = &__pyx_type_5btdht_3dht___pyx_scope_struct_11_genexpr;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct_12__merge) < 0) __PYX_ERR(0, 2611, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct_12__merge.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct_12__merge.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct_12__merge.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct_12__merge.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct_12__merge = &__pyx_type_5btdht_3dht___pyx_scope_struct_12__merge;
  if (PyType_Ready(&__pyx_type_5btdht_3dht___pyx_scope_struct_13_genexpr) < 0) __PYX_ERR(0, 2677, __pyx_L1_error)
  #if PY_VERSION_HEX < 0x030800B1
  __pyx_type_5btdht_3dht___pyx_scope_struct_13_genexpr.tp_print = 0;
  #endif
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_5btdht_3dht___pyx_scope_struct_13_genexpr.tp_dictoffset && __pyx_type_5btdht_3dht___pyx_scope_struct_13_genexpr.tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_type_5btdht_3dht___pyx_scope_struct_13_genexpr.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  }
  __pyx_ptype_5btdht_3dht___pyx_scope_struct_13_genexpr = &__pyx_type_5btdht_3dht___pyx_scope_struct_13_genexpr;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_type_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  /*--- Type import code ---*/
  __pyx_t_1 = PyImport_ImportModule("btdht.krcp"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_5btdht_4krcp_BMessage = __Pyx_ImportType(__pyx_t_1, "btdht.krcp", "BMessage", sizeof(struct __pyx_obj_5btdht_4krcp_BMessage), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_5btdht_4krcp_BMessage) __PYX_ERR(2, 3, __pyx_L1_error)
  __pyx_vtabptr_5btdht_4krcp_BMessage = (struct __pyx_vtabstruct_5btdht_4krcp_BMessage*)__Pyx_GetVtable(__pyx_ptype_5btdht_4krcp_BMessage->tp_dict); if (unlikely(!__pyx_vtabptr_5btdht_4krcp_BMessage)) __PYX_ERR(2, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_variable_import_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
  /*--- Variable import code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_import_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  /*--- Function import code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}


#ifndef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#elif PY_MAJOR_VERSION < 3
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" void
#else
#define __Pyx_PyMODINIT_FUNC void
#endif
#else
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
#else
#define __Pyx_PyMODINIT_FUNC PyObject *
#endif
#endif


#if PY_MAJOR_VERSION < 3
__Pyx_PyMODINIT_FUNC initdht(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC initdht(void)
#else
__Pyx_PyMODINIT_FUNC PyInit_dht(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC PyInit_dht(void)
#if CYTHON_PEP489_MULTI_PHASE_INIT
{
  return PyModuleDef_Init(&__pyx_moduledef);
}
static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
    #if PY_VERSION_HEX >= 0x030700A1
    static PY_INT64_T main_interpreter_id = -1;
    PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
    if (main_interpreter_id == -1) {
        main_interpreter_id = current_id;
        return (unlikely(current_id == -1)) ? -1 : 0;
    } else if (unlikely(main_interpreter_id != current_id))
    #else
    static PyInterpreterState *main_interpreter = NULL;
    PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
    if (!main_interpreter) {
        main_interpreter = current_interpreter;
    } else if (unlikely(main_interpreter != current_interpreter))
    #endif
    {
        PyErr_SetString(
            PyExc_ImportError,
            "Interpreter change detected - this module can only be loaded into one interpreter per process.");
        return -1;
    }
    return 0;
}
static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) {
    PyObject *value = PyObject_GetAttrString(spec, from_name);
    int result = 0;
    if (likely(value)) {
        if (allow_none || value != Py_None) {
            result = PyDict_SetItemString(moddict, to_name, value);
        }
        Py_DECREF(value);
    } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Clear();
    } else {
        result = -1;
    }
    return result;
}
static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
    PyObject *module = NULL, *moddict, *modname;
    if (__Pyx_check_single_interpreter())
        return NULL;
    if (__pyx_m)
        return __Pyx_NewRef(__pyx_m);
    modname = PyObject_GetAttrString(spec, "name");
    if (unlikely(!modname)) goto bad;
    module = PyModule_NewObject(modname);
    Py_DECREF(modname);
    if (unlikely(!module)) goto bad;
    moddict = PyModule_GetDict(module);
    if (unlikely(!moddict)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
    return module;
bad:
    Py_XDECREF(module);
    return NULL;
}


static CYTHON_SMALL_CODE int __pyx_pymod_exec_dht(PyObject *__pyx_pyinit_module)
#endif
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  if (__pyx_m) {
    if (__pyx_m == __pyx_pyinit_module) return 0;
    PyErr_SetString(PyExc_RuntimeError, "Module 'dht' has already been imported. Re-initialisation is not supported.");
    return -1;
  }
  #elif PY_MAJOR_VERSION >= 3
  if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  #endif
  #if CYTHON_REFNANNY
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
if (!__Pyx_RefNanny) {
  PyErr_Clear();
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
  if (!__Pyx_RefNanny)
      Py_FatalError("failed to import 'refnanny' module");
}
#endif
  __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_dht(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pxy_PyFrame_Initialize_Offsets
  __Pxy_PyFrame_Initialize_Offsets();
  #endif
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_AsyncGen_USED
  if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  PyEval_InitThreads();
  #endif
  /*--- Module creation code ---*/
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  __pyx_m = __pyx_pyinit_module;
  Py_INCREF(__pyx_m);
  #else
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("dht", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_b);
  __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_cython_runtime);
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  if (__pyx_module_is_main_btdht__dht) {
    if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
    if (!PyDict_GetItemString(modules, "btdht.dht")) {
      if (unlikely(PyDict_SetItemString(modules, "btdht.dht", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Global type/function init code ---*/
  (void)__Pyx_modinit_global_init_code();
  (void)__Pyx_modinit_variable_export_code();
  (void)__Pyx_modinit_function_export_code();
  if (unlikely(__Pyx_modinit_type_init_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  (void)__Pyx_modinit_variable_import_code();
  (void)__Pyx_modinit_function_import_code();
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif

  /* "btdht/dht.pyx":16
 * from libc.stdlib cimport atoi, malloc, free
 * 
 * import os             # <<<<<<<<<<<<<<
 * import sys
 * import time
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":17
 * 
 * import os
 * import sys             # <<<<<<<<<<<<<<
 * import time
 * import six
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":18
 * import os
 * import sys
 * import time             # <<<<<<<<<<<<<<
 * import six
 * import heapq
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_time, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_1) < 0) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":19
 * import sys
 * import time
 * import six             # <<<<<<<<<<<<<<
 * import heapq
 * import traceback
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_six, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 19, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_six, __pyx_t_1) < 0) __PYX_ERR(0, 19, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":20
 * import time
 * import six
 * import heapq             # <<<<<<<<<<<<<<
 * import traceback
 * import struct
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_heapq, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_heapq, __pyx_t_1) < 0) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":21
 * import six
 * import heapq
 * import traceback             # <<<<<<<<<<<<<<
 * import struct
 * import socket
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_traceback, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_traceback, __pyx_t_1) < 0) __PYX_ERR(0, 21, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":22
 * import heapq
 * import traceback
 * import struct             # <<<<<<<<<<<<<<
 * import socket
 * import select
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_struct, __pyx_t_1) < 0) __PYX_ERR(0, 22, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":23
 * import traceback
 * import struct
 * import socket             # <<<<<<<<<<<<<<
 * import select
 * import collections
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_socket, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_socket, __pyx_t_1) < 0) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":24
 * import struct
 * import socket
 * import select             # <<<<<<<<<<<<<<
 * import collections
 * import netaddr
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_select, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_select, __pyx_t_1) < 0) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":25
 * import socket
 * import select
 * import collections             # <<<<<<<<<<<<<<
 * import netaddr
 * import binascii
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_collections, __pyx_t_1) < 0) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":26
 * import select
 * import collections
 * import netaddr             # <<<<<<<<<<<<<<
 * import binascii
 * try:
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_netaddr, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_netaddr, __pyx_t_1) < 0) __PYX_ERR(0, 26, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":27
 * import collections
 * import netaddr
 * import binascii             # <<<<<<<<<<<<<<
 * try:
 *     import Queue
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_binascii, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_binascii, __pyx_t_1) < 0) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":28
 * import netaddr
 * import binascii
 * try:             # <<<<<<<<<<<<<<
 *     import Queue
 * except ImportError:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_4);
    /*try:*/ {

      /* "btdht/dht.pyx":29
 * import binascii
 * try:
 *     import Queue             # <<<<<<<<<<<<<<
 * except ImportError:
 *     import queue as Queue
 */
      __pyx_t_1 = __Pyx_Import(__pyx_n_s_Queue, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 29, __pyx_L2_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_Queue, __pyx_t_1) < 0) __PYX_ERR(0, 29, __pyx_L2_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "btdht/dht.pyx":28
 * import netaddr
 * import binascii
 * try:             # <<<<<<<<<<<<<<
 *     import Queue
 * except ImportError:
 */
    }
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L7_try_end;
    __pyx_L2_error:;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "btdht/dht.pyx":30
 * try:
 *     import Queue
 * except ImportError:             # <<<<<<<<<<<<<<
 *     import queue as Queue
 * from functools import total_ordering, reduce
 */
    __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ImportError);
    if (__pyx_t_5) {
      __Pyx_AddTraceback("btdht.dht", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 30, __pyx_L4_except_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);

      /* "btdht/dht.pyx":31
 *     import Queue
 * except ImportError:
 *     import queue as Queue             # <<<<<<<<<<<<<<
 * from functools import total_ordering, reduce
 * from threading import Thread, Lock
 */
      __pyx_t_8 = __Pyx_Import(__pyx_n_s_queue, 0, -1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 31, __pyx_L4_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_Queue, __pyx_t_8) < 0) __PYX_ERR(0, 31, __pyx_L4_except_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L3_exception_handled;
    }
    goto __pyx_L4_except_error;
    __pyx_L4_except_error:;

    /* "btdht/dht.pyx":28
 * import netaddr
 * import binascii
 * try:             # <<<<<<<<<<<<<<
 *     import Queue
 * except ImportError:
 */
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
    goto __pyx_L1_error;
    __pyx_L3_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
    __pyx_L7_try_end:;
  }

  /* "btdht/dht.pyx":32
 * except ImportError:
 *     import queue as Queue
 * from functools import total_ordering, reduce             # <<<<<<<<<<<<<<
 * from threading import Thread, Lock
 * from random import shuffle, randint
 */
  __pyx_t_7 = PyList_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_n_s_total_ordering);
  __Pyx_GIVEREF(__pyx_n_s_total_ordering);
  PyList_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_total_ordering);
  __Pyx_INCREF(__pyx_n_s_reduce_2);
  __Pyx_GIVEREF(__pyx_n_s_reduce_2);
  PyList_SET_ITEM(__pyx_t_7, 1, __pyx_n_s_reduce_2);
  __pyx_t_6 = __Pyx_Import(__pyx_n_s_functools, __pyx_t_7, -1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_6, __pyx_n_s_total_ordering); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_total_ordering, __pyx_t_7) < 0) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_6, __pyx_n_s_reduce_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_2, __pyx_t_7) < 0) __PYX_ERR(0, 32, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "btdht/dht.pyx":33
 *     import queue as Queue
 * from functools import total_ordering, reduce
 * from threading import Thread, Lock             # <<<<<<<<<<<<<<
 * from random import shuffle, randint
 * 
 */
  __pyx_t_6 = PyList_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(__pyx_n_s_Thread);
  __Pyx_GIVEREF(__pyx_n_s_Thread);
  PyList_SET_ITEM(__pyx_t_6, 0, __pyx_n_s_Thread);
  __Pyx_INCREF(__pyx_n_s_Lock);
  __Pyx_GIVEREF(__pyx_n_s_Lock);
  PyList_SET_ITEM(__pyx_t_6, 1, __pyx_n_s_Lock);
  __pyx_t_7 = __Pyx_Import(__pyx_n_s_threading, __pyx_t_6, -1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_Thread); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_Thread, __pyx_t_6) < 0) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_Lock); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_Lock, __pyx_t_6) < 0) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":34
 * from functools import total_ordering, reduce
 * from threading import Thread, Lock
 * from random import shuffle, randint             # <<<<<<<<<<<<<<
 * 
 * try:
 */
  __pyx_t_7 = PyList_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_n_s_shuffle);
  __Pyx_GIVEREF(__pyx_n_s_shuffle);
  PyList_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_shuffle);
  __Pyx_INCREF(__pyx_n_s_randint);
  __Pyx_GIVEREF(__pyx_n_s_randint);
  PyList_SET_ITEM(__pyx_t_7, 1, __pyx_n_s_randint);
  __pyx_t_6 = __Pyx_Import(__pyx_n_s_random, __pyx_t_7, -1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_6, __pyx_n_s_shuffle); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_shuffle, __pyx_t_7) < 0) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_6, __pyx_n_s_randint); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_randint, __pyx_t_7) < 0) __PYX_ERR(0, 34, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "btdht/dht.pyx":36
 * from random import shuffle, randint
 * 
 * try:             # <<<<<<<<<<<<<<
 *     import IN
 * except ImportError:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_3, &__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_4);
    __Pyx_XGOTREF(__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_2);
    /*try:*/ {

      /* "btdht/dht.pyx":37
 * 
 * try:
 *     import IN             # <<<<<<<<<<<<<<
 * except ImportError:
 *     IN = None
 */
      __pyx_t_6 = __Pyx_Import(__pyx_n_s_IN, 0, -1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 37, __pyx_L10_error)
      __Pyx_GOTREF(__pyx_t_6);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_IN, __pyx_t_6) < 0) __PYX_ERR(0, 37, __pyx_L10_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "btdht/dht.pyx":36
 * from random import shuffle, randint
 * 
 * try:             # <<<<<<<<<<<<<<
 *     import IN
 * except ImportError:
 */
    }
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L15_try_end;
    __pyx_L10_error:;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "btdht/dht.pyx":38
 * try:
 *     import IN
 * except ImportError:             # <<<<<<<<<<<<<<
 *     IN = None
 * 
 */
    __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ImportError);
    if (__pyx_t_5) {
      __Pyx_AddTraceback("btdht.dht", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_7, &__pyx_t_1) < 0) __PYX_ERR(0, 38, __pyx_L12_except_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GOTREF(__pyx_t_1);

      /* "btdht/dht.pyx":39
 *     import IN
 * except ImportError:
 *     IN = None             # <<<<<<<<<<<<<<
 * 
 * import datrie
 */
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_IN, Py_None) < 0) __PYX_ERR(0, 39, __pyx_L12_except_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L11_exception_handled;
    }
    goto __pyx_L12_except_error;
    __pyx_L12_except_error:;

    /* "btdht/dht.pyx":36
 * from random import shuffle, randint
 * 
 * try:             # <<<<<<<<<<<<<<
 *     import IN
 * except ImportError:
 */
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_3, __pyx_t_2);
    goto __pyx_L1_error;
    __pyx_L11_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_3, __pyx_t_2);
    __pyx_L15_try_end:;
  }

  /* "btdht/dht.pyx":41
 *     IN = None
 * 
 * import datrie             # <<<<<<<<<<<<<<
 * 
 * import utils
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_datrie, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_datrie, __pyx_t_1) < 0) __PYX_ERR(0, 41, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":43
 * import datrie
 * 
 * import utils             # <<<<<<<<<<<<<<
 * from .utils import ID, nbit, nflip, nset, PollableQueue
 * from .exceptions import BucketFull, BucketNotFull, NoTokenError, FailToStop, TransactionIdUnknown
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_utils, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_utils, __pyx_t_1) < 0) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":44
 * 
 * import utils
 * from .utils import ID, nbit, nflip, nset, PollableQueue             # <<<<<<<<<<<<<<
 * from .exceptions import BucketFull, BucketNotFull, NoTokenError, FailToStop, TransactionIdUnknown
 * from .exceptions import NotFound
 */
  __pyx_t_1 = PyList_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_ID);
  __Pyx_GIVEREF(__pyx_n_s_ID);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_ID);
  __Pyx_INCREF(__pyx_n_s_nbit);
  __Pyx_GIVEREF(__pyx_n_s_nbit);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_nbit);
  __Pyx_INCREF(__pyx_n_s_nflip);
  __Pyx_GIVEREF(__pyx_n_s_nflip);
  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_nflip);
  __Pyx_INCREF(__pyx_n_s_nset);
  __Pyx_GIVEREF(__pyx_n_s_nset);
  PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_nset);
  __Pyx_INCREF(__pyx_n_s_PollableQueue);
  __Pyx_GIVEREF(__pyx_n_s_PollableQueue);
  PyList_SET_ITEM(__pyx_t_1, 4, __pyx_n_s_PollableQueue);
  __pyx_t_7 = __Pyx_Import(__pyx_n_s_utils, __pyx_t_1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_ID); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ID, __pyx_t_1) < 0) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_nbit); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_nbit, __pyx_t_1) < 0) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_nflip); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_nflip, __pyx_t_1) < 0) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_nset); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_nset, __pyx_t_1) < 0) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_PollableQueue); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_PollableQueue, __pyx_t_1) < 0) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":45
 * import utils
 * from .utils import ID, nbit, nflip, nset, PollableQueue
 * from .exceptions import BucketFull, BucketNotFull, NoTokenError, FailToStop, TransactionIdUnknown             # <<<<<<<<<<<<<<
 * from .exceptions import NotFound
 * 
 */
  __pyx_t_7 = PyList_New(5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_n_s_BucketFull);
  __Pyx_GIVEREF(__pyx_n_s_BucketFull);
  PyList_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_BucketFull);
  __Pyx_INCREF(__pyx_n_s_BucketNotFull);
  __Pyx_GIVEREF(__pyx_n_s_BucketNotFull);
  PyList_SET_ITEM(__pyx_t_7, 1, __pyx_n_s_BucketNotFull);
  __Pyx_INCREF(__pyx_n_s_NoTokenError);
  __Pyx_GIVEREF(__pyx_n_s_NoTokenError);
  PyList_SET_ITEM(__pyx_t_7, 2, __pyx_n_s_NoTokenError);
  __Pyx_INCREF(__pyx_n_s_FailToStop);
  __Pyx_GIVEREF(__pyx_n_s_FailToStop);
  PyList_SET_ITEM(__pyx_t_7, 3, __pyx_n_s_FailToStop);
  __Pyx_INCREF(__pyx_n_s_TransactionIdUnknown);
  __Pyx_GIVEREF(__pyx_n_s_TransactionIdUnknown);
  PyList_SET_ITEM(__pyx_t_7, 4, __pyx_n_s_TransactionIdUnknown);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_exceptions, __pyx_t_7, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_BucketFull); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_BucketFull, __pyx_t_7) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_BucketNotFull); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_BucketNotFull, __pyx_t_7) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_NoTokenError); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_NoTokenError, __pyx_t_7) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_FailToStop); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_FailToStop, __pyx_t_7) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_TransactionIdUnknown); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_TransactionIdUnknown, __pyx_t_7) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":46
 * from .utils import ID, nbit, nflip, nset, PollableQueue
 * from .exceptions import BucketFull, BucketNotFull, NoTokenError, FailToStop, TransactionIdUnknown
 * from .exceptions import NotFound             # <<<<<<<<<<<<<<
 * 
 * from .krcp cimport BMessage
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_NotFound);
  __Pyx_GIVEREF(__pyx_n_s_NotFound);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_NotFound);
  __pyx_t_7 = __Pyx_Import(__pyx_n_s_exceptions, __pyx_t_1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_NotFound); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_NotFound, __pyx_t_1) < 0) __PYX_ERR(0, 46, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":49
 * 
 * from .krcp cimport BMessage
 * from .krcp import BError, ProtocolError, GenericError, ServerError, MethodUnknownError, MissingT             # <<<<<<<<<<<<<<
 * from .krcp import DecodeError
 * 
 */
  __pyx_t_7 = PyList_New(6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_n_s_BError);
  __Pyx_GIVEREF(__pyx_n_s_BError);
  PyList_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_BError);
  __Pyx_INCREF(__pyx_n_s_ProtocolError);
  __Pyx_GIVEREF(__pyx_n_s_ProtocolError);
  PyList_SET_ITEM(__pyx_t_7, 1, __pyx_n_s_ProtocolError);
  __Pyx_INCREF(__pyx_n_s_GenericError);
  __Pyx_GIVEREF(__pyx_n_s_GenericError);
  PyList_SET_ITEM(__pyx_t_7, 2, __pyx_n_s_GenericError);
  __Pyx_INCREF(__pyx_n_s_ServerError);
  __Pyx_GIVEREF(__pyx_n_s_ServerError);
  PyList_SET_ITEM(__pyx_t_7, 3, __pyx_n_s_ServerError);
  __Pyx_INCREF(__pyx_n_s_MethodUnknownError);
  __Pyx_GIVEREF(__pyx_n_s_MethodUnknownError);
  PyList_SET_ITEM(__pyx_t_7, 4, __pyx_n_s_MethodUnknownError);
  __Pyx_INCREF(__pyx_n_s_MissingT);
  __Pyx_GIVEREF(__pyx_n_s_MissingT);
  PyList_SET_ITEM(__pyx_t_7, 5, __pyx_n_s_MissingT);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_krcp, __pyx_t_7, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_BError); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_BError, __pyx_t_7) < 0) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_ProtocolError); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ProtocolError, __pyx_t_7) < 0) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_GenericError); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_GenericError, __pyx_t_7) < 0) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_ServerError); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ServerError, __pyx_t_7) < 0) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_MethodUnknownError); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_MethodUnknownError, __pyx_t_7) < 0) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_MissingT); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_MissingT, __pyx_t_7) < 0) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "btdht/dht.pyx":50
 * from .krcp cimport BMessage
 * from .krcp import BError, ProtocolError, GenericError, ServerError, MethodUnknownError, MissingT
 * from .krcp import DecodeError             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 50, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_DecodeError);
  __Pyx_GIVEREF(__pyx_n_s_DecodeError);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_DecodeError);
  __pyx_t_7 = __Pyx_Import(__pyx_n_s_krcp, __pyx_t_1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 50, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_7, __pyx_n_s_DecodeError); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 50, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_DecodeError, __pyx_t_1) < 0) __PYX_ERR(0, 50, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":84
 * 
 *     #: :class:`str` interface the dht is binded to
 *     bind_ip = "0.0.0.0"             # <<<<<<<<<<<<<<
 *     #: :class:`int` port the dht is binded to
 *     bind_port = None
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_bind_ip, __pyx_kp_s_0_0_0_0) < 0) __PYX_ERR(0, 84, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":86
 *     bind_ip = "0.0.0.0"
 *     #: :class:`int` port the dht is binded to
 *     bind_port = None             # <<<<<<<<<<<<<<
 *     #: :class:`int` the dht instance verbosity level
 *     debuglvl = 0
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_bind_port, Py_None) < 0) __PYX_ERR(0, 86, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":88
 *     bind_port = None
 *     #: :class:`int` the dht instance verbosity level
 *     debuglvl = 0             # <<<<<<<<<<<<<<
 *     #: last time we received any message
 *     last_msg = 0
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_debuglvl, __pyx_int_0) < 0) __PYX_ERR(0, 88, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":90
 *     debuglvl = 0
 *     #: last time we received any message
 *     last_msg = 0             # <<<<<<<<<<<<<<
 *     #: last time we receive a response to one of our messages
 *     last_msg_rep = 0
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_last_msg, __pyx_int_0) < 0) __PYX_ERR(0, 90, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":92
 *     last_msg = 0
 *     #: last time we receive a response to one of our messages
 *     last_msg_rep = 0             # <<<<<<<<<<<<<<
 *     #: :class:`set` of ignored ip in dotted notation
 *     ignored_ip = []
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_last_msg_rep, __pyx_int_0) < 0) __PYX_ERR(0, 92, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":94
 *     last_msg_rep = 0
 *     #: :class:`set` of ignored ip in dotted notation
 *     ignored_ip = []             # <<<<<<<<<<<<<<
 *     #: :class:`list` of default ignored ip networks
 *     ignored_net = []
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 94, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_ignored_ip, __pyx_t_7) < 0) __PYX_ERR(0, 94, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":96
 *     ignored_ip = []
 *     #: :class:`list` of default ignored ip networks
 *     ignored_net = []             # <<<<<<<<<<<<<<
 *     #: :class:`utils.ID` the dht instance id, 160bits long (20 Bytes)
 *     myid = None
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 96, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_ignored_net, __pyx_t_7) < 0) __PYX_ERR(0, 96, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":98
 *     ignored_net = []
 *     #: :class:`utils.ID` the dht instance id, 160bits long (20 Bytes)
 *     myid = None             # <<<<<<<<<<<<<<
 *     #: :class:`str` prefixing all debug message
 *     prefix = ""
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_myid, Py_None) < 0) __PYX_ERR(0, 98, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":100
 *     myid = None
 *     #: :class:`str` prefixing all debug message
 *     prefix = ""             # <<<<<<<<<<<<<<
 *     #: :class:`RoutingTable` the used instance of the routing table
 *     root = None
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_prefix, __pyx_kp_s__2) < 0) __PYX_ERR(0, 100, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":102
 *     prefix = ""
 *     #: :class:`RoutingTable` the used instance of the routing table
 *     root = None             # <<<<<<<<<<<<<<
 *     #: The current dht :class:`socket.Socket`
 *     sock = None
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_root, Py_None) < 0) __PYX_ERR(0, 102, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":104
 *     root = None
 *     #: The current dht :class:`socket.Socket`
 *     sock = None             # <<<<<<<<<<<<<<
 *     #: the state (stoped ?) of the dht
 *     stoped = True
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_sock, Py_None) < 0) __PYX_ERR(0, 104, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":106
 *     sock = None
 *     #: the state (stoped ?) of the dht
 *     stoped = True             # <<<<<<<<<<<<<<
 *     #: :class:`list` of the :class:`Thread<threading.Thread>` of the dht instance
 *     threads = []
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_stoped, Py_True) < 0) __PYX_ERR(0, 106, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":108
 *     stoped = True
 *     #: :class:`list` of the :class:`Thread<threading.Thread>` of the dht instance
 *     threads = []             # <<<<<<<<<<<<<<
 *     #: Token send with get_peers response. Map between ip addresses and a list of random token.
 *     #: A new token by ip is genereted at most every 5 min, a single token is valid 10 min.
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_threads, __pyx_t_7) < 0) __PYX_ERR(0, 108, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":113
 *     #: On reception of a announce_peer query from ip, the query is only accepted if we have a
 *     #: valid token (generated less than 10min ago).
 *     token = collections.defaultdict(list)             # <<<<<<<<<<<<<<
 *     #: Tokens received on get_peers response. Map between ip addresses and received token from ip.
 *     #: Needed to send announce_peer to that particular ip.
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_collections); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 113, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 113, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_1, ((PyObject *)(&PyList_Type))) : __Pyx_PyObject_CallOneArg(__pyx_t_6, ((PyObject *)(&PyList_Type)));
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 113, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_token, __pyx_t_7) < 0) __PYX_ERR(0, 113, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":116
 *     #: Tokens received on get_peers response. Map between ip addresses and received token from ip.
 *     #: Needed to send announce_peer to that particular ip.
 *     mytoken = {}             # <<<<<<<<<<<<<<
 *     #: Map beetween transaction id and messages type (to be able to match responses)
 *     transaction_type = {}
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_mytoken, __pyx_t_7) < 0) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":118
 *     mytoken = {}
 *     #: Map beetween transaction id and messages type (to be able to match responses)
 *     transaction_type = {}             # <<<<<<<<<<<<<<
 *     #: A :class:`PollableQueue` of messages (data, (ip, port)) to send
 *     to_send = PollableQueue()
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_transaction_type, __pyx_t_7) < 0) __PYX_ERR(0, 118, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":120
 *     transaction_type = {}
 *     #: A :class:`PollableQueue` of messages (data, (ip, port)) to send
 *     to_send = PollableQueue()             # <<<<<<<<<<<<<<
 *     #: A list of looping iterator to schedule. Calling :meth:`schedule` will do a scheduling for
 *     #: 1 DHT instance
 */
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_PollableQueue); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 120, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_1) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 120, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_to_send, __pyx_t_7) < 0) __PYX_ERR(0, 120, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":123
 *     #: A list of looping iterator to schedule. Calling :meth:`schedule` will do a scheduling for
 *     #: 1 DHT instance
 *     to_schedule = []             # <<<<<<<<<<<<<<
 * 
 *     #: Map torrent hash -> peer ip and port -> received time. hash, ip and port are from
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 123, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_to_schedule, __pyx_t_7) < 0) __PYX_ERR(0, 123, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":128
 *     #: announce_peer query messages. time is the time of the received message. We only keep the
 *     #: 100 most recent (ip, port). A (ip, port) couple is kept max 30min
 *     _peers=collections.defaultdict(collections.OrderedDict)             # <<<<<<<<<<<<<<
 *     #: Map torrent hash -> peer ip and port -> received time. hash, ip and port are from get_peers
 *     #: response messages. time is the time of the received message. We keep the 1000 most recent
 */
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_collections); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_collections); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_7 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_6, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_peers, __pyx_t_7) < 0) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":132
 *     #: response messages. time is the time of the received message. We keep the 1000 most recent
 *     #: (ip, port). A (ip, port) couple is kept max 15min
 *     _got_peers=collections.defaultdict(collections.OrderedDict)             # <<<<<<<<<<<<<<
 *     #: internal heap structure used to find the K closed nodes in the DHT from one id
 *     _get_peer_loop_list = []
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_collections); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_collections); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
    }
  }
  __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_1, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_6);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_got_peers, __pyx_t_7) < 0) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":134
 *     _got_peers=collections.defaultdict(collections.OrderedDict)
 *     #: internal heap structure used to find the K closed nodes in the DHT from one id
 *     _get_peer_loop_list = []             # <<<<<<<<<<<<<<
 *     #: Map hash -> time. Pseudo lock structure to ensure we only run background process for
 *     #: :meth:`get_peers` only once by hash
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_get_peer_loop_list, __pyx_t_7) < 0) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":137
 *     #: Map hash -> time. Pseudo lock structure to ensure we only run background process for
 *     #: :meth:`get_peers` only once by hash
 *     _get_peer_loop_lock = {}             # <<<<<<<<<<<<<<
 *     #: same as previous but for :meth:`announce_peer`
 *     _get_closest_loop_lock = {}
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 137, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_get_peer_loop_lock, __pyx_t_7) < 0) __PYX_ERR(0, 137, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":139
 *     _get_peer_loop_lock = {}
 *     #: same as previous but for :meth:`announce_peer`
 *     _get_closest_loop_lock = {}             # <<<<<<<<<<<<<<
 *     #: A queue of DHT messages to send to user defined function (on_`msg`_(query|response)).
 *     #: See the :meth:`register_message` method.
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 139, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_get_closest_loop_lock, __pyx_t_7) < 0) __PYX_ERR(0, 139, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":142
 *     #: A queue of DHT messages to send to user defined function (on_`msg`_(query|response)).
 *     #: See the :meth:`register_message` method.
 *     _to_process = None             # <<<<<<<<<<<<<<
 *     #: A set of messages name (e.g. ``b"find_node"``, ``b"ping"``, ``b"get_peers"``,
 *     #: ``b"announce_peer"``) for which we call user defined functions.
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_to_process, Py_None) < 0) __PYX_ERR(0, 142, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":146
 *     #: ``b"announce_peer"``) for which we call user defined functions.
 *     #: See the :meth:`register_message` method.
 *     _to_process_registered = set()             # <<<<<<<<<<<<<<
 *     #: internal list of supposed alive threads
 *     _threads = []
 */
  __pyx_t_7 = PySet_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 146, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_to_process_registered, __pyx_t_7) < 0) __PYX_ERR(0, 146, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":148
 *     _to_process_registered = set()
 *     #: internal list of supposed alive threads
 *     _threads = []             # <<<<<<<<<<<<<<
 *     #: internal list of supposed zombie (asked to stop but still running) threads
 *     _threads_zombie = []
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_threads_2, __pyx_t_7) < 0) __PYX_ERR(0, 148, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":150
 *     _threads = []
 *     #: internal list of supposed zombie (asked to stop but still running) threads
 *     _threads_zombie = []             # <<<<<<<<<<<<<<
 *     #: last debug message, use to prevent duplicate messages over 5 seconds
 *     _last_debug = ""
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 150, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_threads_zombie, __pyx_t_7) < 0) __PYX_ERR(0, 150, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":152
 *     _threads_zombie = []
 *     #: last debug message, use to prevent duplicate messages over 5 seconds
 *     _last_debug = ""             # <<<<<<<<<<<<<<
 *     #: time of the lat debug message, use to prevent duplicate messages over 5 seconds
 *     _last_debug_time = 0
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_last_debug, __pyx_kp_s__2) < 0) __PYX_ERR(0, 152, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":154
 *     _last_debug = ""
 *     #: time of the lat debug message, use to prevent duplicate messages over 5 seconds
 *     _last_debug_time = 0             # <<<<<<<<<<<<<<
 *     #: number of received messages since the last time :meth:`socket_stats` was called
 *     _socket_in = 0
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_last_debug_time, __pyx_int_0) < 0) __PYX_ERR(0, 154, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":156
 *     _last_debug_time = 0
 *     #: number of received messages since the last time :meth:`socket_stats` was called
 *     _socket_in = 0             # <<<<<<<<<<<<<<
 *     #: number of sended messages since the last time :meth:`socket_stats` was called
 *     _socket_out = 0
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_socket_in, __pyx_int_0) < 0) __PYX_ERR(0, 156, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":158
 *     _socket_in = 0
 *     #: number of sended messages since the last time :meth:`socket_stats` was called
 *     _socket_out = 0             # <<<<<<<<<<<<<<
 *     #: last time :meth:`socket_stats` was called
 *     _last_socket_stats = 0
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_socket_out, __pyx_int_0) < 0) __PYX_ERR(0, 158, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":160
 *     _socket_out = 0
 *     #: last time :meth:`socket_stats` was called
 *     _last_socket_stats = 0             # <<<<<<<<<<<<<<
 *     #: last time the long background cleaning was run
 *     _long_clean = 0
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_last_socket_stats, __pyx_int_0) < 0) __PYX_ERR(0, 160, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":162
 *     _last_socket_stats = 0
 *     #: last time the long background cleaning was run
 *     _long_clean = 0             # <<<<<<<<<<<<<<
 *     #: heigth of the routing table (a binary tree) during the last run of :meth:`_routine`
 *     _root_heigth = 0
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_long_clean, __pyx_int_0) < 0) __PYX_ERR(0, 162, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":164
 *     _long_clean = 0
 *     #: heigth of the routing table (a binary tree) during the last run of :meth:`_routine`
 *     _root_heigth = 0             # <<<<<<<<<<<<<<
 *     #: a :class:`utils.Scheduler` instance
 *     _scheduler = None
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_root_heigth, __pyx_int_0) < 0) __PYX_ERR(0, 164, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":166
 *     _root_heigth = 0
 *     #: a :class:`utils.Scheduler` instance
 *     _scheduler = None             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE->tp_dict, __pyx_n_s_scheduler_2, Py_None) < 0) __PYX_ERR(0, 166, __pyx_L1_error)
  PyType_Modified(__pyx_ptype_5btdht_3dht_DHT_BASE);

  /* "btdht/dht.pyx":170
 * 
 *     def __init__(self, routing_table=None, bind_port=None, bind_ip="0.0.0.0",
 *       id=None, ignored_ip=[], debuglvl=0, prefix="", process_queue_size=500,             # <<<<<<<<<<<<<<
 *       ignored_net=None, scheduler=None
 *     ):
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_k_ = __pyx_t_7;
  __Pyx_GIVEREF(__pyx_t_7);
  __pyx_t_7 = 0;

  /* "btdht/dht.pyx":811
 *     def bootstarp(
 *         self,
 *         addresses=[             # <<<<<<<<<<<<<<
 *             ("router.utorrent.com", 6881),
 *             ("router.bittorrent.com", 6881),
 */
  __pyx_t_7 = PyList_New(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);
  PyList_SET_ITEM(__pyx_t_7, 0, __pyx_tuple__42);
  __Pyx_INCREF(__pyx_tuple__43);
  __Pyx_GIVEREF(__pyx_tuple__43);
  PyList_SET_ITEM(__pyx_t_7, 1, __pyx_tuple__43);
  __Pyx_INCREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);
  PyList_SET_ITEM(__pyx_t_7, 2, __pyx_tuple__44);
  __Pyx_INCREF(__pyx_tuple__45);
  __Pyx_GIVEREF(__pyx_tuple__45);
  PyList_SET_ITEM(__pyx_t_7, 3, __pyx_tuple__45);
  __pyx_k__18 = __pyx_t_7;
  __Pyx_GIVEREF(__pyx_t_7);
  __pyx_t_7 = 0;

  /* "btdht/dht.pyx":1740
 * 
 *     @classmethod
 *     def from_compact_infos(cls, infos):             # <<<<<<<<<<<<<<
 *         """
 *             This is a classmethod
 */
  __Pyx_GetNameInClass(__pyx_t_7, (PyObject *)__pyx_ptype_5btdht_3dht_Node, __pyx_n_s_from_compact_infos); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1740, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);

  /* "btdht/dht.pyx":1739
 *         return struct.pack("!20s4sH", self.id, self._ip, self.port)
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_compact_infos(cls, infos):
 *         """
 */
  __pyx_t_8 = __Pyx_Method_ClassMethod(__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1739, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_Node->tp_dict, __pyx_n_s_from_compact_infos, __pyx_t_8) < 0) __PYX_ERR(0, 1740, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_Node);

  /* "btdht/dht.pyx":1774
 * 
 *     @classmethod
 *     def from_compact_info(cls, info):             # <<<<<<<<<<<<<<
 *         """
 *             This is a classmethod
 */
  __Pyx_GetNameInClass(__pyx_t_8, (PyObject *)__pyx_ptype_5btdht_3dht_Node, __pyx_n_s_from_compact_info); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1774, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "btdht/dht.pyx":1773
 *         return nodes
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_compact_info(cls, info):
 *         """
 */
  __pyx_t_7 = __Pyx_Method_ClassMethod(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1773, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (PyDict_SetItem((PyObject *)__pyx_ptype_5btdht_3dht_Node->tp_dict, __pyx_n_s_from_compact_info, __pyx_t_7) < 0) __PYX_ERR(0, 1774, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5btdht_3dht_Node);

  /* "btdht/dht.pyx":1902
 * 
 * @total_ordering
 * class Bucket(list):             # <<<<<<<<<<<<<<
 *     """
 *         A bucket of nodes in the routing table
 */
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1902, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(((PyObject *)(&PyList_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyList_Type)));
  PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)(&PyList_Type)));
  __pyx_t_8 = __Pyx_CalculateMetaclass(NULL, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1902, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_6 = __Pyx_Py3MetaclassPrepare(__pyx_t_8, __pyx_t_7, __pyx_n_s_Bucket, __pyx_n_s_Bucket, (PyObject *) NULL, __pyx_n_s_btdht_dht, __pyx_kp_s_A_bucket_of_nodes_in_the_routin); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1902, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);

  /* "btdht/dht.pyx":1912
 *     """
 *     #: Maximun number of element in the bucket
 *     max_size = 8             # <<<<<<<<<<<<<<
 *     #: Unix timestamp, last time the bucket had been updated
 *     last_changed = 0
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_max_size, __pyx_int_8) < 0) __PYX_ERR(0, 1912, __pyx_L1_error)

  /* "btdht/dht.pyx":1914
 *     max_size = 8
 *     #: Unix timestamp, last time the bucket had been updated
 *     last_changed = 0             # <<<<<<<<<<<<<<
 *     #: A prefix identifier from 0 to 160 bits for the bucket
 *     id = None
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_last_changed, __pyx_int_0) < 0) __PYX_ERR(0, 1914, __pyx_L1_error)

  /* "btdht/dht.pyx":1916
 *     last_changed = 0
 *     #: A prefix identifier from 0 to 160 bits for the bucket
 *     id = None             # <<<<<<<<<<<<<<
 *     #: Number of signifiant bit in :attr:`id`
 *     id_length = 0
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_id, Py_None) < 0) __PYX_ERR(0, 1916, __pyx_L1_error)

  /* "btdht/dht.pyx":1918
 *     id = None
 *     #: Number of signifiant bit in :attr:`id`
 *     id_length = 0             # <<<<<<<<<<<<<<
 * 
 *     @property
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_id_length, __pyx_int_0) < 0) __PYX_ERR(0, 1918, __pyx_L1_error)

  /* "btdht/dht.pyx":1921
 * 
 *     @property
 *     def to_refresh(self):             # <<<<<<<<<<<<<<
 *         """``True`` if the bucket need refreshing"""
 *         return time.time() - self.last_changed > 15 * 60
 */
  __pyx_t_1 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_6Bucket_1to_refresh, 0, __pyx_n_s_Bucket_to_refresh, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__47)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1921, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "btdht/dht.pyx":1920
 *     id_length = 0
 * 
 *     @property             # <<<<<<<<<<<<<<
 *     def to_refresh(self):
 *         """``True`` if the bucket need refreshing"""
 */
  __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_property, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1920, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_to_refresh, __pyx_t_9) < 0) __PYX_ERR(0, 1921, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":1925
 *         return time.time() - self.last_changed > 15 * 60
 * 
 *     __slot__ = ("id", "id_length")             # <<<<<<<<<<<<<<
 * 
 *     def own(self, id):
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_slot, __pyx_tuple__48) < 0) __PYX_ERR(0, 1925, __pyx_L1_error)

  /* "btdht/dht.pyx":1927
 *     __slot__ = ("id", "id_length")
 * 
 *     def own(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             :param bytes id: A 60bit (20 Bytes) identifier
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_6Bucket_3own, 0, __pyx_n_s_Bucket_own, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__50)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1927, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_own, __pyx_t_9) < 0) __PYX_ERR(0, 1927, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":1952
 *             return False
 * 
 *     def __init__(self, id=b"", id_length=0, init=None):             # <<<<<<<<<<<<<<
 *         self.id = id
 *         self.id_length = id_length # en bit
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_6Bucket_5__init__, 0, __pyx_n_s_Bucket___init, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__52)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1952, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_9, __pyx_tuple__53);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_init_2, __pyx_t_9) < 0) __PYX_ERR(0, 1952, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":1958
 *             super(Bucket, self).__init__(init)
 * 
 *     def random_id(self):             # <<<<<<<<<<<<<<
 *         """
 *             :return: A random id handle by the bucket
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_6Bucket_7random_id, 0, __pyx_n_s_Bucket_random_id, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__55)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1958, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_random_id, __pyx_t_9) < 0) __PYX_ERR(0, 1958, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":1985
 *         return ID(self.id[0:id_length//8] + char + id[id_length//8+1:])
 * 
 *     def get_node(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             :return: A :class:`Node` with :attr:`Node.id` equal to ``id``
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_6Bucket_9get_node, 0, __pyx_n_s_Bucket_get_node, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__57)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1985, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_get_node, __pyx_t_9) < 0) __PYX_ERR(0, 1985, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":1996
 *         raise NotFound()
 * 
 *     def add(self, dht, node):             # <<<<<<<<<<<<<<
 *         """
 *             Try to add a node to the bucket.
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_6Bucket_11add, 0, __pyx_n_s_Bucket_add, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__59)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1996, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_add, __pyx_t_9) < 0) __PYX_ERR(0, 1996, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2044
 *             raise BucketFull()
 * 
 *     def split(self, rt, dht):             # <<<<<<<<<<<<<<
 *         """
 *             Split the bucket into two buckets
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_6Bucket_13split, 0, __pyx_n_s_Bucket_split, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__61)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2044, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_split, __pyx_t_9) < 0) __PYX_ERR(0, 2044, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2080
 *             return (b2, b1)
 * 
 *     def merge(self, bucket):             # <<<<<<<<<<<<<<
 *         """
 *             Merge the bucket with ``bucket``
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_6Bucket_15merge, 0, __pyx_n_s_Bucket_merge, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__63)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2080, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_merge_2, __pyx_t_9) < 0) __PYX_ERR(0, 2080, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2091
 *         return Bucket(id=self.id, id_length=self.id_length - 1, init=l)
 * 
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         return hash(utils.id_to_longid(ID.to_bytes(self.id))[:self.id_length])
 * 
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_6Bucket_17__hash__, 0, __pyx_n_s_Bucket___hash, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__65)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2091, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_hash_2, __pyx_t_9) < 0) __PYX_ERR(0, 2091, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2094
 *         return hash(utils.id_to_longid(ID.to_bytes(self.id))[:self.id_length])
 * 
 *     def __eq__(self, other):             # <<<<<<<<<<<<<<
 *         try:
 *             return self.id_length == other.id_length and self.id == other.id
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_6Bucket_19__eq__, 0, __pyx_n_s_Bucket___eq, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__67)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2094, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_eq, __pyx_t_9) < 0) __PYX_ERR(0, 2094, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2101
 *             return False
 * 
 *     def __lt__(self, other):             # <<<<<<<<<<<<<<
 *         try:
 *             if self.id_length == other.id_length:
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_6Bucket_21__lt__, 0, __pyx_n_s_Bucket___lt, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__69)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2101, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_lt, __pyx_t_9) < 0) __PYX_ERR(0, 2101, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":1901
 *             raise NoTokenError()
 * 
 * @total_ordering             # <<<<<<<<<<<<<<
 * class Bucket(list):
 *     """
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_total_ordering); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1901, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "btdht/dht.pyx":1902
 * 
 * @total_ordering
 * class Bucket(list):             # <<<<<<<<<<<<<<
 *     """
 *         A bucket of nodes in the routing table
 */
  __pyx_t_10 = __Pyx_Py3ClassCreate(__pyx_t_8, __pyx_n_s_Bucket, __pyx_t_7, __pyx_t_6, NULL, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1902, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_11 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_11)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_11);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_9 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_11, __pyx_t_10) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1901, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_Bucket, __pyx_t_9) < 0) __PYX_ERR(0, 1902, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":2115
 * DHT = type(
 *     "DHT",
 *     (DHT_BASE,),             # <<<<<<<<<<<<<<
 *     {
 *         '__doc__': "\n    A DHT class ready for instanciation\n%s" % (
 */
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2115, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE));
  __Pyx_GIVEREF(((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE));
  PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE));

  /* "btdht/dht.pyx":2117
 *     (DHT_BASE,),
 *     {
 *         '__doc__': "\n    A DHT class ready for instanciation\n%s" % (             # <<<<<<<<<<<<<<
 *             "\n".join(DHT_BASE.__doc__.split('\n')[2:]),
 *         )
 */
  __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "btdht/dht.pyx":2118
 *     {
 *         '__doc__': "\n    A DHT class ready for instanciation\n%s" % (
 *             "\n".join(DHT_BASE.__doc__.split('\n')[2:]),             # <<<<<<<<<<<<<<
 *         )
 *     }
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5btdht_3dht_DHT_BASE), __pyx_n_s_doc); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_split); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__71, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyObject_GetSlice(__pyx_t_6, 2, 0, NULL, NULL, &__pyx_slice__72, 1, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyString_Join(__pyx_kp_s__70, __pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_6);
  __pyx_t_6 = 0;

  /* "btdht/dht.pyx":2117
 *     (DHT_BASE,),
 *     {
 *         '__doc__': "\n    A DHT class ready for instanciation\n%s" % (             # <<<<<<<<<<<<<<
 *             "\n".join(DHT_BASE.__doc__.split('\n')[2:]),
 *         )
 */
  __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_A_DHT_class_ready_for_instancia, __pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_doc, __pyx_t_6) < 0) __PYX_ERR(0, 2117, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "btdht/dht.pyx":2113
 * 
 * 
 * DHT = type(             # <<<<<<<<<<<<<<
 *     "DHT",
 *     (DHT_BASE,),
 */
  __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2113, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(__pyx_n_s_DHT);
  __Pyx_GIVEREF(__pyx_n_s_DHT);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_n_s_DHT);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_8);
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)(&PyType_Type)), __pyx_t_6, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2113, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_DHT, __pyx_t_8) < 0) __PYX_ERR(0, 2113, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "btdht/dht.pyx":2124
 * 
 * 
 * class RoutingTable(object):             # <<<<<<<<<<<<<<
 *     """
 *         A routing table for one or more :class:`DHT_BASE` instances
 */
  __pyx_t_8 = __Pyx_CalculateMetaclass(NULL, __pyx_tuple__73); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2124, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_6 = __Pyx_Py3MetaclassPrepare(__pyx_t_8, __pyx_tuple__73, __pyx_n_s_RoutingTable, __pyx_n_s_RoutingTable, (PyObject *) NULL, __pyx_n_s_btdht_dht, __pyx_kp_s_A_routing_table_for_one_or_more); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2124, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);

  /* "btdht/dht.pyx":2132
 *     """
 *     #: :class:`int` the routing table instance verbosity level
 *     debuglvl = 0             # <<<<<<<<<<<<<<
 *     #: The routing table storage data structure, an instance of :class:`datrie.Trie`
 *     trie = None
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_debuglvl, __pyx_int_0) < 0) __PYX_ERR(0, 2132, __pyx_L1_error)

  /* "btdht/dht.pyx":2134
 *     debuglvl = 0
 *     #: The routing table storage data structure, an instance of :class:`datrie.Trie`
 *     trie = None             # <<<<<<<<<<<<<<
 *     #: The state (stoped ?) of the routing table
 *     stoped = True
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_trie, Py_None) < 0) __PYX_ERR(0, 2134, __pyx_L1_error)

  /* "btdht/dht.pyx":2136
 *     trie = None
 *     #: The state (stoped ?) of the routing table
 *     stoped = True             # <<<<<<<<<<<<<<
 *     #: Is a merge sheduled ?
 *     need_merge = False
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_stoped, Py_True) < 0) __PYX_ERR(0, 2136, __pyx_L1_error)

  /* "btdht/dht.pyx":2138
 *     stoped = True
 *     #: Is a merge sheduled ?
 *     need_merge = False             # <<<<<<<<<<<<<<
 *     #: :class:`list` of the :class:`Thread<threading.Thread>` of the routing table instance
 *     threads = []
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_need_merge, Py_False) < 0) __PYX_ERR(0, 2138, __pyx_L1_error)

  /* "btdht/dht.pyx":2140
 *     need_merge = False
 *     #: :class:`list` of the :class:`Thread<threading.Thread>` of the routing table instance
 *     threads = []             # <<<<<<<<<<<<<<
 *     #: A class:`list` of couple (weightless thread name, weightless thread function)
 *     to_schedule = []
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2140, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_threads, __pyx_t_7) < 0) __PYX_ERR(0, 2140, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":2142
 *     threads = []
 *     #: A class:`list` of couple (weightless thread name, weightless thread function)
 *     to_schedule = []             # <<<<<<<<<<<<<<
 *     #: Prefix in logs and threads name
 *     prefix = ""
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2142, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_to_schedule, __pyx_t_7) < 0) __PYX_ERR(0, 2142, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":2144
 *     to_schedule = []
 *     #: Prefix in logs and threads name
 *     prefix = ""             # <<<<<<<<<<<<<<
 * 
 *     #: Current height of the tree :attr:`trie` structure of the routing table
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_prefix, __pyx_kp_s__2) < 0) __PYX_ERR(0, 2144, __pyx_L1_error)

  /* "btdht/dht.pyx":2147
 * 
 *     #: Current height of the tree :attr:`trie` structure of the routing table
 *     _heigth = 1             # <<<<<<<<<<<<<<
 *     #: A set of registered dht instance with this routing table
 *     _dhts = set()
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_heigth_2, __pyx_int_1) < 0) __PYX_ERR(0, 2147, __pyx_L1_error)

  /* "btdht/dht.pyx":2149
 *     _heigth = 1
 *     #: A set of registered dht instance with this routing table
 *     _dhts = set()             # <<<<<<<<<<<<<<
 *     #: A set of torrent id
 *     _info_hash = set()
 */
  __pyx_t_7 = PySet_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2149, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_dhts, __pyx_t_7) < 0) __PYX_ERR(0, 2149, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":2151
 *     _dhts = set()
 *     #: A set of torrent id
 *     _info_hash = set()             # <<<<<<<<<<<<<<
 *     #: A set of dht id
 *     _split_ids = set()
 */
  __pyx_t_7 = PySet_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2151, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_info_hash_2, __pyx_t_7) < 0) __PYX_ERR(0, 2151, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":2153
 *     _info_hash = set()
 *     #: A set of dht id
 *     _split_ids = set()             # <<<<<<<<<<<<<<
 *     #: Internal list of supposed alive threads
 *     _threads = []
 */
  __pyx_t_7 = PySet_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2153, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_split_ids, __pyx_t_7) < 0) __PYX_ERR(0, 2153, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":2155
 *     _split_ids = set()
 *     #: Internal list of supposed alive threads
 *     _threads = []             # <<<<<<<<<<<<<<
 *     #: A set of bucket id to merge (keys of :class:`datrie.Trie`)
 *     _to_merge = set()
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2155, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_threads_2, __pyx_t_7) < 0) __PYX_ERR(0, 2155, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":2157
 *     _threads = []
 *     #: A set of bucket id to merge (keys of :class:`datrie.Trie`)
 *     _to_merge = set()             # <<<<<<<<<<<<<<
 *     #: Internal list of supposed zombie (asked to stop but still running) threads
 *     _threads_zombie= []
 */
  __pyx_t_7 = PySet_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2157, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_to_merge, __pyx_t_7) < 0) __PYX_ERR(0, 2157, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":2159
 *     _to_merge = set()
 *     #: Internal list of supposed zombie (asked to stop but still running) threads
 *     _threads_zombie= []             # <<<<<<<<<<<<<<
 *     #: Last debug message, use to prevent duplicate messages over 5 seconds
 *     _last_debug = ""
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2159, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_threads_zombie, __pyx_t_7) < 0) __PYX_ERR(0, 2159, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":2161
 *     _threads_zombie= []
 *     #: Last debug message, use to prevent duplicate messages over 5 seconds
 *     _last_debug = ""             # <<<<<<<<<<<<<<
 *     #: Time of the last debug message, use to prevent duplicate messages over 5 seconds
 *     _last_debug_time = 0
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_last_debug, __pyx_kp_s__2) < 0) __PYX_ERR(0, 2161, __pyx_L1_error)

  /* "btdht/dht.pyx":2163
 *     _last_debug = ""
 *     #: Time of the last debug message, use to prevent duplicate messages over 5 seconds
 *     _last_debug_time = 0             # <<<<<<<<<<<<<<
 *     #: A :class:`utils.Scheduler` instance
 *     _scheduler = None
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_last_debug_time, __pyx_int_0) < 0) __PYX_ERR(0, 2163, __pyx_L1_error)

  /* "btdht/dht.pyx":2165
 *     _last_debug_time = 0
 *     #: A :class:`utils.Scheduler` instance
 *     _scheduler = None             # <<<<<<<<<<<<<<
 *     #: A :class:`threading.Lock` instance to prevent concurrent start to happend
 *     _lock = None
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_scheduler_2, Py_None) < 0) __PYX_ERR(0, 2165, __pyx_L1_error)

  /* "btdht/dht.pyx":2167
 *     _scheduler = None
 *     #: A :class:`threading.Lock` instance to prevent concurrent start to happend
 *     _lock = None             # <<<<<<<<<<<<<<
 * 
 *     def __init__(self, scheduler, debuglvl=0, prefix=""):
 */
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_lock, Py_None) < 0) __PYX_ERR(0, 2167, __pyx_L1_error)

  /* "btdht/dht.pyx":2169
 *     _lock = None
 * 
 *     def __init__(self, scheduler, debuglvl=0, prefix=""):             # <<<<<<<<<<<<<<
 *         self.debuglvl = debuglvl
 *         self.trie = datrie.Trie(u"01")
 */
  __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_1__init__, 0, __pyx_n_s_RoutingTable___init, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__75)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2169, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_7, __pyx_tuple__76);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_init_2, __pyx_t_7) < 0) __PYX_ERR(0, 2169, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":2193
 *         ]
 * 
 *     def stop_bg(self):             # <<<<<<<<<<<<<<
 *         """stop the routing table and return immediately"""
 *         if not self.stoped:
 */
  __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_3stop_bg, 0, __pyx_n_s_RoutingTable_stop_bg, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__78)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_stop_bg, __pyx_t_7) < 0) __PYX_ERR(0, 2193, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":2198
 *             Thread(target=self.stop).start()
 * 
 *     def stop(self):             # <<<<<<<<<<<<<<
 *         """stop the routing table and wait for all threads to terminate"""
 *         if self.stoped:
 */
  __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_5stop, 0, __pyx_n_s_RoutingTable_stop, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__80)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2198, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_stop, __pyx_t_7) < 0) __PYX_ERR(0, 2198, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "btdht/dht.pyx":2226
 * 
 *     @property
 *     def zombie(self):             # <<<<<<<<<<<<<<
 *         """``True`` if dht is stopped but one thread or more remains alive, ``False`` otherwise"""
 *         return self.stoped and [t for t in self._threads if t.is_alive()]
 */
  __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_7zombie, 0, __pyx_n_s_RoutingTable_zombie, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__82)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);

  /* "btdht/dht.pyx":2225
 *             self._threads = []
 * 
 *     @property             # <<<<<<<<<<<<<<
 *     def zombie(self):
 *         """``True`` if dht is stopped but one thread or more remains alive, ``False`` otherwise"""
 */
  __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_property, __pyx_t_7); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2225, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_zombie, __pyx_t_9) < 0) __PYX_ERR(0, 2226, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2230
 *         return self.stoped and [t for t in self._threads if t.is_alive()]
 * 
 *     def start(self):             # <<<<<<<<<<<<<<
 *         """start the routing table"""
 *         with self._lock:
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_9start, 0, __pyx_n_s_RoutingTable_start, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__84)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2230, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_start, __pyx_t_9) < 0) __PYX_ERR(0, 2230, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2244
 *             self._scheduler.add_thread(name, function)
 * 
 *     def is_alive(self):             # <<<<<<<<<<<<<<
 *         """
 *             Test if all routing table threads are alive. If a thread is found dead, stop the
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_11is_alive, 0, __pyx_n_s_RoutingTable_is_alive, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__86)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2244, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_is_alive, __pyx_t_9) < 0) __PYX_ERR(0, 2244, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2268
 *             return True
 * 
 *     def register_torrent(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             Register a torrent ``id`` (info_hash) for being tracked by the routing table.
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_13register_torrent, 0, __pyx_n_s_RoutingTable_register_torrent, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__88)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2268, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_register_torrent, __pyx_t_9) < 0) __PYX_ERR(0, 2268, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2282
 *         self._info_hash.add(id)
 * 
 *     def release_torrent(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             Release a torrent ``id`` (info_hash) and program the routing table to be merged
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_15release_torrent, 0, __pyx_n_s_RoutingTable_release_torrent, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__90)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2282, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_release_torrent, __pyx_t_9) < 0) __PYX_ERR(0, 2282, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2302
 *             pass
 * 
 *     def _merge_loop(self):             # <<<<<<<<<<<<<<
 *         """Weigthless thread handling the merge of the routing table"""
 *         yield 0
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_17_merge_loop, 0, __pyx_n_s_RoutingTable__merge_loop, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__33)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2302, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_merge_loop, __pyx_t_9) < 0) __PYX_ERR(0, 2302, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2330
 *                     yield i
 * 
 *     def register_torrent_longterm(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             Same as :meth:`register_torrent` but garanty that the torrent wont be released
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_20register_torrent_longterm, 0, __pyx_n_s_RoutingTable_register_torrent_lo, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__93)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2330, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_register_torrent_longterm, __pyx_t_9) < 0) __PYX_ERR(0, 2330, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2339
 *         self._split_ids.add(id)
 * 
 *     def release_torrent_longterm(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             For releasing torrent registered with the :meth`register_torrent_longterm` method
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_22release_torrent_longterm, 0, __pyx_n_s_RoutingTable_release_torrent_lon, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__95)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2339, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_release_torrent_longterm, __pyx_t_9) < 0) __PYX_ERR(0, 2339, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2354
 *             pass
 * 
 *     def register_dht(self, dht):             # <<<<<<<<<<<<<<
 *         """
 *             Register a ``dht`` instance to the routing table
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_24register_dht, 0, __pyx_n_s_RoutingTable_register_dht, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__97)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2354, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_register_dht, __pyx_t_9) < 0) __PYX_ERR(0, 2354, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2366
 *         self._split_ids.add(dht.myid.value)
 * 
 *     def release_dht(self, dht):             # <<<<<<<<<<<<<<
 *         """
 *             Release a ``dht`` instance to the routing table, and shedule the routing table for a
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_26release_dht, 0, __pyx_n_s_RoutingTable_release_dht, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__99)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2366, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_release_dht, __pyx_t_9) < 0) __PYX_ERR(0, 2366, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2388
 *             self.stop()
 * 
 *     def debug(self, lvl, msg):             # <<<<<<<<<<<<<<
 *         """same as :meth:`DHT_BASE.debug`"""
 *         if (
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_28debug, 0, __pyx_n_s_RoutingTable_debug, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__101)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_debug, __pyx_t_9) < 0) __PYX_ERR(0, 2388, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2398
 *             self._last_debug_time = time.time()
 * 
 *     def _routine(self):             # <<<<<<<<<<<<<<
 *         """
 *             Weigthless thread perfoming routine on the routing table like performing quering to
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_30_routine, 0, __pyx_n_s_RoutingTable__routine, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__34)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2398, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_routine, __pyx_t_9) < 0) __PYX_ERR(0, 2398, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2447
 *             last_explore_tree = time.time()
 * 
 *     def empty(self):             # <<<<<<<<<<<<<<
 *         """Empty the routing table, deleting all buckets"""
 *         self.trie = datrie.Trie("".join(chr(i) for i in range(256)))
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_33empty, 0, __pyx_n_s_RoutingTable_empty, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__104)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2447, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_empty, __pyx_t_9) < 0) __PYX_ERR(0, 2447, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2452
 *         self.trie[u""]=Bucket()
 * 
 *     def stats(self):             # <<<<<<<<<<<<<<
 *         """
 *             :return: A triple (number of nodes, number of good nodes, number of bad nodes)
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_35stats, 0, __pyx_n_s_RoutingTable_stats, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__106)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2452, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_stats, __pyx_t_9) < 0) __PYX_ERR(0, 2452, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2475
 *         return (nodes, goods, bads)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return iter(self.trie.values())
 * 
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_37__iter__, 0, __pyx_n_s_RoutingTable___iter, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__108)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2475, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_iter, __pyx_t_9) < 0) __PYX_ERR(0, 2475, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2478
 *         return iter(self.trie.values())
 * 
 *     def get_node(self, id):             # <<<<<<<<<<<<<<
 *         """
 *             :param bytes id: A 160 bits (20 Bytes) identifier
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_39get_node, 0, __pyx_n_s_RoutingTable_get_node, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__110)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2478, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_get_node, __pyx_t_9) < 0) __PYX_ERR(0, 2478, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2488
 *         return b.get_node(id)
 * 
 *     def find(self, id, errno=0):             # <<<<<<<<<<<<<<
 *         """
 *             :param bytes id: A 160 bits (20 Bytes) identifier
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_41find, 0, __pyx_n_s_RoutingTable_find, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__112)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2488, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_9, __pyx_tuple__113);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_find, __pyx_t_9) < 0) __PYX_ERR(0, 2488, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2515
 *                     raise
 * 
 *     def get_closest_nodes(self, id, bad=False, errno=0):             # <<<<<<<<<<<<<<
 *         """
 *             Return the K closest nodes from ``id`` in the routing table
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_43get_closest_nodes, 0, __pyx_n_s_RoutingTable_get_closest_nodes, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__115)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2515, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_9, __pyx_tuple__116);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_get_closest_nodes, __pyx_t_9) < 0) __PYX_ERR(0, 2515, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2552
 *             return self.get_closest_nodes(id, bad=bad, errno=errno+1)
 * 
 *     def add(self, dht, node):             # <<<<<<<<<<<<<<
 *         """
 *             Add a node the the routing table
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_45add, 0, __pyx_n_s_RoutingTable_add, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__118)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2552, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_add, __pyx_t_9) < 0) __PYX_ERR(0, 2552, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2577
 *                 print("%r" % b)
 * 
 *     def heigth(self):             # <<<<<<<<<<<<<<
 *         """
 *             :return: the height of the tree of the routing table
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_47heigth, 0, __pyx_n_s_RoutingTable_heigth, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__120)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_heigth, __pyx_t_9) < 0) __PYX_ERR(0, 2577, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2584
 *         return self._heigth
 * 
 *     def split(self, dht, bucket):             # <<<<<<<<<<<<<<
 *         """
 *             Split ``bucket`` in two
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_49split, 0, __pyx_n_s_RoutingTable_split, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__122)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2584, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_split, __pyx_t_9) < 0) __PYX_ERR(0, 2584, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2607
 *             self.debug(1, "%r" % e)
 * 
 *     def merge(self):             # <<<<<<<<<<<<<<
 *         """Request a merge to be perform"""
 *         self.need_merge = True
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_51merge, 0, __pyx_n_s_RoutingTable_merge, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__124)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2607, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_merge_2, __pyx_t_9) < 0) __PYX_ERR(0, 2607, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2611
 *         self.need_merge = True
 * 
 *     def _merge(self, stack=None):             # <<<<<<<<<<<<<<
 *         """
 *             Perform a merge of the routing table. If ``stack`` is provided, only a partial merge
 */
  __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_5btdht_3dht_12RoutingTable_53_merge, 0, __pyx_n_s_RoutingTable__merge, NULL, __pyx_n_s_btdht_dht, __pyx_d, ((PyObject *)__pyx_codeobj__37)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2611, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_9, __pyx_tuple__126);
  if (__Pyx_SetNameInClass(__pyx_t_6, __pyx_n_s_merge, __pyx_t_9) < 0) __PYX_ERR(0, 2611, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "btdht/dht.pyx":2124
 * 
 * 
 * class RoutingTable(object):             # <<<<<<<<<<<<<<
 *     """
 *         A routing table for one or more :class:`DHT_BASE` instances
 */
  __pyx_t_9 = __Pyx_Py3ClassCreate(__pyx_t_8, __pyx_n_s_RoutingTable, __pyx_tuple__73, __pyx_t_6, NULL, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2124, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_RoutingTable, __pyx_t_9) < 0) __PYX_ERR(0, 2124, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "(tree fragment)":1
 * def __pyx_unpickle_DHT_BASE(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */
  __pyx_t_8 = PyCFunction_NewEx(&__pyx_mdef_5btdht_3dht_1__pyx_unpickle_DHT_BASE, NULL, __pyx_n_s_btdht_dht); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_DHT_BASE, __pyx_t_8) < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "(tree fragment)":11
 *         __pyx_unpickle_DHT_BASE__set_state(<DHT_BASE> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_DHT_BASE__set_state(DHT_BASE __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result._myid = __pyx_state[0]
 *     if len(__pyx_state) > 1 and hasattr(__pyx_result, '__dict__'):
 */
  __pyx_t_8 = PyCFunction_NewEx(&__pyx_mdef_5btdht_3dht_3__pyx_unpickle_Node, NULL, __pyx_n_s_btdht_dht); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_Node, __pyx_t_8) < 0) __PYX_ERR(1, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "btdht/dht.pyx":1
 * # -*- coding: utf-8 -*-             # <<<<<<<<<<<<<<
 * # This program is distributed in the hope that it will be useful, but WITHOUT
 * # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 */
  __pyx_t_8 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_8) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "carray.from_py":77
 * 
 * @cname("__Pyx_carray_from_py_char")
 * cdef int __Pyx_carray_from_py_char(object o, base_type *v, Py_ssize_t length) except -1:             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t i = length
 *     try:
 */

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init btdht.dht", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_CLEAR(__pyx_m);
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init btdht.dht");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  return (__pyx_m != NULL) ? 0 : -1;
  #elif PY_MAJOR_VERSION >= 3
  return __pyx_m;
  #else
  return;
  #endif
}

/* --- Runtime support code --- */
/* Refnanny */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule(modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, "RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

/* PyObjectGetAttrStr */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#endif

/* GetBuiltinName */
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

/* RaiseDoubleKeywords */
static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

/* ParseKeywords */
static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

/* RaiseArgTupleInvalid */
static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

/* PyObjectCall */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = Py_TYPE(func)->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyErrFetchRestore */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}
#endif

/* RaiseException */
#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    __Pyx_PyThreadState_declare
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_PyThreadState_assign
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
    if (cause) {
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
#if CYTHON_COMPILING_IN_PYPY
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#else
        PyThreadState *tstate = __Pyx_PyThreadState_Current;
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

/* PyDictVersioning */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
    PyObject **dictptr = NULL;
    Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
    if (offset) {
#if CYTHON_COMPILING_IN_CPYTHON
        dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
#else
        dictptr = _PyObject_GetDictPtr(obj);
#endif
    }
    return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
}
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
        return 0;
    return obj_dict_version == __Pyx_get_object_dict_version(obj);
}
#endif

/* GetModuleGlobalName */
#if CYTHON_USE_DICT_VERSIONS
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
#else
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
#endif
{
    PyObject *result;
#if !CYTHON_AVOID_BORROWED_REFS
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
    result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    } else if (unlikely(PyErr_Occurred())) {
        return NULL;
    }
#else
    result = PyDict_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
#endif
#else
    result = PyObject_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
    PyErr_Clear();
#endif
    return __Pyx_GetBuiltinName(name);
}

/* PyCFunctionFastCall */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
    PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
    PyObject *self = PyCFunction_GET_SELF(func);
    int flags = PyCFunction_GET_FLAGS(func);
    assert(PyCFunction_Check(func));
    assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)));
    assert(nargs >= 0);
    assert(nargs == 0 || args != NULL);
    /* _PyCFunction_FastCallDict() must not be called with an exception set,
       because it may clear it (directly or indirectly) and so the
       caller loses its exception */
    assert(!PyErr_Occurred());
    if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
        return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL);
    } else {
        return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs);
    }
}
#endif

/* PyFunctionFastCall */
#if CYTHON_FAST_PYCALL
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
                                               PyObject *globals) {
    PyFrameObject *f;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject **fastlocals;
    Py_ssize_t i;
    PyObject *result;
    assert(globals != NULL);
    /* XXX Perhaps we should create a specialized
       PyFrame_New() that doesn't take locals, but does
       take builtins without sanity checking them.
       */
    assert(tstate != NULL);
    f = PyFrame_New(tstate, co, globals, NULL);
    if (f == NULL) {
        return NULL;
    }
    fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
    for (i = 0; i < na; i++) {
        Py_INCREF(*args);
        fastlocals[i] = *args++;
    }
    result = PyEval_EvalFrameEx(f,0);
    ++tstate->recursion_depth;
    Py_DECREF(f);
    --tstate->recursion_depth;
    return result;
}
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) {
    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
    PyObject *globals = PyFunction_GET_GLOBALS(func);
    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
    PyObject *closure;
#if PY_MAJOR_VERSION >= 3
    PyObject *kwdefs;
#endif
    PyObject *kwtuple, **k;
    PyObject **d;
    Py_ssize_t nd;
    Py_ssize_t nk;
    PyObject *result;
    assert(kwargs == NULL || PyDict_Check(kwargs));
    nk = kwargs ? PyDict_Size(kwargs) : 0;
    if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
        return NULL;
    }
    if (
#if PY_MAJOR_VERSION >= 3
            co->co_kwonlyargcount == 0 &&
#endif
            likely(kwargs == NULL || nk == 0) &&
            co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
        if (argdefs == NULL && co->co_argcount == nargs) {
            result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
            goto done;
        }
        else if (nargs == 0 && argdefs != NULL
                 && co->co_argcount == Py_SIZE(argdefs)) {
            /* function called with no arguments, but all parameters have
               a default value: use default values as arguments .*/
            args = &PyTuple_GET_ITEM(argdefs, 0);
            result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
            goto done;
        }
    }
    if (kwargs != NULL) {
        Py_ssize_t pos, i;
        kwtuple = PyTuple_New(2 * nk);
        if (kwtuple == NULL) {
            result = NULL;
            goto done;
        }
        k = &PyTuple_GET_ITEM(kwtuple, 0);
        pos = i = 0;
        while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
            Py_INCREF(k[i]);
            Py_INCREF(k[i+1]);
            i += 2;
        }
        nk = i / 2;
    }
    else {
        kwtuple = NULL;
        k = NULL;
    }
    closure = PyFunction_GET_CLOSURE(func);
#if PY_MAJOR_VERSION >= 3
    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
#endif
    if (argdefs != NULL) {
        d = &PyTuple_GET_ITEM(argdefs, 0);
        nd = Py_SIZE(argdefs);
    }
    else {
        d = NULL;
        nd = 0;
    }
#if PY_MAJOR_VERSION >= 3
    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, kwdefs, closure);
#else
    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, closure);
#endif
    Py_XDECREF(kwtuple);
done:
    Py_LeaveRecursiveCall();
    return result;
}
#endif
#endif

/* PyObjectCall2Args */
static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
    PyObject *args, *result = NULL;
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(function)) {
        PyObject *args[2] = {arg1, arg2};
        return __Pyx_PyFunction_FastCall(function, args, 2);
    }
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(function)) {
        PyObject *args[2] = {arg1, arg2};
        return __Pyx_PyCFunction_FastCall(function, args, 2);
    }
    #endif
    args = PyTuple_New(2);
    if (unlikely(!args)) goto done;
    Py_INCREF(arg1);
    PyTuple_SET_ITEM(args, 0, arg1);
    Py_INCREF(arg2);
    PyTuple_SET_ITEM(args, 1, arg2);
    Py_INCREF(function);
    result = __Pyx_PyObject_Call(function, args, NULL);
    Py_DECREF(args);
    Py_DECREF(function);
done:
    return result;
}

/* PyObjectCallMethO */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallOneArg */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, &arg, 1);
    }
#endif
    if (likely(PyCFunction_Check(func))) {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
#if CYTHON_FAST_PYCCALL
        } else if (__Pyx_PyFastCFunction_Check(func)) {
            return __Pyx_PyCFunction_FastCall(func, &arg, 1);
#endif
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_Pack(1, arg);
    if (unlikely(!args)) return NULL;
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
#endif

/* PyObjectCallNoArg */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, NULL, 0);
    }
#endif
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func)))
#else
    if (likely(PyCFunction_Check(func)))
#endif
    {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

/* PyObjectSetAttrStr */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_setattro))
        return tp->tp_setattro(obj, attr_name, value);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_setattr))
        return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
#endif
    return PyObject_SetAttr(obj, attr_name, value);
}
#endif

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* GetTopmostException */
#if CYTHON_USE_EXC_INFO_STACK
static _PyErr_StackItem *
__Pyx_PyErr_GetTopmostException(PyThreadState *tstate)
{
    _PyErr_StackItem *exc_info = tstate->exc_info;
    while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
           exc_info->previous_item != NULL)
    {
        exc_info = exc_info->previous_item;
    }
    return exc_info;
}
#endif

/* SaveResetException */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
    *type = exc_info->exc_type;
    *value = exc_info->exc_value;
    *tb = exc_info->exc_traceback;
    #else
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    #endif
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = tstate->exc_info;
    tmp_type = exc_info->exc_type;
    tmp_value = exc_info->exc_value;
    tmp_tb = exc_info->exc_traceback;
    exc_info->exc_type = type;
    exc_info->exc_value = value;
    exc_info->exc_traceback = tb;
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
#endif

/* GetException */
#if CYTHON_FAST_THREAD_STATE
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb)
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
#endif
{
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_FAST_THREAD_STATE
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_FAST_THREAD_STATE
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_FAST_THREAD_STATE
    #if CYTHON_USE_EXC_INFO_STACK
    {
        _PyErr_StackItem *exc_info = tstate->exc_info;
        tmp_type = exc_info->exc_type;
        tmp_value = exc_info->exc_value;
        tmp_tb = exc_info->exc_traceback;
        exc_info->exc_type = local_type;
        exc_info->exc_value = local_value;
        exc_info->exc_traceback = local_tb;
    }
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}

/* PyErrExceptionMatches */
#if CYTHON_FAST_THREAD_STATE
static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        if (__Pyx_PyErr_GivenExceptionMatches(exc_type, PyTuple_GET_ITEM(tuple, i))) return 1;
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
    PyObject *exc_type = tstate->curexc_type;
    if (exc_type == err) return 1;
    if (unlikely(!exc_type)) return 0;
    if (unlikely(PyTuple_Check(err)))
        return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err);
    return __Pyx_PyErr_GivenExceptionMatches(exc_type, err);
}
#endif

/* SliceObject */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
        Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
        int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
#if CYTHON_USE_TYPE_SLOTS
    PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3
    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
    if (likely(ms && ms->sq_slice)) {
        if (!has_cstart) {
            if (_py_start && (*_py_start != Py_None)) {
                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstart = 0;
        }
        if (!has_cstop) {
            if (_py_stop && (*_py_stop != Py_None)) {
                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstop = PY_SSIZE_T_MAX;
        }
        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
            Py_ssize_t l = ms->sq_length(obj);
            if (likely(l >= 0)) {
                if (cstop < 0) {
                    cstop += l;
                    if (cstop < 0) cstop = 0;
                }
                if (cstart < 0) {
                    cstart += l;
                    if (cstart < 0) cstart = 0;
                }
            } else {
                if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                    goto bad;
                PyErr_Clear();
            }
        }
        return ms->sq_slice(obj, cstart, cstop);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_subscript))
#endif
    {
        PyObject* result;
        PyObject *py_slice, *py_start, *py_stop;
        if (_py_slice) {
            py_slice = *_py_slice;
        } else {
            PyObject* owned_start = NULL;
            PyObject* owned_stop = NULL;
            if (_py_start) {
                py_start = *_py_start;
            } else {
                if (has_cstart) {
                    owned_start = py_start = PyInt_FromSsize_t(cstart);
                    if (unlikely(!py_start)) goto bad;
                } else
                    py_start = Py_None;
            }
            if (_py_stop) {
                py_stop = *_py_stop;
            } else {
                if (has_cstop) {
                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
                    if (unlikely(!py_stop)) {
                        Py_XDECREF(owned_start);
                        goto bad;
                    }
                } else
                    py_stop = Py_None;
            }
            py_slice = PySlice_New(py_start, py_stop, Py_None);
            Py_XDECREF(owned_start);
            Py_XDECREF(owned_stop);
            if (unlikely(!py_slice)) goto bad;
        }
#if CYTHON_USE_TYPE_SLOTS
        result = mp->mp_subscript(obj, py_slice);
#else
        result = PyObject_GetItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
bad:
    return NULL;
}

/* GetItemInt */
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyList_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyTuple_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return NULL;
                    PyErr_Clear();
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

/* FastTypeChecks */
#if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
    while (a) {
        a = a->tp_base;
        if (a == b)
            return 1;
    }
    return b == &PyBaseObject_Type;
}
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
    PyObject *mro;
    if (a == b) return 1;
    mro = a->tp_mro;
    if (likely(mro)) {
        Py_ssize_t i, n;
        n = PyTuple_GET_SIZE(mro);
        for (i = 0; i < n; i++) {
            if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
                return 1;
        }
        return 0;
    }
    return __Pyx_InBases(a, b);
}
#if PY_MAJOR_VERSION == 2
static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
    PyObject *exception, *value, *tb;
    int res;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&exception, &value, &tb);
    res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
    if (unlikely(res == -1)) {
        PyErr_WriteUnraisable(err);
        res = 0;
    }
    if (!res) {
        res = PyObject_IsSubclass(err, exc_type2);
        if (unlikely(res == -1)) {
            PyErr_WriteUnraisable(err);
            res = 0;
        }
    }
    __Pyx_ErrRestore(exception, value, tb);
    return res;
}
#else
static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
    int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
    if (!res) {
        res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
    }
    return res;
}
#endif
static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    assert(PyExceptionClass_Check(exc_type));
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        PyObject *t = PyTuple_GET_ITEM(tuple, i);
        #if PY_MAJOR_VERSION < 3
        if (likely(exc_type == t)) return 1;
        #endif
        if (likely(PyExceptionClass_Check(t))) {
            if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
        } else {
        }
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
    if (likely(err == exc_type)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        if (likely(PyExceptionClass_Check(exc_type))) {
            return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
        } else if (likely(PyTuple_Check(exc_type))) {
            return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
        } else {
        }
    }
    return PyErr_GivenExceptionMatches(err, exc_type);
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
    assert(PyExceptionClass_Check(exc_type1));
    assert(PyExceptionClass_Check(exc_type2));
    if (likely(err == exc_type1 || err == exc_type2)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
    }
    return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
}
#endif

/* None */
static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) {
    PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname);
}

/* FetchCommonType */
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
    PyObject* fake_module;
    PyTypeObject* cached_type = NULL;
    fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
    if (!fake_module) return NULL;
    Py_INCREF(fake_module);
    cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
    if (cached_type) {
        if (!PyType_Check((PyObject*)cached_type)) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s is not a type object",
                type->tp_name);
            goto bad;
        }
        if (cached_type->tp_basicsize != type->tp_basicsize) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s has the wrong size, try recompiling",
                type->tp_name);
            goto bad;
        }
    } else {
        if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
        PyErr_Clear();
        if (PyType_Ready(type) < 0) goto bad;
        if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
            goto bad;
        Py_INCREF(type);
        cached_type = type;
    }
done:
    Py_DECREF(fake_module);
    return cached_type;
bad:
    Py_XDECREF(cached_type);
    cached_type = NULL;
    goto done;
}

/* CythonFunctionShared */
#include <structmember.h>
static PyObject *
__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure)
{
    if (unlikely(op->func_doc == NULL)) {
        if (op->func.m_ml->ml_doc) {
#if PY_MAJOR_VERSION >= 3
            op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc);
#else
            op->func_doc = PyString_FromString(op->func.m_ml->ml_doc);
#endif
            if (unlikely(op->func_doc == NULL))
                return NULL;
        } else {
            Py_INCREF(Py_None);
            return Py_None;
        }
    }
    Py_INCREF(op->func_doc);
    return op->func_doc;
}
static int
__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value, CYTHON_UNUSED void *context)
{
    PyObject *tmp = op->func_doc;
    if (value == NULL) {
        value = Py_None;
    }
    Py_INCREF(value);
    op->func_doc = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
{
    if (unlikely(op->func_name == NULL)) {
#if PY_MAJOR_VERSION >= 3
        op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name);
#else
        op->func_name = PyString_InternFromString(op->func.m_ml->ml_name);
#endif
        if (unlikely(op->func_name == NULL))
            return NULL;
    }
    Py_INCREF(op->func_name);
    return op->func_name;
}
static int
__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value, CYTHON_UNUSED void *context)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value)))
#else
    if (unlikely(value == NULL || !PyString_Check(value)))
#endif
    {
        PyErr_SetString(PyExc_TypeError,
                        "__name__ must be set to a string object");
        return -1;
    }
    tmp = op->func_name;
    Py_INCREF(value);
    op->func_name = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
{
    Py_INCREF(op->func_qualname);
    return op->func_qualname;
}
static int
__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value, CYTHON_UNUSED void *context)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value)))
#else
    if (unlikely(value == NULL || !PyString_Check(value)))
#endif
    {
        PyErr_SetString(PyExc_TypeError,
                        "__qualname__ must be set to a string object");
        return -1;
    }
    tmp = op->func_qualname;
    Py_INCREF(value);
    op->func_qualname = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure)
{
    PyObject *self;
    self = m->func_closure;
    if (self == NULL)
        self = Py_None;
    Py_INCREF(self);
    return self;
}
static PyObject *
__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
{
    if (unlikely(op->func_dict == NULL)) {
        op->func_dict = PyDict_New();
        if (unlikely(op->func_dict == NULL))
            return NULL;
    }
    Py_INCREF(op->func_dict);
    return op->func_dict;
}
static int
__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value, CYTHON_UNUSED void *context)
{
    PyObject *tmp;
    if (unlikely(value == NULL)) {
        PyErr_SetString(PyExc_TypeError,
               "function's dictionary may not be deleted");
        return -1;
    }
    if (unlikely(!PyDict_Check(value))) {
        PyErr_SetString(PyExc_TypeError,
               "setting function's dictionary to a non-dict");
        return -1;
    }
    tmp = op->func_dict;
    Py_INCREF(value);
    op->func_dict = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
{
    Py_INCREF(op->func_globals);
    return op->func_globals;
}
static PyObject *
__Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
{
    Py_INCREF(Py_None);
    return Py_None;
}
static PyObject *
__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context)
{
    PyObject* result = (op->func_code) ? op->func_code : Py_None;
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) {
    int result = 0;
    PyObject *res = op->defaults_getter((PyObject *) op);
    if (unlikely(!res))
        return -1;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    op->defaults_tuple = PyTuple_GET_ITEM(res, 0);
    Py_INCREF(op->defaults_tuple);
    op->defaults_kwdict = PyTuple_GET_ITEM(res, 1);
    Py_INCREF(op->defaults_kwdict);
    #else
    op->defaults_tuple = PySequence_ITEM(res, 0);
    if (unlikely(!op->defaults_tuple)) result = -1;
    else {
        op->defaults_kwdict = PySequence_ITEM(res, 1);
        if (unlikely(!op->defaults_kwdict)) result = -1;
    }
    #endif
    Py_DECREF(res);
    return result;
}
static int
__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value, CYTHON_UNUSED void *context) {
    PyObject* tmp;
    if (!value) {
        value = Py_None;
    } else if (value != Py_None && !PyTuple_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__defaults__ must be set to a tuple object");
        return -1;
    }
    Py_INCREF(value);
    tmp = op->defaults_tuple;
    op->defaults_tuple = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context) {
    PyObject* result = op->defaults_tuple;
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
            result = op->defaults_tuple;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value, CYTHON_UNUSED void *context) {
    PyObject* tmp;
    if (!value) {
        value = Py_None;
    } else if (value != Py_None && !PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__kwdefaults__ must be set to a dict object");
        return -1;
    }
    Py_INCREF(value);
    tmp = op->defaults_kwdict;
    op->defaults_kwdict = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context) {
    PyObject* result = op->defaults_kwdict;
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
            result = op->defaults_kwdict;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value, CYTHON_UNUSED void *context) {
    PyObject* tmp;
    if (!value || value == Py_None) {
        value = NULL;
    } else if (!PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__annotations__ must be set to a dict object");
        return -1;
    }
    Py_XINCREF(value);
    tmp = op->func_annotations;
    op->func_annotations = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *context) {
    PyObject* result = op->func_annotations;
    if (unlikely(!result)) {
        result = PyDict_New();
        if (unlikely(!result)) return NULL;
        op->func_annotations = result;
    }
    Py_INCREF(result);
    return result;
}
static PyGetSetDef __pyx_CyFunction_getsets[] = {
    {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    {(char *) "__doc__",  (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0},
    {(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0},
    {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0},
    {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0},
    {0, 0, 0, 0, 0}
};
static PyMemberDef __pyx_CyFunction_members[] = {
    {(char *) "__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), PY_WRITE_RESTRICTED, 0},
    {0, 0, 0,  0, 0}
};
static PyObject *
__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args)
{
#if PY_MAJOR_VERSION >= 3
    Py_INCREF(m->func_qualname);
    return m->func_qualname;
#else
    return PyString_FromString(m->func.m_ml->ml_name);
#endif
}
static PyMethodDef __pyx_CyFunction_methods[] = {
    {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0},
    {0, 0, 0, 0}
};
#if PY_VERSION_HEX < 0x030500A0
#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist)
#else
#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func.m_weakreflist)
#endif
static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject *op, PyMethodDef *ml, int flags, PyObject* qualname,
                                       PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
    if (unlikely(op == NULL))
        return NULL;
    op->flags = flags;
    __Pyx_CyFunction_weakreflist(op) = NULL;
    op->func.m_ml = ml;
    op->func.m_self = (PyObject *) op;
    Py_XINCREF(closure);
    op->func_closure = closure;
    Py_XINCREF(module);
    op->func.m_module = module;
    op->func_dict = NULL;
    op->func_name = NULL;
    Py_INCREF(qualname);
    op->func_qualname = qualname;
    op->func_doc = NULL;
    op->func_classobj = NULL;
    op->func_globals = globals;
    Py_INCREF(op->func_globals);
    Py_XINCREF(code);
    op->func_code = code;
    op->defaults_pyobjects = 0;
    op->defaults_size = 0;
    op->defaults = NULL;
    op->defaults_tuple = NULL;
    op->defaults_kwdict = NULL;
    op->defaults_getter = NULL;
    op->func_annotations = NULL;
    return (PyObject *) op;
}
static int
__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m)
{
    Py_CLEAR(m->func_closure);
    Py_CLEAR(m->func.m_module);
    Py_CLEAR(m->func_dict);
    Py_CLEAR(m->func_name);
    Py_CLEAR(m->func_qualname);
    Py_CLEAR(m->func_doc);
    Py_CLEAR(m->func_globals);
    Py_CLEAR(m->func_code);
    Py_CLEAR(m->func_classobj);
    Py_CLEAR(m->defaults_tuple);
    Py_CLEAR(m->defaults_kwdict);
    Py_CLEAR(m->func_annotations);
    if (m->defaults) {
        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
        int i;
        for (i = 0; i < m->defaults_pyobjects; i++)
            Py_XDECREF(pydefaults[i]);
        PyObject_Free(m->defaults);
        m->defaults = NULL;
    }
    return 0;
}
static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m)
{
    if (__Pyx_CyFunction_weakreflist(m) != NULL)
        PyObject_ClearWeakRefs((PyObject *) m);
    __Pyx_CyFunction_clear(m);
    PyObject_GC_Del(m);
}
static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m)
{
    PyObject_GC_UnTrack(m);
    __Pyx__CyFunction_dealloc(m);
}
static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg)
{
    Py_VISIT(m->func_closure);
    Py_VISIT(m->func.m_module);
    Py_VISIT(m->func_dict);
    Py_VISIT(m->func_name);
    Py_VISIT(m->func_qualname);
    Py_VISIT(m->func_doc);
    Py_VISIT(m->func_globals);
    Py_VISIT(m->func_code);
    Py_VISIT(m->func_classobj);
    Py_VISIT(m->defaults_tuple);
    Py_VISIT(m->defaults_kwdict);
    if (m->defaults) {
        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
        int i;
        for (i = 0; i < m->defaults_pyobjects; i++)
            Py_VISIT(pydefaults[i]);
    }
    return 0;
}
static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type)
{
#if PY_MAJOR_VERSION < 3
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) {
        Py_INCREF(func);
        return func;
    }
    if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) {
        if (type == NULL)
            type = (PyObject *)(Py_TYPE(obj));
        return __Pyx_PyMethod_New(func, type, (PyObject *)(Py_TYPE(type)));
    }
    if (obj == Py_None)
        obj = NULL;
#endif
    return __Pyx_PyMethod_New(func, obj, type);
}
static PyObject*
__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
{
#if PY_MAJOR_VERSION >= 3
    return PyUnicode_FromFormat("<cyfunction %U at %p>",
                                op->func_qualname, (void *)op);
#else
    return PyString_FromFormat("<cyfunction %s at %p>",
                               PyString_AsString(op->func_qualname), (void *)op);
#endif
}
static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) {
    PyCFunctionObject* f = (PyCFunctionObject*)func;
    PyCFunction meth = f->m_ml->ml_meth;
    Py_ssize_t size;
    switch (f->m_ml->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) {
    case METH_VARARGS:
        if (likely(kw == NULL || PyDict_Size(kw) == 0))
            return (*meth)(self, arg);
        break;
    case METH_VARARGS | METH_KEYWORDS:
        return (*(PyCFunctionWithKeywords)(void*)meth)(self, arg, kw);
    case METH_NOARGS:
        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
            size = PyTuple_GET_SIZE(arg);
            if (likely(size == 0))
                return (*meth)(self, NULL);
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)",
                f->m_ml->ml_name, size);
            return NULL;
        }
        break;
    case METH_O:
        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
            size = PyTuple_GET_SIZE(arg);
            if (likely(size == 1)) {
                PyObject *result, *arg0;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                arg0 = PyTuple_GET_ITEM(arg, 0);
                #else
                arg0 = PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL;
                #endif
                result = (*meth)(self, arg0);
                #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS)
                Py_DECREF(arg0);
                #endif
                return result;
            }
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)",
                f->m_ml->ml_name, size);
            return NULL;
        }
        break;
    default:
        PyErr_SetString(PyExc_SystemError, "Bad call flags in "
                        "__Pyx_CyFunction_Call. METH_OLDARGS is no "
                        "longer supported!");
        return NULL;
    }
    PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
                 f->m_ml->ml_name);
    return NULL;
}
static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    return __Pyx_CyFunction_CallMethod(func, ((PyCFunctionObject*)func)->m_self, arg, kw);
}
static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) {
    PyObject *result;
    __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func;
    if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) {
        Py_ssize_t argc;
        PyObject *new_args;
        PyObject *self;
        argc = PyTuple_GET_SIZE(args);
        new_args = PyTuple_GetSlice(args, 1, argc);
        if (unlikely(!new_args))
            return NULL;
        self = PyTuple_GetItem(args, 0);
        if (unlikely(!self)) {
            Py_DECREF(new_args);
            PyErr_Format(PyExc_TypeError,
                         "unbound method %.200S() needs an argument",
                         cyfunc->func_qualname);
            return NULL;
        }
        result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw);
        Py_DECREF(new_args);
    } else {
        result = __Pyx_CyFunction_Call(func, args, kw);
    }
    return result;
}
static PyTypeObject __pyx_CyFunctionType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    "cython_function_or_method",
    sizeof(__pyx_CyFunctionObject),
    0,
    (destructor) __Pyx_CyFunction_dealloc,
    0,
    0,
    0,
#if PY_MAJOR_VERSION < 3
    0,
#else
    0,
#endif
    (reprfunc) __Pyx_CyFunction_repr,
    0,
    0,
    0,
    0,
    __Pyx_CyFunction_CallAsMethod,
    0,
    0,
    0,
    0,
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
    0,
    (traverseproc) __Pyx_CyFunction_traverse,
    (inquiry) __Pyx_CyFunction_clear,
    0,
#if PY_VERSION_HEX < 0x030500A0
    offsetof(__pyx_CyFunctionObject, func_weakreflist),
#else
    offsetof(PyCFunctionObject, m_weakreflist),
#endif
    0,
    0,
    __pyx_CyFunction_methods,
    __pyx_CyFunction_members,
    __pyx_CyFunction_getsets,
    0,
    0,
    __Pyx_CyFunction_descr_get,
    0,
    offsetof(__pyx_CyFunctionObject, func_dict),
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
#if PY_VERSION_HEX >= 0x030400a1
    0,
#endif
#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
    0,
#endif
#if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
    0,
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
    0,
#endif
};
static int __pyx_CyFunction_init(void) {
    __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type);
    if (unlikely(__pyx_CyFunctionType == NULL)) {
        return -1;
    }
    return 0;
}
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults = PyObject_Malloc(size);
    if (unlikely(!m->defaults))
        return PyErr_NoMemory();
    memset(m->defaults, 0, size);
    m->defaults_pyobjects = pyobjects;
    m->defaults_size = size;
    return m->defaults;
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults_tuple = tuple;
    Py_INCREF(tuple);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults_kwdict = dict;
    Py_INCREF(dict);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->func_annotations = dict;
    Py_INCREF(dict);
}

/* CythonFunction */
static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qualname,
                                      PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
    PyObject *op = __Pyx_CyFunction_Init(
        PyObject_GC_New(__pyx_CyFunctionObject, __pyx_CyFunctionType),
        ml, flags, qualname, closure, module, globals, code
    );
    if (likely(op)) {
        PyObject_GC_Track(op);
    }
    return op;
}

/* ObjectGetItem */
#if CYTHON_USE_TYPE_SLOTS
static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) {
    PyObject *runerr;
    Py_ssize_t key_value;
    PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence;
    if (unlikely(!(m && m->sq_item))) {
        PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name);
        return NULL;
    }
    key_value = __Pyx_PyIndex_AsSsize_t(index);
    if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
        return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
    }
    if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
        PyErr_Clear();
        PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name);
    }
    return NULL;
}
static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) {
    PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping;
    if (likely(m && m->mp_subscript)) {
        return m->mp_subscript(obj, key);
    }
    return __Pyx_PyObject_GetIndex(obj, key);
}
#endif

/* BytesEquals */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result;
#if CYTHON_USE_UNICODE_INTERNALS && (PY_VERSION_HEX < 0x030B0000)
            Py_hash_t hash1, hash2;
            hash1 = ((PyBytesObject*)s1)->ob_shash;
            hash2 = ((PyBytesObject*)s2)->ob_shash;
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                return (equals == Py_NE);
            }
#endif
            result = memcmp(ps1, ps2, (size_t)length);
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
#endif
}

/* UnicodeEquals */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
#if PY_MAJOR_VERSION < 3
    PyObject* owned_ref = NULL;
#endif
    int s1_is_unicode, s2_is_unicode;
    if (s1 == s2) {
        goto return_eq;
    }
    s1_is_unicode = PyUnicode_CheckExact(s1);
    s2_is_unicode = PyUnicode_CheckExact(s2);
#if PY_MAJOR_VERSION < 3
    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
        owned_ref = PyUnicode_FromObject(s2);
        if (unlikely(!owned_ref))
            return -1;
        s2 = owned_ref;
        s2_is_unicode = 1;
    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
        owned_ref = PyUnicode_FromObject(s1);
        if (unlikely(!owned_ref))
            return -1;
        s1 = owned_ref;
        s1_is_unicode = 1;
    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
        return __Pyx_PyBytes_Equals(s1, s2, equals);
    }
#endif
    if (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length;
        int kind;
        void *data1, *data2;
        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
            return -1;
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
            goto return_ne;
        }
#if CYTHON_USE_UNICODE_INTERNALS
        {
            Py_hash_t hash1, hash2;
        #if CYTHON_PEP393_ENABLED
            hash1 = ((PyASCIIObject*)s1)->hash;
            hash2 = ((PyASCIIObject*)s2)->hash;
        #else
            hash1 = ((PyUnicodeObject*)s1)->hash;
            hash2 = ((PyUnicodeObject*)s2)->hash;
        #endif
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                goto return_ne;
            }
        }
#endif
        kind = __Pyx_PyUnicode_KIND(s1);
        if (kind != __Pyx_PyUnicode_KIND(s2)) {
            goto return_ne;
        }
        data1 = __Pyx_PyUnicode_DATA(s1);
        data2 = __Pyx_PyUnicode_DATA(s2);
        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
            goto return_ne;
        } else if (length == 1) {
            goto return_eq;
        } else {
            int result = memcmp(data1, data2, (size_t)(length * kind));
            #if PY_MAJOR_VERSION < 3
            Py_XDECREF(owned_ref);
            #endif
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & s2_is_unicode) {
        goto return_ne;
    } else if ((s2 == Py_None) & s1_is_unicode) {
        goto return_ne;
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        #if PY_MAJOR_VERSION < 3
        Py_XDECREF(owned_ref);
        #endif
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
return_eq:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_EQ);
return_ne:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_NE);
#endif
}

/* RaiseTooManyValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

/* RaiseNeedMoreValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

/* IterFinish */
static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_FAST_THREAD_STATE
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) {
            PyObject *exc_value, *exc_tb;
            exc_value = tstate->curexc_value;
            exc_tb = tstate->curexc_traceback;
            tstate->curexc_type = 0;
            tstate->curexc_value = 0;
            tstate->curexc_traceback = 0;
            Py_DECREF(exc_type);
            Py_XDECREF(exc_value);
            Py_XDECREF(exc_tb);
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#else
    if (unlikely(PyErr_Occurred())) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#endif
}

/* UnpackItemEndCheck */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    } else {
        return __Pyx_IterFinish();
    }
    return 0;
}

/* SliceTupleAndList */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE void __Pyx_crop_slice(Py_ssize_t* _start, Py_ssize_t* _stop, Py_ssize_t* _length) {
    Py_ssize_t start = *_start, stop = *_stop, length = *_length;
    if (start < 0) {
        start += length;
        if (start < 0)
            start = 0;
    }
    if (stop < 0)
        stop += length;
    else if (stop > length)
        stop = length;
    *_length = stop - start;
    *_start = start;
    *_stop = stop;
}
static CYTHON_INLINE void __Pyx_copy_object_array(PyObject** CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) {
    PyObject *v;
    Py_ssize_t i;
    for (i = 0; i < length; i++) {
        v = dest[i] = src[i];
        Py_INCREF(v);
    }
}
static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(
            PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
    PyObject* dest;
    Py_ssize_t length = PyList_GET_SIZE(src);
    __Pyx_crop_slice(&start, &stop, &length);
    if (unlikely(length <= 0))
        return PyList_New(0);
    dest = PyList_New(length);
    if (unlikely(!dest))
        return NULL;
    __Pyx_copy_object_array(
        ((PyListObject*)src)->ob_item + start,
        ((PyListObject*)dest)->ob_item,
        length);
    return dest;
}
static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(
            PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
    PyObject* dest;
    Py_ssize_t length = PyTuple_GET_SIZE(src);
    __Pyx_crop_slice(&start, &stop, &length);
    if (unlikely(length <= 0))
        return PyTuple_New(0);
    dest = PyTuple_New(length);
    if (unlikely(!dest))
        return NULL;
    __Pyx_copy_object_array(
        ((PyTupleObject*)src)->ob_item + start,
        ((PyTupleObject*)dest)->ob_item,
        length);
    return dest;
}
#endif

/* None */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

/* StringJoin */
#if !CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values) {
    return PyObject_CallMethodObjArgs(sep, __pyx_n_s_join, values, NULL);
}
#endif

/* PyIntCompare */
static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) {
    if (op1 == op2) {
        Py_RETURN_TRUE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a == b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        int unequal;
        unsigned long uintval;
        Py_ssize_t size = Py_SIZE(op1);
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        if (intval == 0) {
            if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
        } else if (intval < 0) {
            if (size >= 0)
                Py_RETURN_FALSE;
            intval = -intval;
            size = -size;
        } else {
            if (size <= 0)
                Py_RETURN_FALSE;
        }
        uintval = (unsigned long) intval;
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 4)) {
            unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 3)) {
            unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 2)) {
            unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 1)) {
            unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
            unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
        if (unequal == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
        if ((double)a == (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    return (
        PyObject_RichCompare(op1, op2, Py_EQ));
}

/* PyIntCompare */
static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) {
    if (op1 == op2) {
        Py_RETURN_FALSE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a != b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        int unequal;
        unsigned long uintval;
        Py_ssize_t size = Py_SIZE(op1);
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        if (intval == 0) {
            if (size != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
        } else if (intval < 0) {
            if (size >= 0)
                Py_RETURN_TRUE;
            intval = -intval;
            size = -size;
        } else {
            if (size <= 0)
                Py_RETURN_TRUE;
        }
        uintval = (unsigned long) intval;
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 4)) {
            unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 3)) {
            unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 2)) {
            unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 1)) {
            unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
            unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
        if (unequal != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
        if ((double)a != (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    return (
        PyObject_RichCompare(op1, op2, Py_NE));
}

/* WriteUnraisableException */
static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback, CYTHON_UNUSED int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_PyThreadState_declare
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
#ifdef _MSC_VER
    else state = (PyGILState_STATE)-1;
#endif
#endif
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

/* PyObjectGetMethod */
static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) {
    PyObject *attr;
#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP
    PyTypeObject *tp = Py_TYPE(obj);
    PyObject *descr;
    descrgetfunc f = NULL;
    PyObject **dictptr, *dict;
    int meth_found = 0;
    assert (*method == NULL);
    if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) {
        attr = __Pyx_PyObject_GetAttrStr(obj, name);
        goto try_unpack;
    }
    if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) {
        return 0;
    }
    descr = _PyType_Lookup(tp, name);
    if (likely(descr != NULL)) {
        Py_INCREF(descr);
#if PY_MAJOR_VERSION >= 3
        #ifdef __Pyx_CyFunction_USED
        if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr)))
        #else
        if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type)))
        #endif
#else
        #ifdef __Pyx_CyFunction_USED
        if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr)))
        #else
        if (likely(PyFunction_Check(descr)))
        #endif
#endif
        {
            meth_found = 1;
        } else {
            f = Py_TYPE(descr)->tp_descr_get;
            if (f != NULL && PyDescr_IsData(descr)) {
                attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
                Py_DECREF(descr);
                goto try_unpack;
            }
        }
    }
    dictptr = _PyObject_GetDictPtr(obj);
    if (dictptr != NULL && (dict = *dictptr) != NULL) {
        Py_INCREF(dict);
        attr = __Pyx_PyDict_GetItemStr(dict, name);
        if (attr != NULL) {
            Py_INCREF(attr);
            Py_DECREF(dict);
            Py_XDECREF(descr);
            goto try_unpack;
        }
        Py_DECREF(dict);
    }
    if (meth_found) {
        *method = descr;
        return 1;
    }
    if (f != NULL) {
        attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
        Py_DECREF(descr);
        goto try_unpack;
    }
    if (descr != NULL) {
        *method = descr;
        return 0;
    }
    PyErr_Format(PyExc_AttributeError,
#if PY_MAJOR_VERSION >= 3
                 "'%.50s' object has no attribute '%U'",
                 tp->tp_name, name);
#else
                 "'%.50s' object has no attribute '%.400s'",
                 tp->tp_name, PyString_AS_STRING(name));
#endif
    return 0;
#else
    attr = __Pyx_PyObject_GetAttrStr(obj, name);
    goto try_unpack;
#endif
try_unpack:
#if CYTHON_UNPACK_METHODS
    if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) {
        PyObject *function = PyMethod_GET_FUNCTION(attr);
        Py_INCREF(function);
        Py_DECREF(attr);
        *method = function;
        return 1;
    }
#endif
    *method = attr;
    return 0;
}

/* PyObjectCallMethod1 */
static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) {
    PyObject *result = __Pyx_PyObject_CallOneArg(method, arg);
    Py_DECREF(method);
    return result;
}
static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
    PyObject *method = NULL, *result;
    int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
    if (likely(is_method)) {
        result = __Pyx_PyObject_Call2Args(method, obj, arg);
        Py_DECREF(method);
        return result;
    }
    if (unlikely(!method)) return NULL;
    return __Pyx__PyObject_CallMethod1(method, arg);
}

/* append */
static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
    } else {
        PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x);
        if (unlikely(!retval))
            return -1;
        Py_DECREF(retval);
    }
    return 0;
}

/* DictGetItem */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
    PyObject *value;
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (!PyErr_Occurred()) {
            if (unlikely(PyTuple_Check(key))) {
                PyObject* args = PyTuple_Pack(1, key);
                if (likely(args)) {
                    PyErr_SetObject(PyExc_KeyError, args);
                    Py_DECREF(args);
                }
            } else {
                PyErr_SetObject(PyExc_KeyError, key);
            }
        }
        return NULL;
    }
    Py_INCREF(value);
    return value;
}
#endif

/* GetAttr */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
#if CYTHON_USE_TYPE_SLOTS
#if PY_MAJOR_VERSION >= 3
    if (likely(PyUnicode_Check(n)))
#else
    if (likely(PyString_Check(n)))
#endif
        return __Pyx_PyObject_GetAttrStr(o, n);
#endif
    return PyObject_GetAttr(o, n);
}

/* GetAttr3 */
static PyObject *__Pyx_GetAttr3Default(PyObject *d) {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        return NULL;
    __Pyx_PyErr_Clear();
    Py_INCREF(d);
    return d;
}
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) {
    PyObject *r = __Pyx_GetAttr(o, n);
    return (likely(r)) ? r : __Pyx_GetAttr3Default(d);
}

/* ArgTypeTest */
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    else if (exact) {
        #if PY_MAJOR_VERSION == 2
        if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(__Pyx_TypeCheck(obj, type))) return 1;
    }
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
    return 0;
}

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
#if PY_MAJOR_VERSION < 3 || CYTHON_USE_PYLONG_INTERNALS
#define __Pyx_PyInt_FloorDivideObjC_ZeroDivisionError(operand)\
    if (unlikely(zerodivision_check && ((operand) == 0))) {\
        PyErr_SetString(PyExc_ZeroDivisionError, "integer division by zero");\
        return NULL;\
    }
#endif
static PyObject* __Pyx_PyInt_FloorDivideObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            __Pyx_PyInt_FloorDivideObjC_ZeroDivisionError(b)
            if (unlikely(b == -1 && ((unsigned long)a) == 0-(unsigned long)a))
                return PyInt_Type.tp_as_number->nb_floor_divide(op1, op2);
            else {
                long q, r;
                q = a / b;
                r = a - q*b;
                q -= ((r != 0) & ((r ^ b) < 0));
                x = q;
            }
            return PyInt_FromLong(x);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_floor_divide(op1, op2);
            }
        }
                __Pyx_PyInt_FloorDivideObjC_ZeroDivisionError(b)
                {
                    long q, r;
                    q = a / b;
                    r = a - q*b;
                    q -= ((r != 0) & ((r ^ b) < 0));
                    x = q;
                }
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                {
                    PY_LONG_LONG q, r;
                    q = lla / llb;
                    r = lla - q*llb;
                    q -= ((r != 0) & ((r ^ llb) < 0));
                    llx = q;
                }
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    return (inplace ? PyNumber_InPlaceFloorDivide : PyNumber_FloorDivide)(op1, op2);
}
#endif

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
#if PY_MAJOR_VERSION < 3 || CYTHON_USE_PYLONG_INTERNALS
#define __Pyx_PyInt_RemainderObjC_ZeroDivisionError(operand)\
    if (unlikely(zerodivision_check && ((operand) == 0))) {\
        PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");\
        return NULL;\
    }
#endif
static PyObject* __Pyx_PyInt_RemainderObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            __Pyx_PyInt_RemainderObjC_ZeroDivisionError(b)
            x = a % b;
            x += ((x != 0) & ((x ^ b) < 0)) * b;
            return PyInt_FromLong(x);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_remainder(op1, op2);
            }
        }
                __Pyx_PyInt_RemainderObjC_ZeroDivisionError(b)
                x = a % b;
                x += ((x != 0) & ((x ^ b) < 0)) * b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla % llb;
                llx += ((llx != 0) & ((llx ^ llb) < 0)) * llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    return (inplace ? PyNumber_InPlaceRemainder : PyNumber_Remainder)(op1, op2);
}
#endif

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a - b);
            if (likely((x^a) >= 0 || (x^~b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
            }
        }
                x = a - b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla - llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("subtract", return NULL)
            result = ((double)a) - (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
}
#endif

/* PyObjectCallMethod0 */
static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
    PyObject *method = NULL, *result = NULL;
    int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
    if (likely(is_method)) {
        result = __Pyx_PyObject_CallOneArg(method, obj);
        Py_DECREF(method);
        return result;
    }
    if (unlikely(!method)) goto bad;
    result = __Pyx_PyObject_CallNoArg(method);
    Py_DECREF(method);
bad:
    return result;
}

/* UnpackUnboundCMethod */
static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
    PyObject *method;
    method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
    if (unlikely(!method))
        return -1;
    target->method = method;
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION >= 3
    if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type)))
    #endif
    {
        PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
        target->func = descr->d_method->ml_meth;
        target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
    }
#endif
    return 0;
}

/* CallUnboundCMethod0 */
static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_ASSUME_SAFE_MACROS
    args = PyTuple_New(1);
    if (unlikely(!args)) goto bad;
    Py_INCREF(self);
    PyTuple_SET_ITEM(args, 0, self);
#else
    args = PyTuple_Pack(1, self);
    if (unlikely(!args)) goto bad;
#endif
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    Py_DECREF(args);
bad:
    return result;
}

/* pop */
static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) {
    if (Py_TYPE(L) == &PySet_Type) {
        return PySet_Pop(L);
    }
    return __Pyx_PyObject_CallMethod0(L, __pyx_n_s_pop);
}
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L) {
    if (likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) {
        __Pyx_SET_SIZE(L, Py_SIZE(L) - 1);
        return PyList_GET_ITEM(L, PyList_GET_SIZE(L));
    }
    return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyList_Type_pop, L);
}
#endif

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_XorObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
            return PyInt_FromLong(a ^ b);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_xor(op1, op2);
            }
        }
                x = a ^ b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla ^ llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    return (inplace ? PyNumber_InPlaceXor : PyNumber_Xor)(op1, op2);
}
#endif

/* Import */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) {
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_MAJOR_VERSION < 3
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, (PyObject *)NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

/* ImportFrom */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

/* HasAttr */
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
    PyObject *r;
    if (unlikely(!__Pyx_PyBaseString_Check(n))) {
        PyErr_SetString(PyExc_TypeError,
                        "hasattr(): attribute name must be string");
        return -1;
    }
    r = __Pyx_GetAttr(o, n);
    if (unlikely(!r)) {
        PyErr_Clear();
        return 0;
    } else {
        Py_DECREF(r);
        return 1;
    }
}

/* PyObject_GenericGetAttrNoDict */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) {
    PyErr_Format(PyExc_AttributeError,
#if PY_MAJOR_VERSION >= 3
                 "'%.50s' object has no attribute '%U'",
                 tp->tp_name, attr_name);
#else
                 "'%.50s' object has no attribute '%.400s'",
                 tp->tp_name, PyString_AS_STRING(attr_name));
#endif
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) {
    PyObject *descr;
    PyTypeObject *tp = Py_TYPE(obj);
    if (unlikely(!PyString_Check(attr_name))) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    assert(!tp->tp_dictoffset);
    descr = _PyType_Lookup(tp, attr_name);
    if (unlikely(!descr)) {
        return __Pyx_RaiseGenericGetAttributeError(tp, attr_name);
    }
    Py_INCREF(descr);
    #if PY_MAJOR_VERSION < 3
    if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)))
    #endif
    {
        descrgetfunc f = Py_TYPE(descr)->tp_descr_get;
        if (unlikely(f)) {
            PyObject *res = f(descr, obj, (PyObject *)tp);
            Py_DECREF(descr);
            return res;
        }
    }
    return descr;
}
#endif

/* PyObject_GenericGetAttr */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) {
    if (unlikely(Py_TYPE(obj)->tp_dictoffset)) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name);
}
#endif

/* SetVTable */
static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

/* PyObjectGetAttrStrNoError */
static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        __Pyx_PyErr_Clear();
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) {
        return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1);
    }
#endif
    result = __Pyx_PyObject_GetAttrStr(obj, attr_name);
    if (unlikely(!result)) {
        __Pyx_PyObject_GetAttrStr_ClearAttributeError();
    }
    return result;
}

/* SetupReduce */
static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) {
  int ret;
  PyObject *name_attr;
  name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name);
  if (likely(name_attr)) {
      ret = PyObject_RichCompareBool(name_attr, name, Py_EQ);
  } else {
      ret = -1;
  }
  if (unlikely(ret < 0)) {
      PyErr_Clear();
      ret = 0;
  }
  Py_XDECREF(name_attr);
  return ret;
}
static int __Pyx_setup_reduce(PyObject* type_obj) {
    int ret = 0;
    PyObject *object_reduce = NULL;
    PyObject *object_getstate = NULL;
    PyObject *object_reduce_ex = NULL;
    PyObject *reduce = NULL;
    PyObject *reduce_ex = NULL;
    PyObject *reduce_cython = NULL;
    PyObject *setstate = NULL;
    PyObject *setstate_cython = NULL;
    PyObject *getstate = NULL;
#if CYTHON_USE_PYTYPE_LOOKUP
    getstate = _PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate);
#else
    getstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_getstate);
    if (!getstate && PyErr_Occurred()) {
        goto __PYX_BAD;
    }
#endif
    if (getstate) {
#if CYTHON_USE_PYTYPE_LOOKUP
        object_getstate = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_getstate);
#else
        object_getstate = __Pyx_PyObject_GetAttrStrNoError((PyObject*)&PyBaseObject_Type, __pyx_n_s_getstate);
        if (!object_getstate && PyErr_Occurred()) {
            goto __PYX_BAD;
        }
#endif
        if (object_getstate != getstate) {
            goto __PYX_GOOD;
        }
    }
#if CYTHON_USE_PYTYPE_LOOKUP
    object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD;
#else
    object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD;
#endif
    reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD;
    if (reduce_ex == object_reduce_ex) {
#if CYTHON_USE_PYTYPE_LOOKUP
        object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD;
#else
        object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD;
#endif
        reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD;
        if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) {
            reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython);
            if (likely(reduce_cython)) {
                ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
            } else if (reduce == object_reduce || PyErr_Occurred()) {
                goto __PYX_BAD;
            }
            setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate);
            if (!setstate) PyErr_Clear();
            if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) {
                setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython);
                if (likely(setstate_cython)) {
                    ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                    ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                } else if (!setstate || PyErr_Occurred()) {
                    goto __PYX_BAD;
                }
            }
            PyType_Modified((PyTypeObject*)type_obj);
        }
    }
    goto __PYX_GOOD;
__PYX_BAD:
    if (!PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name);
    ret = -1;
__PYX_GOOD:
#if !CYTHON_USE_PYTYPE_LOOKUP
    Py_XDECREF(object_reduce);
    Py_XDECREF(object_reduce_ex);
    Py_XDECREF(object_getstate);
    Py_XDECREF(getstate);
#endif
    Py_XDECREF(reduce);
    Py_XDECREF(reduce_ex);
    Py_XDECREF(reduce_cython);
    Py_XDECREF(setstate);
    Py_XDECREF(setstate_cython);
    return ret;
}

/* TypeImport */
#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name,
    size_t size, enum __Pyx_ImportType_CheckSize check_size)
{
    PyObject *result = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    result = PyObject_GetAttrString(module, class_name);
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#ifndef Py_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if ((size_t)basicsize < size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        goto bad;
    }
    if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        goto bad;
    }
    else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(result);
    return NULL;
}
#endif

/* GetVTable */
static void* __Pyx_GetVtable(PyObject *dict) {
    void* ptr;
    PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable);
    if (!ob)
        goto bad;
#if PY_VERSION_HEX >= 0x02070000
    ptr = PyCapsule_GetPointer(ob, 0);
#else
    ptr = PyCObject_AsVoidPtr(ob);
#endif
    if (!ptr && !PyErr_Occurred())
        PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
    Py_DECREF(ob);
    return ptr;
bad:
    Py_XDECREF(ob);
    return NULL;
}

/* ClassMethod */
static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
#if CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM <= 0x05080000
    if (PyObject_TypeCheck(method, &PyWrapperDescr_Type)) {
        return PyClassMethod_New(method);
    }
#else
#if CYTHON_COMPILING_IN_PYSTON || CYTHON_COMPILING_IN_PYPY
    if (PyMethodDescr_Check(method))
#else
    #if PY_MAJOR_VERSION == 2
    static PyTypeObject *methoddescr_type = NULL;
    if (methoddescr_type == NULL) {
       PyObject *meth = PyObject_GetAttrString((PyObject*)&PyList_Type, "append");
       if (!meth) return NULL;
       methoddescr_type = Py_TYPE(meth);
       Py_DECREF(meth);
    }
    #else
    PyTypeObject *methoddescr_type = &PyMethodDescr_Type;
    #endif
    if (__Pyx_TypeCheck(method, methoddescr_type))
#endif
    {
        PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
        #if PY_VERSION_HEX < 0x03020000
        PyTypeObject *d_type = descr->d_type;
        #else
        PyTypeObject *d_type = descr->d_common.d_type;
        #endif
        return PyDescr_NewClassMethod(d_type, descr->d_method);
    }
#endif
    else if (PyMethod_Check(method)) {
        return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
    }
    else {
        return PyClassMethod_New(method);
    }
}

/* GetNameInClass */
static PyObject *__Pyx_GetGlobalNameAfterAttributeLookup(PyObject *name) {
    PyObject *result;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        return NULL;
    __Pyx_PyErr_Clear();
    __Pyx_GetModuleGlobalNameUncached(result, name);
    return result;
}
static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name) {
    PyObject *result;
    result = __Pyx_PyObject_GetAttrStr(nmspace, name);
    if (!result) {
        result = __Pyx_GetGlobalNameAfterAttributeLookup(name);
    }
    return result;
}

/* CalculateMetaclass */
static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) {
    Py_ssize_t i, nbases = PyTuple_GET_SIZE(bases);
    for (i=0; i < nbases; i++) {
        PyTypeObject *tmptype;
        PyObject *tmp = PyTuple_GET_ITEM(bases, i);
        tmptype = Py_TYPE(tmp);
#if PY_MAJOR_VERSION < 3
        if (tmptype == &PyClass_Type)
            continue;
#endif
        if (!metaclass) {
            metaclass = tmptype;
            continue;
        }
        if (PyType_IsSubtype(metaclass, tmptype))
            continue;
        if (PyType_IsSubtype(tmptype, metaclass)) {
            metaclass = tmptype;
            continue;
        }
        PyErr_SetString(PyExc_TypeError,
                        "metaclass conflict: "
                        "the metaclass of a derived class "
                        "must be a (non-strict) subclass "
                        "of the metaclasses of all its bases");
        return NULL;
    }
    if (!metaclass) {
#if PY_MAJOR_VERSION < 3
        metaclass = &PyClass_Type;
#else
        metaclass = &PyType_Type;
#endif
    }
    Py_INCREF((PyObject*) metaclass);
    return (PyObject*) metaclass;
}

/* Py3ClassCreate */
static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name,
                                           PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) {
    PyObject *ns;
    if (metaclass) {
        PyObject *prep = __Pyx_PyObject_GetAttrStr(metaclass, __pyx_n_s_prepare);
        if (prep) {
            PyObject *pargs = PyTuple_Pack(2, name, bases);
            if (unlikely(!pargs)) {
                Py_DECREF(prep);
                return NULL;
            }
            ns = PyObject_Call(prep, pargs, mkw);
            Py_DECREF(prep);
            Py_DECREF(pargs);
        } else {
            if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError)))
                return NULL;
            PyErr_Clear();
            ns = PyDict_New();
        }
    } else {
        ns = PyDict_New();
    }
    if (unlikely(!ns))
        return NULL;
    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_module, modname) < 0)) goto bad;
    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_qualname, qualname) < 0)) goto bad;
    if (unlikely(doc && PyObject_SetItem(ns, __pyx_n_s_doc, doc) < 0)) goto bad;
    return ns;
bad:
    Py_DECREF(ns);
    return NULL;
}
static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases,
                                      PyObject *dict, PyObject *mkw,
                                      int calculate_metaclass, int allow_py2_metaclass) {
    PyObject *result, *margs;
    PyObject *owned_metaclass = NULL;
    if (allow_py2_metaclass) {
        owned_metaclass = PyObject_GetItem(dict, __pyx_n_s_metaclass);
        if (owned_metaclass) {
            metaclass = owned_metaclass;
        } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) {
            PyErr_Clear();
        } else {
            return NULL;
        }
    }
    if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) {
        metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
        Py_XDECREF(owned_metaclass);
        if (unlikely(!metaclass))
            return NULL;
        owned_metaclass = metaclass;
    }
    margs = PyTuple_Pack(3, name, bases, dict);
    if (unlikely(!margs)) {
        result = NULL;
    } else {
        result = PyObject_Call(metaclass, margs, mkw);
        Py_DECREF(margs);
    }
    Py_XDECREF(owned_metaclass);
    return result;
}

/* CLineInTraceback */
#ifndef CYTHON_CLINE_IN_TRACEBACK
static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) {
    PyObject *use_cline;
    PyObject *ptype, *pvalue, *ptraceback;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject **cython_runtime_dict;
#endif
    if (unlikely(!__pyx_cython_runtime)) {
        return c_line;
    }
    __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
#if CYTHON_COMPILING_IN_CPYTHON
    cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
    if (likely(cython_runtime_dict)) {
        __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
            use_cline, *cython_runtime_dict,
            __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
    } else
#endif
    {
      PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
      if (use_cline_obj) {
        use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
        Py_DECREF(use_cline_obj);
      } else {
        PyErr_Clear();
        use_cline = NULL;
      }
    }
    if (!use_cline) {
        c_line = 0;
        (void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
    }
    else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
        c_line = 0;
    }
    __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
    return c_line;
}
#endif

/* CodeObjectCache */
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = start + (end - start) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

/* AddTraceback */
#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
#if PY_VERSION_HEX >= 0x030b00a6
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = NULL;
    PyObject *py_funcname = NULL;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_srcfile = NULL;
    py_srcfile = PyString_FromString(filename);
    if (!py_srcfile) goto bad;
    #endif
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        funcname = PyUnicode_AsUTF8(py_funcname);
        if (!funcname) goto bad;
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        if (!py_funcname) goto bad;
        #endif
    }
    #if PY_MAJOR_VERSION < 3
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    #else
    py_code = PyCode_NewEmpty(filename, funcname, py_line);
    #endif
    Py_XDECREF(py_funcname);  // XDECREF since it's only set on Py3 if cline
    return py_code;
bad:
    Py_XDECREF(py_funcname);
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_srcfile);
    #endif
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject *ptype, *pvalue, *ptraceback;
    if (c_line) {
        c_line = __Pyx_CLineForTraceback(tstate, c_line);
    }
    py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
    if (!py_code) {
        __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) {
            /* If the code object creation fails, then we should clear the
               fetched exception references and propagate the new exception */
            Py_XDECREF(ptype);
            Py_XDECREF(pvalue);
            Py_XDECREF(ptraceback);
            goto bad;
        }
        __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
        __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        tstate,            /*PyThreadState *tstate,*/
        py_code,           /*PyCodeObject *code,*/
        __pyx_d,    /*PyObject *globals,*/
        0                  /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

/* CIntFromPyVerify */
#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

/* Print */
#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static PyObject *__Pyx_GetStdout(void) {
    PyObject *f = PySys_GetObject((char *)"stdout");
    if (!f) {
        PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
    }
    return f;
}
static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) {
    int i;
    if (!f) {
        if (!(f = __Pyx_GetStdout()))
            return -1;
    }
    Py_INCREF(f);
    for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
        PyObject* v;
        if (PyFile_SoftSpace(f, 1)) {
            if (PyFile_WriteString(" ", f) < 0)
                goto error;
        }
        v = PyTuple_GET_ITEM(arg_tuple, i);
        if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
            goto error;
        if (PyString_Check(v)) {
            char *s = PyString_AsString(v);
            Py_ssize_t len = PyString_Size(v);
            if (len > 0) {
                switch (s[len-1]) {
                    case ' ': break;
                    case '\f': case '\r': case '\n': case '\t': case '\v':
                        PyFile_SoftSpace(f, 0);
                        break;
                    default:  break;
                }
            }
        }
    }
    if (newline) {
        if (PyFile_WriteString("\n", f) < 0)
            goto error;
        PyFile_SoftSpace(f, 0);
    }
    Py_DECREF(f);
    return 0;
error:
    Py_DECREF(f);
    return -1;
}
#else
static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
    PyObject* kwargs = 0;
    PyObject* result = 0;
    PyObject* end_string;
    if (unlikely(!__pyx_print)) {
        __pyx_print = PyObject_GetAttr(__pyx_b, __pyx_n_s_print);
        if (!__pyx_print)
            return -1;
    }
    if (stream) {
        kwargs = PyDict_New();
        if (unlikely(!kwargs))
            return -1;
        if (unlikely(PyDict_SetItem(kwargs, __pyx_n_s_file, stream) < 0))
            goto bad;
        if (!newline) {
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (unlikely(!end_string))
                goto bad;
            if (PyDict_SetItem(kwargs, __pyx_n_s_end, end_string) < 0) {
                Py_DECREF(end_string);
                goto bad;
            }
            Py_DECREF(end_string);
        }
    } else if (!newline) {
        if (unlikely(!__pyx_print_kwargs)) {
            __pyx_print_kwargs = PyDict_New();
            if (unlikely(!__pyx_print_kwargs))
                return -1;
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (unlikely(!end_string))
                return -1;
            if (PyDict_SetItem(__pyx_print_kwargs, __pyx_n_s_end, end_string) < 0) {
                Py_DECREF(end_string);
                return -1;
            }
            Py_DECREF(end_string);
        }
        kwargs = __pyx_print_kwargs;
    }
    result = PyObject_Call(__pyx_print, arg_tuple, kwargs);
    if (unlikely(kwargs) && (kwargs != __pyx_print_kwargs))
        Py_DECREF(kwargs);
    if (!result)
        return -1;
    Py_DECREF(result);
    return 0;
bad:
    if (kwargs != __pyx_print_kwargs)
        Py_XDECREF(kwargs);
    return -1;
}
#endif

/* CIntFromPy */
static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const char neg_one = (char) -1, const_zero = (char) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(char) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(char, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (char) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (char) 0;
                case  1: __PYX_VERIFY_RETURN_INT(char, digit, digits[0])
                case 2:
                    if (8 * sizeof(char) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 2 * PyLong_SHIFT) {
                            return (char) (((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(char) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 3 * PyLong_SHIFT) {
                            return (char) (((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(char) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) >= 4 * PyLong_SHIFT) {
                            return (char) (((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (char) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(char) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (char) 0;
                case -1: __PYX_VERIFY_RETURN_INT(char, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(char,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(char) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(char) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                            return (char) ((((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(char) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(char) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                            return (char) ((((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(char) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) {
                            return (char) (((char)-1)*(((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(char) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(char) - 1 > 4 * PyLong_SHIFT) {
                            return (char) ((((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(char) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(char, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            char val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (char) -1;
        }
    } else {
        char val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (char) -1;
        val = __Pyx_PyInt_As_char(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to char");
    return (char) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to char");
    return (char) -1;
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

/* CIntFromPy */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

/* PrintOne */
#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static int __Pyx_PrintOne(PyObject* f, PyObject *o) {
    if (!f) {
        if (!(f = __Pyx_GetStdout()))
            return -1;
    }
    Py_INCREF(f);
    if (PyFile_SoftSpace(f, 0)) {
        if (PyFile_WriteString(" ", f) < 0)
            goto error;
    }
    if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
        goto error;
    if (PyFile_WriteString("\n", f) < 0)
        goto error;
    Py_DECREF(f);
    return 0;
error:
    Py_DECREF(f);
    return -1;
    /* the line below is just to avoid C compiler
     * warnings about unused functions */
    return __Pyx_Print(f, NULL, 0);
}
#else
static int __Pyx_PrintOne(PyObject* stream, PyObject *o) {
    int res;
    PyObject* arg_tuple = PyTuple_Pack(1, o);
    if (unlikely(!arg_tuple))
        return -1;
    res = __Pyx_Print(stream, arg_tuple, 1);
    Py_DECREF(arg_tuple);
    return res;
}
#endif

/* SwapException */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = tstate->exc_info;
    tmp_type = exc_info->exc_type;
    tmp_value = exc_info->exc_value;
    tmp_tb = exc_info->exc_traceback;
    exc_info->exc_type = *type;
    exc_info->exc_value = *value;
    exc_info->exc_traceback = *tb;
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = *type;
    tstate->exc_value = *value;
    tstate->exc_traceback = *tb;
    #endif
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}
#else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
    PyErr_SetExcInfo(*type, *value, *tb);
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}
#endif

/* CoroutineBase */
#include <structmember.h>
#include <frameobject.h>
#if PY_VERSION_HEX >= 0x030b00a6
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
#define __Pyx_Coroutine_Undelegate(gen) Py_CLEAR((gen)->yieldfrom)
static int __Pyx_PyGen__FetchStopIterationValue(CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject **pvalue) {
    PyObject *et, *ev, *tb;
    PyObject *value = NULL;
    __Pyx_ErrFetch(&et, &ev, &tb);
    if (!et) {
        Py_XDECREF(tb);
        Py_XDECREF(ev);
        Py_INCREF(Py_None);
        *pvalue = Py_None;
        return 0;
    }
    if (likely(et == PyExc_StopIteration)) {
        if (!ev) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#if PY_VERSION_HEX >= 0x030300A0
        else if (Py_TYPE(ev) == (PyTypeObject*)PyExc_StopIteration) {
            value = ((PyStopIterationObject *)ev)->value;
            Py_INCREF(value);
            Py_DECREF(ev);
        }
#endif
        else if (unlikely(PyTuple_Check(ev))) {
            if (PyTuple_GET_SIZE(ev) >= 1) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                value = PyTuple_GET_ITEM(ev, 0);
                Py_INCREF(value);
#else
                value = PySequence_ITEM(ev, 0);
#endif
            } else {
                Py_INCREF(Py_None);
                value = Py_None;
            }
            Py_DECREF(ev);
        }
        else if (!__Pyx_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) {
            value = ev;
        }
        if (likely(value)) {
            Py_XDECREF(tb);
            Py_DECREF(et);
            *pvalue = value;
            return 0;
        }
    } else if (!__Pyx_PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) {
        __Pyx_ErrRestore(et, ev, tb);
        return -1;
    }
    PyErr_NormalizeException(&et, &ev, &tb);
    if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration))) {
        __Pyx_ErrRestore(et, ev, tb);
        return -1;
    }
    Py_XDECREF(tb);
    Py_DECREF(et);
#if PY_VERSION_HEX >= 0x030300A0
    value = ((PyStopIterationObject *)ev)->value;
    Py_INCREF(value);
    Py_DECREF(ev);
#else
    {
        PyObject* args = __Pyx_PyObject_GetAttrStr(ev, __pyx_n_s_args);
        Py_DECREF(ev);
        if (likely(args)) {
            value = PySequence_GetItem(args, 0);
            Py_DECREF(args);
        }
        if (unlikely(!value)) {
            __Pyx_ErrRestore(NULL, NULL, NULL);
            Py_INCREF(Py_None);
            value = Py_None;
        }
    }
#endif
    *pvalue = value;
    return 0;
}
static CYTHON_INLINE
void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *exc_state) {
    PyObject *t, *v, *tb;
    t = exc_state->exc_type;
    v = exc_state->exc_value;
    tb = exc_state->exc_traceback;
    exc_state->exc_type = NULL;
    exc_state->exc_value = NULL;
    exc_state->exc_traceback = NULL;
    Py_XDECREF(t);
    Py_XDECREF(v);
    Py_XDECREF(tb);
}
#define __Pyx_Coroutine_AlreadyRunningError(gen)  (__Pyx__Coroutine_AlreadyRunningError(gen), (PyObject*)NULL)
static void __Pyx__Coroutine_AlreadyRunningError(CYTHON_UNUSED __pyx_CoroutineObject *gen) {
    const char *msg;
    if ((0)) {
    #ifdef __Pyx_Coroutine_USED
    } else if (__Pyx_Coroutine_Check((PyObject*)gen)) {
        msg = "coroutine already executing";
    #endif
    #ifdef __Pyx_AsyncGen_USED
    } else if (__Pyx_AsyncGen_CheckExact((PyObject*)gen)) {
        msg = "async generator already executing";
    #endif
    } else {
        msg = "generator already executing";
    }
    PyErr_SetString(PyExc_ValueError, msg);
}
#define __Pyx_Coroutine_NotStartedError(gen)  (__Pyx__Coroutine_NotStartedError(gen), (PyObject*)NULL)
static void __Pyx__Coroutine_NotStartedError(CYTHON_UNUSED PyObject *gen) {
    const char *msg;
    if ((0)) {
    #ifdef __Pyx_Coroutine_USED
    } else if (__Pyx_Coroutine_Check(gen)) {
        msg = "can't send non-None value to a just-started coroutine";
    #endif
    #ifdef __Pyx_AsyncGen_USED
    } else if (__Pyx_AsyncGen_CheckExact(gen)) {
        msg = "can't send non-None value to a just-started async generator";
    #endif
    } else {
        msg = "can't send non-None value to a just-started generator";
    }
    PyErr_SetString(PyExc_TypeError, msg);
}
#define __Pyx_Coroutine_AlreadyTerminatedError(gen, value, closing)  (__Pyx__Coroutine_AlreadyTerminatedError(gen, value, closing), (PyObject*)NULL)
static void __Pyx__Coroutine_AlreadyTerminatedError(CYTHON_UNUSED PyObject *gen, PyObject *value, CYTHON_UNUSED int closing) {
    #ifdef __Pyx_Coroutine_USED
    if (!closing && __Pyx_Coroutine_Check(gen)) {
        PyErr_SetString(PyExc_RuntimeError, "cannot reuse already awaited coroutine");
    } else
    #endif
    if (value) {
        #ifdef __Pyx_AsyncGen_USED
        if (__Pyx_AsyncGen_CheckExact(gen))
            PyErr_SetNone(__Pyx_PyExc_StopAsyncIteration);
        else
        #endif
        PyErr_SetNone(PyExc_StopIteration);
    }
}
static
PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value, int closing) {
    __Pyx_PyThreadState_declare
    PyThreadState *tstate;
    __Pyx_ExcInfoStruct *exc_state;
    PyObject *retval;
    assert(!self->is_running);
    if (unlikely(self->resume_label == 0)) {
        if (unlikely(value && value != Py_None)) {
            return __Pyx_Coroutine_NotStartedError((PyObject*)self);
        }
    }
    if (unlikely(self->resume_label == -1)) {
        return __Pyx_Coroutine_AlreadyTerminatedError((PyObject*)self, value, closing);
    }
#if CYTHON_FAST_THREAD_STATE
    __Pyx_PyThreadState_assign
    tstate = __pyx_tstate;
#else
    tstate = __Pyx_PyThreadState_Current;
#endif
    exc_state = &self->gi_exc_state;
    if (exc_state->exc_type) {
        #if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
        #else
        if (exc_state->exc_traceback) {
            PyTracebackObject *tb = (PyTracebackObject *) exc_state->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            assert(f->f_back == NULL);
            #if PY_VERSION_HEX >= 0x030B00A1
            f->f_back = PyThreadState_GetFrame(tstate);
            #else
            Py_XINCREF(tstate->frame);
            f->f_back = tstate->frame;
            #endif
        }
        #endif
    }
#if CYTHON_USE_EXC_INFO_STACK
    exc_state->previous_item = tstate->exc_info;
    tstate->exc_info = exc_state;
#else
    if (exc_state->exc_type) {
        __Pyx_ExceptionSwap(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback);
    } else {
        __Pyx_Coroutine_ExceptionClear(exc_state);
        __Pyx_ExceptionSave(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback);
    }
#endif
    self->is_running = 1;
    retval = self->body((PyObject *) self, tstate, value);
    self->is_running = 0;
#if CYTHON_USE_EXC_INFO_STACK
    exc_state = &self->gi_exc_state;
    tstate->exc_info = exc_state->previous_item;
    exc_state->previous_item = NULL;
    __Pyx_Coroutine_ResetFrameBackpointer(exc_state);
#endif
    return retval;
}
static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state) {
    PyObject *exc_tb = exc_state->exc_traceback;
    if (likely(exc_tb)) {
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
#else
        PyTracebackObject *tb = (PyTracebackObject *) exc_tb;
        PyFrameObject *f = tb->tb_frame;
        Py_CLEAR(f->f_back);
#endif
    }
}
static CYTHON_INLINE
PyObject *__Pyx_Coroutine_MethodReturn(CYTHON_UNUSED PyObject* gen, PyObject *retval) {
    if (unlikely(!retval)) {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        if (!__Pyx_PyErr_Occurred()) {
            PyObject *exc = PyExc_StopIteration;
            #ifdef __Pyx_AsyncGen_USED
            if (__Pyx_AsyncGen_CheckExact(gen))
                exc = __Pyx_PyExc_StopAsyncIteration;
            #endif
            __Pyx_PyErr_SetNone(exc);
        }
    }
    return retval;
}
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
static CYTHON_INLINE
PyObject *__Pyx_PyGen_Send(PyGenObject *gen, PyObject *arg) {
#if PY_VERSION_HEX <= 0x030A00A1
    return _PyGen_Send(gen, arg);
#else
    PyObject *result;
    if (PyIter_Send((PyObject*)gen, arg ? arg : Py_None, &result) == PYGEN_RETURN) {
        if (PyAsyncGen_CheckExact(gen)) {
            assert(result == Py_None);
            PyErr_SetNone(PyExc_StopAsyncIteration);
        }
        else if (result == Py_None) {
            PyErr_SetNone(PyExc_StopIteration);
        }
        else {
            _PyGen_SetStopIterationValue(result);
        }
        Py_CLEAR(result);
    }
    return result;
#endif
}
#endif
static CYTHON_INLINE
PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) {
    PyObject *ret;
    PyObject *val = NULL;
    __Pyx_Coroutine_Undelegate(gen);
    __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, &val);
    ret = __Pyx_Coroutine_SendEx(gen, val, 0);
    Py_XDECREF(val);
    return ret;
}
static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) {
    PyObject *retval;
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(gen->is_running))
        return __Pyx_Coroutine_AlreadyRunningError(gen);
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        #ifdef __Pyx_Generator_USED
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Coroutine_Send(yf, value);
        } else
        #endif
        #ifdef __Pyx_Coroutine_USED
        if (__Pyx_Coroutine_Check(yf)) {
            ret = __Pyx_Coroutine_Send(yf, value);
        } else
        #endif
        #ifdef __Pyx_AsyncGen_USED
        if (__pyx_PyAsyncGenASend_CheckExact(yf)) {
            ret = __Pyx_async_gen_asend_send(yf, value);
        } else
        #endif
        #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
        if (PyGen_CheckExact(yf)) {
            ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value);
        } else
        #endif
        #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03050000 && defined(PyCoro_CheckExact) && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
        if (PyCoro_CheckExact(yf)) {
            ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value);
        } else
        #endif
        {
            if (value == Py_None)
                ret = Py_TYPE(yf)->tp_iternext(yf);
            else
                ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value);
        }
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        retval = __Pyx_Coroutine_FinishDelegation(gen);
    } else {
        retval = __Pyx_Coroutine_SendEx(gen, value, 0);
    }
    return __Pyx_Coroutine_MethodReturn(self, retval);
}
static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) {
    PyObject *retval = NULL;
    int err = 0;
    #ifdef __Pyx_Generator_USED
    if (__Pyx_Generator_CheckExact(yf)) {
        retval = __Pyx_Coroutine_Close(yf);
        if (!retval)
            return -1;
    } else
    #endif
    #ifdef __Pyx_Coroutine_USED
    if (__Pyx_Coroutine_Check(yf)) {
        retval = __Pyx_Coroutine_Close(yf);
        if (!retval)
            return -1;
    } else
    if (__Pyx_CoroutineAwait_CheckExact(yf)) {
        retval = __Pyx_CoroutineAwait_Close((__pyx_CoroutineAwaitObject*)yf, NULL);
        if (!retval)
            return -1;
    } else
    #endif
    #ifdef __Pyx_AsyncGen_USED
    if (__pyx_PyAsyncGenASend_CheckExact(yf)) {
        retval = __Pyx_async_gen_asend_close(yf, NULL);
    } else
    if (__pyx_PyAsyncGenAThrow_CheckExact(yf)) {
        retval = __Pyx_async_gen_athrow_close(yf, NULL);
    } else
    #endif
    {
        PyObject *meth;
        gen->is_running = 1;
        meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_close);
        if (unlikely(!meth)) {
            if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                PyErr_WriteUnraisable(yf);
            }
            PyErr_Clear();
        } else {
            retval = PyObject_CallFunction(meth, NULL);
            Py_DECREF(meth);
            if (!retval)
                err = -1;
        }
        gen->is_running = 0;
    }
    Py_XDECREF(retval);
    return err;
}
static PyObject *__Pyx_Generator_Next(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(gen->is_running))
        return __Pyx_Coroutine_AlreadyRunningError(gen);
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        #ifdef __Pyx_Generator_USED
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Generator_Next(yf);
        } else
        #endif
        #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
        if (PyGen_CheckExact(yf)) {
            ret = __Pyx_PyGen_Send((PyGenObject*)yf, NULL);
        } else
        #endif
        #ifdef __Pyx_Coroutine_USED
        if (__Pyx_Coroutine_Check(yf)) {
            ret = __Pyx_Coroutine_Send(yf, Py_None);
        } else
        #endif
            ret = Py_TYPE(yf)->tp_iternext(yf);
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        return __Pyx_Coroutine_FinishDelegation(gen);
    }
    return __Pyx_Coroutine_SendEx(gen, Py_None, 0);
}
static PyObject *__Pyx_Coroutine_Close_Method(PyObject *self, CYTHON_UNUSED PyObject *arg) {
    return __Pyx_Coroutine_Close(self);
}
static PyObject *__Pyx_Coroutine_Close(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    PyObject *retval, *raised_exception;
    PyObject *yf = gen->yieldfrom;
    int err = 0;
    if (unlikely(gen->is_running))
        return __Pyx_Coroutine_AlreadyRunningError(gen);
    if (yf) {
        Py_INCREF(yf);
        err = __Pyx_Coroutine_CloseIter(gen, yf);
        __Pyx_Coroutine_Undelegate(gen);
        Py_DECREF(yf);
    }
    if (err == 0)
        PyErr_SetNone(PyExc_GeneratorExit);
    retval = __Pyx_Coroutine_SendEx(gen, NULL, 1);
    if (unlikely(retval)) {
        const char *msg;
        Py_DECREF(retval);
        if ((0)) {
        #ifdef __Pyx_Coroutine_USED
        } else if (__Pyx_Coroutine_Check(self)) {
            msg = "coroutine ignored GeneratorExit";
        #endif
        #ifdef __Pyx_AsyncGen_USED
        } else if (__Pyx_AsyncGen_CheckExact(self)) {
#if PY_VERSION_HEX < 0x03060000
            msg = "async generator ignored GeneratorExit - might require Python 3.6+ finalisation (PEP 525)";
#else
            msg = "async generator ignored GeneratorExit";
#endif
        #endif
        } else {
            msg = "generator ignored GeneratorExit";
        }
        PyErr_SetString(PyExc_RuntimeError, msg);
        return NULL;
    }
    raised_exception = PyErr_Occurred();
    if (likely(!raised_exception || __Pyx_PyErr_GivenExceptionMatches2(raised_exception, PyExc_GeneratorExit, PyExc_StopIteration))) {
        if (raised_exception) PyErr_Clear();
        Py_INCREF(Py_None);
        return Py_None;
    }
    return NULL;
}
static PyObject *__Pyx__Coroutine_Throw(PyObject *self, PyObject *typ, PyObject *val, PyObject *tb,
                                        PyObject *args, int close_on_genexit) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(gen->is_running))
        return __Pyx_Coroutine_AlreadyRunningError(gen);
    if (yf) {
        PyObject *ret;
        Py_INCREF(yf);
        if (__Pyx_PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) && close_on_genexit) {
            int err = __Pyx_Coroutine_CloseIter(gen, yf);
            Py_DECREF(yf);
            __Pyx_Coroutine_Undelegate(gen);
            if (err < 0)
                return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0));
            goto throw_here;
        }
        gen->is_running = 1;
        if (0
        #ifdef __Pyx_Generator_USED
            || __Pyx_Generator_CheckExact(yf)
        #endif
        #ifdef __Pyx_Coroutine_USED
            || __Pyx_Coroutine_Check(yf)
        #endif
            ) {
            ret = __Pyx__Coroutine_Throw(yf, typ, val, tb, args, close_on_genexit);
        #ifdef __Pyx_Coroutine_USED
        } else if (__Pyx_CoroutineAwait_CheckExact(yf)) {
            ret = __Pyx__Coroutine_Throw(((__pyx_CoroutineAwaitObject*)yf)->coroutine, typ, val, tb, args, close_on_genexit);
        #endif
        } else {
            PyObject *meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_throw);
            if (unlikely(!meth)) {
                Py_DECREF(yf);
                if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                    gen->is_running = 0;
                    return NULL;
                }
                PyErr_Clear();
                __Pyx_Coroutine_Undelegate(gen);
                gen->is_running = 0;
                goto throw_here;
            }
            if (likely(args)) {
                ret = PyObject_CallObject(meth, args);
            } else {
                ret = PyObject_CallFunctionObjArgs(meth, typ, val, tb, NULL);
            }
            Py_DECREF(meth);
        }
        gen->is_running = 0;
        Py_DECREF(yf);
        if (!ret) {
            ret = __Pyx_Coroutine_FinishDelegation(gen);
        }
        return __Pyx_Coroutine_MethodReturn(self, ret);
    }
throw_here:
    __Pyx_Raise(typ, val, tb, NULL);
    return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0));
}
static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) {
    PyObject *typ;
    PyObject *val = NULL;
    PyObject *tb = NULL;
    if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
        return NULL;
    return __Pyx__Coroutine_Throw(self, typ, val, tb, args, 1);
}
static CYTHON_INLINE int __Pyx_Coroutine_traverse_excstate(__Pyx_ExcInfoStruct *exc_state, visitproc visit, void *arg) {
    Py_VISIT(exc_state->exc_type);
    Py_VISIT(exc_state->exc_value);
    Py_VISIT(exc_state->exc_traceback);
    return 0;
}
static int __Pyx_Coroutine_traverse(__pyx_CoroutineObject *gen, visitproc visit, void *arg) {
    Py_VISIT(gen->closure);
    Py_VISIT(gen->classobj);
    Py_VISIT(gen->yieldfrom);
    return __Pyx_Coroutine_traverse_excstate(&gen->gi_exc_state, visit, arg);
}
static int __Pyx_Coroutine_clear(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    Py_CLEAR(gen->closure);
    Py_CLEAR(gen->classobj);
    Py_CLEAR(gen->yieldfrom);
    __Pyx_Coroutine_ExceptionClear(&gen->gi_exc_state);
#ifdef __Pyx_AsyncGen_USED
    if (__Pyx_AsyncGen_CheckExact(self)) {
        Py_CLEAR(((__pyx_PyAsyncGenObject*)gen)->ag_finalizer);
    }
#endif
    Py_CLEAR(gen->gi_code);
    Py_CLEAR(gen->gi_frame);
    Py_CLEAR(gen->gi_name);
    Py_CLEAR(gen->gi_qualname);
    Py_CLEAR(gen->gi_modulename);
    return 0;
}
static void __Pyx_Coroutine_dealloc(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    PyObject_GC_UnTrack(gen);
    if (gen->gi_weakreflist != NULL)
        PyObject_ClearWeakRefs(self);
    if (gen->resume_label >= 0) {
        PyObject_GC_Track(self);
#if PY_VERSION_HEX >= 0x030400a1 && CYTHON_USE_TP_FINALIZE
        if (PyObject_CallFinalizerFromDealloc(self))
#else
        Py_TYPE(gen)->tp_del(self);
        if (Py_REFCNT(self) > 0)
#endif
        {
            return;
        }
        PyObject_GC_UnTrack(self);
    }
#ifdef __Pyx_AsyncGen_USED
    if (__Pyx_AsyncGen_CheckExact(self)) {
        /* We have to handle this case for asynchronous generators
           right here, because this code has to be between UNTRACK
           and GC_Del. */
        Py_CLEAR(((__pyx_PyAsyncGenObject*)self)->ag_finalizer);
    }
#endif
    __Pyx_Coroutine_clear(self);
    PyObject_GC_Del(gen);
}
static void __Pyx_Coroutine_del(PyObject *self) {
    PyObject *error_type, *error_value, *error_traceback;
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    __Pyx_PyThreadState_declare
    if (gen->resume_label < 0) {
        return;
    }
#if !CYTHON_USE_TP_FINALIZE
    assert(self->ob_refcnt == 0);
    __Pyx_SET_REFCNT(self, 1);
#endif
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&error_type, &error_value, &error_traceback);
#ifdef __Pyx_AsyncGen_USED
    if (__Pyx_AsyncGen_CheckExact(self)) {
        __pyx_PyAsyncGenObject *agen = (__pyx_PyAsyncGenObject*)self;
        PyObject *finalizer = agen->ag_finalizer;
        if (finalizer && !agen->ag_closed) {
            PyObject *res = __Pyx_PyObject_CallOneArg(finalizer, self);
            if (unlikely(!res)) {
                PyErr_WriteUnraisable(self);
            } else {
                Py_DECREF(res);
            }
            __Pyx_ErrRestore(error_type, error_value, error_traceback);
            return;
        }
    }
#endif
    if (unlikely(gen->resume_label == 0 && !error_value)) {
#ifdef __Pyx_Coroutine_USED
#ifdef __Pyx_Generator_USED
    if (!__Pyx_Generator_CheckExact(self))
#endif
        {
        PyObject_GC_UnTrack(self);
#if PY_MAJOR_VERSION >= 3  || defined(PyErr_WarnFormat)
        if (unlikely(PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "coroutine '%.50S' was never awaited", gen->gi_qualname) < 0))
            PyErr_WriteUnraisable(self);
#else
        {PyObject *msg;
        char *cmsg;
        #if CYTHON_COMPILING_IN_PYPY
        msg = NULL;
        cmsg = (char*) "coroutine was never awaited";
        #else
        char *cname;
        PyObject *qualname;
        qualname = gen->gi_qualname;
        cname = PyString_AS_STRING(qualname);
        msg = PyString_FromFormat("coroutine '%.50s' was never awaited", cname);
        if (unlikely(!msg)) {
            PyErr_Clear();
            cmsg = (char*) "coroutine was never awaited";
        } else {
            cmsg = PyString_AS_STRING(msg);
        }
        #endif
        if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, cmsg, 1) < 0))
            PyErr_WriteUnraisable(self);
        Py_XDECREF(msg);}
#endif
        PyObject_GC_Track(self);
        }
#endif
    } else {
        PyObject *res = __Pyx_Coroutine_Close(self);
        if (unlikely(!res)) {
            if (PyErr_Occurred())
                PyErr_WriteUnraisable(self);
        } else {
            Py_DECREF(res);
        }
    }
    __Pyx_ErrRestore(error_type, error_value, error_traceback);
#if !CYTHON_USE_TP_FINALIZE
    assert(Py_REFCNT(self) > 0);
    if (--self->ob_refcnt == 0) {
        return;
    }
    {
        Py_ssize_t refcnt = Py_REFCNT(self);
        _Py_NewReference(self);
        __Pyx_SET_REFCNT(self, refcnt);
    }
#if CYTHON_COMPILING_IN_CPYTHON
    assert(PyType_IS_GC(Py_TYPE(self)) &&
           _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
    _Py_DEC_REFTOTAL;
#endif
#ifdef COUNT_ALLOCS
    --Py_TYPE(self)->tp_frees;
    --Py_TYPE(self)->tp_allocs;
#endif
#endif
}
static PyObject *
__Pyx_Coroutine_get_name(__pyx_CoroutineObject *self, CYTHON_UNUSED void *context)
{
    PyObject *name = self->gi_name;
    if (unlikely(!name)) name = Py_None;
    Py_INCREF(name);
    return name;
}
static int
__Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, PyObject *value, CYTHON_UNUSED void *context)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value)))
#else
    if (unlikely(value == NULL || !PyString_Check(value)))
#endif
    {
        PyErr_SetString(PyExc_TypeError,
                        "__name__ must be set to a string object");
        return -1;
    }
    tmp = self->gi_name;
    Py_INCREF(value);
    self->gi_name = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self, CYTHON_UNUSED void *context)
{
    PyObject *name = self->gi_qualname;
    if (unlikely(!name)) name = Py_None;
    Py_INCREF(name);
    return name;
}
static int
__Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, PyObject *value, CYTHON_UNUSED void *context)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value)))
#else
    if (unlikely(value == NULL || !PyString_Check(value)))
#endif
    {
        PyErr_SetString(PyExc_TypeError,
                        "__qualname__ must be set to a string object");
        return -1;
    }
    tmp = self->gi_qualname;
    Py_INCREF(value);
    self->gi_qualname = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_Coroutine_get_frame(__pyx_CoroutineObject *self, CYTHON_UNUSED void *context)
{
    PyObject *frame = self->gi_frame;
    if (!frame) {
        if (unlikely(!self->gi_code)) {
            Py_RETURN_NONE;
        }
        frame = (PyObject *) PyFrame_New(
            PyThreadState_Get(),            /*PyThreadState *tstate,*/
            (PyCodeObject*) self->gi_code,  /*PyCodeObject *code,*/
            __pyx_d,                 /*PyObject *globals,*/
            0                               /*PyObject *locals*/
        );
        if (unlikely(!frame))
            return NULL;
        self->gi_frame = frame;
    }
    Py_INCREF(frame);
    return frame;
}
static __pyx_CoroutineObject *__Pyx__Coroutine_New(
            PyTypeObject* type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
            PyObject *name, PyObject *qualname, PyObject *module_name) {
    __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type);
    if (unlikely(!gen))
        return NULL;
    return __Pyx__Coroutine_NewInit(gen, body, code, closure, name, qualname, module_name);
}
static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit(
            __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
            PyObject *name, PyObject *qualname, PyObject *module_name) {
    gen->body = body;
    gen->closure = closure;
    Py_XINCREF(closure);
    gen->is_running = 0;
    gen->resume_label = 0;
    gen->classobj = NULL;
    gen->yieldfrom = NULL;
    gen->gi_exc_state.exc_type = NULL;
    gen->gi_exc_state.exc_value = NULL;
    gen->gi_exc_state.exc_traceback = NULL;
#if CYTHON_USE_EXC_INFO_STACK
    gen->gi_exc_state.previous_item = NULL;
#endif
    gen->gi_weakreflist = NULL;
    Py_XINCREF(qualname);
    gen->gi_qualname = qualname;
    Py_XINCREF(name);
    gen->gi_name = name;
    Py_XINCREF(module_name);
    gen->gi_modulename = module_name;
    Py_XINCREF(code);
    gen->gi_code = code;
    gen->gi_frame = NULL;
    PyObject_GC_Track(gen);
    return gen;
}

/* PatchModuleWithCoroutine */
static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) {
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
    int result;
    PyObject *globals, *result_obj;
    globals = PyDict_New();  if (unlikely(!globals)) goto ignore;
    result = PyDict_SetItemString(globals, "_cython_coroutine_type",
    #ifdef __Pyx_Coroutine_USED
        (PyObject*)__pyx_CoroutineType);
    #else
        Py_None);
    #endif
    if (unlikely(result < 0)) goto ignore;
    result = PyDict_SetItemString(globals, "_cython_generator_type",
    #ifdef __Pyx_Generator_USED
        (PyObject*)__pyx_GeneratorType);
    #else
        Py_None);
    #endif
    if (unlikely(result < 0)) goto ignore;
    if (unlikely(PyDict_SetItemString(globals, "_module", module) < 0)) goto ignore;
    if (unlikely(PyDict_SetItemString(globals, "__builtins__", __pyx_b) < 0)) goto ignore;
    result_obj = PyRun_String(py_code, Py_file_input, globals, globals);
    if (unlikely(!result_obj)) goto ignore;
    Py_DECREF(result_obj);
    Py_DECREF(globals);
    return module;
ignore:
    Py_XDECREF(globals);
    PyErr_WriteUnraisable(module);
    if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, "Cython module failed to patch module with custom type", 1) < 0)) {
        Py_DECREF(module);
        module = NULL;
    }
#else
    py_code++;
#endif
    return module;
}

/* PatchGeneratorABC */
#ifndef CYTHON_REGISTER_ABCS
#define CYTHON_REGISTER_ABCS 1
#endif
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
static PyObject* __Pyx_patch_abc_module(PyObject *module);
static PyObject* __Pyx_patch_abc_module(PyObject *module) {
    module = __Pyx_Coroutine_patch_module(
        module, ""
"if _cython_generator_type is not None:\n"
"    try: Generator = _module.Generator\n"
"    except AttributeError: pass\n"
"    else: Generator.register(_cython_generator_type)\n"
"if _cython_coroutine_type is not None:\n"
"    try: Coroutine = _module.Coroutine\n"
"    except AttributeError: pass\n"
"    else: Coroutine.register(_cython_coroutine_type)\n"
    );
    return module;
}
#endif
static int __Pyx_patch_abc(void) {
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
    static int abc_patched = 0;
    if (CYTHON_REGISTER_ABCS && !abc_patched) {
        PyObject *module;
        module = PyImport_ImportModule((PY_MAJOR_VERSION >= 3) ? "collections.abc" : "collections");
        if (!module) {
            PyErr_WriteUnraisable(NULL);
            if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning,
                    ((PY_MAJOR_VERSION >= 3) ?
                        "Cython module failed to register with collections.abc module" :
                        "Cython module failed to register with collections module"), 1) < 0)) {
                return -1;
            }
        } else {
            module = __Pyx_patch_abc_module(module);
            abc_patched = 1;
            if (unlikely(!module))
                return -1;
            Py_DECREF(module);
        }
        module = PyImport_ImportModule("backports_abc");
        if (module) {
            module = __Pyx_patch_abc_module(module);
            Py_XDECREF(module);
        }
        if (!module) {
            PyErr_Clear();
        }
    }
#else
    if ((0)) __Pyx_Coroutine_patch_module(NULL, NULL);
#endif
    return 0;
}

/* Generator */
static PyMethodDef __pyx_Generator_methods[] = {
    {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O,
     (char*) PyDoc_STR("send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")},
    {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS,
     (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in generator,\nreturn next yielded value or raise StopIteration.")},
    {"close", (PyCFunction) __Pyx_Coroutine_Close_Method, METH_NOARGS,
     (char*) PyDoc_STR("close() -> raise GeneratorExit inside generator.")},
    {0, 0, 0, 0}
};
static PyMemberDef __pyx_Generator_memberlist[] = {
    {(char *) "gi_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL},
    {(char*) "gi_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
     (char*) PyDoc_STR("object being iterated by 'yield from', or None")},
    {(char*) "gi_code", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_code), READONLY, NULL},
    {0, 0, 0, 0, 0}
};
static PyGetSetDef __pyx_Generator_getsets[] = {
    {(char *) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name,
     (char*) PyDoc_STR("name of the generator"), 0},
    {(char *) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname,
     (char*) PyDoc_STR("qualified name of the generator"), 0},
    {(char *) "gi_frame", (getter)__Pyx_Coroutine_get_frame, NULL,
     (char*) PyDoc_STR("Frame of the generator"), 0},
    {0, 0, 0, 0, 0}
};
static PyTypeObject __pyx_GeneratorType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    "generator",
    sizeof(__pyx_CoroutineObject),
    0,
    (destructor) __Pyx_Coroutine_dealloc,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE,
    0,
    (traverseproc) __Pyx_Coroutine_traverse,
    0,
    0,
    offsetof(__pyx_CoroutineObject, gi_weakreflist),
    0,
    (iternextfunc) __Pyx_Generator_Next,
    __pyx_Generator_methods,
    __pyx_Generator_memberlist,
    __pyx_Generator_getsets,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
#if CYTHON_USE_TP_FINALIZE
    0,
#else
    __Pyx_Coroutine_del,
#endif
    0,
#if CYTHON_USE_TP_FINALIZE
    __Pyx_Coroutine_del,
#elif PY_VERSION_HEX >= 0x030400a1
    0,
#endif
#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
    0,
#endif
#if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
    0,
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000
    0,
#endif
};
static int __pyx_Generator_init(void) {
    __pyx_GeneratorType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
    __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter;
    __pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type);
    if (unlikely(!__pyx_GeneratorType)) {
        return -1;
    }
    return 0;
}

/* CheckBinaryVersion */
static int __Pyx_check_binary_version(void) {
    char ctversion[5];
    int same=1, i, found_dot;
    const char* rt_from_call = Py_GetVersion();
    PyOS_snprintf(ctversion, 5, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    found_dot = 0;
    for (i = 0; i < 4; i++) {
        if (!ctversion[i]) {
            same = (rt_from_call[i] < '0' || rt_from_call[i] > '9');
            break;
        }
        if (rt_from_call[i] != ctversion[i]) {
            same = 0;
            break;
        }
    }
    if (!same) {
        char rtversion[5] = {'\0'};
        char message[200];
        for (i=0; i<4; ++i) {
            if (rt_from_call[i] == '.') {
                if (found_dot) break;
                found_dot = 1;
            } else if (rt_from_call[i] < '0' || rt_from_call[i] > '9') {
                break;
            }
            rtversion[i] = rt_from_call[i];
        }
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

/* InitStrings */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        if (PyObject_Hash(*t->p) == -1)
            return -1;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
#if !CYTHON_PEP393_ENABLED
static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    char* defenc_c;
    PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
    if (!defenc) return NULL;
    defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    {
        char* end = defenc_c + PyBytes_GET_SIZE(defenc);
        char* c;
        for (c = defenc_c; c < end; c++) {
            if ((unsigned char) (*c) >= 128) {
                PyUnicode_AsASCIIString(o);
                return NULL;
            }
        }
    }
#endif
    *length = PyBytes_GET_SIZE(defenc);
    return defenc_c;
}
#else
static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    if (likely(PyUnicode_IS_ASCII(o))) {
        *length = PyUnicode_GET_LENGTH(o);
        return PyUnicode_AsUTF8(o);
    } else {
        PyUnicode_AsASCIIString(o);
        return NULL;
    }
#else
    return PyUnicode_AsUTF8AndSize(o, length);
#endif
}
#endif
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
        return __Pyx_PyUnicode_AsStringAndSize(o, length);
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
    int retval;
    if (unlikely(!x)) return -1;
    retval = __Pyx_PyObject_IsTrue(x);
    Py_DECREF(x);
    return retval;
}
static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
#if PY_MAJOR_VERSION >= 3
    if (PyLong_Check(result)) {
        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                "__int__ returned non-int (type %.200s).  "
                "The ability to return an instance of a strict subclass of int "
                "is deprecated, and may be removed in a future version of Python.",
                Py_TYPE(result)->tp_name)) {
            Py_DECREF(result);
            return NULL;
        }
        return result;
    }
#endif
    PyErr_Format(PyExc_TypeError,
                 "__%.4s__ returned non-%.4s (type %.200s)",
                 type_name, type_name, Py_TYPE(result)->tp_name);
    Py_DECREF(result);
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
#if CYTHON_USE_TYPE_SLOTS
  PyNumberMethods *m;
#endif
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_Check(x) || PyLong_Check(x)))
#else
  if (likely(PyLong_Check(x)))
#endif
    return __Pyx_NewRef(x);
#if CYTHON_USE_TYPE_SLOTS
  m = Py_TYPE(x)->tp_as_number;
  #if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = m->nb_int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = m->nb_long(x);
  }
  #else
  if (likely(m && m->nb_int)) {
    name = "int";
    res = m->nb_int(x);
  }
  #endif
#else
  if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
    res = PyNumber_Int(x);
  }
#endif
  if (likely(res)) {
#if PY_MAJOR_VERSION < 3
    if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
#else
    if (unlikely(!PyLong_CheckExact(res))) {
#endif
        return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(b);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    const digit* digits = ((PyLongObject*)b)->ob_digit;
    const Py_ssize_t size = Py_SIZE(b);
    if (likely(__Pyx_sst_abs(size) <= 1)) {
        ival = likely(size) ? digits[0] : 0;
        if (size == -1) ival = -ival;
        return ival;
    } else {
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) {
  if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) {
    return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o);
#if PY_MAJOR_VERSION < 3
  } else if (likely(PyInt_CheckExact(o))) {
    return PyInt_AS_LONG(o);
#endif
  } else {
    Py_ssize_t ival;
    PyObject *x;
    x = PyNumber_Index(o);
    if (!x) return -1;
    ival = PyInt_AsLong(x);
    Py_DECREF(x);
    return ival;
  }
}
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
  return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
