docs: function createPeerListener(self, peerIdentifier) {
  
    // This section manages a server that accepts incoming connections
    // from the application. The first connection causes the p2p link to
    // be established and connects a mux to the native listener that will
    // have been set up. Subsequent connections create new streams on that
    // link.
  
    // In general:
    // - an incoming socket is one _from_ the application
    // - an outgoing socket is one to the native listener on the p2p side
    // - a client socket is one _to_ the application, 1 per remote created stream
  
    switch (self._state) {
      case self.TCPServersManagerStates.INITIALIZED: {
        return Promise.reject(new Error('Call Start!'));
      }
      case self.TCPServersManagerStates.STARTED: {
        break;
      }
      case self.TCPServersManagerStates.STOPPED: {
        return Promise.reject(new Error('We are stopped!'));
      }
      default: {
        return Promise.reject(new Error('Unsupported state ' + self._state));
      }
    }
  
    function _do(resolve, reject) {
      var incomingConnectionId = -1;
      function onNewConnection(incoming) {
        ++incomingConnectionId;
        var localIncomingConnectionId = incomingConnectionId;
  
        logger.silly('incoming (TCP) - Node TCP/IP client <-> Mux stream' +
          ' - %s - %d - got a new incoming connection', peerIdentifier,
          localIncomingConnectionId);
        // Handle a new connection from the app to the server
        if (server._firstConnection) {
          server.muxPromise = connectToRemotePeer(self, incoming, peerIdentifier,
                                                  server);
        }
  
        var incomingStream;
  
        // We need to subscribe to `incoming` immediately.
        // We want not to loose any event (issue #1473).
        incoming
        .on('error', function (err) {
          logger.error('incoming (TCP) - Node TCP/IP client <-> Mux stream' +
            '- %s - %d - error: %s', peerIdentifier,
            localIncomingConnectionId, err);
          if (incomingStream) {
            incomingStream.destroy();
          }
        })
        .on('finish', function () {
          logger.silly('incoming (TCP) - Node TCP/IP client <-> Mux stream ' +
            '- %s - %d - finish', peerIdentifier, localIncomingConnectionId);
          if (incomingStream) {
            incomingStream.destroy();
          }
        })
        .on('close', function () {
          logger.silly('incoming (TCP) - Node TCP/IP client <-> Mux stream' +
            ' - %s - %d - close', peerIdentifier, localIncomingConnectionId);
          if (incomingStream) {
            incomingStream.destroy();
          }
        });
  
        server.muxPromise
          .then(function () {
            // We don't need to create `incomingStream` and `pipe`
            //   if `incoming` is already closed (issue #1473).
            if (incoming.readyState === 'closed') {
              logger.debug('incoming (TCP) - Node TCP/IP client - is already closed');
              return;
            }
  
            assert(server._mux, 'server._mux must exist by now');
            incomingStream = server._mux.createStream();
  
            incomingStream
            .on('error', function (err) {
              logger.error('incomingStream (mux) - Node TCP/IP client <-> ' +
                'Mux stream - %s - %d - error: %s', peerIdentifier,
                localIncomingConnectionId, err);
              incoming.destroy();
            })
            .on('finish', function () {
              logger.silly('incomingStream (mux) - Node TCP/IP client <-> ' +
                'Mux stream - %s - %d - finish', peerIdentifier,
                localIncomingConnectionId);
              incoming.destroy();
            })
            .on('close', function () {
              logger.silly('incomingStream (mux) - Node TCP/IP client <-> ' +
                'Mux stream -  %s - %d - close', peerIdentifier,
                localIncomingConnectionId);
              incoming.destroy();
            });
  
            // I had wanted to add an incoming.on('data) event handler here to
            // just measure the amount of data being sent but when I put on the
            // event handler, even if it doesn't do anything, it causes a massive
            // slow down in the rate at which JXcore executes and so causes
            // tests to fail.
  
            incomingStream.pipe(incoming).pipe(incomingStream);
          })
          .catch(function () {
            incoming.end();
          });
      }
  
      function createServer(onNewConnection) {
        // This is the server that will listen for connection coming from the
        // application
  
        function closeOldestServer() {
          var oldest = null;
          Object.keys(self._peerServers).forEach(function (k) {
            if (oldest == null) {
              oldest = k;
            }
            else {
              if (self._peerServers[k].lastActive <
                self._peerServers[oldest].lastActive) {
                oldest = k;
              }
            }
          });
          if (oldest) {
            closeServer(self, self._peerServers[oldest], null, false);
          }
        }
  
        if (self._peerServers.length === maxPeersToAdvertise) {
          closeOldestServer();
        }
  
        var server = makeIntoCloseAllServer(net.createServer(), true);
        server._peerIdentifier = peerIdentifier;
        server._firstConnection = true;
  
        server.on('connection', onNewConnection);
  
        server.on('close', function onClose() {
          logger.silly('Closed Node TCP/IP listener (server) for %s',
            peerIdentifier);
        });
  
        return server;
      }
  
      var peerServerEntry = self._peerServers[peerIdentifier];
      if (peerServerEntry) {
        // If address is there then we have successfully gotten a port for the
        // server
        var address = peerServerEntry.server.address();
        if (address) {
          return resolve(address.port);
        }
        // Otherwise we need to record the resolve and reject and clean things
        // up one way or another when we figure out if we are going to get
        // a port
        peerServerEntry.promisesOnListen.push({
          resolve: resolve,
          reject: reject
        });
        return;
      }
  
      logger.debug('creating new server for %s', peerIdentifier);
  
      var server = createServer(onNewConnection);
  
      self._peerServers[peerIdentifier] =
      { lastActive: Date.now(), server: server, promisesOnListen: []};
  
      /**
        * We have to keep this value around because by the time we call failed
        * startup the server's entry will have been deleted from _peerServers
        * as part of closing the server (the inevitably result of anything that
        * ends up with us calling failedStartup).
        */
      peerServerEntry = self._peerServers[peerIdentifier];
  
      function successfulStartup() {
        resolve(server.address().port);
        self._peerServers[peerIdentifier].promisesOnListen.forEach(
          function (resolveReject) {
            resolveReject.resolve(server.address().port);
          });
        // Once successfulStartup is called it means that we are out of listen
        // and so no further promises should be enqueued, they will instead
        // be returned the server's address. So we can set this to null.
        self._peerServers[peerIdentifier].promisesOnListen = null;
      }
  
      function failedStartup(err) {
        peerServerEntry.promisesOnListen
          .forEach(function (resolveReject) {
            resolveReject.reject(err);
          });
  
        reject(err);
      }
  
      server.on('error', function (err) {
        logger.warn('Node TCP/IP listener (server) for %s received error %s',
          peerIdentifier, err);
        failedStartup(err);
      });
  
      // listen(port, ...) port = 0 for random port
      server.listen(0, function () {
        var port = server.address().port;
        logger.debug('Node TCP/IP listener (server) for %s listening on %d',
          peerIdentifier, port);
  
        successfulStartup();
      });
    }
  
    return new Promise(_do);
  }