Compare commits
4 Commits
92bf01a183
...
20701d9cf1
Author | SHA1 | Date | |
---|---|---|---|
20701d9cf1 | |||
fa94442eb2 | |||
68ff77e172 | |||
102e9be3a8 |
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"type": "tildefriends-app",
|
"type": "tildefriends-app",
|
||||||
"emoji": "🐌",
|
"emoji": "🐌",
|
||||||
"previous": "&CKsS2aS8+7u9S5jDCiqBLA6xr7xLdMHclMKHjzwxcnM=.sha256"
|
"previous": "&olI6SRBA/dThYusGLGhZ9T2nFKyGB9r+/kb7bJxa4gg=.sha256"
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,9 @@ class TfTabConnectionsElement extends LitElement {
|
|||||||
stored_connections: {type: Array},
|
stored_connections: {type: Array},
|
||||||
users: {type: Object},
|
users: {type: Object},
|
||||||
server_identity: {type: String},
|
server_identity: {type: String},
|
||||||
connect_error: {type: String},
|
connect_attempt: {type: Object},
|
||||||
|
connect_message: {type: String},
|
||||||
|
connect_success: {type: Boolean},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,20 +91,36 @@ class TfTabConnectionsElement extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
render_message(connection) {
|
||||||
|
return html`<div
|
||||||
|
?hidden=${this.connect_message === undefined ||
|
||||||
|
this.connect_attempt != connection}
|
||||||
|
style="cursor: pointer"
|
||||||
|
class=${'w3-panel ' + (this.connect_success ? 'w3-green' : 'w3-red')}
|
||||||
|
@click=${() => this.connect_attempt = undefined}
|
||||||
|
>
|
||||||
|
<p>${this.connect_message}</p>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
render_broadcast(connection) {
|
render_broadcast(connection) {
|
||||||
|
let self = this;
|
||||||
return html`
|
return html`
|
||||||
<li class="w3-bar" style="overflow: hidden; overflow-wrap: nowrap">
|
<li>
|
||||||
<button
|
<div class="w3-bar" style="overflow: hidden; overflow-wrap: nowrap">
|
||||||
class="w3-bar-item w3-button w3-theme-d1"
|
<button
|
||||||
@click=${() => tfrpc.rpc.connect(connection)}
|
class="w3-bar-item w3-button w3-theme-d1"
|
||||||
>
|
@click=${() => self.connect(connection)}
|
||||||
Connect
|
>
|
||||||
</button>
|
Connect
|
||||||
<div class="w3-bar-item">
|
</button>
|
||||||
${TfTabConnectionsElement.k_broadcast_emojis[connection.origin]}
|
<div class="w3-bar-item">
|
||||||
<tf-user id=${connection.pubkey} .users=${this.users}></tf-user>
|
${TfTabConnectionsElement.k_broadcast_emojis[connection.origin]}
|
||||||
${this.render_connection_summary(connection)}
|
<tf-user id=${connection.pubkey} .users=${this.users}></tf-user>
|
||||||
|
${this.render_connection_summary(connection)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
${this.render_message(connection)}
|
||||||
</li>
|
</li>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -166,11 +184,23 @@ class TfTabConnectionsElement extends LitElement {
|
|||||||
|
|
||||||
connect(address) {
|
connect(address) {
|
||||||
let self = this;
|
let self = this;
|
||||||
tfrpc.rpc.connect(address).then(function() {
|
self.connect_attempt = address;
|
||||||
self.connect_error = 'connected!';
|
self.connect_message = undefined;
|
||||||
}).catch(function(error) {
|
self.connect_success = false;
|
||||||
self.connect_error = error;
|
tfrpc.rpc
|
||||||
});
|
.connect(address)
|
||||||
|
.then(function () {
|
||||||
|
if (self.connect_attempt == address) {
|
||||||
|
self.connect_message = 'Connected.';
|
||||||
|
self.connect_success = true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
if (self.connect_attempt == address) {
|
||||||
|
self.connect_message = 'Error: ' + error;
|
||||||
|
self.connect_success = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -185,14 +215,14 @@ class TfTabConnectionsElement extends LitElement {
|
|||||||
</button>
|
</button>
|
||||||
<h2>New Connection</h2>
|
<h2>New Connection</h2>
|
||||||
<textarea class="w3-input w3-theme-d1" id="code"></textarea>
|
<textarea class="w3-input w3-theme-d1" id="code"></textarea>
|
||||||
|
${this.render_message(this.renderRoot.getElementById('code')?.value)}
|
||||||
<button
|
<button
|
||||||
class="w3-button w3-theme-d1"
|
class="w3-button w3-theme-d1"
|
||||||
@click=${() =>
|
@click=${() =>
|
||||||
self.connect(self.renderRoot.getElementById('code').value)}
|
self.connect(self.renderRoot.getElementById('code')?.value)}
|
||||||
>
|
>
|
||||||
Connect
|
Connect
|
||||||
</button>
|
</button>
|
||||||
<div ?hidden=${this.connect_error === undefined}>${this.connect_error}</div>
|
|
||||||
<h2>Broadcasts</h2>
|
<h2>Broadcasts</h2>
|
||||||
<ul class="w3-ul w3-border">
|
<ul class="w3-ul w3-border">
|
||||||
${this.broadcasts
|
${this.broadcasts
|
||||||
@ -213,23 +243,26 @@ class TfTabConnectionsElement extends LitElement {
|
|||||||
<ul class="w3-ul w3-border">
|
<ul class="w3-ul w3-border">
|
||||||
${this.stored_connections.map(
|
${this.stored_connections.map(
|
||||||
(x) => html`
|
(x) => html`
|
||||||
<li class="w3-bar">
|
<li>
|
||||||
<button
|
<div class="w3-bar">
|
||||||
class="w3-bar-item w3-button w3-theme-d1"
|
<button
|
||||||
@click=${() => self.forget_stored_connection(x)}
|
class="w3-bar-item w3-button w3-theme-d1"
|
||||||
>
|
@click=${() => self.forget_stored_connection(x)}
|
||||||
Forget
|
>
|
||||||
</button>
|
Forget
|
||||||
<button
|
</button>
|
||||||
class="w3-bar-item w3-button w3-theme-d1"
|
<button
|
||||||
@click=${() => tfrpc.rpc.connect(x)}
|
class="w3-bar-item w3-button w3-theme-d1"
|
||||||
>
|
@click=${() => this.connect(x)}
|
||||||
Connect
|
>
|
||||||
</button>
|
Connect
|
||||||
<div class="w3-bar-item">
|
</button>
|
||||||
<tf-user id=${x.pubkey} .users=${self.users}></tf-user>
|
<div class="w3-bar-item">
|
||||||
<div><small>${x.address}:${x.port}</small></div>
|
<tf-user id=${x.pubkey} .users=${self.users}></tf-user>
|
||||||
|
<div><small>${x.address}:${x.port}</small></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
${this.render_message(x)}
|
||||||
</li>
|
</li>
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
|
2
deps/c-ares
vendored
2
deps/c-ares
vendored
@ -1 +1 @@
|
|||||||
Subproject commit a57ff692eeab8d21c853dc1ddaf0164f517074c3
|
Subproject commit c29e75d54c3743783d51a609980495cf553b4bca
|
37
src/ssb.c
37
src/ssb.c
@ -511,7 +511,9 @@ static void _tf_ssb_write(tf_ssb_connection_t* connection, void* data, size_t si
|
|||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
tf_ssb_connection_adjust_write_count(connection, -1);
|
tf_ssb_connection_adjust_write_count(connection, -1);
|
||||||
_tf_ssb_connection_close(connection, "write failed");
|
char buffer[256];
|
||||||
|
snprintf(buffer, sizeof(buffer), "write failed : %s", uv_strerror(result));
|
||||||
|
_tf_ssb_connection_close(connection, buffer);
|
||||||
tf_free(write);
|
tf_free(write);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2127,8 +2129,9 @@ static bool _tf_ssb_connection_read_start(tf_ssb_connection_t* connection)
|
|||||||
int result = uv_read_start((uv_stream_t*)&connection->tcp, _tf_ssb_connection_on_tcp_alloc, _tf_ssb_connection_on_tcp_recv);
|
int result = uv_read_start((uv_stream_t*)&connection->tcp, _tf_ssb_connection_on_tcp_alloc, _tf_ssb_connection_on_tcp_recv);
|
||||||
if (result && result != UV_EALREADY)
|
if (result && result != UV_EALREADY)
|
||||||
{
|
{
|
||||||
tf_printf("uv_read_start => %s\n", uv_strerror(result));
|
char reason[1024];
|
||||||
_tf_ssb_connection_close(connection, "uv_read_start failed");
|
snprintf(reason, sizeof(reason), "uv_read_start failed: %s", uv_strerror(result));
|
||||||
|
_tf_ssb_connection_close(connection, reason);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -2139,8 +2142,9 @@ static bool _tf_ssb_connection_read_stop(tf_ssb_connection_t* connection)
|
|||||||
int result = uv_read_stop((uv_stream_t*)&connection->tcp);
|
int result = uv_read_stop((uv_stream_t*)&connection->tcp);
|
||||||
if (result && result != UV_EALREADY)
|
if (result && result != UV_EALREADY)
|
||||||
{
|
{
|
||||||
tf_printf("uv_read_stop => %s\n", uv_strerror(result));
|
char reason[1024];
|
||||||
_tf_ssb_connection_close(connection, "uv_read_stop failed");
|
snprintf(reason, sizeof(reason), "uv_read_stop failed: %s", uv_strerror(result));
|
||||||
|
_tf_ssb_connection_close(connection, reason);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -2160,7 +2164,9 @@ static void _tf_ssb_connection_on_connect(uv_connect_t* connect, int status)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_tf_ssb_connection_close(connection, "uv_tcp_connect failed");
|
char reason[1024];
|
||||||
|
snprintf(reason, sizeof(reason), "uv_tcp_connect failed: %s", uv_strerror(status));
|
||||||
|
_tf_ssb_connection_close(connection, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2779,9 +2785,10 @@ static tf_ssb_connection_t* _tf_ssb_connection_create(
|
|||||||
int result = uv_tcp_connect(&connection->connect, &connection->tcp, (const struct sockaddr*)addr, _tf_ssb_connection_on_connect);
|
int result = uv_tcp_connect(&connection->connect, &connection->tcp, (const struct sockaddr*)addr, _tf_ssb_connection_on_connect);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
tf_printf("uv_tcp_connect(%s): %s\n", host, uv_strerror(result));
|
char reason[1024];
|
||||||
|
snprintf(reason, sizeof(reason), "uv_tcp_connect(%s) => %s", host, uv_strerror(result));
|
||||||
connection->connect.data = NULL;
|
connection->connect.data = NULL;
|
||||||
_tf_ssb_connection_destroy(connection, "connect failed");
|
_tf_ssb_connection_destroy(connection, reason);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2966,15 +2973,21 @@ static void _tf_ssb_on_connection(uv_stream_t* stream, int status)
|
|||||||
connection->object = JS_NewObjectClass(ssb->context, _connection_class_id);
|
connection->object = JS_NewObjectClass(ssb->context, _connection_class_id);
|
||||||
JS_SetOpaque(connection->object, connection);
|
JS_SetOpaque(connection->object, connection);
|
||||||
|
|
||||||
if (uv_tcp_init(ssb->loop, &connection->tcp) != 0)
|
int result = uv_tcp_init(ssb->loop, &connection->tcp);
|
||||||
|
if (result != 0)
|
||||||
{
|
{
|
||||||
_tf_ssb_connection_destroy(connection, "init failed");
|
char reason[1024];
|
||||||
|
snprintf(reason, sizeof(reason), "uv_tcp_init() => %s", uv_strerror(result));
|
||||||
|
_tf_ssb_connection_destroy(connection, reason);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uv_accept(stream, (uv_stream_t*)&connection->tcp) != 0)
|
result = uv_accept(stream, (uv_stream_t*)&connection->tcp);
|
||||||
|
if (result != 0)
|
||||||
{
|
{
|
||||||
_tf_ssb_connection_destroy(connection, "accept failed");
|
char reason[1024];
|
||||||
|
snprintf(reason, sizeof(reason), "uv_accept() => %s", uv_strerror(result));
|
||||||
|
_tf_ssb_connection_destroy(connection, reason);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user