Fixed startup and store in db.

This commit is contained in:
Willem Cazander 2023-09-25 16:33:33 +02:00
parent 73f201bdac
commit b93f1d7ef1
15 changed files with 172 additions and 107 deletions

View file

@ -21,5 +21,10 @@
<artifactId>no2all-wire-ojw</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View file

@ -60,7 +60,7 @@ public class NoStrRtsServer implements No2AllReactTypeScript {
NoStrFirePipe pipeReader = NoStr.FACTORY.pipeReaderRelay(reason -> {
react.fire(socketSlot, No2AllActServerSocketClose.ofRefuse(reason));
}, message -> {
react.fire(serverSlot, message);
react.fire(socketSlot, message);
});
react.registrate(socketSlot, No2AllArtServerSocketOnMessage.class, v -> {
pipeReader.onFire(v.getData().getMessage());

View file

@ -1,5 +1,7 @@
package love.distributedrebirth.no2all.react.nostr.server.relay;
import java.util.logging.Logger;
import love.distributedrebirth.no2all.nostr.model.event.NoStrEvent;
import love.distributedrebirth.no2all.nostr.model.event.NoStrEventSignature;
import love.distributedrebirth.no2all.nostr.model.message.NoStrMsgToClientOk;
@ -18,11 +20,13 @@ import love.distributedrebirth.no2all.react.wire.server.No2AllRtsServer;
public class NoStrRtsServerRelay implements No2AllReactTypeScript {
public static final No2AllReactSlot API = No2AllReactSlot.ofClass(NoStrRtsServerRelay.class);
private static final Logger logger = Logger.getLogger(NoStrRtsServerRelay.class.getName());
@Override
public void onEvent(No2AllReactSlotSignal<No2AllReactSlotLoad> signal) {
No2AllReact react = signal.getReact();
react.claim(API);
react.claimOut(API, NoStrArtServerRelayStoreEvent.class);
react.requireSlot(API, NoStrRtsServer.API);
react.registrate(No2AllRtsServer.API, No2AllArtServer.class, artServer -> {
No2AllReactSlot serverSlot = artServer.getData().getSlot();
@ -50,7 +54,7 @@ public class NoStrRtsServerRelay implements No2AllReactTypeScript {
eventReason = NoStrImplMessageOkReason.INVALID;
}
System.out.println("Validate event: " + eventSaved + " eventId: " + event.getId());
logger.fine("Validate event: " + eventSaved + " eventId: " + event.getId());
if (eventSaved) {

View file

@ -10,7 +10,7 @@ import love.distributedrebirth.no2all.nostr.fire.NoStrFireWaterBoiler;
import love.distributedrebirth.no2all.nostr.model.NoStrIdentity;
import love.distributedrebirth.no2all.nostr.model.NoStrIdentityPrivateKey;
import love.distributedrebirth.no2all.nostr.model.event.NoStrEvent;
import love.distributedrebirth.no2all.nostr.model.message.NoStrMsgToRelayClose;
import love.distributedrebirth.no2all.nostr.model.message.NoStrMsgToRelayEvent;
import love.distributedrebirth.no2all.nostr.nip.NoStrImplEventKind;
import love.distributedrebirth.no2all.react.No2AllReactSlot;
import love.distributedrebirth.no2all.react.warp.No2AllReactWarpCore;
@ -21,18 +21,17 @@ import love.distributedrebirth.no2all.react.wire.client.No2AllActClientConnect;
import love.distributedrebirth.no2all.react.wire.client.No2AllArtClient;
import love.distributedrebirth.no2all.react.wire.client.No2AllArtClientOnClose;
import love.distributedrebirth.no2all.react.wire.client.No2AllArtClientOnError;
import love.distributedrebirth.no2all.react.wire.client.No2AllArtClientOnMessage;
import love.distributedrebirth.no2all.react.wire.client.No2AllArtClientOnOpen;
import love.distributedrebirth.no2all.react.wire.client.No2AllArtClientOnStart;
import love.distributedrebirth.no2all.react.wire.client.No2AllRtsClient;
import love.distributedrebirth.no2all.wire.ojw.OjwWireClientEndpoint;
public class NoStrClientTest {
private final static NoStrIdentity SENDER = new NoStrIdentity(NoStrIdentityPrivateKey.ofRandom());
// private final static Map<String, String> RELAYS = Map.of("brb", "brb.io",
// "damus", "relay.damus.io", "ZBD", "nostr.zebedee.cloud", "taxi",
// "relay.taxi", "vision", "relay.nostr.vision");
public static void main(String[] args) throws Exception {
ExecutorService executor = Executors.newFixedThreadPool(10);
NoStrIdentity nid = new NoStrIdentity(NoStrIdentityPrivateKey.ofRandom());
No2AllReactWarpCore react = new No2AllReactWarpCore();
react.load(new No2AllRtsWarpSpeedMonitor());
react.load(new No2AllRtsClient());
@ -40,35 +39,55 @@ public class NoStrClientTest {
react.registrate(No2AllRtsClient.API, No2AllArtClient.class, v -> {
No2AllReactSlot clientSlot = v.getData().getSlot();
System.out.println("NoStrClient connect");
System.out.println("NoStrClient created: " + clientSlot.getSlotPath());
react.registrate(clientSlot, No2AllArtClientOnError.class, x -> {
System.out.println("NoStrClient socket error: " + x.getData().getError().getMessage());
});
react.registrate(clientSlot, No2AllArtClientOnClose.class, x -> {
System.out.println("NoStrClient socket close");
System.out.println("NoStrClient socket close: " + x.getData().getCode() + " " + x.getData().getReason());
});
react.registrate(clientSlot, No2AllArtClientOnOpen.class, x -> {
System.out.println("NoStrClient socket open");
react.fire(clientSlot, new NoStrMsgToRelayClose("give-me-error"));
executor.submit(() -> {
try {
for (int i = 0; i < 10; i++) {
NoStrFireWaterBoiler userBoiler = NoStr.FACTORY.boiler(nid);
NoStrEvent event = userBoiler.smoker()
.tagSubject("Reply to all")
.tagR("")
.burn()
.water(NoStrImplEventKind.TEXT_NOTE, "Hello world:"+i);
System.out.println("send msg");
NoStrMsgToRelayEvent msg = new NoStrMsgToRelayEvent(event);
react.fire(clientSlot, msg);
Thread.sleep(1000);
}
} catch (Exception ex) {
ex.printStackTrace();
}
});
});
react.registrate(clientSlot, No2AllArtClientOnMessage.class, y -> {
System.out.println("NoStrClient got msg1: " + y.getData().getMessage());
});
// Todo "OnStart" is not working...
react.registrate(clientSlot, No2AllArtClientOnStart.class, x -> {
System.out.println("NoStrClient socket start");
});
react.fire(clientSlot, new No2AllActClientConnect());
});
OjwWireClientEndpoint clientEndpoint = new OjwWireClientEndpoint(new URI("ws://localhost:8080"));
OjwWireClientEndpoint clientEndpoint = new OjwWireClientEndpoint(new URI("ws://localhost:8080/event"));
System.out.println("NoStrClient start");
react.fire(No2AllRtsClient.API, new No2AllActClient(clientEndpoint));
OjwWireClientEndpoint clientEndpoint2 = new OjwWireClientEndpoint(new URI("ws://localhost:8080"));
System.out.println("NoStrClient start2");
react.fire(No2AllRtsClient.API, new No2AllActClient(clientEndpoint2));
for (int i = 0; i < 100; i++) {
react.fire(No2AllRtsClient.API, SENDER);
Thread.sleep(100);
}
Thread.sleep(500);
Thread.sleep(30000);
executor.shutdown();
executor.awaitTermination(60, TimeUnit.SECONDS);
Thread exitTimer = new Thread(() -> {
try {
Thread.sleep(2000);
@ -82,29 +101,4 @@ public class NoStrClientTest {
});
exitTimer.start();
}
public static void main2(String[] args) throws Exception {
ExecutorService executor = Executors.newFixedThreadPool(10);
executor.submit(() -> {
try {
NoStrFireWaterBoiler userBoiler = NoStr.FACTORY.boiler(SENDER);
NoStrEvent event = userBoiler.smoker()
.tagSubject("Reply to all")
.tagR("")
.burn()
.water(NoStrImplEventKind.TEXT_NOTE, "Hello world");
System.out.println(event);
// GenericMessage message = new EventMessage(event);
// CLIENT.send(message);
} catch (Exception ex) {
ex.printStackTrace();
}
});
executor.shutdown();
executor.awaitTermination(60, TimeUnit.SECONDS);
}
}