- {stats.info.supported_nips.map(a => (
+ {stats.Info?.supported_nips?.map(a => (
- {stats?.activeRequests.map(a => (
+ {[...(stats?.ActiveRequests ?? [])].map(a => (
{a}
@@ -97,9 +97,9 @@ const RelayInfo = () => {
- {stats?.pendingRequests.map(a => (
-
- {a}
+ {stats?.PendingRequests?.map(a => (
+
+ {a.obj[1]}
))}
@@ -107,7 +107,7 @@ const RelayInfo = () => {
{
- removeRelay(login, unwrap(conn).address);
+ removeRelay(login, unwrap(conn).Address);
navigate("/settings/relays");
}}>
diff --git a/packages/app/src/Pages/settings/Relays.tsx b/packages/app/src/Pages/settings/Relays.tsx
index d6a095a6..43ea43bf 100644
--- a/packages/app/src/Pages/settings/Relays.tsx
+++ b/packages/app/src/Pages/settings/Relays.tsx
@@ -21,7 +21,7 @@ const RelaySettingsPage = () => {
const [newRelay, setNewRelay] = useState
();
const otherConnections = useMemo(() => {
- return system.Sockets.filter(a => relays.item[a.address] === undefined);
+ return [...system.pool].filter(([k]) => relays.item[k] === undefined).map(([, v]) => v);
}, [relays]);
const handleNewRelayChange = (event: React.ChangeEvent) => {
@@ -83,7 +83,7 @@ const RelaySettingsPage = () => {
{otherConnections.map(a => (
-
+
))}
diff --git a/packages/app/src/Utils/Login/Functions.ts b/packages/app/src/Utils/Login/Functions.ts
index f92bbd30..078cac50 100644
--- a/packages/app/src/Utils/Login/Functions.ts
+++ b/packages/app/src/Utils/Login/Functions.ts
@@ -23,9 +23,9 @@ import { SubscriptionEvent } from "@/Utils/Subscription";
import { Nip7OsSigner } from "./Nip7OsSigner";
export function setRelays(state: LoginSession, relays: Record
, createdAt: number) {
- if (SINGLE_RELAY) {
+ if (import.meta.env.VITE_SINGLE_RELAY) {
state.relays.item = {
- [SINGLE_RELAY]: { read: true, write: true },
+ [import.meta.env.VITE_SINGLE_RELAY]: { read: true, write: true },
};
state.relays.timestamp = 100;
LoginStore.updateSession(state);
diff --git a/packages/app/src/Utils/Login/MultiAccountStore.ts b/packages/app/src/Utils/Login/MultiAccountStore.ts
index c6f32742..dacd3976 100644
--- a/packages/app/src/Utils/Login/MultiAccountStore.ts
+++ b/packages/app/src/Utils/Login/MultiAccountStore.ts
@@ -183,7 +183,7 @@ export class MultiAccountStore extends ExternalStore {
}
decideInitRelays(relays: Record | undefined): Record {
- if (SINGLE_RELAY) return { [SINGLE_RELAY]: { read: true, write: true } };
+ if (import.meta.env.VITE_SINGLE_RELAY) return { [import.meta.env.VITE_SINGLE_RELAY]: { read: true, write: true } };
if (relays && Object.keys(relays).length > 0) {
return relays;
}
diff --git a/packages/app/src/Utils/Zapper.ts b/packages/app/src/Utils/Zapper.ts
index 0005f51b..57fc423a 100644
--- a/packages/app/src/Utils/Zapper.ts
+++ b/packages/app/src/Utils/Zapper.ts
@@ -104,7 +104,7 @@ export class Zapper {
if (!svc) {
throw new Error(`Failed to get invoice from ${t.value}`);
}
- const relays = this.system.Sockets.filter(a => !a.ephemeral).map(v => v.address);
+ const relays = [...this.system.pool].filter(([, v]) => !v.Ephemeral).map(([k]) => k);
const pub = t.zap?.anon ?? false ? EventPublisher.privateKey(generateRandomKey().privateKey) : this.publisher;
const zap =
t.zap && svc.canZap
@@ -199,7 +199,7 @@ export class Zapper {
await svc.load();
return svc;
} else if (t.type === "pubkey") {
- const profile = await this.system.ProfileLoader.fetchProfile(t.value);
+ const profile = await this.system.profileLoader.fetch(t.value);
if (profile) {
const svc = new LNURL(profile.lud16 ?? profile.lud06 ?? "");
await svc.load();
diff --git a/packages/app/vite.config.ts b/packages/app/vite.config.ts
index 3747bc0f..3b808780 100644
--- a/packages/app/vite.config.ts
+++ b/packages/app/vite.config.ts
@@ -60,7 +60,6 @@ export default defineConfig({
define: {
CONFIG: JSON.stringify(appConfig),
global: {}, // needed for custom-event lib
- SINGLE_RELAY: JSON.stringify(process.env.SINGLE_RELAY),
},
test: {
globals: true,
diff --git a/packages/system/package.json b/packages/system/package.json
index ee6764ab..8f3606b9 100644
--- a/packages/system/package.json
+++ b/packages/system/package.json
@@ -20,7 +20,7 @@
"@jest/globals": "^29.5.0",
"@peculiar/webcrypto": "^1.4.3",
"@types/debug": "^4.1.8",
- "@types/jest": "^29.5.1",
+ "@types/jest": "^29.5.11",
"@types/lokijs": "^1.5.14",
"@types/node": "^20.5.9",
"@types/uuid": "^9.0.2",
diff --git a/packages/system/src/connection-pool.ts b/packages/system/src/connection-pool.ts
index bf99ea7c..e7a6e9f8 100644
--- a/packages/system/src/connection-pool.ts
+++ b/packages/system/src/connection-pool.ts
@@ -2,7 +2,7 @@ import { removeUndefined, sanitizeRelayUrl, unwrap } from "@snort/shared";
import debug from "debug";
import EventEmitter from "eventemitter3";
-import { Connection, ConnectionStateSnapshot, RelaySettings } from "./connection";
+import { Connection, RelaySettings } from "./connection";
import { NostrEvent, OkResponse, TaggedNostrEvent } from "./nostr";
import { pickRelaysForReply } from "./outbox-model";
import { SystemInterface } from ".";
@@ -18,7 +18,6 @@ export interface NostrConnectionPoolEvents {
}
export type ConnectionPool = {
- getState(): ConnectionStateSnapshot[];
getConnection(id: string): Connection | undefined;
connect(address: string, options: RelaySettings, ephemeral: boolean): Promise;
disconnect(address: string): void;
@@ -45,13 +44,6 @@ export class DefaultConnectionPool extends EventEmitter a.takeSnapshot());
- }
-
/**
* Get a connection object from the pool
*/
@@ -81,7 +73,7 @@ export class DefaultConnectionPool extends EventEmitter this.emit("disconnect", addr, code));
c.on("connected", r => this.emit("connected", addr, r));
c.on("auth", (cx, r, cb) => this.emit("auth", addr, cx, r, cb));
- await c.Connect();
+ await c.connect();
return c;
} else {
// update settings if already connected
@@ -107,7 +99,7 @@ export class DefaultConnectionPool extends EventEmitter {
try {
- const rsp = await s.SendAsync(ev);
+ const rsp = await s.sendEventAsync(ev);
cb?.(rsp);
return rsp;
} catch (e) {
@@ -145,7 +137,7 @@ export class DefaultConnectionPool extends EventEmitter((resolve, reject) => {
const c = new Connection(address, { write: true, read: true }, true);
@@ -153,11 +145,11 @@ export class DefaultConnectionPool extends EventEmitter {
clearTimeout(t);
- const rsp = await c.SendAsync(ev);
- c.Close();
+ const rsp = await c.sendEventAsync(ev);
+ c.close();
resolve(rsp);
});
- c.Connect();
+ c.connect();
});
}
}
diff --git a/packages/system/src/connection.ts b/packages/system/src/connection.ts
index 120ff048..96a21e93 100644
--- a/packages/system/src/connection.ts
+++ b/packages/system/src/connection.ts
@@ -5,11 +5,11 @@ import { unixNowMs, dedupe } from "@snort/shared";
import EventEmitter from "eventemitter3";
import { DefaultConnectTimeout } from "./const";
-import { ConnectionStats } from "./connection-stats";
import { NostrEvent, OkResponse, ReqCommand, ReqFilter, TaggedNostrEvent, u256 } from "./nostr";
import { RelayInfo } from "./relay-info";
import EventKind from "./event-kind";
import { EventExt } from "./event-ext";
+import { NegentropyFlow } from "./negentropy/negentropy-flow";
/**
* Relay settings
@@ -19,28 +19,8 @@ export interface RelaySettings {
write: boolean;
}
-/**
- * Snapshot of connection stats
- */
-export interface ConnectionStateSnapshot {
- connected: boolean;
- disconnects: number;
- avgLatency: number;
- events: {
- received: number;
- send: number;
- };
- settings?: RelaySettings;
- info?: RelayInfo;
- pendingRequests: Array;
- activeRequests: Array;
- id: string;
- ephemeral: boolean;
- address: string;
-}
-
interface ConnectionEvents {
- change: (snapshot: ConnectionStateSnapshot) => void;
+ change: () => void;
connected: (wasReconnect: boolean) => void;
event: (sub: string, e: TaggedNostrEvent) => void;
eose: (sub: string) => void;
@@ -48,6 +28,13 @@ interface ConnectionEvents {
disconnect: (code: number) => void;
auth: (challenge: string, relay: string, cb: (ev: NostrEvent) => void) => void;
notice: (msg: string) => void;
+ unknownMessage: (obj: Array) => void;
+}
+
+export type SyncCommand = ["SYNC", id: string, fromSet: Array, ...filters: Array];
+interface ConnectionQueueItem {
+ obj: ReqCommand | SyncCommand;
+ cb: () => void;
}
export class Connection extends EventEmitter {
@@ -58,20 +45,16 @@ export class Connection extends EventEmitter {
#ephemeral: boolean;
Id: string;
- Address: string;
+ readonly Address: string;
Socket: WebSocket | null = null;
PendingRaw: Array