braidfs 0.0.129 → 0.0.131
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 +106 -4
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -30,6 +30,9 @@ braid_text.db_folder = `${braidfs_config_dir}/braid-text-db`
|
|
|
30
30
|
var trash = `${braidfs_config_dir}/trash`
|
|
31
31
|
var temp_folder = `${braidfs_config_dir}/temp`
|
|
32
32
|
|
|
33
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
34
|
+
var investigating_disconnects_log = `${braidfs_config_dir}/investigating_disconnects.log`
|
|
35
|
+
|
|
33
36
|
var config = null,
|
|
34
37
|
watcher_misses = 0,
|
|
35
38
|
reconnect_rate_limiter = new ReconnectRateLimiter(() =>
|
|
@@ -70,6 +73,13 @@ require('fs').mkdirSync(sync_base_meta, { recursive: true })
|
|
|
70
73
|
require('fs').mkdirSync(trash, { recursive: true })
|
|
71
74
|
require('fs').mkdirSync(temp_folder, { recursive: true })
|
|
72
75
|
|
|
76
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
77
|
+
require('fs').appendFileSync(investigating_disconnects_log, `${Date.now()} -- braidfs starting\n`)
|
|
78
|
+
function do_investigating_disconnects_log(url, message) {
|
|
79
|
+
if (url.match(/^https:\/\/(dt\.)?braid\.org\/hello$/))
|
|
80
|
+
require('fs').appendFileSync(investigating_disconnects_log, `${Date.now()}:${url} -- ${message}\n`)
|
|
81
|
+
}
|
|
82
|
+
|
|
73
83
|
// Add instructions for how to run in the background on this OS
|
|
74
84
|
var to_run_in_background = process.platform === 'darwin' ? `
|
|
75
85
|
To run daemon in background:
|
|
@@ -176,6 +186,9 @@ async function main() {
|
|
|
176
186
|
var version = [sync.peer + "-" + (sync.local_edit_counter - 1)]
|
|
177
187
|
await braid_text.put(sync.url, { version, parents, patches, merge_type: 'dt' })
|
|
178
188
|
|
|
189
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
190
|
+
require('fs').appendFileSync(investigating_disconnects_log, `${Date.now()}:${sync.url} -- plugin edited (${sync.investigating_disconnects_thinks_connected})\n`)
|
|
191
|
+
|
|
179
192
|
// may be able to do this more efficiently.. we want to make sure we're capturing a file write that is after our version was written.. there may be a way we can avoid calling file_needs_writing here
|
|
180
193
|
await new Promise(done => {
|
|
181
194
|
sync.file_written_cbs.push(done)
|
|
@@ -389,6 +402,9 @@ function unsync_url(url) {
|
|
|
389
402
|
|
|
390
403
|
console.log(`unsync_url: ${url}`)
|
|
391
404
|
|
|
405
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
406
|
+
do_investigating_disconnects_log(url, `unsync_url: ${url}`)
|
|
407
|
+
|
|
392
408
|
delete sync_url.cache[url]
|
|
393
409
|
sync_url.chain = sync_url.chain.then(unsync_url.cache[url])
|
|
394
410
|
delete unsync_url.cache[url]
|
|
@@ -407,6 +423,9 @@ async function sync_url(url) {
|
|
|
407
423
|
fullpath = `${sync_base}/${path}`,
|
|
408
424
|
meta_path = `${sync_base_meta}/${braid_text.encode_filename(url)}`
|
|
409
425
|
|
|
426
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
427
|
+
do_investigating_disconnects_log(url, `sync_url`)
|
|
428
|
+
|
|
410
429
|
if (!sync_url.cache) sync_url.cache = {}
|
|
411
430
|
if (!sync_url.chain) sync_url.chain = Promise.resolve()
|
|
412
431
|
if (!sync_url.cache[path]) {
|
|
@@ -444,6 +463,41 @@ async function sync_url(url) {
|
|
|
444
463
|
}
|
|
445
464
|
sync_url.cache[path] = sync_url.chain = sync_url.chain.then(init)
|
|
446
465
|
}
|
|
466
|
+
|
|
467
|
+
async function detect_merge_type() {
|
|
468
|
+
// special case for .braidfs/config and .braidfs/error
|
|
469
|
+
if (url.startsWith('.braidfs/')) return 'dt'
|
|
470
|
+
|
|
471
|
+
try {
|
|
472
|
+
var meta = JSON.parse(await require('fs').promises.readFile(meta_path, 'utf8'))
|
|
473
|
+
|
|
474
|
+
// optimization for old braidfs versions
|
|
475
|
+
if (typeof meta.local_edit_counter === 'number') return 'dt'
|
|
476
|
+
|
|
477
|
+
if (meta.merge_type) return meta.merge_type
|
|
478
|
+
} catch (e) {}
|
|
479
|
+
if (freed) return
|
|
480
|
+
|
|
481
|
+
var res = await braid_fetch(url, {
|
|
482
|
+
method: 'HEAD',
|
|
483
|
+
retry: () => true,
|
|
484
|
+
// braid_fetch will await this function on each reconnect when retrying
|
|
485
|
+
parents: async () => reconnect_rate_limiter.get_turn(url),
|
|
486
|
+
// version needed to force Merge-Type return header
|
|
487
|
+
version: [],
|
|
488
|
+
headers: {
|
|
489
|
+
// needed for braid.org routing
|
|
490
|
+
Accept: 'text/plain',
|
|
491
|
+
// in case it supports dt, so it doesn't give us "simpleton"
|
|
492
|
+
'Merge-Type': 'dt',
|
|
493
|
+
}
|
|
494
|
+
})
|
|
495
|
+
|
|
496
|
+
var merge_type = res.headers.get('merge-type')
|
|
497
|
+
if (merge_type) return merge_type
|
|
498
|
+
|
|
499
|
+
throw `failed to get merge type for ${url}`
|
|
500
|
+
}
|
|
447
501
|
|
|
448
502
|
async function init_binary_sync() {
|
|
449
503
|
if (freed) return
|
|
@@ -722,6 +776,9 @@ async function sync_url(url) {
|
|
|
722
776
|
// hack: remvoe in future
|
|
723
777
|
var old_meta_fork_point = null
|
|
724
778
|
|
|
779
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
780
|
+
self.investigating_disconnects_thinks_connected = false
|
|
781
|
+
|
|
725
782
|
// store a recent mapping of content-hashes to their versions,
|
|
726
783
|
// to support the command line: braidfs editing filename < file
|
|
727
784
|
self.hash_to_version_cache = new Map()
|
|
@@ -764,6 +821,9 @@ async function sync_url(url) {
|
|
|
764
821
|
file_loop_pump()
|
|
765
822
|
}
|
|
766
823
|
|
|
824
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
825
|
+
do_investigating_disconnects_log(url, 'before within_fiber')
|
|
826
|
+
|
|
767
827
|
await within_fiber(fullpath, async () => {
|
|
768
828
|
if (freed) return
|
|
769
829
|
var fullpath = await get_fullpath()
|
|
@@ -780,8 +840,12 @@ async function sync_url(url) {
|
|
|
780
840
|
!({
|
|
781
841
|
version: file_last_version,
|
|
782
842
|
digest: file_last_digest,
|
|
783
|
-
|
|
784
|
-
|
|
843
|
+
|
|
844
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
845
|
+
// create new peer to eliminate this as a potential issue for now:
|
|
846
|
+
// peer: self.peer,
|
|
847
|
+
// local_edit_counter: self.local_edit_counter,
|
|
848
|
+
|
|
785
849
|
fork_point: old_meta_fork_point
|
|
786
850
|
} = Array.isArray(meta) ? { version: meta } : meta)
|
|
787
851
|
|
|
@@ -822,6 +886,9 @@ async function sync_url(url) {
|
|
|
822
886
|
})
|
|
823
887
|
if (freed) return
|
|
824
888
|
|
|
889
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
890
|
+
do_investigating_disconnects_log(url, 'after within_fiber')
|
|
891
|
+
|
|
825
892
|
await file_loop_pump()
|
|
826
893
|
async function file_loop_pump() {
|
|
827
894
|
if (freed) return
|
|
@@ -890,6 +957,9 @@ async function sync_url(url) {
|
|
|
890
957
|
await wait_on(braid_text.put(url, { version, parents, patches, merge_type: 'dt' }))
|
|
891
958
|
if (freed) return
|
|
892
959
|
|
|
960
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
961
|
+
require('fs').appendFileSync(investigating_disconnects_log, `${Date.now()}:${url} -- file edited (${self.investigating_disconnects_thinks_connected})\n`)
|
|
962
|
+
|
|
893
963
|
await write_meta_file()
|
|
894
964
|
if (freed) return
|
|
895
965
|
} else {
|
|
@@ -961,12 +1031,21 @@ async function sync_url(url) {
|
|
|
961
1031
|
file_loop_pump_lock--
|
|
962
1032
|
}
|
|
963
1033
|
|
|
1034
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
1035
|
+
do_investigating_disconnects_log(url, 'after file_loop_pump')
|
|
1036
|
+
|
|
964
1037
|
function start_sync() {
|
|
1038
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
1039
|
+
do_investigating_disconnects_log(url, 'start_sync')
|
|
1040
|
+
|
|
965
1041
|
var closed = false
|
|
966
1042
|
var ac = new AbortController()
|
|
967
1043
|
aborts.add(ac)
|
|
968
1044
|
|
|
969
1045
|
self.disconnect = async () => {
|
|
1046
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
1047
|
+
do_investigating_disconnects_log(url, 'self.disconnect')
|
|
1048
|
+
|
|
970
1049
|
if (closed) return
|
|
971
1050
|
closed = true
|
|
972
1051
|
reconnect_rate_limiter.on_diss(url)
|
|
@@ -987,32 +1066,55 @@ async function sync_url(url) {
|
|
|
987
1066
|
|
|
988
1067
|
// Use braid_text.sync for bidirectional sync with the remote URL
|
|
989
1068
|
if (is_external_link) braid_text.sync(url, new URL(url), {
|
|
1069
|
+
|
|
1070
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
1071
|
+
do_investigating_disconnects_log_L04LPFHQ1M: do_investigating_disconnects_log,
|
|
1072
|
+
|
|
990
1073
|
fork_point_hint: old_meta_fork_point,
|
|
991
1074
|
signal: ac.signal,
|
|
992
1075
|
headers: {
|
|
993
1076
|
'Content-Type': 'text/plain',
|
|
994
1077
|
...(x => x && { Cookie: x })(config.cookies?.[new URL(url).hostname])
|
|
995
1078
|
},
|
|
996
|
-
on_pre_connect: () =>
|
|
1079
|
+
on_pre_connect: () => {
|
|
1080
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
1081
|
+
do_investigating_disconnects_log(url, `sync.on_pre_connect`)
|
|
1082
|
+
|
|
1083
|
+
return reconnect_rate_limiter.get_turn(url)
|
|
1084
|
+
},
|
|
997
1085
|
on_res: res => {
|
|
1086
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
1087
|
+
do_investigating_disconnects_log(url, `sync.on_res status:${res?.status}`)
|
|
1088
|
+
self.investigating_disconnects_thinks_connected = res?.status
|
|
1089
|
+
|
|
998
1090
|
if (freed) return
|
|
999
1091
|
reconnect_rate_limiter.on_conn(url)
|
|
1000
1092
|
self.file_read_only = res.headers.get('editable') === 'false'
|
|
1001
1093
|
console.log(`connected to ${url}${self.file_read_only ? ' (readonly)' : ''}`)
|
|
1002
1094
|
},
|
|
1003
1095
|
on_unauthorized: async () => {
|
|
1096
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
1097
|
+
do_investigating_disconnects_log(url, `sync.on_unauthorized`)
|
|
1098
|
+
|
|
1004
1099
|
console.log(`access denied: reverting local edits`)
|
|
1005
1100
|
unsync_url(url)
|
|
1006
1101
|
//await sync_url.chain
|
|
1007
1102
|
sync_url(url)
|
|
1008
1103
|
},
|
|
1009
1104
|
on_disconnect: () => {
|
|
1010
|
-
|
|
1105
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
1106
|
+
do_investigating_disconnects_log(url, `sync.on_disconnect`)
|
|
1107
|
+
self.investigating_disconnects_thinks_connected = false
|
|
1108
|
+
|
|
1109
|
+
return reconnect_rate_limiter.on_diss(url)
|
|
1011
1110
|
}
|
|
1012
1111
|
})
|
|
1013
1112
|
}
|
|
1014
1113
|
|
|
1015
1114
|
self.reconnect = () => {
|
|
1115
|
+
// DEBUGGING HACK ID: L04LPFHQ1M -- INVESTIGATING DISCONNECTS
|
|
1116
|
+
do_investigating_disconnects_log(url, `reconnect`)
|
|
1117
|
+
|
|
1016
1118
|
for (var a of aborts) a.abort()
|
|
1017
1119
|
aborts.clear()
|
|
1018
1120
|
start_sync()
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "braidfs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.131",
|
|
4
4
|
"description": "braid technology synchronizing files and webpages",
|
|
5
5
|
"author": "Braid Working Group",
|
|
6
6
|
"repository": "braid-org/braidfs",
|
|
7
7
|
"homepage": "https://braid.org",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"braid-http": "~1.3.
|
|
10
|
-
"braid-text": "~0.2.
|
|
9
|
+
"braid-http": "~1.3.85",
|
|
10
|
+
"braid-text": "~0.2.97",
|
|
11
11
|
"braid-blob": "~0.0.30",
|
|
12
12
|
"chokidar": "^4.0.3"
|
|
13
13
|
},
|