| 
									
										
										
										
											2017-04-26 20:16:47 -06:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-09 12:40:39 -06:00
										 |  |  | var config; | 
					
						
							| 
									
										
										
										
											2017-10-10 11:08:19 -06:00
										 |  |  | var modules; | 
					
						
							| 
									
										
										
										
											2017-06-09 12:40:39 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Everything that uses the config should be reading it when relevant rather than
 | 
					
						
							|  |  |  | // just at the beginning, so we keep the reference for the main object and just
 | 
					
						
							|  |  |  | // change all of its properties to match the new config.
 | 
					
						
							|  |  |  | function update(conf) { | 
					
						
							|  |  |  |   var newKeys = Object.keys(conf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Object.keys(config).forEach(function (key) { | 
					
						
							|  |  |  |     if (newKeys.indexOf(key) < 0) { | 
					
						
							|  |  |  |       delete config[key]; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       config[key] = conf[key]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2017-10-10 11:08:19 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   console.log('config update', JSON.stringify(config)); | 
					
						
							|  |  |  |   Object.values(modules).forEach(function (mod) { | 
					
						
							|  |  |  |     if (typeof mod.updateConf === 'function') { | 
					
						
							|  |  |  |       mod.updateConf(config); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2017-06-09 12:40:39 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function create(conf) { | 
					
						
							| 
									
										
										
										
											2017-09-25 18:06:48 -06:00
										 |  |  |   var PromiseA = require('bluebird'); | 
					
						
							|  |  |  |   var OAUTH3 = require('../packages/assets/org.oauth3'); | 
					
						
							|  |  |  |   require('../packages/assets/org.oauth3/oauth3.domains.js'); | 
					
						
							|  |  |  |   require('../packages/assets/org.oauth3/oauth3.dns.js'); | 
					
						
							|  |  |  |   require('../packages/assets/org.oauth3/oauth3.tunnel.js'); | 
					
						
							|  |  |  |   OAUTH3._hooks = require('../packages/assets/org.oauth3/oauth3.node.storage.js'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-09 12:40:39 -06:00
										 |  |  |   config = conf; | 
					
						
							| 
									
										
										
										
											2017-04-26 20:16:47 -06:00
										 |  |  |   var deps = { | 
					
						
							|  |  |  |     messenger: process | 
					
						
							| 
									
										
										
										
											2017-09-25 18:06:48 -06:00
										 |  |  |   , PromiseA: PromiseA | 
					
						
							|  |  |  |   , OAUTH3: OAUTH3 | 
					
						
							|  |  |  |   , request: PromiseA.promisify(require('request')) | 
					
						
							|  |  |  |   , recase: require('recase').create({}) | 
					
						
							| 
									
										
										
										
											2017-05-10 16:05:54 -06:00
										 |  |  |     // Note that if a custom createConnections is used it will be called with different
 | 
					
						
							|  |  |  |     // sets of custom options based on what is actually being proxied. Most notably the
 | 
					
						
							|  |  |  |     // HTTP proxying connection creation is not something we currently control.
 | 
					
						
							| 
									
										
										
										
											2017-04-27 16:05:34 -06:00
										 |  |  |   , net: require('net') | 
					
						
							| 
									
										
										
										
											2017-04-26 20:16:47 -06:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2017-10-10 11:08:19 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   modules = { | 
					
						
							|  |  |  |     storage:  require('./storage').create(deps, conf) | 
					
						
							|  |  |  |   , socks5:   require('./socks5-server').create(deps, conf) | 
					
						
							|  |  |  |   , ddns:     require('./ddns').create(deps, conf) | 
					
						
							| 
									
										
										
										
											2017-10-27 12:56:09 -06:00
										 |  |  |   , mdns:     require('./mdns').create(deps, conf) | 
					
						
							| 
									
										
										
										
											2017-10-26 16:27:10 -06:00
										 |  |  |   , udp:      require('./udp').create(deps, conf) | 
					
						
							| 
									
										
										
										
											2017-10-30 15:57:18 -06:00
										 |  |  |   , tcp:      require('./tcp').create(deps, conf) | 
					
						
							| 
									
										
										
										
											2017-10-31 15:39:24 -06:00
										 |  |  |   , stunneld: require('./tunnel-server-manager').create(deps, config) | 
					
						
							| 
									
										
										
										
											2017-10-10 11:08:19 -06:00
										 |  |  |   }; | 
					
						
							|  |  |  |   Object.assign(deps, modules); | 
					
						
							| 
									
										
										
										
											2017-05-17 14:06:24 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-09 12:40:39 -06:00
										 |  |  |   process.removeListener('message', create); | 
					
						
							|  |  |  |   process.on('message', update); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | process.on('message', create); |