mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
set multicast advertised port in examples/http.js
This commit is contained in:
parent
ad079ad49b
commit
058bd3cae9
@ -1,21 +1,22 @@
|
||||
;(function(){
|
||||
var cluster = require('cluster');
|
||||
if(cluster.isMaster){
|
||||
return cluster.fork() && cluster.on('exit', function(){ cluster.fork() });
|
||||
}
|
||||
|
||||
var fs = require('fs');
|
||||
var config = { port: process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765 };
|
||||
var Gun = require('../'); // require('gun')
|
||||
|
||||
if(process.env.HTTPS_KEY){
|
||||
config.key = fs.readFileSync(process.env.HTTPS_KEY);
|
||||
config.cert = fs.readFileSync(process.env.HTTPS_CERT);
|
||||
config.server = require('https').createServer(config, Gun.serve(__dirname));
|
||||
} else {
|
||||
config.server = require('http').createServer(Gun.serve(__dirname));
|
||||
}
|
||||
|
||||
var gun = Gun({web: config.server.listen(config.port) });
|
||||
console.log('Relay peer started on port ' + config.port + ' with /gun');
|
||||
}());
|
||||
;(function(){
|
||||
var cluster = require('cluster');
|
||||
if(cluster.isMaster){
|
||||
return cluster.fork() && cluster.on('exit', function(){ cluster.fork() });
|
||||
}
|
||||
|
||||
var fs = require('fs');
|
||||
var config = { port: process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765 };
|
||||
var Gun = require('../'); // require('gun')
|
||||
|
||||
if(process.env.HTTPS_KEY){
|
||||
config.key = fs.readFileSync(process.env.HTTPS_KEY);
|
||||
config.cert = fs.readFileSync(process.env.HTTPS_CERT);
|
||||
config.server = require('https').createServer(config, Gun.serve(__dirname));
|
||||
} else {
|
||||
config.server = require('http').createServer(Gun.serve(__dirname));
|
||||
}
|
||||
|
||||
require('../lib/multicast');
|
||||
var gun = Gun({web: config.server.listen(config.port), multicast: { port: 8765 } });
|
||||
console.log('Relay peer started on port ' + config.port + ' with /gun');
|
||||
}());
|
||||
|
@ -10,7 +10,9 @@ Gun.on('create', function(root){
|
||||
opt.multicast = opt.multicast || {};
|
||||
|
||||
var MULTICAST_ADDR = "233.255.255.255";
|
||||
var MULTICAST_INTERVAL = 1000;
|
||||
var PORT = 20000;
|
||||
var DEFAULT_GUN_PORT = 8765;
|
||||
var ENC = 'utf8';
|
||||
|
||||
var dgram = require("dgram");
|
||||
@ -24,7 +26,8 @@ Gun.on('create', function(root){
|
||||
socket.on("listening", function() {
|
||||
socket.addMembership(MULTICAST_ADDR);
|
||||
if (opt.multicast && opt.multicast.port) { // if port is specified, advertise our node
|
||||
setInterval(sendMessage, 1000);
|
||||
console.log(`Advertising this node (port ${opt.multicast.port}) on multicast (${MULTICAST_ADDR})`);
|
||||
setInterval(sendMessage, MULTICAST_INTERVAL);
|
||||
}
|
||||
address = socket.address();
|
||||
});
|
||||
@ -33,7 +36,7 @@ Gun.on('create', function(root){
|
||||
var msgObj = {
|
||||
gun: {
|
||||
version: Gun.version,
|
||||
port: opt.multicast.port || 8765
|
||||
port: opt.multicast.port || DEFAULT_GUN_PORT
|
||||
}
|
||||
};
|
||||
var message = Buffer.from(JSON.stringify(msgObj), ENC);
|
||||
|
@ -18,4 +18,4 @@
|
||||
require('./evict');
|
||||
if('debug' === process.env.GUN_ENV){ require('./debug') }
|
||||
module.exports = Gun;
|
||||
}());
|
||||
}());
|
||||
|
Loading…
x
Reference in New Issue
Block a user