NostrRelay

- Fixed relay reconnect logic by catching deadline exceeded excweption
This commit is contained in:
Tristan B. Velloza Kildaire 2023-02-21 19:46:15 +02:00
parent 98bea6ed69
commit c3f3872e20
1 changed files with 32 additions and 7 deletions

View File

@ -35,17 +35,22 @@ public class NostrRelay : Thread
private bool attemptConnection()
{
logger.print("Connecting to relay at "~endpointURL~"...\n", DebugType.INFO);
logger.print("Connecting to relay at "~endpointURL~"...\n", DebugType.WARNING);
HTTPClientSettings clientSettings = new HTTPClientSettings();
clientSettings.connectTimeout = connectTimeout;
try
{
ws = connectWebSocket(URL(endpointURL), clientSettings);
logger.print("Connected to relay\n", DebugType.INFO);
}
catch(Exception e)
{
// Catches the timeout
}
ws = connectWebSocket(URL(endpointURL), clientSettings);
import std.stdio;
writeln("kak");
return ws.connected;
return ws.connected();
}
/**
@ -86,6 +91,7 @@ public class NostrRelay : Thread
/* If we disconnected */
else
{
logger.print("Relay connection state is closed\n", DebugType.ERROR);
untilConnected();
}
@ -108,19 +114,38 @@ public class NostrRelay : Thread
}
}
/**
* Called before any of the below methods, ensures
* the connection to the relay is open, if not,
* re-opens it
*/
private void ensureOpen()
{
if(!ws.connected())
{
untilConnected();
}
}
public void unsubscribe()
{
ensureOpen();
// TODO: Implement me
}
public void subscribe()
{
ensureOpen();
// TODO: Implement me
}
import dnostr.client : NostrEvent;
public void event(NostrEvent event)
{
ensureOpen();
// TODO: Implement me
}
}