Skip to content

Instantly share code, notes, and snippets.

@mattcollier
Created March 24, 2015 13:33
Show Gist options
  • Save mattcollier/5703ae124c2bc14653ab to your computer and use it in GitHub Desktop.
Save mattcollier/5703ae124c2bc14653ab to your computer and use it in GitHub Desktop.
signalReload can't be called immediately after createHiddenService/saveConfig
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