* Parse list of endpoints. * @param {string[] | undefined} listenOn - List of string of the form "ip:port" * @param {string} fieldName - Name of field being parsed * @returns {{ip: string, port: number}[]} - List of ip/port pairs
(listenOn, fieldName)
| 913 | * @returns {{ip: string, port: number}[]} - List of ip/port pairs |
| 914 | */ |
| 915 | _parseEndpoints(listenOn, fieldName) { |
| 916 | let result = []; |
| 917 | if (listenOn !== undefined) { |
| 918 | assert(Array.isArray(listenOn) |
| 919 | && listenOn.every(e => typeof e === 'string'), |
| 920 | `bad config: ${fieldName} must be a list of strings`); |
| 921 | result = listenOn.map(item => { |
| 922 | const lastColon = item.lastIndexOf(':'); |
| 923 | // if address is IPv6 format, it includes brackets |
| 924 | // that have to be removed from the final IP address |
| 925 | const ipAddress = item.indexOf(']') > 0 ? |
| 926 | item.substr(1, lastColon - 2) : |
| 927 | item.substr(0, lastColon); |
| 928 | // the port should not include the colon |
| 929 | const port = item.substr(lastColon + 1); |
| 930 | assert(Number.parseInt(port, 10), |
| 931 | `bad config: ${fieldName} port must be a positive integer`); |
| 932 | return { ip: ipAddress, port }; |
| 933 | }); |
| 934 | } |
| 935 | return result; |
| 936 | } |
| 937 | |
| 938 | _getConfig() { |
| 939 | let config; |