 ###
 
 DHT::_onQuery = (addr, message) ->
-  self = this
   query = message.q.toString()
-  if typeof self.queryHandler[query] == 'function'
-    self.queryHandler[query].call self, addr, message
+  if typeof @queryHandler[query] == 'function'
+    @queryHandler[query].call @, addr, message
   else
     errMessage = 'unexpected query type'
-    self._debug errMessage
-    self._sendError addr, message.t, ERROR_TYPE.METHOD_UNKNOWN, errMessage
+    @_debug errMessage
+    @_sendError addr, message.t, ERROR_TYPE.METHOD_UNKNOWN, errMessage
   return
 
 ###*

  # Note: `_sendFindNode` and `_sendGetPeers` will insert newly discovered nodes into
  # the routing table, so that's not done here.

  onResponse = (addr, err, res) ->
    if self._destroyed
      return cb(new Error('dht is destroyed'))
    pending -= 1
    nodeId = res and res.id
    nodeIdHex = idToHexString(nodeId)
    # ignore errors - they are just timeouts
    if err
      self._debug 'got lookup error: %s', err.message
    else
      self._debug 'got lookup response from %s', nodeIdHex
      # add node that sent this response
      contact = table.get(nodeId) or
        id: nodeId

###

DHT::_sendFindNode = (addr, nodeId, cb) ->
  data =
    q: 'find_node'
    a:
      id: @nodeId
      target: nodeId

  onResponse = (err, res) =>
    if err
      return cb(err)
    if res.nodes
      res.nodes = parseNodeInfo(res.nodes)
      res.nodes.forEach (node) =>
        @addNode node.addr, node.id, addr
        return
    cb null, res
    return

  @_query data, addr, onResponse
  return

###*
