Skip to content

Commit b33ec24

Browse files
committed
more sha1 cleanup
1 parent 9a69f84 commit b33ec24

File tree

7 files changed

+14
-8
lines changed

7 files changed

+14
-8
lines changed

src/packages/frontend/client/nats.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { redux } from "../app-framework";
77
import * as jetstream from "@nats-io/jetstream";
88
import { createSyncTable, type SyncTable } from "@cocalc/nats/sync/synctable";
99
import { parse_query } from "@cocalc/sync/table/util";
10-
import sha1 from "sha1";
10+
import { sha1 } from "@cocalc/util/misc";
1111
import { keys } from "lodash";
1212
import { type HubApi, initHubApi } from "@cocalc/nats/api/index";
1313

src/packages/frontend/frame-editors/terminal-editor/nats-terminal-connection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { webapp_client } from "@cocalc/frontend/webapp-client";
22
import { EventEmitter } from "events";
33
import { JSONCodec } from "nats.ws";
4-
import sha1 from "sha1";
54
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
6-
import { uuid } from "@cocalc/util/misc";
5+
import { sha1, uuid } from "@cocalc/util/misc";
76
import { delay } from "awaiting";
87

98
const jc = JSONCodec();

src/packages/nats/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### NOTES
2+
3+
- we are using sha1 hashes a lot because we have to store various data, e.g., arbitrary file paths, as nats segments, so MUST have a bounded size string with simple characters.
4+
The very low probability of a collision is discussed here: https://crypto.stackexchange.com/questions/2583/is-it-fair-to-assume-that-sha1-collisions-wont-occur-on-a-set-of-100k-strings

src/packages/nats/sync/synctable-kv-atomic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import sha1 from "sha1";
21
import { keys } from "lodash";
32
import { client_db } from "@cocalc/util/db-schema/client-db";
43
import { getKv, toKey, type NatsEnv, natsKeyPrefix } from "./synctable-kv";
4+
import { sha1 } from "@cocalc/util/misc";
55

66
export class SyncTableKVAtomic {
77
private kv?;

src/packages/nats/sync/synctable-kv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ It uses a SINGLE NATS key-value store to represent
99
*/
1010

1111
import { Kvm } from "@nats-io/kv";
12-
import sha1 from "sha1";
12+
import { sha1 } from "@cocalc/util/misc";
1313
import jsonStableStringify from "json-stable-stringify";
1414
import { keys } from "lodash";
1515
import { client_db } from "@cocalc/util/db-schema/client-db";

src/packages/nats/sync/synctable-stream.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ It uses a NATS stream to store the elements in a well defined order.
1010
*/
1111

1212
import { jetstreamManager, jetstream } from "@nats-io/jetstream";
13-
import sha1 from "sha1";
1413
import jsonStableStringify from "json-stable-stringify";
1514
import { keys } from "lodash";
16-
import { cmp_Date, is_array, isValidUUID } from "@cocalc/util/misc";
15+
import { cmp_Date, is_array, isValidUUID, sha1 } from "@cocalc/util/misc";
1716
import { client_db } from "@cocalc/util/db-schema/client-db";
1817
import { EventEmitter } from "events";
1918

src/packages/project/nats/synctable.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ const synctable = reuseInFlight(
2424
}
2525
}
2626
query[table][0].project_id = project_id;
27-
const s = createSyncTable({ ...options, query, env: { sha1, jc, nc } });
27+
const s = createSyncTable({
28+
...options,
29+
query,
30+
env: { sha1, jc, nc },
31+
});
2832
await s.init();
2933
cache[key] = s;
3034
}

0 commit comments

Comments
 (0)