ControlServer.js.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>ControlServer.js - Documentation</title>
  6. <script src="scripts/prettify/prettify.js"></script>
  7. <script src="scripts/prettify/lang-css.js"></script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
  13. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  14. </head>
  15. <body>
  16. <input type="checkbox" id="nav-trigger" class="nav-trigger" />
  17. <label for="nav-trigger" class="navicon-button x">
  18. <div class="navicon"></div>
  19. </label>
  20. <label for="nav-trigger" class="overlay"></label>
  21. <nav>
  22. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="ControlServer.html">ControlServer</a><ul class='methods'><li data-type='method'><a href="ControlServer.html#.instance_info">instance_info</a></li><li data-type='method'><a href="ControlServer.html#close">close</a></li><li data-type='method'><a href="ControlServer.html#createDNSServer">createDNSServer</a></li><li data-type='method'><a href="ControlServer.html#createHTTPServer">createHTTPServer</a></li><li data-type='method'><a href="ControlServer.html#createSOCKSServer">createSOCKSServer</a></li><li data-type='method'><a href="ControlServer.html#createTorPool">createTorPool</a></li><li data-type='method'><a href="ControlServer.html#listen">listen</a></li><li data-type='method'><a href="ControlServer.html#listenTcp">listenTcp</a></li><li data-type='method'><a href="ControlServer.html#listenWs">listenWs</a></li></ul></li><li><a href="DNSServer.html">DNSServer</a><ul class='methods'><li data-type='method'><a href="DNSServer.html#listen">listen</a></li></ul></li><li><a href="HTTPServer.html">HTTPServer</a><ul class='methods'><li data-type='method'><a href="HTTPServer.html#listen">listen</a></li></ul></li><li><a href="SOCKSServer.html">SOCKSServer</a><ul class='methods'><li data-type='method'><a href="SOCKSServer.html#listen">listen</a></li></ul></li><li><a href="TorPool.html">TorPool</a><ul class='methods'><li data-type='method'><a href="TorPool.html#add">add</a></li><li data-type='method'><a href="TorPool.html#add_instance_to_group">add_instance_to_group</a></li><li data-type='method'><a href="TorPool.html#add_instance_to_group_at">add_instance_to_group_at</a></li><li data-type='method'><a href="TorPool.html#add_instance_to_group_by_name">add_instance_to_group_by_name</a></li><li data-type='method'><a href="TorPool.html#create">create</a></li><li data-type='method'><a href="TorPool.html#create_instance">create_instance</a></li><li data-type='method'><a href="TorPool.html#exit">exit</a></li><li data-type='method'><a href="TorPool.html#get_config_at">get_config_at</a></li><li data-type='method'><a href="TorPool.html#get_config_by_name">get_config_by_name</a></li><li data-type='method'><a href="TorPool.html#instance_at">instance_at</a></li><li data-type='method'><a href="TorPool.html#instance_by_name">instance_by_name</a></li><li data-type='method'><a href="TorPool.html#instances_by_group">instances_by_group</a></li><li data-type='method'><a href="TorPool.html#new_identites">new_identites</a></li><li data-type='method'><a href="TorPool.html#new_identites_by_group">new_identites_by_group</a></li><li data-type='method'><a href="TorPool.html#new_identity_at">new_identity_at</a></li><li data-type='method'><a href="TorPool.html#new_identity_by_name">new_identity_by_name</a></li><li data-type='method'><a href="TorPool.html#next">next</a></li><li data-type='method'><a href="TorPool.html#next_by_group">next_by_group</a></li><li data-type='method'><a href="TorPool.html#remove">remove</a></li><li data-type='method'><a href="TorPool.html#remove_at">remove_at</a></li><li data-type='method'><a href="TorPool.html#remove_by_name">remove_by_name</a></li><li data-type='method'><a href="TorPool.html#remove_instance_from_group">remove_instance_from_group</a></li><li data-type='method'><a href="TorPool.html#remove_instance_from_group_at">remove_instance_from_group_at</a></li><li data-type='method'><a href="TorPool.html#remove_instance_from_group_by_name">remove_instance_from_group_by_name</a></li><li data-type='method'><a href="TorPool.html#set_config_all">set_config_all</a></li><li data-type='method'><a href="TorPool.html#set_config_at">set_config_at</a></li><li data-type='method'><a href="TorPool.html#set_config_by_group">set_config_by_group</a></li><li data-type='method'><a href="TorPool.html#set_config_by_name">set_config_by_name</a></li><li data-type='method'><a href="TorPool.html#signal_all">signal_all</a></li><li data-type='method'><a href="TorPool.html#signal_at">signal_at</a></li><li data-type='method'><a href="TorPool.html#signal_by_group">signal_by_group</a></li><li data-type='method'><a href="TorPool.html#signal_by_name">signal_by_name</a></li></ul></li><li><a href="TorProcess.html">TorProcess</a><ul class='methods'><li data-type='method'><a href="TorProcess.html#create">create</a></li><li data-type='method'><a href="TorProcess.html#exit">exit</a></li><li data-type='method'><a href="TorProcess.html#get_config">get_config</a></li><li data-type='method'><a href="TorProcess.html#new_identity">new_identity</a></li><li data-type='method'><a href="TorProcess.html#set_config">set_config</a></li><li data-type='method'><a href="TorProcess.html#signal">signal</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-tor-router.html">tor-router</a></li><li><a href="module-tor-router_ControlServer.html">tor-router/ControlServer</a></li><li><a href="module-tor-router_default_config.html">tor-router/default_config</a></li><li><a href="module-tor-router_default_ports.html">tor-router/default_ports</a></li><li><a href="module-tor-router_DNSServer.html">tor-router/DNSServer</a></li><li><a href="module-tor-router_HTTPServer.html">tor-router/HTTPServer</a></li><li><a href="module-tor-router_launch.html">tor-router/launch</a></li><li><a href="module-tor-router_nconf_load_env.html">tor-router/nconf_load_env</a></li><li><a href="module-tor-router_SOCKSServer.html">tor-router/SOCKSServer</a></li><li><a href="module-tor-router_TorPool.html">tor-router/TorPool</a></li><li><a href="module-tor-router_TorProcess.html">tor-router/TorProcess</a></li><li><a href="module-tor-router_winston_silent_logger.html">tor-router/winston_silent_logger</a></li></ul><h3>Events</h3><ul><li><a href="DNSServer.html#event:instance-connection">instance-connection</a></li><li><a href="HTTPServer.html#event:instance-connection">instance-connection</a></li><li><a href="SOCKSServer.html#event:instance-connection">instance-connection</a></li><li><a href="TorPool.html#event:instance_created">instance_created</a></li><li><a href="TorProcess.html#event:control_listen">control_listen</a></li><li><a href="TorProcess.html#event:controller_ready">controller_ready</a></li><li><a href="TorProcess.html#event:dns_listen">dns_listen</a></li><li><a href="TorProcess.html#event:error">error</a></li><li><a href="TorProcess.html#event:process_exit">process_exit</a></li><li><a href="TorProcess.html#event:ready">ready</a></li><li><a href="TorProcess.html#event:socks_listen">socks_listen</a></li></ul><h3>Global</h3><ul><li><a href="global.html#assembleHost">assembleHost</a></li><li><a href="global.html#cleanUp">cleanUp</a></li><li><a href="global.html#env_whitelist">env_whitelist</a></li><li><a href="global.html#logger">logger</a></li><li><a href="global.html#main">main</a></li><li><a href="global.html#nconf">nconf</a></li><li><a href="global.html#REALM">REALM</a></li><li><a href="global.html#setup_nconf_env">setup_nconf_env</a></li><li><a href="global.html#TOR_ROUTER_PROXY_AGENT">TOR_ROUTER_PROXY_AGENT</a></li></ul>
  23. </nav>
  24. <div id="main">
  25. <h1 class="page-title">ControlServer.js</h1>
  26. <section>
  27. <article>
  28. <pre class="prettyprint source linenums"><code>const { Server, WebSocketTransport, TCPTransport, JSONSerializer } = require("multi-rpc");
  29. const Promise = require('bluebird');
  30. const SOCKSServer = require('./SOCKSServer');
  31. const HTTPServer = require('./HTTPServer');
  32. const DNSServer = require('./DNSServer');
  33. const TorPool = require('./TorPool');
  34. const default_ports = require('./default_ports');
  35. /**
  36. * @typedef ControlServer~InstanceInfo
  37. *
  38. * @property {string} name - Name of the instance.
  39. * @property {string[]} group - Groups the instance belongs to.
  40. * @property {number} dns_port - Port Tor is listening on for DNS Traffic.
  41. * @property {number} socks_port - Port Tor is listening on for SOCKS Traffic.
  42. * @property {number} process_id - Process ID for the Tor process.
  43. * @property {Object} config - Configuration (torrc) set when starting the process.
  44. * @property {number} [weight] - Weight of the instance for weighted load balancing.
  45. */
  46. /**
  47. * A server which exposes an RPC interface that can control the application.
  48. */
  49. class ControlServer {
  50. /**
  51. *
  52. * @param {Provider} nconf - Instance of nconf.Provider that will be used to obtain configuration values.
  53. * @param {Logger} [logger] - Winston logger that will be used for logging. If not provided will disable logging.
  54. */
  55. constructor(nconf, logger) {
  56. /**
  57. * Pool of Tor instances
  58. *
  59. * @type {TorPool}
  60. */
  61. this.tor_pool = new TorPool(nconf.get('torPath'), (() => nconf.get('torConfig')), nconf.get('parentDataDirectory'), nconf.get('loadBalanceMethod'), nconf.get('granaxOptions'), logger);
  62. /**
  63. * Winston Logger for logging
  64. *
  65. * @type {Logger}
  66. */
  67. this.logger = logger || require('./winston_silent_logger');
  68. /**
  69. * Nconf Provider for configuration
  70. *
  71. * @type {Provider}
  72. */
  73. this.nconf = nconf;
  74. /**
  75. * RPC Server instance
  76. *
  77. * @type {Server}
  78. */
  79. let server = this.server = new Server();
  80. this.serializer = new JSONSerializer();
  81. this.server.methods.createTorPool = this.createTorPool.bind(this);
  82. this.server.methods.createSocksServer = this.createSOCKSServer.bind(this);
  83. this.server.methods.createDNSServer = this.createDNSServer.bind(this);
  84. this.server.methods.createHTTPServer = this.createHTTPServer.bind(this);
  85. /**
  86. * Returns a list of all instances currently in the pool.
  87. */
  88. this.server.methods.queryInstances = (() => {
  89. return this.tor_pool.instances.map(ControlServer.instance_info);
  90. }).bind(this);
  91. /**
  92. * Returns information on an instance identified by the {@link TorProcess#instance_name} field.
  93. */
  94. this.server.methods.queryInstanceByName = ((instance_name) => {
  95. let instance = this.tor_pool.instance_by_name(instance_name);
  96. if (!instance)
  97. throw new Error(`Instance "${instance_name}"" does not exist`);
  98. return ControlServer.instance_info(instance);
  99. }).bind(this);
  100. /**
  101. * Returns information on an instance identified by its index in the pool.
  102. */
  103. this.server.methods.queryInstanceAt = ((index) => {
  104. if (!this.tor_pool)
  105. throw new Error('No pool created');
  106. let instance = this.tor_pool.instance_at(index);
  107. if (!instance)
  108. throw new Error(`Instance at "${i}"" does not exist`);
  109. return ControlServer.instance_info(this.tor_pool.instance_at(index));
  110. }).bind(this);
  111. /**
  112. * Returns a list of the names of all of the instances in the pool.
  113. */
  114. this.server.methods.queryInstanceNames = (() => this.tor_pool.instance_names).bind(this);
  115. /**
  116. * Returns a list of the names of all of the current groups.
  117. */
  118. this.server.methods.queryGroupNames = (() => Array.from(this.tor_pool.group_names)).bind(this);
  119. /**
  120. * Returns a list of the instances that exist in a given group.
  121. */
  122. this.server.methods.queryInstancesByGroup = ((group) => this.tor_pool.instances_by_group(group).map(ControlServer.instance_info)).bind(this);
  123. /**
  124. * Creates instances from a number, an array of instance definitions or a single instance definition.
  125. * If a number is provided, creates n many instances.
  126. */
  127. this.server.methods.createInstances = (async (instances_to_create) => {
  128. let instances = await this.tor_pool.create(instances_to_create);
  129. return instances.map(ControlServer.instance_info);
  130. }).bind(this);
  131. /**
  132. * Creates instances from an array of instance definitions or a single instance definition.
  133. */
  134. this.server.methods.addInstances = (async (defs) => {
  135. let instances = await this.tor_pool.add(defs);
  136. return instances.map(ControlServer.instance_info);
  137. }).bind(this);
  138. /**
  139. * Removes a number of instances from the pool.
  140. */
  141. this.server.methods.removeInstances = this.tor_pool.remove.bind(this.tor_pool);
  142. /**
  143. * Remove an instance at the index provided from the pool.
  144. */
  145. this.server.methods.removeInstanceAt = this.tor_pool.remove_at.bind(this.tor_pool);
  146. /**
  147. * Remove an instance from the pool by the {@link TorProcess#instance_name} field.
  148. */
  149. this.server.methods.removeInstanceByName = this.tor_pool.remove_by_name.bind(this.tor_pool);
  150. /**
  151. * Gets new identities for all instances in the pool.
  152. */
  153. this.server.methods.newIdentites = this.tor_pool.new_identites.bind(this.tor_pool);
  154. /**
  155. * Get a new identity for the instance at the index provided in the pool.
  156. */
  157. this.server.methods.newIdentityAt = this.tor_pool.new_identity_at.bind(this.tor_pool);
  158. /**
  159. * Get a new identity for the instance by the {@link TorProcess#instance_name} field.
  160. */
  161. this.server.methods.newIdentityByName = this.tor_pool.new_identity_by_name.bind(this.tor_pool);
  162. /**
  163. * Gets new identities for all instances in the group.
  164. */
  165. this.server.methods.newIdentitiesByGroup = this.tor_pool.new_identites_by_group.bind(this.tor_pool);
  166. /**
  167. * Gets the next instance in the pool using the load balance method.
  168. */
  169. this.server.methods.nextInstance = (() => ControlServer.instance_info(this.tor_pool.next())).bind(this);
  170. /**
  171. * Gets the next instance in the group using the load balance method.
  172. */
  173. this.server.methods.nextInstanceByGroup = ((group) => {
  174. return ControlServer.instance_info(this.tor_pool.next_by_group(group));
  175. }).bind(this);
  176. /**
  177. * Kills the processes of all instances in the pool.
  178. */
  179. this.server.methods.closeInstances = this.tor_pool.exit.bind(this.tor_pool);
  180. /**
  181. * Sets a property in the application configuration.
  182. */
  183. this.server.methods.setConfig = ((key, value) => {
  184. this.nconf.set(key, value);
  185. }).bind(this);
  186. /**
  187. * Gets a property in the application configuration.
  188. */
  189. this.server.methods.getConfig = ((key) => {
  190. return this.nconf.get(key);
  191. }).bind(this);
  192. /**
  193. * Saves the application configuration to the underlying store (usually a JSON file).
  194. */
  195. this.server.methods.saveConfig = (async () => {
  196. await new Promise((resolve, reject) => {
  197. this.nconf.save((err) => {
  198. if (err) return reject(err);
  199. resolve();
  200. });
  201. });
  202. }).bind(this);
  203. /**
  204. * Loads the application configuration from the underlying store (usually a JSON file).
  205. */
  206. this.server.methods.loadConfig = (async () => {
  207. await new Promise((resolve, reject) => {
  208. this.nconf.load((err) => {
  209. if (err) return reject(err);
  210. resolve();
  211. });
  212. });
  213. }).bind(this);
  214. /**
  215. * Sets a configuration property on all instances in the pool.
  216. */
  217. this.server.methods.setTorConfig = (async (config) => {
  218. await Promise.all(Object.keys(config).map((key) => {
  219. let value = config[key];
  220. return this.tor_pool.set_config_all(key, value);
  221. }));
  222. }).bind(this);
  223. /**
  224. * Sets a configuration property on all instances in a group.
  225. */
  226. this.server.methods.setTorConfigByGroup = (async (group, config) => {
  227. await Promise.all(Object.keys(config).map((key) => {
  228. let value = config[key];
  229. return this.tor_pool.set_config_by_group(group, key, value);
  230. }));
  231. }).bind(this);
  232. /**
  233. * Retrieves the current load balance method for the pool
  234. */
  235. this.server.methods.getLoadBalanceMethod = (() => {
  236. return this.tor_pool.load_balance_method;
  237. }).bind(this);
  238. /**
  239. * Sets the current load balance method for the pool
  240. */
  241. this.server.methods.setLoadBalanceMethod = ((loadBalanceMethod) => {
  242. this.tor_pool.load_balance_method = loadBalanceMethod;
  243. this.nconf.set('loadBalanceMethod', loadBalanceMethod);
  244. }).bind(this);
  245. /**
  246. * Retrieve a configuration property for an instance identified by the {@link TorProcess#instance_name} field.
  247. */
  248. this.server.methods.getInstanceConfigByName = this.tor_pool.get_config_by_name.bind(this.tor_pool);
  249. /**
  250. * Retrieves a configuration property for an instance by its index in the pool.
  251. */
  252. this.server.methods.getInstanceConfigAt = this.tor_pool.get_config_at.bind(this.tor_pool);
  253. /**
  254. * Sets a configuration property for an instance identified by the {@link TorProcess#instance_name} field.
  255. */
  256. this.server.methods.setInstanceConfigByName = this.tor_pool.set_config_by_name.bind(this.tor_pool);
  257. /**
  258. * Sets a configuration property for an instance identified by its index in the pool.
  259. */
  260. this.server.methods.setInstanceConfigAt = this.tor_pool.set_config_at.bind(this.tor_pool);
  261. /**
  262. * Sends a signal to all instances in the pool
  263. */
  264. this.server.methods.signalAllInstances = this.tor_pool.signal_all.bind(this.tor_pool);
  265. /**
  266. * Sends a signal to an instance identified by its index in the pool.
  267. */
  268. this.server.methods.signalInstanceAt = this.tor_pool.signal_at.bind(this.tor_pool);
  269. /**
  270. * Sends a signal to an instance identified by the {@link TorProcess#instance_name} field.
  271. */
  272. this.server.methods.signalInstanceByName = this.tor_pool.signal_by_name.bind(this.tor_pool);
  273. /**
  274. * Sends a singal to all instances in a group.
  275. */
  276. this.server.methods.signalInstancesByGroup = this.tor_pool.signal_by_group.bind(this.tor_pool);
  277. /**
  278. * Adds an instance to a group identified by its {@link TorProcess#instance_name} field.
  279. */
  280. this.server.methods.addInstanceToGroupByName = this.tor_pool.add_instance_to_group_by_name.bind(this.tor_pool);
  281. /**
  282. * Adds an instance to a group identified by its index in the pool.
  283. */
  284. this.server.methods.addInstanceToGroupAt = this.tor_pool.add_instance_to_group_at.bind(this.tor_pool);
  285. /**
  286. * Removes an instance from a group identified by its {@link TorProcess#instance_name} field.
  287. */
  288. this.server.methods.removeInstanceFromGroupByName = this.tor_pool.remove_instance_from_group_by_name.bind(this.tor_pool);
  289. /**
  290. * Remove an instance from a group identified by its index in the pool.
  291. */
  292. this.server.methods.removeInstanceFromGroupAt = this.tor_pool.remove_instance_from_group_at .bind(this.tor_pool);
  293. }
  294. /**
  295. * Returns a summary of information on the running instance
  296. * @param {TorProcess} instance
  297. * @static
  298. * @returns {ControlServer~InstanceInfo}
  299. */
  300. static instance_info(instance) {
  301. return {
  302. name: instance.instance_name,
  303. group: instance.instance_group,
  304. dns_port: instance.dns_port,
  305. socks_port: instance.socks_port,
  306. process_id: instance.process.pid,
  307. config: instance.definition.Config,
  308. weight: instance.definition.weight
  309. };
  310. }
  311. /**
  312. * Binds the server to a host and port and begins listening for TCP traffic
  313. * @param {number} port - Port the server should bind to
  314. * @param {string} [hostname] - Host the server should bind to
  315. * @async
  316. * @returns {Promise}
  317. */
  318. async listenTcp(port, hostname) {
  319. this.tcpTransport = new TCPTransport(this.serializer, port, hostname);
  320. this.server.addTransport(this.tcpTransport);
  321. this.logger.info(`[control]: control server listening on tcp://${hostname}:${port}`);
  322. await this.tcpTransport.listen();
  323. }
  324. /**
  325. * Binds the server to a host and port and begins listening for WebSocket traffic
  326. * @param {number} port - Port the server should bind to
  327. * @param {string} [hostname] - Host the server should bind to
  328. * @async
  329. * @returns {Promise}
  330. */
  331. async listenWs(port, hostname) {
  332. this.wsTransport = new WebSocketTransport(this.serializer, port, hostname);
  333. this.server.addTransport(this.wsTransport);
  334. this.logger.info(`[control]: control server listening on ws://${hostname}:${port}`);
  335. await this.wsTransport.listen();
  336. }
  337. /**
  338. * Calls {@link ControlServer#listenTcp} with the same arguments
  339. * @param {number} port - Port the server should bind to
  340. * @param {string} [hostname] - Host the server should bind to
  341. * @async
  342. * @returns {Promise}
  343. */
  344. async listen(port, hostname) { return await this.listenTcp(port, hostname); }
  345. /**
  346. * Closes the TCP and/or WebSocket servers
  347. */
  348. close() {
  349. this.server.close();
  350. }
  351. /**
  352. * Creates a new {@link TorPool} instance
  353. * @param {Object} [tor_config] - Default Tor config to be used for the pool of instances.
  354. * @param {string} [load_balance_method] - Load balance method to be used for the pool. Will default to the global configuration if not provided.
  355. *
  356. * @returns {TorPool} - The {@link TorPool} that was created.
  357. */
  358. createTorPool(tor_config, load_balance_method) {
  359. this.tor_pool = new TorPool(this.nconf.get('torPath'), tor_config, this.nconf.get('parentDataDirectory'), (load_balance_method || this.nconf.get('loadBalanceMethod')), this.nconf.get('granaxOptions'), this.logger);
  360. return this.tor_pool;
  361. }
  362. /**
  363. * Creates an instance of {@link SOCKSServer} and begins listening for traffic
  364. * @param {number} port - Port the server should bind to
  365. * @param {string} [hostname] - Host the server should bind to
  366. * @async
  367. * @returns {Promise}
  368. */
  369. async createSOCKSServer(port, hostname) {
  370. this.socksServer = new SOCKSServer(this.tor_pool, this.logger, (this.nconf.get('proxyByName') ? { mode: this.nconf.get('proxyByName'), deny_unidentified_users: this.nconf.get('denyUnidentifiedUsers') } : ""));
  371. await this.socksServer.listen(port || default_ports.socks, hostname);
  372. this.logger.info(`[socks]: listening on socks5://${hostname}:${port}`);
  373. }
  374. /**
  375. * Creates an instance of {@link HTTPServer} and begins listening for traffic
  376. * @param {number} port - Port the server should bind to
  377. * @param {string} [hostname] - Host the server should bind to
  378. * @async
  379. * @returns {Promise}
  380. */
  381. async createHTTPServer(port, hostname) {
  382. this.httpServer = new HTTPServer(this.tor_pool, this.logger, (this.nconf.get('proxyByName') ? { mode: this.nconf.get('proxyByName'), deny_unidentified_users: this.nconf.get('denyUnidentifiedUsers') } : ""));
  383. await this.httpServer.listen(port || default_ports.http, hostname);
  384. this.logger.info(`[http]: listening on http://${hostname}:${port}`);
  385. }
  386. /**
  387. * Creates an instance of {@link DNSServer} and begins listening for traffic
  388. * @param {number} port - Port the server should bind to
  389. * @param {string} [hostname] - Host the server should bind to
  390. * @async
  391. * @returns {Promise}
  392. */
  393. async createDNSServer(port, hostname) {
  394. this.dnsServer = new DNSServer(this.tor_pool, this.nconf.get('dns:options'), this.nconf.get('dns:timeout'), this.logger);
  395. await this.dnsServer.serve(port || default_ports.dns, hostname);
  396. this.logger.info(`[dns]: listening on dns://${hostname}:${port}`);
  397. }
  398. };
  399. /**
  400. * Module that contains the {@link ControlServer} class.
  401. * @module tor-router/ControlServer
  402. * @see ControlServer
  403. */
  404. module.exports = ControlServer;
  405. </code></pre>
  406. </article>
  407. </section>
  408. </div>
  409. <br class="clear">
  410. <footer>
  411. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Sep 25 2018 12:53:23 GMT-0400 (Eastern Daylight Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
  412. </footer>
  413. <script>prettyPrint();</script>
  414. <script src="scripts/linenumber.js"></script>
  415. </body>
  416. </html>