 ###
 
 DHT::_onAnnouncePeer = (addr, message) ->
-  self = this
   errMessage = undefined
   addrData = addrToIPPort(addr)
   infoHash = idToHexString(message.a and message.a.info_hash)
   if !infoHash
     errMessage = '`announce_peer` missing required `a.info_hash` field'
-    self._debug errMessage
-    self._sendError addr, message.t, ERROR_TYPE.PROTOCOL, errMessage
+    @_debug errMessage
+    @_sendError addr, message.t, ERROR_TYPE.PROTOCOL, errMessage
     return
   token = message.a and message.a.token
-  if !self._isValidToken(token, addrData[0])
+  if !@_isValidToken(token, addrData[0])
     errMessage = 'cannot `announce_peer` with bad token'
-    self._sendError addr, message.t, ERROR_TYPE.PROTOCOL, errMessage
+    @_sendError addr, message.t, ERROR_TYPE.PROTOCOL, errMessage
     return
   port = if message.a.implied_port != 0 then addrData[1] else message.a.port
   # use port in `announce_peer` message
-  self._debug 'got announce_peer %s %s from %s with token %s', idToHexString(infoHash), port, addr, idToHexString(token)
-  self._addPeer addrData[0] + ':' + port, infoHash
+  @_debug 'got announce_peer %s %s from %s with token %s', idToHexString(infoHash), port, addr, idToHexString(token)
+  @_addPeer addrData[0] + ':' + port, infoHash
   # send acknowledgement
   res =
     t: message.t
     y: MESSAGE_TYPE.RESPONSE
-    r: id: self.nodeId
-  self._send addr, res
+    r: id: @nodeId
+  @_send addr, res
   return
 
 ###*

###

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

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

  self._query data, addr, onResponse
  return

###*

###

DHT::_onResponseOrError = (addr, type, message) ->
  transactionId = Buffer.isBuffer(message.t) and message.t.length == 2 and message.t.readUInt16BE(0)
  transaction = @transactions and @transactions[addr] and @transactions[addr][transactionId]
  err = null
  if type == MESSAGE_TYPE.ERROR
    err = new Error(if Array.isArray(message.e) then message.e.join(' ') else undefined)
