forked from cory/tildefriends
		
	Make the connections tab know more about tunnels and such.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4426 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		| @@ -42,11 +42,8 @@ class TfTabConnectionsElement extends LitElement { | ||||
| 		let self = this; | ||||
| 		let peers = this.broadcasts.filter(x => x.tunnel?.id == connection); | ||||
| 		if (peers.length) { | ||||
| 			return html` | ||||
| 				<ul> | ||||
| 					${peers.map(x => html`${self.render_room_peer(x)}`)} | ||||
| 				</ul> | ||||
| 			`; | ||||
| 			let connections = this.connections.map(x => x.id); | ||||
| 			return html`${peers.filter(x => connections.indexOf(x.pubkey) == -1).map(x => html`${self.render_room_peer(x)}`)}`; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -59,7 +56,7 @@ class TfTabConnectionsElement extends LitElement { | ||||
| 		return html` | ||||
| 			<li> | ||||
| 				<input type="button" @click=${() => self._tunnel(connection.tunnel.id, connection.pubkey)} value="Connect"></input> | ||||
| 				<tf-user id=${connection.pubkey} .users=${this.users}></tf-user> | ||||
| 				<tf-user id=${connection.pubkey} .users=${this.users}></tf-user> 📡 | ||||
| 			</li> | ||||
| 		`; | ||||
| 	} | ||||
| @@ -79,6 +76,18 @@ class TfTabConnectionsElement extends LitElement { | ||||
| 		this.stored_connections = (await tfrpc.rpc.getStoredConnections()) || []; | ||||
| 	} | ||||
|  | ||||
| 	render_connection(connection) { | ||||
| 		return html` | ||||
| 			<input type="button" @click=${() => tfrpc.rpc.closeConnection(connection.id)} value="Close"></input> | ||||
| 			<tf-user id=${connection.id} .users=${this.users}></tf-user> | ||||
| 			${connection.tunnel !== undefined ? '🚇' : html`(${connection.host}:${connection.port})`} | ||||
| 			<ul> | ||||
| 				${this.connections.filter(x => x.tunnel === this.connections.indexOf(connection)).map(x => html`<li>${this.render_connection(x)}</li>`)} | ||||
| 				${this.render_room_peers(connection.id)} | ||||
| 			</ul> | ||||
| 		`; | ||||
| 	} | ||||
|  | ||||
| 	render() { | ||||
| 		let self = this; | ||||
| 		return html` | ||||
| @@ -93,12 +102,8 @@ class TfTabConnectionsElement extends LitElement { | ||||
| 			</ul> | ||||
| 			<h2>Connections</h2> | ||||
| 			<ul> | ||||
| 				${this.connections.map(x => html` | ||||
| 					<li> | ||||
| 						<input type="button" @click=${() => tfrpc.rpc.closeConnection(x)} value="Close"></input> | ||||
| 						<tf-user id=${x} .users=${this.users}></tf-user> | ||||
| 						${self.render_room_peers(x)} | ||||
| 					</li> | ||||
| 				${this.connections.filter(x => x.tunnel === undefined).map(x => html` | ||||
| 					<li>${this.render_connection(x)}</li> | ||||
| 				`)} | ||||
| 			</ul> | ||||
| 			<h2>Stored Connections (WIP)</h2> | ||||
|   | ||||
| @@ -1219,6 +1219,11 @@ bool tf_ssb_connection_get_id(tf_ssb_connection_t* connection, char* out_id, siz | ||||
| 		tf_ssb_id_bin_to_str(out_id, out_id_size, connection->serverpub); | ||||
| } | ||||
|  | ||||
| tf_ssb_connection_t* tf_ssb_connection_get_tunnel(tf_ssb_connection_t* connection) | ||||
| { | ||||
| 	return connection ? connection->tunnel_connection : NULL; | ||||
| } | ||||
|  | ||||
| static bool _tf_ssb_is_already_connected(tf_ssb_t* ssb, uint8_t* id, tf_ssb_connection_t* ignore_connection) | ||||
| { | ||||
| 	for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next) | ||||
|   | ||||
| @@ -125,6 +125,7 @@ void tf_ssb_verify_strip_and_store_message(tf_ssb_t* ssb, JSValue value, tf_ssb_ | ||||
| bool tf_ssb_connection_is_client(tf_ssb_connection_t* connection); | ||||
| const char* tf_ssb_connection_get_host(tf_ssb_connection_t* connection); | ||||
| int tf_ssb_connection_get_port(tf_ssb_connection_t* connection); | ||||
| tf_ssb_connection_t* tf_ssb_connection_get_tunnel(tf_ssb_connection_t* connection); | ||||
| tf_ssb_t* tf_ssb_connection_get_ssb(tf_ssb_connection_t* connection); | ||||
| JSContext* tf_ssb_connection_get_context(tf_ssb_connection_t* connection); | ||||
| sqlite3* tf_ssb_connection_get_db(tf_ssb_connection_t* connection); | ||||
|   | ||||
							
								
								
									
										36
									
								
								src/ssb.js.c
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								src/ssb.js.c
									
									
									
									
									
								
							| @@ -22,6 +22,10 @@ | ||||
| #include <assert.h> | ||||
| #include <inttypes.h> | ||||
|  | ||||
| #if !defined(_countof) | ||||
| #define _countof(a) ((int)(sizeof((a)) / sizeof(*(a)))) | ||||
| #endif | ||||
|  | ||||
| static JSClassID _tf_ssb_classId; | ||||
|  | ||||
| void _tf_ssb_on_rpc(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data); | ||||
| @@ -319,16 +323,34 @@ static JSValue _tf_ssb_connections(JSContext* context, JSValueConst this_val, in | ||||
| 	tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId); | ||||
| 	if (ssb) | ||||
| 	{ | ||||
| 		const char** connections = tf_ssb_get_connection_ids(ssb); | ||||
| 		if (connections) | ||||
| 		tf_ssb_connection_t* connections[32]; | ||||
| 		int count = tf_ssb_get_connections(ssb, connections, _countof(connections)); | ||||
|  | ||||
| 		result = JS_NewArray(context); | ||||
| 		for (int i = 0; i < count; i++) | ||||
| 		{ | ||||
| 			result = JS_NewArray(context); | ||||
| 			uint32_t i = 0; | ||||
| 			for (const char** p = connections; *p; p++, i++) | ||||
| 			char id[k_id_base64_len] = { 0 }; | ||||
| 			tf_ssb_connection_t* connection = connections[i]; | ||||
| 			JSValue object = JS_NewObject(context); | ||||
| 			tf_ssb_connection_get_id(connection, id, sizeof(id)); | ||||
| 			JS_SetPropertyStr(context, object, "id", JS_NewString(context, id)); | ||||
| 			JS_SetPropertyStr(context, object, "host", JS_NewString(context, tf_ssb_connection_get_host(connection))); | ||||
| 			JS_SetPropertyStr(context, object, "port", JS_NewInt32(context, tf_ssb_connection_get_port(connection))); | ||||
| 			tf_ssb_connection_t* tunnel = tf_ssb_connection_get_tunnel(connection); | ||||
| 			if (tunnel) | ||||
| 			{ | ||||
| 				JS_SetPropertyUint32(context, result, i, JS_NewString(context, *p)); | ||||
| 				int tunnel_index = -1; | ||||
| 				for (int j = 0; j < count; j++) | ||||
| 				{ | ||||
| 					if (connections[j] == tunnel) | ||||
| 					{ | ||||
| 						tunnel_index = j; | ||||
| 						break; | ||||
| 					} | ||||
| 				} | ||||
| 				JS_SetPropertyStr(context, object, "tunnel", JS_NewInt32(context, tunnel_index)); | ||||
| 			} | ||||
| 			tf_free(connections); | ||||
| 			JS_SetPropertyUint32(context, result, i, object); | ||||
| 		} | ||||
| 	} | ||||
| 	return result; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user