I am too good at breaking syncing.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3684 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		
							
								
								
									
										35
									
								
								core/ssb.js
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								core/ssb.js
									
									
									
									
									
								
							| @@ -45,7 +45,7 @@ async function followingDeep(db, seed_ids, depth) { | ||||
| 	var f = await Promise.all(seed_ids.map(x => following(db, x))); | ||||
| 	var ids = [].concat(...f); | ||||
| 	var x = await followingDeep(db, [...new Set(ids)].sort(), depth - 1); | ||||
| 	x = [].concat(...x, ...seed_ids); | ||||
| 	x = [...new Set([].concat(...x, ...seed_ids))].sort(); | ||||
| 	return x; | ||||
| } | ||||
|  | ||||
| @@ -65,8 +65,8 @@ function get_latest_sequence_for_author(author) { | ||||
| ssb.registerConnectionsChanged(function(change, connection) { | ||||
| 	if (change == 'add') { | ||||
| 		var sequence = get_latest_sequence_for_author(connection.id); | ||||
| 		connection.send_json({'name': ['createHistoryStream'], 'type': 'source', 'args': [{'id': connection.id, 'seq': sequence, 'live': true}]}, function(message) { | ||||
| 			ssb.storeMessage(message.message.value); | ||||
| 		connection.send_json({'name': ['createHistoryStream'], 'type': 'source', 'args': [{'id': connection.id, 'seq': sequence, 'live': true, keys: false}]}, function(message) { | ||||
| 			ssb.storeMessage(message.message.value ? message.message.value : message.message); | ||||
| 		}); | ||||
| 		connection.send_json({'name': ['blobs', 'createWants'], 'type': 'source', 'args': []}, function(message) { | ||||
| 			Object.keys(message.message).forEach(function(id) { | ||||
| @@ -95,8 +95,8 @@ ssb.registerConnectionsChanged(function(change, connection) { | ||||
| 		followingDeep(g_database, [ssb.whoami()], 2).then(function(ids) { | ||||
| 			for (let id of ids) { | ||||
| 				var sequence = get_latest_sequence_for_author(id); | ||||
| 				connection.send_json({'name': ['createHistoryStream'], 'type': 'source', 'args': [{'id': id, 'seq': sequence}]}, function(message) { | ||||
| 					ssb.storeMessage(message.message.value); | ||||
| 				connection.send_json({'name': ['createHistoryStream'], 'type': 'source', 'args': [{'id': id, 'seq': sequence, 'live': true, 'keys': false}]}, function(message) { | ||||
| 					ssb.storeMessage(message.message.value ? message.message.value : message.message); | ||||
| 				}); | ||||
| 			} | ||||
| 		}); | ||||
| @@ -143,13 +143,27 @@ ssb.registerRpc(['blobs', 'get'], function(request) { | ||||
| ssb.registerRpc(['createHistoryStream'], function(request) { | ||||
| 	var id = request.args[0].id; | ||||
| 	var seq = request.args[0].seq; | ||||
| 	var keys = request.args[0].keys || request.args[0].keys === undefined; | ||||
| 	ssb.sqlStream( | ||||
| 		'SELECT previous, id, sequence, timestamp, hash, content, signature FROM messages WHERE author = ?1 AND sequence >= ?2 ORDER BY sequence', | ||||
| 		[id, seq ?? 0], | ||||
| 		function(row) { | ||||
| 			var message = { | ||||
| 				key: row.id + '.' + row.hash, | ||||
| 				value: { | ||||
| 			if (keys) { | ||||
| 				var message = { | ||||
| 					key: row.id, | ||||
| 					value: { | ||||
| 						previous: row.previous, | ||||
| 						author: id, | ||||
| 						sequence: row.sequence, | ||||
| 						timestamp: row.timestamp, | ||||
| 						hash: row.hash, | ||||
| 						content: JSON.parse(row.content), | ||||
| 						signature: row.signature, | ||||
| 					}, | ||||
| 					timestamp: row.timestamp, | ||||
| 				}; | ||||
| 			} else { | ||||
| 				var message = { | ||||
| 					previous: row.previous, | ||||
| 					author: id, | ||||
| 					sequence: row.sequence, | ||||
| @@ -157,9 +171,8 @@ ssb.registerRpc(['createHistoryStream'], function(request) { | ||||
| 					hash: row.hash, | ||||
| 					content: JSON.parse(row.content), | ||||
| 					signature: row.signature, | ||||
| 				}, | ||||
| 				timestamp: row.timestamp, | ||||
| 			}; | ||||
| 				}; | ||||
| 			} | ||||
| 			request.send_json(message); | ||||
| 		}); | ||||
| }); | ||||
|   | ||||
| @@ -484,7 +484,7 @@ bool tf_ssb_verify_and_strip_signature(JSContext* context, JSValue val, char* ou | ||||
| 			verified = r == 0; | ||||
| 			if (!verified) | ||||
| 			{ | ||||
| 				printf("crypto_sign_verify_detached fail\n"); | ||||
| 				printf("crypto_sign_verify_detached fail (r=%d)\n", r); | ||||
| 			} | ||||
| 		} | ||||
| 		else | ||||
| @@ -1115,12 +1115,10 @@ void tf_ssb_append_message(tf_ssb_t* ssb, JSValue message) | ||||
| 	len = 0; | ||||
| 	json = JS_ToCStringLen(context, &len, jsonval); | ||||
|  | ||||
| 	printf("appending message %.*s\n", (int)len, json); | ||||
|  | ||||
| 	JS_FreeCString(context, json); | ||||
| 	JS_FreeValue(context, jsonval); | ||||
|  | ||||
| 	char id[sodium_base64_ENCODED_LEN(crypto_hash_sha256_BYTES, sodium_base64_VARIANT_ORIGINAL) + 1]; | ||||
| 	char id[sodium_base64_ENCODED_LEN(crypto_hash_sha256_BYTES, sodium_base64_VARIANT_ORIGINAL) + 7 + 1]; | ||||
| 	tf_ssb_calculate_message_id(ssb->context, root, id, sizeof(id)); | ||||
| 	if (valid && | ||||
| 		!tf_ssb_db_store_message(ssb, ssb->context, id, root, signature_base64)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user