Created
March 24, 2015 13:33
-
-
Save mattcollier/5703ae124c2bc14653ab to your computer and use it in GitHub Desktop.
signalReload can't be called immediately after createHiddenService/saveConfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var dataDir = __dirname + '/demo-data'; | |
rmDir = function(dirPath) { | |
console.log('Removing:', dirPath); | |
try { var files = fs.readdirSync(dirPath); } | |
catch(e) { console.log(e); return; } | |
if (files.length > 0) | |
for (var i = 0; i < files.length; i++) { | |
var filePath = dirPath + '/' + files[i]; | |
if (fs.statSync(filePath).isFile()) | |
fs.unlinkSync(filePath); | |
else | |
rmDir(filePath); | |
} | |
fs.rmdirSync(dirPath); | |
}; | |
// Wipe all data | |
var wipeStat = rmDir(dataDir); | |
// myDelay = 0, getOnionAddress fails. myDelay > 5 works. | |
var myDelay = 5; | |
var thsBuilder = require('ths'); | |
var ths = new thsBuilder(dataDir); | |
console.log('attempting to start now'); | |
ths.start(false, function() { | |
console.log('ths has started'); | |
var serviceList = ths.getServices(); | |
console.log('Service List: %j',serviceList); | |
function noxiousExists(element) { | |
return element.name=='noxious'; | |
} | |
noxiousProperties=serviceList.filter(noxiousExists); | |
if (noxiousProperties==0) { | |
// does not exist, create it | |
console.log('Creating new noxious service'); | |
ths.createHiddenService('noxious','1111'); | |
ths.saveConfig(); | |
var myDelegate = function() { | |
ths.signalReload(); | |
} | |
var myVar = setTimeout(myDelegate, myDelay); | |
} | |
ths.getOnionAddress('noxious', function(err, onionAddress) { | |
if(err) { | |
console.error('[getOnionAddress] Error while reading hostname file: ' + err); | |
} | |
else { | |
console.log('[getOnionAddress] Onion Address is: ', onionAddress); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment