INNER CODE UNIT · JavaScript

getRandomPort

shadowsocks/shadowsocks-manager · plugins/account/index.js:447

          const getRandomPort = () => {
            if(orderPorts.length) {
              return orderPorts[Math.floor(Math.random() * orderPorts.length)];
            } else {
              return Math.floor(Math.random() * (port.end - port.start + 1) + port.start);
            }
          };
          let retry = 0;
          let myPort = getRandomPort();
          const checkIfPortExists = port => {
            let myPort = port;
            return knex('account_plugin').select()
            .where({ port }).then(success => {
              if(success.length && retry <= 30) {
                retry++;
                myPort = getRandomPort();
                return checkIfPortExists(myPort);
              } else if (success.length && retry > 30) {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…