device.js
function sendMessageToHub(ws, recipient_device_pubkey, subject, body, callbacks, conn){
	// this content is hidden from the hub by encryption
	var json = {
		from: my_device_address, // presence of this field guarantees that you cannot strip off the signature and add your own signature instead
		device_hub: my_device_hub, 
		subject: subject, 
		body: body
	};
	conn = conn || db;
	if (ws)
		return reliablySendPreparedMessageToHub(ws, recipient_device_pubkey, json, callbacks, conn);
	var recipient_device_address = objectHash.getDeviceAddress(recipient_device_pubkey);
	conn.query("SELECT hub FROM correspondent_devices WHERE device_address=?", [recipient_device_address], function(rows){
		if (rows.length !== 1)
			throw Error("no hub in correspondents");
		reliablySendPreparedMessageToHub(rows[0].hub, recipient_device_pubkey, json, callbacks, conn);
	});
}
function sendMessageToHub(ws, recipient_device_pubkey, subject, body, callbacks, conn){
	// this content is hidden from the hub by encryption
	var json = {
		from: my_device_address, // presence of this field guarantees that you cannot strip off the signature and add your own signature instead
		device_hub: my_device_hub, 
		subject: subject, 
		body: body
	};
	conn = conn || db;
	if (ws)
		return reliablySendPreparedMessageToHub(ws, recipient_device_pubkey, json, callbacks, conn);
	var recipient_device_address = objectHash.getDeviceAddress(recipient_device_pubkey);
	conn.query("SELECT hub FROM correspondent_devices WHERE device_address=?", [recipient_device_address], function(rows){
		if (rows.length !== 1)
			throw Error("no hub in correspondents");
		reliablySendPreparedMessageToHub(rows[0].hub, recipient_device_pubkey, json, callbacks, conn);
	});
}
function sendMessageToHub ( ws , recipient_device_pubkey , subject , body , callbacks , conn ) { // this content is hidden from the hub by encryption var json = { from : my_device_address , // presence of this field guarantees that you cannot strip off the signature and add your own signature instead device_hub : my_device_hub , subject : subject , body : body } ; conn = conn || db ; if ( ws ) return reliablySendPreparedMessageToHub ( ws , recipient_device_pubkey , json , callbacks , conn ) ; var recipient_device_address = objectHash . getDeviceAddress ( recipient_device_pubkey ) ; conn . query ( "SELECT hub FROM correspondent_devices WHERE device_address=?" , [ recipient_device_address ] , function ( rows ) { if ( rows . length !== 1 ) throw Error ( "no hub in correspondents" ) ; reliablySendPreparedMessageToHub ( rows [ 0 ] . hub , recipient_device_pubkey , json , callbacks , conn ) ; } ) ; }
first param is either WebSocket or hostname of the hub or null
first param is either WebSocket or hostname of the hub or null