p2p/gossiper.js
function _gossiperStartWithOptions( oOptions )
{
	//
	//	create Gossiper instance
	//
	_oGossiper	= new Gossiper( oOptions );

	//
	//	listen ...
	//
	_oGossiper.on( 'peer_update', ( sPeerUrl, sKey, vValue ) =>
	{
		// console.log( `GOSSIPER ))) EVENT [peer_update] (${ GossiperUtils.isReservedKey( sKey ) ? "Reserved" : "Customized" }):: `, sPeerUrl, sKey, vValue );

		//
		//	callback while we received a update from remote peers
		//
		if ( ! GossiperUtils.isReservedKey( sKey ) )
		{
			_oGossiperOptions.pfnPeerUpdate( sPeerUrl, sKey, vValue );
		}
	});
	_oGossiper.on( 'peer_alive', ( sPeerUrl ) =>
	{
		// console.log( `GOSSIPER ))) EVENT [peer_alive] :: `, sPeerUrl );
	});
	_oGossiper.on( 'peer_failed', ( sPeerUrl ) =>
	{
		console.error( `GOSSIPER ))) EVENT [peer_failed] :: `, sPeerUrl );
	});
	_oGossiper.on( 'new_peer', ( sPeerUrl ) =>
	{
		// console.log( `GOSSIPER ))) EVENT [new_peer] :: `, sPeerUrl );
		if ( sPeerUrl !== _oGossiperOptions.url &&
			! _oGossiper.m_oRouter.getSocket( sPeerUrl ) )
		{
			//
			//	try to connect to the new peer
			//
			_oGossiperOptions.pfnConnectToPeer( sPeerUrl, ( err, oNewWs ) =>
			{
				if ( err )
				{
					return console.error( `GOSSIPER ))) failed to connectToPeer: ${ sPeerUrl }.` );
				}
				if ( ! oNewWs )
				{
					return console.error( `GOSSIPER ))) connectToPeer returns an invalid oNewWs: ${ JSON.stringify( oNewWs ) }.` );
				}

				//
				//	update the remote socket
				//
				if ( ! DeUtilsCore.isPlainObjectWithKeys( oNewWs, 'url' ) ||
					! GossiperUtils.isValidPeerUrl( oNewWs.url ) )
				{
					oNewWs.url	= sPeerUrl;
				}

				//
				//	update router
				//
				_oGossiper.updatePeerList({
					[ sPeerUrl ] : oNewWs
				});
			});
		}
	});
	_oGossiper.on( 'log', ( sType, vData ) =>
	{
		// console.log( `GOSSIPER ))) EVENT [log/${ sType }] :: `, vData );
	});


	//
	//	start gossiper
	//
	_oGossiper.start( {} );
}
function _gossiperStartWithOptions( oOptions )
{
	//
	//	create Gossiper instance
	//
	_oGossiper	= new Gossiper( oOptions );

	//
	//	listen ...
	//
	_oGossiper.on( 'peer_update', ( sPeerUrl, sKey, vValue ) =>
	{
		// console.log( `GOSSIPER ))) EVENT [peer_update] (${ GossiperUtils.isReservedKey( sKey ) ? "Reserved" : "Customized" }):: `, sPeerUrl, sKey, vValue );

		//
		//	callback while we received a update from remote peers
		//
		if ( ! GossiperUtils.isReservedKey( sKey ) )
		{
			_oGossiperOptions.pfnPeerUpdate( sPeerUrl, sKey, vValue );
		}
	});
	_oGossiper.on( 'peer_alive', ( sPeerUrl ) =>
	{
		// console.log( `GOSSIPER ))) EVENT [peer_alive] :: `, sPeerUrl );
	});
	_oGossiper.on( 'peer_failed', ( sPeerUrl ) =>
	{
		console.error( `GOSSIPER ))) EVENT [peer_failed] :: `, sPeerUrl );
	});
	_oGossiper.on( 'new_peer', ( sPeerUrl ) =>
	{
		// console.log( `GOSSIPER ))) EVENT [new_peer] :: `, sPeerUrl );
		if ( sPeerUrl !== _oGossiperOptions.url &&
			! _oGossiper.m_oRouter.getSocket( sPeerUrl ) )
		{
			//
			//	try to connect to the new peer
			//
			_oGossiperOptions.pfnConnectToPeer( sPeerUrl, ( err, oNewWs ) =>
			{
				if ( err )
				{
					return console.error( `GOSSIPER ))) failed to connectToPeer: ${ sPeerUrl }.` );
				}
				if ( ! oNewWs )
				{
					return console.error( `GOSSIPER ))) connectToPeer returns an invalid oNewWs: ${ JSON.stringify( oNewWs ) }.` );
				}

				//
				//	update the remote socket
				//
				if ( ! DeUtilsCore.isPlainObjectWithKeys( oNewWs, 'url' ) ||
					! GossiperUtils.isValidPeerUrl( oNewWs.url ) )
				{
					oNewWs.url	= sPeerUrl;
				}

				//
				//	update router
				//
				_oGossiper.updatePeerList({
					[ sPeerUrl ] : oNewWs
				});
			});
		}
	});
	_oGossiper.on( 'log', ( sType, vData ) =>
	{
		// console.log( `GOSSIPER ))) EVENT [log/${ sType }] :: `, vData );
	});


	//
	//	start gossiper
	//
	_oGossiper.start( {} );
}
function _gossiperStartWithOptions ( oOptions ) { // //	create Gossiper instance // _oGossiper = new Gossiper ( oOptions ) ; // //	listen ... // _oGossiper . on ( 'peer_update' , ( sPeerUrl , sKey , vValue ) => { // console.log( `GOSSIPER ))) EVENT [peer_update] (${ GossiperUtils.isReservedKey( sKey ) ? "Reserved" : "Customized" }):: `, sPeerUrl, sKey, vValue ); // //	callback while we received a update from remote peers // if ( ! GossiperUtils . isReservedKey ( sKey ) ) { _oGossiperOptions . pfnPeerUpdate ( sPeerUrl , sKey , vValue ) ; } } ) ; _oGossiper . on ( 'peer_alive' , ( sPeerUrl ) => { // console.log( `GOSSIPER ))) EVENT [peer_alive] :: `, sPeerUrl ); } ) ; _oGossiper . on ( 'peer_failed' , ( sPeerUrl ) => { console . error ( ` ` , sPeerUrl ) ; } ) ; _oGossiper . on ( 'new_peer' , ( sPeerUrl ) => { // console.log( `GOSSIPER ))) EVENT [new_peer] :: `, sPeerUrl ); if ( sPeerUrl !== _oGossiperOptions . url && ! _oGossiper . m_oRouter . getSocket ( sPeerUrl ) ) { // //	try to connect to the new peer // _oGossiperOptions . pfnConnectToPeer ( sPeerUrl , ( err , oNewWs ) => { if ( err ) { return console . error ( ` ${ sPeerUrl } ` ) ; } if ( ! oNewWs ) { return console . error ( ` ${ JSON . stringify ( oNewWs ) } ` ) ; } // //	update the remote socket // if ( ! DeUtilsCore . isPlainObjectWithKeys ( oNewWs , 'url' ) || ! GossiperUtils . isValidPeerUrl ( oNewWs . url ) ) { oNewWs . url = sPeerUrl ; } // //	update router // _oGossiper . updatePeerList ( { [ sPeerUrl ] : oNewWs } ) ; } ) ; } } ) ; _oGossiper . on ( 'log' , ( sType , vData ) => { // console.log( `GOSSIPER ))) EVENT [log/${ sType }] :: `, vData ); } ) ; // //	start gossiper // _oGossiper . start ( { } ) ; }
start gossiper with options

@param	{object}	oOptions
@private
start gossiper with options