network.js
function handlePostedJoint(ws, objJoint, onDone){
	
	if (!objJoint || !objJoint.unit || !objJoint.unit.unit)
		return onDone('no unit');
	
	var unit = objJoint.unit.unit;
	delete objJoint.unit.main_chain_index;
	
	handleJoint(ws, objJoint, false, {
		ifUnitInWork: function(){
			onDone("already handling this unit");
		},
		ifUnitError: function(error){
			onDone(error);
		},
		ifJointError: function(error){
			onDone(error);
		},
		ifNeedHashTree: function(){
			onDone("need hash tree");
		},
		ifNeedParentUnits: function(arrMissingUnits){
			onDone("unknown parents");
		},
		ifOk: function(){
			onDone();
			
			// forward to other peers
			if (!bCatchingUp && !conf.bLight)
				forwardJoint(ws, objJoint);

			delete assocUnitsInWork[unit];
		},
		ifOkUnsigned: function(){
			delete assocUnitsInWork[unit];
			onDone("you can't send unsigned units");
		},
		ifKnown: function(){
			if (objJoint.unsigned)
				return onDone("you can't send unsigned units");
			onDone("known");
			writeEvent('known_good', ws.host);
		},
		ifKnownBad: function(){
			onDone("known bad");
			writeEvent('known_bad', ws.host);
		},
		ifKnownUnverified: function(){ // impossible unless the peer also sends this joint by 'joint' justsaying
			onDone("known unverified");
			delete assocUnitsInWork[unit];
		}
	});
}
function handlePostedJoint(ws, objJoint, onDone){
	
	if (!objJoint || !objJoint.unit || !objJoint.unit.unit)
		return onDone('no unit');
	
	var unit = objJoint.unit.unit;
	delete objJoint.unit.main_chain_index;
	
	handleJoint(ws, objJoint, false, {
		ifUnitInWork: function(){
			onDone("already handling this unit");
		},
		ifUnitError: function(error){
			onDone(error);
		},
		ifJointError: function(error){
			onDone(error);
		},
		ifNeedHashTree: function(){
			onDone("need hash tree");
		},
		ifNeedParentUnits: function(arrMissingUnits){
			onDone("unknown parents");
		},
		ifOk: function(){
			onDone();
			
			// forward to other peers
			if (!bCatchingUp && !conf.bLight)
				forwardJoint(ws, objJoint);

			delete assocUnitsInWork[unit];
		},
		ifOkUnsigned: function(){
			delete assocUnitsInWork[unit];
			onDone("you can't send unsigned units");
		},
		ifKnown: function(){
			if (objJoint.unsigned)
				return onDone("you can't send unsigned units");
			onDone("known");
			writeEvent('known_good', ws.host);
		},
		ifKnownBad: function(){
			onDone("known bad");
			writeEvent('known_bad', ws.host);
		},
		ifKnownUnverified: function(){ // impossible unless the peer also sends this joint by 'joint' justsaying
			onDone("known unverified");
			delete assocUnitsInWork[unit];
		}
	});
}
function handlePostedJoint ( ws , objJoint , onDone ) { if ( ! objJoint || ! objJoint . unit || ! objJoint . unit . unit ) return onDone ( 'no unit' ) ; var unit = objJoint . unit . unit ; delete objJoint . unit . main_chain_index ; handleJoint ( ws , objJoint , false , { ifUnitInWork : function ( ) { onDone ( "already handling this unit" ) ; } , ifUnitError : function ( error ) { onDone ( error ) ; } , ifJointError : function ( error ) { onDone ( error ) ; } , ifNeedHashTree : function ( ) { onDone ( "need hash tree" ) ; } , ifNeedParentUnits : function ( arrMissingUnits ) { onDone ( "unknown parents" ) ; } , ifOk : function ( ) { onDone ( ) ; // forward to other peers if ( ! bCatchingUp && ! conf . bLight ) forwardJoint ( ws , objJoint ) ; delete assocUnitsInWork [ unit ] ; } , ifOkUnsigned : function ( ) { delete assocUnitsInWork [ unit ] ; onDone ( "you can't send unsigned units" ) ; } , ifKnown : function ( ) { if ( objJoint . unsigned ) return onDone ( "you can't send unsigned units" ) ; onDone ( "known" ) ; writeEvent ( 'known_good' , ws . host ) ; } , ifKnownBad : function ( ) { onDone ( "known bad" ) ; writeEvent ( 'known_bad' , ws . host ) ; } , ifKnownUnverified : function ( ) { // impossible unless the peer also sends this joint by 'joint' justsaying onDone ( "known unverified" ) ; delete assocUnitsInWork [ unit ] ; } } ) ; }
handle joint posted to me by a light client
handle joint posted to me by a light client