Fix nodeapp nostr relay

This commit is contained in:
koalasat
2025-05-13 12:29:04 +02:00
parent 477c4960d6
commit a1ca8b4ce2
13 changed files with 143 additions and 20 deletions

View File

@ -8,6 +8,7 @@ import {
FederationContext, FederationContext,
type UseFederationStoreType, type UseFederationStoreType,
} from '../../../contexts/FederationContext'; } from '../../../contexts/FederationContext';
import { AppContext, UseAppStoreType } from '../../../contexts/AppContext';
interface Props { interface Props {
order: Order; order: Order;
@ -42,13 +43,16 @@ const EncryptedChat: React.FC<Props> = ({
status, status,
}: Props): React.JSX.Element => { }: Props): React.JSX.Element => {
const [turtleMode, setTurtleMode] = useState<boolean>(false); const [turtleMode, setTurtleMode] = useState<boolean>(false);
const { hostUrl, settings } = useContext<UseAppStoreType>(AppContext);
const { garage } = useContext<UseGarageStoreType>(GarageContext); const { garage } = useContext<UseGarageStoreType>(GarageContext);
const { federation } = useContext<UseFederationStoreType>(FederationContext); const { federation } = useContext<UseFederationStoreType>(FederationContext);
useEffect(() => { useEffect(() => {
// const slot = garage.getSlot(); // const slot = garage.getSlot();
const coordinator = federation.getCoordinator(order.shortAlias); const coordinator = federation.getCoordinator(order.shortAlias);
federation.roboPool.connect([coordinator.getRelayUrl()]); federation.roboPool.connect([
coordinator.getRelayUrl(settings.network, hostUrl, settings.selfhostedClient),
]);
// const since = new Date(order.created_at); // const since = new Date(order.created_at);
// since.setDate(since.getDate() - 2); // since.setDate(since.getDate() - 2);
@ -79,7 +83,7 @@ const EncryptedChat: React.FC<Props> = ({
const recipient = { const recipient = {
publicKey: order.is_maker ? order.taker_nostr_pubkey : order.maker_nostr_pubkey, publicKey: order.is_maker ? order.taker_nostr_pubkey : order.maker_nostr_pubkey,
relayUrl: coordinator.getRelayUrl(), relayUrl: coordinator.getRelayUrl(settings.network, hostUrl, settings.selfhostedClient),
}; };
const wrappedEvent = nip17.wrapEvent(slot?.nostrSecKey, recipient, content); const wrappedEvent = nip17.wrapEvent(slot?.nostrSecKey, recipient, content);

View File

@ -304,8 +304,12 @@ export class Coordinator {
} }
}; };
getRelayUrl = (): string => { getRelayUrl = (network: 'mainnet' | 'testnet', hostUrl: string, selfHosted: boolean): string => {
return `ws://${this.url.replace(/^https?:\/\//, '')}/nostr`; if (selfHosted && this.shortAlias !== 'local') {
return `ws://${hostUrl.replace(/^https?:\/\//, '')}/${network}/${this.shortAlias}/relay`;
} else {
return `ws://${this.url.replace(/^https?:\/\//, '')}/relay`;
}
}; };
} }

View File

@ -65,7 +65,7 @@ export class Federation {
if (tesnetHost) settings.network = 'testnet'; if (tesnetHost) settings.network = 'testnet';
this.connection = null; this.connection = null;
this.roboPool = new RoboPool(settings, Object.values(this.coordinators)); this.roboPool = new RoboPool(settings, hostUrl, Object.values(this.coordinators));
} }
private coordinators: Record<string, Coordinator>; private coordinators: Record<string, Coordinator>;
@ -163,8 +163,13 @@ export class Federation {
updateUrl = async (origin: Origin, settings: Settings, hostUrl: string): Promise<void> => { updateUrl = async (origin: Origin, settings: Settings, hostUrl: string): Promise<void> => {
const federationUrls = {}; const federationUrls = {};
for (const coor of Object.values(this.coordinators)) { for (const coor of Object.values(this.coordinators)) {
coor.updateUrl(origin, settings, hostUrl); const { url, basePath } = coor.getEndpoint(
federationUrls[coor.shortAlias] = coor.url; settings.network,
origin,
settings.selfhostedClient,
hostUrl,
);
federationUrls[coor.shortAlias] = url + basePath;
} }
systemClient.setCookie('federation', JSON.stringify(federationUrls)); systemClient.setCookie('federation', JSON.stringify(federationUrls));
}; };

View File

@ -10,18 +10,21 @@ interface RoboPoolEvents {
} }
class RoboPool { class RoboPool {
constructor(settings: Settings, coordinators: Coordinator[]) { constructor(settings: Settings, hostUrl: string, coordinators: Coordinator[]) {
this.network = settings.network ?? 'mainnet'; this.network = settings.network ?? 'mainnet';
this.relays = []; this.relays = [];
const federationRelays = coordinators.map((coord) => coord.getRelayUrl()); const federationRelays = coordinators.map((coord) =>
coord.getRelayUrl(settings.network, hostUrl, settings.selfhostedClient),
);
if (settings.host) { if (settings.host) {
const hostNostr = `ws://${settings.host.replace(/^https?:\/\//, '')}/nostr`; const hostNostr = `ws://${settings.host.replace(/^https?:\/\//, '')}/relay`;
if (federationRelays.includes(hostNostr)) { if (federationRelays.includes(hostNostr)) {
this.relays.push(hostNostr); this.relays.push(hostNostr);
} }
} }
while (this.relays.length < 3) { while (this.relays.length < 3) {
const randomRelay = const randomRelay =
federationRelays[Math.floor(Math.random() * Object.keys(federationRelays).length)]; federationRelays[Math.floor(Math.random() * Object.keys(federationRelays).length)];

View File

@ -665,7 +665,7 @@
"RoboSats will try to pay your invoice 3 times with a one minute pause in between. If it keeps failing, you will be able to submit a new invoice. Check whether you have enough inbound liquidity. Remember that lightning nodes must be online in order to receive payments.": "RoboSats intentará pagar tu factura 3 veces con una pausa de un minuto entre cada intento. Si sigue fallando, podrás presentar una nueva factura. Comprueba si tienes suficiente liquidez entrante. Recuerda que los nodos de Lightning tienen que estar en línea para poder recibir pagos.", "RoboSats will try to pay your invoice 3 times with a one minute pause in between. If it keeps failing, you will be able to submit a new invoice. Check whether you have enough inbound liquidity. Remember that lightning nodes must be online in order to receive payments.": "RoboSats intentará pagar tu factura 3 veces con una pausa de un minuto entre cada intento. Si sigue fallando, podrás presentar una nueva factura. Comprueba si tienes suficiente liquidez entrante. Recuerda que los nodos de Lightning tienen que estar en línea para poder recibir pagos.",
"Your invoice has expired or more than 3 payment attempts have been made. Submit a new invoice.": "Tu factura ha expirado o se han hecho más de 3 intentos de pago. Aporta una nueva factura.", "Your invoice has expired or more than 3 payment attempts have been made. Submit a new invoice.": "Tu factura ha expirado o se han hecho más de 3 intentos de pago. Aporta una nueva factura.",
"#82": "Phrases in components/TradeBox/Prompts/SendingSats.tsx", "#82": "Phrases in components/TradeBox/Prompts/SendingSats.tsx",
"Lightning payments are usually instantaneous, but sometimes a node in the route may be down, which can cause your payout to take up to 24 hours to arrive in your wallet.": "Los pagos lightning normalmente son instantaneos, pero a veces un nodo en la ruta puede estar caído y probocar que tu pago tarde hasta 24 horas e procesarse.", "Lightning payments are usually instantaneous, but sometimes a node in the route may be down, which can cause your payout to take up to 24 hours to arrive in your wallet.": "Los pagos lightning normalmente son instantaneos, pero a veces un nodo en la ruta puede estar caído y provocar que tu pago tarde hasta 24 horas e procesarse.",
"RoboSats is trying to pay your lightning invoice. Remember that lightning nodes must be online in order to receive payments.": "RoboSats está intentando pagar tu factura de Lightning. Recuerda que los nodos Lightning deben estar en línea para recibir pagos.", "RoboSats is trying to pay your lightning invoice. Remember that lightning nodes must be online in order to receive payments.": "RoboSats está intentando pagar tu factura de Lightning. Recuerda que los nodos Lightning deben estar en línea para recibir pagos.",
"Taking too long?": "¿Tarda demasiado?", "Taking too long?": "¿Tarda demasiado?",
"#83": "Phrases in components/TradeBox/Prompts/Successful.tsx", "#83": "Phrases in components/TradeBox/Prompts/Successful.tsx",

View File

@ -0,0 +1,70 @@
# Libre Bazaar Mainnet Locations
location /mainnet/bazaar/static/assets/avatars/ {
proxy_pass http://mainnet_bazaar/static/assets/avatars/;
}
location /mainnet/bazaar/api/ {
# if ($request_method = 'OPTIONS') {
# add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
# add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
# add_header 'Access-Control-Max-Age' 1728000;
# add_header 'Content-Type' 'text/plain; charset=utf-8';
# add_header 'Content-Length' 0;
# return 204;
# }
# if ($request_method = 'POST') {
# add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
# add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
# add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
# }
# if ($request_method = 'GET') {
# add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
# add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
# add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
# }
proxy_pass http://mainnet_bazaar/api/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
location /mainnet/bazaar/ws/ {
proxy_pass http://mainnet_bazaar/ws/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
location /mainnet/bazaar/relay/ {
proxy_pass http://mainnet_bazaar/relay/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Origin $http_origin;
proxy_set_header Host $host;
add_header Access-Control-Allow-Origin *;
}
# BitcoinVeneto Coordinator Testnet Locations
location /test/bazaar/static/assets/avatars/ {
proxy_pass http://testnet_bazaar/static/assets/avatars/;
}
location /testnet/bazaar/api/ {
proxy_pass http://testnet_bazaar/api/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
location /testnet/bazaar/ws/ {
proxy_pass http://testnet_bazaar/ws/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}

View File

@ -0,0 +1,9 @@
# Libre Bazaar Coordinator Mainnet
upstream mainnet_bazaar {
server localhost:107;
}
# Libre Bazaar Coordinator Testnet
upstream testnet_bazaar {
server localhost:1007;
}

View File

@ -37,12 +37,15 @@ location /mainnet/lake/ws/ {
proxy_set_header Host $host; proxy_set_header Host $host;
} }
location /mainnet/lake/nostr/ { location /mainnet/lake/relay/ {
proxy_pass http://mainnet_lake/nostr/; proxy_pass http://mainnet_lake/relay/;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade"; proxy_set_header Connection "Upgrade";
proxy_set_header Origin $http_origin;
proxy_set_header Host $host; proxy_set_header Host $host;
add_header Access-Control-Allow-Origin *;
} }
# TheBigLake Coordinator Testnet Locations # TheBigLake Coordinator Testnet Locations

View File

@ -37,12 +37,15 @@ location /mainnet/moon/ws/ {
proxy_set_header Host $host; proxy_set_header Host $host;
} }
location /mainnet/moon/nostr/ { location /mainnet/moon/relay/ {
proxy_pass http://mainnet_moon/nostr/; proxy_pass http://mainnet_moon/relay/;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade"; proxy_set_header Connection "Upgrade";
proxy_set_header Origin $http_origin;
proxy_set_header Host $host; proxy_set_header Host $host;
add_header Access-Control-Allow-Origin *;
} }
# Over the Moon Coordinator Testnet Locations # Over the Moon Coordinator Testnet Locations

View File

@ -37,12 +37,15 @@ location /mainnet/temple/ws/ {
proxy_set_header Host $host; proxy_set_header Host $host;
} }
location /mainnet/temple/nostr/ { location /mainnet/temple/relay/ {
proxy_pass http://mainnet_temple/nostr/; proxy_pass http://mainnet_temple/relay/;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade"; proxy_set_header Connection "Upgrade";
proxy_set_header Origin $http_origin;
proxy_set_header Host $host; proxy_set_header Host $host;
add_header Access-Control-Allow-Origin *;
} }
# Temple of Sats Coordinator Testnet Locations # Temple of Sats Coordinator Testnet Locations

View File

@ -37,12 +37,15 @@ location /mainnet/veneto/ws/ {
proxy_set_header Host $host; proxy_set_header Host $host;
} }
location /mainnet/veneto/nostr/ { location /mainnet/veneto/relay/ {
proxy_pass http://mainnet_veneto/nostr/; proxy_pass http://mainnet_veneto/relay/;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade"; proxy_set_header Connection "Upgrade";
proxy_set_header Origin $http_origin;
proxy_set_header Host $host; proxy_set_header Host $host;
add_header Access-Control-Allow-Origin *;
} }
# BitcoinVeneto Coordinator Testnet Locations # BitcoinVeneto Coordinator Testnet Locations

View File

@ -36,6 +36,8 @@ http {
include /etc/nginx/conf.d/veneto/upstreams.conf; include /etc/nginx/conf.d/veneto/upstreams.conf;
# Over the Moon # Over the Moon
include /etc/nginx/conf.d/moon/upstreams.conf; include /etc/nginx/conf.d/moon/upstreams.conf;
# Libre Bazaar
include /etc/nginx/conf.d/bazaar/upstreams.conf;
server { server {
@ -76,6 +78,8 @@ http {
include /etc/nginx/conf.d/veneto/locations.conf; include /etc/nginx/conf.d/veneto/locations.conf;
# Over the Moon # Over the Moon
include /etc/nginx/conf.d/moon/locations.conf; include /etc/nginx/conf.d/moon/locations.conf;
# Libre Bazaar
include /etc/nginx/conf.d/bazaar/locations.conf;
# do not log healtchecks made against "/selfhosted" # do not log healtchecks made against "/selfhosted"
location /selfhosted { location /selfhosted {

View File

@ -56,6 +56,18 @@ testnet_moon_port=1006
mainnet_moon_socat="socat tcp4-LISTEN:${mainnet_moon_port},reuseaddr,fork,keepalive,bind=127.0.0.1 SOCKS4A:${TOR_PROXY_IP:-127.0.0.1}:${mainnet_moon_onion}:80,socksport=${TOR_PROXY_PORT:-9050}" mainnet_moon_socat="socat tcp4-LISTEN:${mainnet_moon_port},reuseaddr,fork,keepalive,bind=127.0.0.1 SOCKS4A:${TOR_PROXY_IP:-127.0.0.1}:${mainnet_moon_onion}:80,socksport=${TOR_PROXY_PORT:-9050}"
testnet_moon_socat="socat tcp4-LISTEN:${testnet_moon_port},reuseaddr,fork,keepalive,bind=127.0.0.1 SOCKS4A:${TOR_PROXY_IP:-127.0.0.1}:${testnet_moon_onion}:80,socksport=${TOR_PROXY_PORT:-9050}" testnet_moon_socat="socat tcp4-LISTEN:${testnet_moon_port},reuseaddr,fork,keepalive,bind=127.0.0.1 SOCKS4A:${TOR_PROXY_IP:-127.0.0.1}:${testnet_moon_onion}:80,socksport=${TOR_PROXY_PORT:-9050}"
################################
# Libre Bazaar
# Mainnet
mainnet_bazaar_onion=librebazovfmmkyi2jekraxsuso3mh622avuuzqpejixdl5dhuhb4tid.onion
mainnet_bazaar_port=107
# Testnet
testnet_bazaar_onion=librebazovfmmkyi2jekraxsuso3mh622avuuzqpejixdl5dhuhb4tid.onion
testnet_bazaar_port=1007
# socat cmd
mainnet_bazaar_socat="socat tcp4-LISTEN:${mainnet_bazaar_port},reuseaddr,fork,keepalive,bind=127.0.0.1 SOCKS4A:${TOR_PROXY_IP:-127.0.0.1}:${mainnet_bazaar_port}:80,socksport=${TOR_PROXY_PORT:-9050}"
testnet_bazaar_socat="socat tcp4-LISTEN:${testnet_bazaar_port},reuseaddr,fork,keepalive,bind=127.0.0.1 SOCKS4A:${TOR_PROXY_IP:-127.0.0.1}:${testnet_bazaar_port}:80,socksport=${TOR_PROXY_PORT:-9050}"
# RUN! # RUN!
$mainnet_temple_socat & $testnet_temple_socat & $mainnet_lake_socat & $testnet_lake_socat & $mainnet_veneto_socat & $testnet_veneto_socat & $mainnet_moon_socat & $testnet_moon_socat & nginx $mainnet_temple_socat & $testnet_temple_socat & $mainnet_lake_socat & $testnet_lake_socat & $mainnet_veneto_socat & $testnet_veneto_socat & $mainnet_moon_socat & $testnet_moon_socat & $mainnet_bazaar_socat & $testnet_bazaar_socat & nginx