Skip to content

Commit

Permalink
Separate testbed fch and local ws
Browse files Browse the repository at this point in the history
  • Loading branch information
zjkmxy committed Mar 4, 2024
1 parent c4f3189 commit 7511af2
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 181 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@ndn/sync": "https://ndnts-nightly.ndn.today/sync.tgz",
"@ndn/tlv": "https://ndnts-nightly.ndn.today/tlv.tgz",
"@ndn/util": "https://ndnts-nightly.ndn.today/util.tgz",
"@ndn/web-bluetooth-transport": "https://ndnts-nightly.ndn.today/web-bluetooth-transport.tgz",
"@ndn/ws-transport": "https://ndnts-nightly.ndn.today/ws-transport.tgz",
"@pdfslick/solid": "^1.3.0",
"@reactivedata/reactive": "^0.2.2",
Expand Down Expand Up @@ -74,6 +75,7 @@
"@types/diff": "^5.0.9",
"@types/qrcode": "^1.5.5",
"@types/uuid": "^9.0.8",
"@types/web-bluetooth": "^0.0.20",
"@types/wicg-file-system-access": "^2023.10.4",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
Expand Down
57 changes: 39 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,33 @@ function App() {
const configToDescription = () => {
const config = currentConnConfig()
if (!config) {
return <div>Finding closest NDN forwarder</div>
return <div>Not connected yet</div>
} else if (config.kind === 'peerJs') {
return (
<div>
<div>Connected to PeerJS</div>
<div style={{ 'font-weight': 300 }}>{config.host}</div>
</div>
)
} else {
} else if (config.kind === 'nfdWs') {
return (
<div>
<div>Connected to NDN forwarder</div>
<div style={{ 'font-weight': 300 }}>{config.uri}</div>
</div>
)
} else if (config.kind === 'ble') {
return (
<div>
<div>Connected to YaNFD via BLE (Web Bluetooth)</div>
</div>
)
} else if (config.kind === 'testbed') {
return (
<div>
<div>Connected to NDN Testbed</div>
</div>
)
}
}

Expand Down
31 changes: 7 additions & 24 deletions src/Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import * as main from './backend/main'
import { type Certificate } from '@ndn/keychain'
import { type Theme, type Breakpoint } from '@suid/material/styles'
import { Endpoint } from '@ndn/endpoint'
import { doFch } from './testbed'
import { loadAll } from './backend/models/connections'
import { Workspace } from '@ucla-irl/ndnts-aux/workspace'
import toast from 'solid-toast'

type ContextType = {
rootDoc: Accessor<RootDocStore | undefined>
Expand Down Expand Up @@ -131,29 +129,14 @@ export async function initTestbed() {
return // already connected or connecting
}

const url = await doFch()
if (url === null) {
toast.error('Failed to connect to the NDN testbed. Please try again later.')
throw new Error('Failed to connect to testbed.')
}
toast.success('Located closest forwarder')

// Attempt to get a config for nfdWs
// Attempt to connect
const configs = await loadAll()
for (const config of configs) {
if (config.kind !== 'nfdWs') continue

// Found a config, connect to it
// TODO: make sure this is a testbed forwarder
// TODO: prefer local forwarders if any configured
ctx.connectFuncs.connect({
...config,
// NOTE: No guarantee that this uri is testbed. Need explicit specification.
// uri: url.toString(),
})

// TODO: break on success only
// TODO: remove config if connection fails?
break
if (config.kind !== 'testbed') continue
ctx.connectFuncs.connect(config)
return
}
// for (const config of configs) {
// if (config.kind !== 'nfdWs') continue
// }
}
Loading

0 comments on commit 7511af2

Please sign in to comment.