Try to clean up some websocket noise, and try harder to not duplicate connections.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3647 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
3487f335e5
commit
03cf347394
@ -548,15 +548,22 @@ function message(event) {
|
|||||||
function reconnect(path) {
|
function reconnect(path) {
|
||||||
let oldSocket = gSocket;
|
let oldSocket = gSocket;
|
||||||
gSocket = null
|
gSocket = null
|
||||||
oldSocket.onclose = function() {}
|
oldSocket.onopen = null;
|
||||||
oldSocket.onmessage = function() {}
|
oldSocket.onclose = null;
|
||||||
|
oldSocket.onmessage = null;
|
||||||
oldSocket.close();
|
oldSocket.close();
|
||||||
connectSocket(path);
|
connectSocket(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
function connectSocket(path) {
|
function connectSocket(path) {
|
||||||
if (!gSocket || gSocket.readyState == gSocket.CLOSED) {
|
if (!gSocket || gSocket.readyState != gSocket.OPEN) {
|
||||||
setStatusMessage("Connecting...", kStatusColor, true);
|
if (gSocket) {
|
||||||
|
gSocket.onopen = null;
|
||||||
|
gSocket.onclose = null;
|
||||||
|
gSocket.onmessage = null;
|
||||||
|
gSocket.close();
|
||||||
|
}
|
||||||
|
setStatusMessage("Connecting...", kStatusColor, false);
|
||||||
gSocket = new WebSocket(
|
gSocket = new WebSocket(
|
||||||
(window.location.protocol == "https:" ? "wss://" : "ws://")
|
(window.location.protocol == "https:" ? "wss://" : "ws://")
|
||||||
+ window.location.hostname
|
+ window.location.hostname
|
||||||
|
17
src/ssb.c
17
src/ssb.c
@ -794,6 +794,18 @@ bool tf_ssb_connection_get_id(tf_ssb_connection_t* connection, char* out_id, siz
|
|||||||
return tf_ssb_id_bin_to_str(out_id, out_id_size, connection->serverpub);
|
return tf_ssb_id_bin_to_str(out_id, out_id_size, connection->serverpub);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool _tf_ssb_is_already_connected(tf_ssb_t* ssb, uint8_t* id)
|
||||||
|
{
|
||||||
|
for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next) {
|
||||||
|
if (memcmp(connection->serverpub, id, k_id_bin_len) == 0) {
|
||||||
|
return true;
|
||||||
|
} else if (memcmp(ssb->pub, id, k_id_bin_len) == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static void _tf_ssb_connection_verify_client_identity(tf_ssb_connection_t* connection, const uint8_t* message, size_t len)
|
static void _tf_ssb_connection_verify_client_identity(tf_ssb_connection_t* connection, const uint8_t* message, size_t len)
|
||||||
{
|
{
|
||||||
uint8_t nonce[crypto_secretbox_NONCEBYTES] = { 0 };
|
uint8_t nonce[crypto_secretbox_NONCEBYTES] = { 0 };
|
||||||
@ -859,6 +871,11 @@ static void _tf_ssb_connection_verify_client_identity(tf_ssb_connection_t* conne
|
|||||||
}
|
}
|
||||||
uint8_t* detached_signature_A = m;
|
uint8_t* detached_signature_A = m;
|
||||||
|
|
||||||
|
if (_tf_ssb_is_already_connected(connection->ssb, m + 64)) {
|
||||||
|
_tf_ssb_connection_close(connection, "already connected");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(connection->serverpub, m + 64, sizeof(connection->serverpub));
|
memcpy(connection->serverpub, m + 64, sizeof(connection->serverpub));
|
||||||
|
|
||||||
uint8_t hash3[crypto_hash_sha256_BYTES];
|
uint8_t hash3[crypto_hash_sha256_BYTES];
|
||||||
|
Loading…
Reference in New Issue
Block a user