src/MasterElector.js
function _onInboxMessage (sender, _, msgBuffer) {
    let message = JSON.parse(msgBuffer)
    masterBroker.setIP(message.toAddress)

    switch (message.type) {
      case 'voteRequest':
        debug(`sending vote to ${node.name === message.from ? 'myself' : message.from}`)
        _inbox.send([sender, _, JSON.stringify({
          id: _advertiseId || node.id,
          name: node.name,
          endpoints: masterBroker.endpoints,
          isMaster: masterBroker.isMaster,
          candidate: !_advertiseId
        })])
        break
      case 'masterRequest':
        let connectedMaster = node.master
        if (connectedMaster) {
          debug(`sending master coordinates to ${message.from}`)
          _inbox.send([sender, _, JSON.stringify(connectedMaster)])
        } else {
          debug(`unable to send master coordinates to ${message.from}`)
          _inbox.send([sender, _, JSON.stringify(false)])
        }
        break
      case 'masterElected':
        _inbox.send([sender, _, ''])
        debug(`received notice of master election: ${message.data.name}`)
        resolver.emit('newmaster', message.data)
    }
  }
function _onInboxMessage (sender, _, msgBuffer) {
    let message = JSON.parse(msgBuffer)
    masterBroker.setIP(message.toAddress)

    switch (message.type) {
      case 'voteRequest':
        debug(`sending vote to ${node.name === message.from ? 'myself' : message.from}`)
        _inbox.send([sender, _, JSON.stringify({
          id: _advertiseId || node.id,
          name: node.name,
          endpoints: masterBroker.endpoints,
          isMaster: masterBroker.isMaster,
          candidate: !_advertiseId
        })])
        break
      case 'masterRequest':
        let connectedMaster = node.master
        if (connectedMaster) {
          debug(`sending master coordinates to ${message.from}`)
          _inbox.send([sender, _, JSON.stringify(connectedMaster)])
        } else {
          debug(`unable to send master coordinates to ${message.from}`)
          _inbox.send([sender, _, JSON.stringify(false)])
        }
        break
      case 'masterElected':
        _inbox.send([sender, _, ''])
        debug(`received notice of master election: ${message.data.name}`)
        resolver.emit('newmaster', message.data)
    }
  }
function _onInboxMessage ( sender , _ , msgBuffer ) { let message = JSON . parse ( msgBuffer ) masterBroker . setIP ( message . toAddress ) switch ( message . type ) { case 'voteRequest' : debug ( ` ${ node . name === message . from ? 'myself' : message . from } ` ) _inbox . send ( [ sender , _ , JSON . stringify ( { id : _advertiseId || node . id , name : node . name , endpoints : masterBroker . endpoints , isMaster : masterBroker . isMaster , candidate : ! _advertiseId } ) ] ) break case 'masterRequest' : let connectedMaster = node . master if ( connectedMaster ) { debug ( ` ${ message . from } ` ) _inbox . send ( [ sender , _ , JSON . stringify ( connectedMaster ) ] ) } else { debug ( ` ${ message . from } ` ) _inbox . send ( [ sender , _ , JSON . stringify ( false ) ] ) } break case 'masterElected' : _inbox . send ( [ sender , _ , '' ] ) debug ( ` ${ message . data . name } ` ) resolver . emit ( 'newmaster' , message . data ) } }
function receiving the messages from the coordination router
@param  {buffer} sender
@param  {void} _
@param  {buffer} msgBuffer
function receiving the messages from the coordination router