Track/show the origin of each broadcast (discovery/room/peer exchange).
This commit is contained in:
parent
34804d5162
commit
463951a4f1
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"type": "tildefriends-app",
|
"type": "tildefriends-app",
|
||||||
"emoji": "🐌",
|
"emoji": "🐌",
|
||||||
"previous": "&2xK//SIpjFb0+uT5I7MSAGJ3d1FKuI/rlzhcCQd3NME=.sha256"
|
"previous": "&xsmsLytB3VvoHphiFHZGGEvrCfTEVGXrGwobGTIYFPQ=.sha256"
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,12 @@ class TfTabConnectionsElement extends LitElement {
|
|||||||
|
|
||||||
static styles = styles;
|
static styles = styles;
|
||||||
|
|
||||||
|
static k_broadcast_emojis = {
|
||||||
|
discovery: '🏓',
|
||||||
|
room: '🚪',
|
||||||
|
peer_exchange: '🕸',
|
||||||
|
};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
let self = this;
|
let self = this;
|
||||||
@ -92,6 +98,7 @@ class TfTabConnectionsElement extends LitElement {
|
|||||||
Connect
|
Connect
|
||||||
</button>
|
</button>
|
||||||
<div class="w3-bar-item">
|
<div class="w3-bar-item">
|
||||||
|
${TfTabConnectionsElement.k_broadcast_emojis[connection.origin]}
|
||||||
<tf-user id=${connection.pubkey} .users=${this.users}></tf-user>
|
<tf-user id=${connection.pubkey} .users=${this.users}></tf-user>
|
||||||
${this.render_connection_summary(connection)}
|
${this.render_connection_summary(connection)}
|
||||||
</div>
|
</div>
|
||||||
|
10
src/ssb.c
10
src/ssb.c
@ -121,6 +121,7 @@ typedef struct _tf_ssb_broadcast_t
|
|||||||
time_t mtime;
|
time_t mtime;
|
||||||
time_t expires_at;
|
time_t expires_at;
|
||||||
char host[256];
|
char host[256];
|
||||||
|
tf_ssb_broadcast_origin_t origin;
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
tf_ssb_connection_t* tunnel_connection;
|
tf_ssb_connection_t* tunnel_connection;
|
||||||
uint8_t pub[crypto_sign_PUBLICKEYBYTES];
|
uint8_t pub[crypto_sign_PUBLICKEYBYTES];
|
||||||
@ -2948,7 +2949,7 @@ static void _tf_ssb_update_seeds_after_work(tf_ssb_t* ssb, int status, void* use
|
|||||||
seeds_t* seeds = user_data;
|
seeds_t* seeds = user_data;
|
||||||
for (int i = 0; i < seeds->seeds_count; i++)
|
for (int i = 0; i < seeds->seeds_count; i++)
|
||||||
{
|
{
|
||||||
tf_ssb_broadcast_t broadcast = { 0 };
|
tf_ssb_broadcast_t broadcast = { .origin = k_tf_ssb_broadcast_origin_peer_exchange };
|
||||||
if (_tf_ssb_parse_broadcast(seeds->seeds[i], &broadcast))
|
if (_tf_ssb_parse_broadcast(seeds->seeds[i], &broadcast))
|
||||||
{
|
{
|
||||||
_tf_ssb_add_broadcast(ssb, &broadcast, k_seed_expire_seconds);
|
_tf_ssb_add_broadcast(ssb, &broadcast, k_seed_expire_seconds);
|
||||||
@ -3163,7 +3164,7 @@ static void _tf_ssb_on_broadcast_listener_recv(uv_udp_t* handle, ssize_t nread,
|
|||||||
char* entry = strtok_r(buf->base, k_delim, &state);
|
char* entry = strtok_r(buf->base, k_delim, &state);
|
||||||
while (entry)
|
while (entry)
|
||||||
{
|
{
|
||||||
tf_ssb_broadcast_t broadcast = { 0 };
|
tf_ssb_broadcast_t broadcast = { .origin = k_tf_ssb_broadcast_origin_discovery };
|
||||||
if (_tf_ssb_parse_broadcast(entry, &broadcast))
|
if (_tf_ssb_parse_broadcast(entry, &broadcast))
|
||||||
{
|
{
|
||||||
_tf_ssb_add_broadcast(ssb, &broadcast, k_udp_discovery_expires_seconds);
|
_tf_ssb_add_broadcast(ssb, &broadcast, k_udp_discovery_expires_seconds);
|
||||||
@ -3174,7 +3175,7 @@ static void _tf_ssb_on_broadcast_listener_recv(uv_udp_t* handle, ssize_t nread,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void tf_ssb_visit_broadcasts(
|
void tf_ssb_visit_broadcasts(
|
||||||
tf_ssb_t* ssb, void (*callback)(const char* host, const struct sockaddr_in* addr, tf_ssb_connection_t* tunnel, const uint8_t* pub, void* user_data), void* user_data)
|
tf_ssb_t* ssb, void (*callback)(const char* host, const struct sockaddr_in* addr, tf_ssb_broadcast_origin_t origin, tf_ssb_connection_t* tunnel, const uint8_t* pub, void* user_data), void* user_data)
|
||||||
{
|
{
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
tf_ssb_broadcast_t* next = NULL;
|
tf_ssb_broadcast_t* next = NULL;
|
||||||
@ -3184,7 +3185,7 @@ void tf_ssb_visit_broadcasts(
|
|||||||
if (node->mtime - now < 60)
|
if (node->mtime - now < 60)
|
||||||
{
|
{
|
||||||
tf_trace_begin(ssb->trace, "broadcast");
|
tf_trace_begin(ssb->trace, "broadcast");
|
||||||
callback(node->host, &node->addr, node->tunnel_connection, node->pub, user_data);
|
callback(node->host, &node->addr, node->origin, node->tunnel_connection, node->pub, user_data);
|
||||||
tf_trace_end(ssb->trace);
|
tf_trace_end(ssb->trace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3610,6 +3611,7 @@ void tf_ssb_notify_blob_want_added(tf_ssb_t* ssb, const char* id)
|
|||||||
void tf_ssb_connection_add_room_attendant(tf_ssb_connection_t* connection, const char* id)
|
void tf_ssb_connection_add_room_attendant(tf_ssb_connection_t* connection, const char* id)
|
||||||
{
|
{
|
||||||
tf_ssb_broadcast_t broadcast = {
|
tf_ssb_broadcast_t broadcast = {
|
||||||
|
.origin = k_tf_ssb_broadcast_origin_room,
|
||||||
.tunnel_connection = connection,
|
.tunnel_connection = connection,
|
||||||
};
|
};
|
||||||
tf_ssb_id_str_to_bin(broadcast.pub, id);
|
tf_ssb_id_str_to_bin(broadcast.pub, id);
|
||||||
|
@ -41,6 +41,13 @@ typedef enum _tf_ssb_change_t
|
|||||||
k_tf_ssb_change_update,
|
k_tf_ssb_change_update,
|
||||||
} tf_ssb_change_t;
|
} tf_ssb_change_t;
|
||||||
|
|
||||||
|
typedef enum _tf_ssb_broadcast_origin_t
|
||||||
|
{
|
||||||
|
k_tf_ssb_broadcast_origin_discovery,
|
||||||
|
k_tf_ssb_broadcast_origin_room,
|
||||||
|
k_tf_ssb_broadcast_origin_peer_exchange,
|
||||||
|
} tf_ssb_broadcast_origin_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Flags describing the structure of a message.
|
** Flags describing the structure of a message.
|
||||||
*/
|
*/
|
||||||
@ -300,7 +307,7 @@ bool tf_ssb_whoami(tf_ssb_t* ssb, char* out_id, size_t out_id_size);
|
|||||||
** @param user_data User data for the callback.
|
** @param user_data User data for the callback.
|
||||||
*/
|
*/
|
||||||
void tf_ssb_visit_broadcasts(
|
void tf_ssb_visit_broadcasts(
|
||||||
tf_ssb_t* ssb, void (*callback)(const char* host, const struct sockaddr_in* addr, tf_ssb_connection_t* tunnel, const uint8_t* pub, void* user_data), void* user_data);
|
tf_ssb_t* ssb, void (*callback)(const char* host, const struct sockaddr_in* addr, tf_ssb_broadcast_origin_t origin, tf_ssb_connection_t* tunnel, const uint8_t* pub, void* user_data), void* user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** Get the identities of all active connections.
|
** Get the identities of all active connections.
|
||||||
|
14
src/ssb.js.c
14
src/ssb.js.c
@ -1450,12 +1450,24 @@ typedef struct _broadcasts_t
|
|||||||
int length;
|
int length;
|
||||||
} broadcasts_t;
|
} broadcasts_t;
|
||||||
|
|
||||||
static void _tf_ssb_broadcasts_visit(const char* host, const struct sockaddr_in* addr, tf_ssb_connection_t* tunnel, const uint8_t* pub, void* user_data)
|
static void _tf_ssb_broadcasts_visit(const char* host, const struct sockaddr_in* addr, tf_ssb_broadcast_origin_t origin, tf_ssb_connection_t* tunnel, const uint8_t* pub, void* user_data)
|
||||||
{
|
{
|
||||||
broadcasts_t* broadcasts = user_data;
|
broadcasts_t* broadcasts = user_data;
|
||||||
JSValue entry = JS_NewObject(broadcasts->context);
|
JSValue entry = JS_NewObject(broadcasts->context);
|
||||||
char pubkey[k_id_base64_len];
|
char pubkey[k_id_base64_len];
|
||||||
tf_ssb_id_bin_to_str(pubkey, sizeof(pubkey), pub);
|
tf_ssb_id_bin_to_str(pubkey, sizeof(pubkey), pub);
|
||||||
|
switch (origin)
|
||||||
|
{
|
||||||
|
case k_tf_ssb_broadcast_origin_discovery:
|
||||||
|
JS_SetPropertyStr(broadcasts->context, entry, "origin", JS_NewString(broadcasts->context, "discovery"));
|
||||||
|
break;
|
||||||
|
case k_tf_ssb_broadcast_origin_room:
|
||||||
|
JS_SetPropertyStr(broadcasts->context, entry, "origin", JS_NewString(broadcasts->context, "room"));
|
||||||
|
break;
|
||||||
|
case k_tf_ssb_broadcast_origin_peer_exchange:
|
||||||
|
JS_SetPropertyStr(broadcasts->context, entry, "origin", JS_NewString(broadcasts->context, "peer_exchange"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (tunnel)
|
if (tunnel)
|
||||||
{
|
{
|
||||||
JS_SetPropertyStr(broadcasts->context, entry, "tunnel", JS_DupValue(broadcasts->context, tf_ssb_connection_get_object(tunnel)));
|
JS_SetPropertyStr(broadcasts->context, entry, "tunnel", JS_DupValue(broadcasts->context, tf_ssb_connection_get_object(tunnel)));
|
||||||
|
@ -323,7 +323,7 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
|
|||||||
uv_loop_close(&loop);
|
uv_loop_close(&loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _broadcasts_visit(const char* host, const struct sockaddr_in* addr, tf_ssb_connection_t* tunnel, const uint8_t* pub, void* user_data)
|
static void _broadcasts_visit(const char* host, const struct sockaddr_in* addr, tf_ssb_broadcast_origin_t origin, tf_ssb_connection_t* tunnel, const uint8_t* pub, void* user_data)
|
||||||
{
|
{
|
||||||
int* count = user_data;
|
int* count = user_data;
|
||||||
(*count)++;
|
(*count)++;
|
||||||
@ -747,7 +747,7 @@ static void _break_in_a_bit(tf_ssb_t* ssb, tf_ssb_connection_t* connection, cons
|
|||||||
uv_timer_start(&data->timer, _close_callback, 3000, 0);
|
uv_timer_start(&data->timer, _close_callback, 3000, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _ssb_test_room_broadcasts_visit(const char* host, const struct sockaddr_in* addr, tf_ssb_connection_t* tunnel, const uint8_t* pub, void* user_data)
|
static void _ssb_test_room_broadcasts_visit(const char* host, const struct sockaddr_in* addr, tf_ssb_broadcast_origin_t origin, tf_ssb_connection_t* tunnel, const uint8_t* pub, void* user_data)
|
||||||
{
|
{
|
||||||
tf_ssb_t* ssb = user_data;
|
tf_ssb_t* ssb = user_data;
|
||||||
char id[k_id_base64_len] = { 0 };
|
char id[k_id_base64_len] = { 0 };
|
||||||
|
Loading…
Reference in New Issue
Block a user