lib/msgServer/mmrp/index.js
function MmrpNode(role, cfg) {
	EventEmitter.call(this);

	this.isRelay = (role === 'relay' || role === 'both');
	this.isClient = (role === 'client' || role === 'both');

	assert(this.isRelay || this.isClient, 'MmrpNode must be relay, client or both');

	// keeping track of who we're connected to

	this.relays = {};   // my peers, master-relay or both { identity: RelayConnection }
	this.clients = {};  // my clients { identity: ClientConnection }

	// router

	this.routerPort = null;
	this.router = null;

	if (this.isRelay) {
		this.router = createRouter(cfg);
		var routerUri = this.router.getsockopt(zmq.ZMQ_LAST_ENDPOINT);

		if (routerUri) {
			this.routerPort = parseInt(routerUri.substr(routerUri.lastIndexOf(':') + 1), 10);

			// Share MMRP master port through the environment
			process.env[ENV_MAGE_MMRP_MASTER_PORT] = this.routerPort;

			// Generate the cluster ID based on the port the master listens on
			this.clusterId = serviceDiscovery.helpers.generateId(this.routerPort);

			// Set the identity of the router socket to the cluster ID
			this.router.setsockopt(zmq.ZMQ_IDENTITY, new Buffer(this.clusterId));
		}
	} else {
		// Retrieve the cluster ID from the environment
		const masterPort = parseInt(process.env[ENV_MAGE_MMRP_MASTER_PORT], 10);

		// Generate the cluster ID based on the port the master listens on
		this.clusterId = serviceDiscovery.helpers.generateId(masterPort);
	}

	// dealer

	this.identity = this.isRelay ? this.clusterId : createDealerIdentity(this.clusterId);
	this.dealer = createDealer(this.identity);
	assert.equal(this.identity, this.dealer.getsockopt(zmq.ZMQ_IDENTITY));

	// mmrp socket event handling

	this._setupSocketEventHandling();

	// mmrp internal message handling

	this.on('delivery.mmrp.handshake', this._handleHandshake);
}
function MmrpNode(role, cfg) {
	EventEmitter.call(this);

	this.isRelay = (role === 'relay' || role === 'both');
	this.isClient = (role === 'client' || role === 'both');

	assert(this.isRelay || this.isClient, 'MmrpNode must be relay, client or both');

	// keeping track of who we're connected to

	this.relays = {};   // my peers, master-relay or both { identity: RelayConnection }
	this.clients = {};  // my clients { identity: ClientConnection }

	// router

	this.routerPort = null;
	this.router = null;

	if (this.isRelay) {
		this.router = createRouter(cfg);
		var routerUri = this.router.getsockopt(zmq.ZMQ_LAST_ENDPOINT);

		if (routerUri) {
			this.routerPort = parseInt(routerUri.substr(routerUri.lastIndexOf(':') + 1), 10);

			// Share MMRP master port through the environment
			process.env[ENV_MAGE_MMRP_MASTER_PORT] = this.routerPort;

			// Generate the cluster ID based on the port the master listens on
			this.clusterId = serviceDiscovery.helpers.generateId(this.routerPort);

			// Set the identity of the router socket to the cluster ID
			this.router.setsockopt(zmq.ZMQ_IDENTITY, new Buffer(this.clusterId));
		}
	} else {
		// Retrieve the cluster ID from the environment
		const masterPort = parseInt(process.env[ENV_MAGE_MMRP_MASTER_PORT], 10);

		// Generate the cluster ID based on the port the master listens on
		this.clusterId = serviceDiscovery.helpers.generateId(masterPort);
	}

	// dealer

	this.identity = this.isRelay ? this.clusterId : createDealerIdentity(this.clusterId);
	this.dealer = createDealer(this.identity);
	assert.equal(this.identity, this.dealer.getsockopt(zmq.ZMQ_IDENTITY));

	// mmrp socket event handling

	this._setupSocketEventHandling();

	// mmrp internal message handling

	this.on('delivery.mmrp.handshake', this._handleHandshake);
}
function MmrpNode ( role , cfg ) { EventEmitter . call ( this ) ; this . isRelay = ( role === 'relay' || role === 'both' ) ; this . isClient = ( role === 'client' || role === 'both' ) ; assert ( this . isRelay || this . isClient , 'MmrpNode must be relay, client or both' ) ; // keeping track of who we're connected to this . relays = { } ; // my peers, master-relay or both { identity: RelayConnection } this . clients = { } ; // my clients { identity: ClientConnection } // router this . routerPort = null ; this . router = null ; if ( this . isRelay ) { this . router = createRouter ( cfg ) ; var routerUri = this . router . getsockopt ( zmq . ZMQ_LAST_ENDPOINT ) ; if ( routerUri ) { this . routerPort = parseInt ( routerUri . substr ( routerUri . lastIndexOf ( ':' ) + 1 ) , 10 ) ; // Share MMRP master port through the environment process . env [ ENV_MAGE_MMRP_MASTER_PORT ] = this . routerPort ; // Generate the cluster ID based on the port the master listens on this . clusterId = serviceDiscovery . helpers . generateId ( this . routerPort ) ; // Set the identity of the router socket to the cluster ID this . router . setsockopt ( zmq . ZMQ_IDENTITY , new Buffer ( this . clusterId ) ) ; } } else { // Retrieve the cluster ID from the environment const masterPort = parseInt ( process . env [ ENV_MAGE_MMRP_MASTER_PORT ] , 10 ) ; // Generate the cluster ID based on the port the master listens on this . clusterId = serviceDiscovery . helpers . generateId ( masterPort ) ; } // dealer this . identity = this . isRelay ? this . clusterId : createDealerIdentity ( this . clusterId ) ; this . dealer = createDealer ( this . identity ) ; assert . equal ( this . identity , this . dealer . getsockopt ( zmq . ZMQ_IDENTITY ) ) ; // mmrp socket event handling this . _setupSocketEventHandling ( ) ; // mmrp internal message handling this . on ( 'delivery.mmrp.handshake' , this . _handleHandshake ) ; }
Instantiates an MmrpNode that represents a client, relay or both in a bigger MMRP network.

@param {string} role
@param {Object} cfg
@param {string} clusterId
@constructor
Instantiates an MmrpNode that represents a client relay or both in a bigger MMRP network .