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