braidfs 0.0.144 → 0.0.145
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +31 -18
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -223,11 +223,11 @@ async function main() {
|
|
|
223
223
|
res.writeHead(500, { 'Error-Message': '' + e })
|
|
224
224
|
res.end('' + e)
|
|
225
225
|
}
|
|
226
|
-
}).listen(config.port, 'localhost', () => {
|
|
226
|
+
}).listen(config.port, 'localhost', async () => {
|
|
227
227
|
console.log(`daemon started on port ${config.port}`)
|
|
228
228
|
console.log('!! only accessible from localhost !!')
|
|
229
229
|
|
|
230
|
-
sync_url('.braidfs/config')
|
|
230
|
+
await sync_url('.braidfs/config')
|
|
231
231
|
braid_text.get('.braidfs/config', {
|
|
232
232
|
subscribe: async update => {
|
|
233
233
|
let prev = config
|
|
@@ -492,6 +492,7 @@ function sync_url(url) {
|
|
|
492
492
|
} else throw new Error(`unknown merge-type: ${self.merge_type}`)
|
|
493
493
|
})()
|
|
494
494
|
}
|
|
495
|
+
return sync_url.cache[path]
|
|
495
496
|
|
|
496
497
|
async function detect_merge_type() {
|
|
497
498
|
// special case for .braidfs/config and .braidfs/error
|
|
@@ -510,23 +511,35 @@ function sync_url(url) {
|
|
|
510
511
|
var retry_count = 0
|
|
511
512
|
while (true) {
|
|
512
513
|
try {
|
|
513
|
-
var
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
//
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
514
|
+
for (var try_sub = 0; try_sub <= 1; try_sub++) {
|
|
515
|
+
var res = await braid_fetch(url, {
|
|
516
|
+
signal: self.ac.signal,
|
|
517
|
+
method: 'HEAD',
|
|
518
|
+
retry: () => true,
|
|
519
|
+
// braid_fetch will await this function on each reconnect when retrying
|
|
520
|
+
parents: async () => reconnect_rate_limiter.get_turn(url),
|
|
521
|
+
// version needed to force Merge-Type return header
|
|
522
|
+
version: [],
|
|
523
|
+
// setting subscribe shouldn't work according to spec,
|
|
524
|
+
// but it does for some old braid-text servers
|
|
525
|
+
subscribe: !!try_sub,
|
|
526
|
+
headers: {
|
|
527
|
+
// in case it supports dt, so it doesn't give us "simpleton"
|
|
528
|
+
'Merge-Type': 'dt',
|
|
529
|
+
}
|
|
530
|
+
})
|
|
531
|
+
if (self.ac.signal.aborted) return
|
|
527
532
|
|
|
528
|
-
|
|
529
|
-
|
|
533
|
+
var merge_type = res.headers.get('merge-type')
|
|
534
|
+
if (merge_type) {
|
|
535
|
+
// convince the rate limiter to give turns to this host for a bit,
|
|
536
|
+
// but use a fake url so we don't on_diss from the real one
|
|
537
|
+
var fake_url = url + '?merge_type'
|
|
538
|
+
reconnect_rate_limiter.on_conn(fake_url)
|
|
539
|
+
setTimeout(() => reconnect_rate_limiter.on_diss(fake_url), 10 * 1000)
|
|
540
|
+
return merge_type
|
|
541
|
+
}
|
|
542
|
+
}
|
|
530
543
|
} catch (e) {
|
|
531
544
|
if (e.name !== 'AbortError') throw e
|
|
532
545
|
}
|