braidfs 0.0.113 → 0.0.114

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.
Files changed (2) hide show
  1. package/index.js +17 -19
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -771,15 +771,17 @@ async function sync_url(url) {
771
771
 
772
772
  await prev_disconnect?.()
773
773
  if (freed || closed) return
774
+
775
+ await reconnect_rate_limiter.get_turn(url)
776
+ if (freed || closed) return
774
777
 
775
- async function retry(e) {
778
+ function retry(e) {
776
779
  if (freed || closed) return
777
780
  var p = self.disconnect()
778
781
 
779
782
  console.log(`reconnecting in ${waitTime}s: ${url} after error: ${e}`)
780
783
  last_connect_timer = setTimeout(async () => {
781
784
  await p
782
- await reconnect_rate_limiter.get_turn(url)
783
785
  last_connect_timer = null
784
786
  connect()
785
787
  }, waitTime * 1000)
@@ -805,11 +807,7 @@ async function sync_url(url) {
805
807
  ...(x => x && {Cookie: x})(config.cookies?.[new URL(url).hostname])
806
808
  },
807
809
  })
808
- } catch (e) {
809
- if (freed || closed) return
810
- aborts.delete(a)
811
- throw e
812
- }
810
+ } catch (e) { retry(e) }
813
811
  }
814
812
 
815
813
  async function send_out(stuff) {
@@ -817,8 +815,7 @@ async function sync_url(url) {
817
815
 
818
816
  console.log(`send_out ${url} ${JSON.stringify(stuff, null, 4).slice(0, 1000)}`)
819
817
 
820
- var r = await my_fetch({ method: "PUT", ...stuff,
821
- retry: { retryRes: r => r.status !== 401 && r.status !== 403 }})
818
+ var r = await my_fetch({ method: "PUT", ...stuff })
822
819
  if (freed || closed) return
823
820
 
824
821
  // the server has acknowledged this version,
@@ -826,7 +823,7 @@ async function sync_url(url) {
826
823
  if (r.ok) self.update_fork_point(stuff.version, stuff.parents)
827
824
 
828
825
  // if we're not authorized,
829
- if (r.status == 401 || r.status == 403) {
826
+ else if (r.status == 401 || r.status == 403) {
830
827
  // and it's one of our versions (a local edit),
831
828
  if (self.peer === braid_text.decode_version(stuff.version[0])[0]) {
832
829
  // then revert it
@@ -835,6 +832,9 @@ async function sync_url(url) {
835
832
  sync_url(url)
836
833
  }
837
834
  }
835
+
836
+ // on other errors, restart the connection
837
+ else retry(new Error(`unexpected PUT status: ${r.status}`))
838
838
  }
839
839
 
840
840
  async function find_fork_point() {
@@ -845,11 +845,12 @@ async function sync_url(url) {
845
845
  if (self.fork_point) {
846
846
  var r = await my_fetch({
847
847
  method: "HEAD",
848
- version: self.fork_point,
849
- retry: { retryRes: r =>
850
- r.status !== 309 && r.status !== 500 }
848
+ version: self.fork_point
851
849
  })
852
850
  if (freed || closed) return
851
+
852
+ if (!r.ok && r.status !== 309 && r.status !== 500) return retry(new Error(`unexpected HEAD status: ${r.status}`))
853
+
853
854
  if (r.ok) return console.log(`[find_fork_point] "${url.split('/').pop()}" has our latest fork point, hooray!`)
854
855
  }
855
856
 
@@ -868,15 +869,12 @@ async function sync_url(url) {
868
869
  console.log(`min=${min}, max=${max}, i=${i}, version=${version}`)
869
870
 
870
871
  var st = Date.now()
871
- var r = await my_fetch({
872
- method: "HEAD",
873
- version,
874
- retry: { retryRes: r =>
875
- r.status !== 309 && r.status !== 500 }
876
- })
872
+ var r = await my_fetch({ method: "HEAD", version })
877
873
  if (freed || closed) return
878
874
  console.log(`fetched in ${Date.now() - st}`)
879
875
 
876
+ if (!r.ok && r.status !== 309 && r.status !== 500) return retry(new Error(`unexpected HEAD status: ${r.status}`))
877
+
880
878
  if (r.ok) {
881
879
  min = i
882
880
  self.fork_point = version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braidfs",
3
- "version": "0.0.113",
3
+ "version": "0.0.114",
4
4
  "description": "braid technology synchronizing files and webpages",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braidfs",