 ###
 
 DHT::removePeer = (addr, infoHash) ->
-  self = this
-  if self._destroyed
+  if @_destroyed
     return
   infoHash = idToHexString(infoHash)
-  peers = self.peers[infoHash]
+  peers = @peers[infoHash]
   if peers and peers.index[addr]
     peers.index[addr] = null
     compactPeerInfo = string2compact(addr)
     peers.list.some (peer, index) ->
       if bufferEqual(peer, compactPeerInfo)
         peers.list.splice index, 1
-        self._debug 'removePeer %s %s', addr, infoHash
+        @_debug 'removePeer %s %s', addr, infoHash
         return true
         # abort early
       return

###

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
    return
  token = message.a and message.a.token
  if !self._isValidToken(token, addrData[0])
    errMessage = 'cannot `announce_peer` with bad token'
    self._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
  # send acknowledgement
  res =
    t: message.t
    y: MESSAGE_TYPE.RESPONSE
    r: id: self.nodeId
  self._send addr, res
  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 @_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
      @_debug 'got lookup error: %s', err.message
    else
      @_debug 'got lookup response from %s', nodeIdHex
      # add node that sent this response
      contact = table.get(nodeId) or
        id: nodeId
