From a1ca8b4ce26efeb16227df18ecc29dee090db923 Mon Sep 17 00:00:00 2001 From: koalasat Date: Tue, 13 May 2025 12:29:04 +0200 Subject: [PATCH] Fix nodeapp nostr relay --- .../TradeBox/EncryptedChat/index.tsx | 8 ++- frontend/src/models/Coordinator.model.ts | 8 ++- frontend/src/models/Federation.model.ts | 11 ++- frontend/src/services/RoboPool/index.ts | 9 ++- frontend/static/locales/es.json | 2 +- nodeapp/coordinators/bazaar/locations.conf | 70 +++++++++++++++++++ nodeapp/coordinators/bazaar/upstreams.conf | 9 +++ nodeapp/coordinators/lake/locations.conf | 7 +- nodeapp/coordinators/moon/locations.conf | 7 +- nodeapp/coordinators/temple/locations.conf | 7 +- nodeapp/coordinators/veneto/locations.conf | 7 +- nodeapp/nginx.conf | 4 ++ nodeapp/robosats-client.sh | 14 +++- 13 files changed, 143 insertions(+), 20 deletions(-) create mode 100644 nodeapp/coordinators/bazaar/locations.conf create mode 100644 nodeapp/coordinators/bazaar/upstreams.conf diff --git a/frontend/src/components/TradeBox/EncryptedChat/index.tsx b/frontend/src/components/TradeBox/EncryptedChat/index.tsx index d357a713..9e2669dd 100644 --- a/frontend/src/components/TradeBox/EncryptedChat/index.tsx +++ b/frontend/src/components/TradeBox/EncryptedChat/index.tsx @@ -8,6 +8,7 @@ import { FederationContext, type UseFederationStoreType, } from '../../../contexts/FederationContext'; +import { AppContext, UseAppStoreType } from '../../../contexts/AppContext'; interface Props { order: Order; @@ -42,13 +43,16 @@ const EncryptedChat: React.FC = ({ status, }: Props): React.JSX.Element => { const [turtleMode, setTurtleMode] = useState(false); + const { hostUrl, settings } = useContext(AppContext); const { garage } = useContext(GarageContext); const { federation } = useContext(FederationContext); useEffect(() => { // const slot = garage.getSlot(); 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); // since.setDate(since.getDate() - 2); @@ -79,7 +83,7 @@ const EncryptedChat: React.FC = ({ const recipient = { 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); diff --git a/frontend/src/models/Coordinator.model.ts b/frontend/src/models/Coordinator.model.ts index f36de2f8..3ae5e6b8 100644 --- a/frontend/src/models/Coordinator.model.ts +++ b/frontend/src/models/Coordinator.model.ts @@ -304,8 +304,12 @@ export class Coordinator { } }; - getRelayUrl = (): string => { - return `ws://${this.url.replace(/^https?:\/\//, '')}/nostr`; + getRelayUrl = (network: 'mainnet' | 'testnet', hostUrl: string, selfHosted: boolean): string => { + if (selfHosted && this.shortAlias !== 'local') { + return `ws://${hostUrl.replace(/^https?:\/\//, '')}/${network}/${this.shortAlias}/relay`; + } else { + return `ws://${this.url.replace(/^https?:\/\//, '')}/relay`; + } }; } diff --git a/frontend/src/models/Federation.model.ts b/frontend/src/models/Federation.model.ts index dcee2483..23cc1762 100644 --- a/frontend/src/models/Federation.model.ts +++ b/frontend/src/models/Federation.model.ts @@ -65,7 +65,7 @@ export class Federation { if (tesnetHost) settings.network = 'testnet'; 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; @@ -163,8 +163,13 @@ export class Federation { updateUrl = async (origin: Origin, settings: Settings, hostUrl: string): Promise => { const federationUrls = {}; for (const coor of Object.values(this.coordinators)) { - coor.updateUrl(origin, settings, hostUrl); - federationUrls[coor.shortAlias] = coor.url; + const { url, basePath } = coor.getEndpoint( + settings.network, + origin, + settings.selfhostedClient, + hostUrl, + ); + federationUrls[coor.shortAlias] = url + basePath; } systemClient.setCookie('federation', JSON.stringify(federationUrls)); }; diff --git a/frontend/src/services/RoboPool/index.ts b/frontend/src/services/RoboPool/index.ts index d21a288c..65738fff 100644 --- a/frontend/src/services/RoboPool/index.ts +++ b/frontend/src/services/RoboPool/index.ts @@ -10,18 +10,21 @@ interface RoboPoolEvents { } class RoboPool { - constructor(settings: Settings, coordinators: Coordinator[]) { + constructor(settings: Settings, hostUrl: string, coordinators: Coordinator[]) { this.network = settings.network ?? 'mainnet'; this.relays = []; - const federationRelays = coordinators.map((coord) => coord.getRelayUrl()); + const federationRelays = coordinators.map((coord) => + coord.getRelayUrl(settings.network, hostUrl, settings.selfhostedClient), + ); if (settings.host) { - const hostNostr = `ws://${settings.host.replace(/^https?:\/\//, '')}/nostr`; + const hostNostr = `ws://${settings.host.replace(/^https?:\/\//, '')}/relay`; if (federationRelays.includes(hostNostr)) { this.relays.push(hostNostr); } } + while (this.relays.length < 3) { const randomRelay = federationRelays[Math.floor(Math.random() * Object.keys(federationRelays).length)]; diff --git a/frontend/static/locales/es.json b/frontend/static/locales/es.json index 41a128e5..25629157 100644 --- a/frontend/static/locales/es.json +++ b/frontend/static/locales/es.json @@ -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.", "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", - "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.", "Taking too long?": "¿Tarda demasiado?", "#83": "Phrases in components/TradeBox/Prompts/Successful.tsx", diff --git a/nodeapp/coordinators/bazaar/locations.conf b/nodeapp/coordinators/bazaar/locations.conf new file mode 100644 index 00000000..2285ba55 --- /dev/null +++ b/nodeapp/coordinators/bazaar/locations.conf @@ -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; +} \ No newline at end of file diff --git a/nodeapp/coordinators/bazaar/upstreams.conf b/nodeapp/coordinators/bazaar/upstreams.conf new file mode 100644 index 00000000..f3a16450 --- /dev/null +++ b/nodeapp/coordinators/bazaar/upstreams.conf @@ -0,0 +1,9 @@ +# Libre Bazaar Coordinator Mainnet +upstream mainnet_bazaar { + server localhost:107; +} + +# Libre Bazaar Coordinator Testnet +upstream testnet_bazaar { + server localhost:1007; +} \ No newline at end of file diff --git a/nodeapp/coordinators/lake/locations.conf b/nodeapp/coordinators/lake/locations.conf index 8c91b44a..082a0d06 100644 --- a/nodeapp/coordinators/lake/locations.conf +++ b/nodeapp/coordinators/lake/locations.conf @@ -37,12 +37,15 @@ location /mainnet/lake/ws/ { proxy_set_header Host $host; } -location /mainnet/lake/nostr/ { - proxy_pass http://mainnet_lake/nostr/; +location /mainnet/lake/relay/ { + proxy_pass http://mainnet_lake/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 *; } # TheBigLake Coordinator Testnet Locations diff --git a/nodeapp/coordinators/moon/locations.conf b/nodeapp/coordinators/moon/locations.conf index 7156cdbd..9d1389ad 100644 --- a/nodeapp/coordinators/moon/locations.conf +++ b/nodeapp/coordinators/moon/locations.conf @@ -37,12 +37,15 @@ location /mainnet/moon/ws/ { proxy_set_header Host $host; } -location /mainnet/moon/nostr/ { - proxy_pass http://mainnet_moon/nostr/; +location /mainnet/moon/relay/ { + proxy_pass http://mainnet_moon/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 *; } # Over the Moon Coordinator Testnet Locations diff --git a/nodeapp/coordinators/temple/locations.conf b/nodeapp/coordinators/temple/locations.conf index 6f28cd9c..d1f70e8c 100644 --- a/nodeapp/coordinators/temple/locations.conf +++ b/nodeapp/coordinators/temple/locations.conf @@ -37,12 +37,15 @@ location /mainnet/temple/ws/ { proxy_set_header Host $host; } -location /mainnet/temple/nostr/ { - proxy_pass http://mainnet_temple/nostr/; +location /mainnet/temple/relay/ { + proxy_pass http://mainnet_temple/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 *; } # Temple of Sats Coordinator Testnet Locations diff --git a/nodeapp/coordinators/veneto/locations.conf b/nodeapp/coordinators/veneto/locations.conf index d5b38738..f5094914 100644 --- a/nodeapp/coordinators/veneto/locations.conf +++ b/nodeapp/coordinators/veneto/locations.conf @@ -37,12 +37,15 @@ location /mainnet/veneto/ws/ { proxy_set_header Host $host; } -location /mainnet/veneto/nostr/ { - proxy_pass http://mainnet_veneto/nostr/; +location /mainnet/veneto/relay/ { + proxy_pass http://mainnet_veneto/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 diff --git a/nodeapp/nginx.conf b/nodeapp/nginx.conf index 612ebe21..9a3ab96e 100644 --- a/nodeapp/nginx.conf +++ b/nodeapp/nginx.conf @@ -36,6 +36,8 @@ http { include /etc/nginx/conf.d/veneto/upstreams.conf; # Over the Moon include /etc/nginx/conf.d/moon/upstreams.conf; + # Libre Bazaar + include /etc/nginx/conf.d/bazaar/upstreams.conf; server { @@ -76,6 +78,8 @@ http { include /etc/nginx/conf.d/veneto/locations.conf; # Over the Moon 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" location /selfhosted { diff --git a/nodeapp/robosats-client.sh b/nodeapp/robosats-client.sh index 98fa7fed..45c4b985 100644 --- a/nodeapp/robosats-client.sh +++ b/nodeapp/robosats-client.sh @@ -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}" 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! -$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 \ No newline at end of file +$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 \ No newline at end of file