Skip to content
This repository was archived by the owner on Nov 23, 2022. It is now read-only.

Commit c5563a6

Browse files
committed
fix(relay, ipfs): add fallback wrtc, get peers list with original multiaddr
1 parent fb3cbf4 commit c5563a6

File tree

7 files changed

+34
-17
lines changed

7 files changed

+34
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"prepare": "npm-run-all prepare:hooks",
8989
"prepare:hooks": "husky install",
9090
"release": "standard-version --bumpFiles package.json packages/lib/package.json packages/ipfs/package.json packages/relay/package.json packages/transport/package.json && scripts/publish",
91-
"serve": "nx run-many --all --target=serve"
91+
"serve": "nx run-many --all --verbose --target=serve"
9292
},
9393
"version": "0.2.48",
9494
"workspaces": [

packages/ipfs/src/bootstrap.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,13 @@ export const bootstrap = async (
99
const query = gql`
1010
query Bootstrap($protocol: Protocol!, $hostname: String!, $port: Int!) {
1111
listen(protocol: $protocol, hostname: $hostname, port: $port)
12-
peers(
13-
randomize: true
14-
protocol: $protocol
15-
hostname: $hostname
16-
port: $port
17-
)
12+
peers(randomize: true)
1813
}
1914
`
2015

2116
const { listen, peers } = await request<{
2217
listen: string[];
2318
peers: string[];
24-
namespace: string;
2519
}>(
2620
relay,
2721
query,

packages/relay/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"nexus": "1.3.0",
1717
"prom-client": "14.0.1",
1818
"redis": "4.0.4",
19-
"socket.io": "4.4.1"
19+
"socket.io": "4.4.1",
20+
"wrtc": "^0.4.7"
2021
},
2122
"devDependencies": {
2223
"@types/lru-cache": "^7.6.0",

packages/relay/src/services/stack.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { join } from 'path'
22
import { Stack, Storage } from '@dstack-js/lib'
3-
// @ts-expect-error: no-types
4-
import wrtc from '@dstack-js/wrtc'
53
import LRUCache from 'lru-cache'
64
import { tmpdir } from 'os'
75
import { redis } from './cache'
6+
import { getWRTC } from './wrtc'
87

98
export class RedisStorage<T = { value: string; date: Date }>
109
implements Storage<T> {
@@ -62,8 +61,10 @@ export const getStack = async (namespace: string) => {
6261
cache.set(namespace, 'allocating')
6362
stack = await Stack.create({
6463
namespace,
65-
wrtc,
66-
relay: `http://127.0.0.1:${process.env['PORT'] || 13579}/graphql`,
64+
wrtc: getWRTC(),
65+
relay:
66+
process.env['RELAY_URL'] ||
67+
`http://127.0.0.1:${process.env['PORT'] || 13579}/graphql`,
6768
repo: join(tmpdir(), '.dstack', namespace),
6869
storage: new RedisStorage(namespace)
6970
})
@@ -78,7 +79,8 @@ export const getStack = async (namespace: string) => {
7879
namespace,
7980
error
8081
)
81-
throw error
82+
83+
return null
8284
}
8385
}
8486

packages/relay/src/services/wrtc.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const getWRTC = () => {
2+
try {
3+
return require('wrtc')
4+
} catch (error) {
5+
return require('@dstack-js/wrtc')
6+
}
7+
}

scripts/deploy

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
yarn build
2+
yarn nx build relay
33
cd dist/packages/relay
4-
heroku container:push web -a dstack-relay
5-
heroku container:release web -a dstack-relay
4+
fly deploy --remote-only

yarn.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,6 +2785,7 @@ __metadata:
27852785
socket.io: 4.4.1
27862786
ts-node: 10.7.0
27872787
tsconfig-paths: 3.14.1
2788+
wrtc: ^0.4.7
27882789
bin:
27892790
dstack-relay: src/index.js
27902791
languageName: unknown
@@ -28279,6 +28280,19 @@ __metadata:
2827928280
languageName: node
2828028281
linkType: hard
2828128282

28283+
"wrtc@npm:^0.4.7":
28284+
version: 0.4.7
28285+
resolution: "wrtc@npm:0.4.7"
28286+
dependencies:
28287+
domexception: ^1.0.1
28288+
node-pre-gyp: ^0.13.0
28289+
dependenciesMeta:
28290+
domexception:
28291+
optional: true
28292+
checksum: 2a2ce03ee15e8ee1737a9b8d0937ededc135f06c8e58bb8c3c0d7028e29ef0b75708616d2ce2a1792c08fab24b2f4c51a8f0d52fe3b296d5d7ac31a8d6eeab5c
28293+
languageName: node
28294+
linkType: hard
28295+
2828228296
"ws@npm:^7.3.1, ws@npm:^7.4.6":
2828328297
version: 7.5.7
2828428298
resolution: "ws@npm:7.5.7"

0 commit comments

Comments
 (0)