Skip to content

Conat -- replacing NATS with socketio + sqlite3 + valkey + nodejs #8346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 404 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
404 commits
Select commit Hold shift + click to select a range
4e274ab
remove nats-server startup from github action workflow
williamstein May 22, 2025
4837b64
remove socketio cluster support libs (not needed)
williamstein May 22, 2025
2740190
conat -- disable the general sqlite3 support for persist for now, of …
williamstein May 22, 2025
ad91330
sqlite test
williamstein May 22, 2025
0967147
conat: ephemeral subscriptions; use for services by default; also add…
williamstein May 22, 2025
641c994
conat: implement per user subscription limit
williamstein May 22, 2025
10abf2f
conat: persistent streams -- send results in batches
williamstein May 23, 2025
d58d2ba
persist send: cap total size of messages
williamstein May 23, 2025
fe794d1
conat: delete wrong msgID implementation; fix a flaky test
williamstein May 23, 2025
1edc789
conat: in persistent storage, properly reference count the stream
williamstein May 23, 2025
e448e16
conat: support msgID properly for persistent storage
williamstein May 23, 2025
1e706a5
conat: implement timeout for publish
williamstein May 23, 2025
aa777b1
conat: implement timeout for creation of subscription
williamstein May 23, 2025
c53b747
unit test msgID
williamstein May 23, 2025
07f4740
conat: implement persistent stream message delete
williamstein May 23, 2025
cee76b1
conat: finish implementing and unit testing stream delete
williamstein May 23, 2025
ccb7374
conat: persistent storage -- add api for setting/getting limits
williamstein May 23, 2025
d475126
dstream and dkv - ability to set/get limits through them
williamstein May 23, 2025
8a9f922
conat: limits --> config
williamstein May 23, 2025
e314f61
conat persistence: add storing the size of messages
williamstein May 23, 2025
efd43d9
conat persist: start implementing limits
williamstein May 23, 2025
9654054
conat: implement max_age
williamstein May 23, 2025
48fd264
conat: work in progress on implementing limits
williamstein May 24, 2025
4d3ff9d
conat: working on limits
williamstein May 24, 2025
0daea3b
conat: add typing to core-stream event; add msgID so it gets properly…
williamstein May 24, 2025
110a43a
conat: ttl for deleting keys from kv store
williamstein May 24, 2025
635050f
conat: more work on limits; fix issue with dkv state and saving where…
williamstein May 24, 2025
b2ae05f
fix all skipped conat tests
williamstein May 24, 2025
8a172ed
conat: *all* limits are implemented and unit tested. Wow.
williamstein May 24, 2025
9250406
conat: ephemeral dstream and dkv with working tests
williamstein May 24, 2025
b59275a
conat: implement heartbeat properly for core-stream (work in progress)
williamstein May 24, 2025
9085730
conat: delete old ephemeral leader-based ephemeral stream code
williamstein May 24, 2025
3828c77
Merge branch 'conat-hb' into conat
williamstein May 24, 2025
200d0a8
no need for printing a warning
williamstein May 24, 2025
d28dae4
Merge branch 'master' into conat
williamstein May 24, 2025
9ab4a64
terminal: properly implement write buffering (so very rarely have to …
williamstein May 24, 2025
a92f3a4
dstream options -- clean up
williamstein May 24, 2025
427a5b0
conat: add astream = async stream... for symmetry
williamstein May 24, 2025
a5a5750
jupyter/sync: use ephemeral dkv for ipywidgets, etc
williamstein May 24, 2025
1401fbd
delete console log message
williamstein May 25, 2025
25a2c42
Merge branch 'master' into conat
williamstein May 25, 2025
fe90a6d
conat: it turns out to be easy to have multiple subscriptions to same…
williamstein May 25, 2025
da95f9e
conat: make core stream much more robust to issues and add unit tests…
williamstein May 25, 2025
579adf4
ephemeral size cap
williamstein May 25, 2025
0e506f0
conat: implement permissions for persistent storage
williamstein May 25, 2025
b660628
fix subtle case of user query that broke due to JSON --> MsgPack switch
williamstein May 25, 2025
b56cff9
tests accessing private members
williamstein May 26, 2025
43f53b6
oops that validate was obviously wrong
williamstein May 26, 2025
9d2fc21
conat: redo how address of conat server is specified/stored/etc.
williamstein May 26, 2025
02a73b6
oops -- left debugging in
williamstein May 26, 2025
923ce25
conat: fix pub/sub (hence cursors)
williamstein May 26, 2025
12dfc6c
fix version mismatch with ttlcache
williamstein May 26, 2025
d38c5ca
conat client -- do allow self-signed cert for nodejs connections
williamstein May 26, 2025
e0f3190
fix computing address on frontend in some cases
williamstein May 26, 2025
f3f142f
improve database error message
williamstein May 26, 2025
2de9c8e
frontend typescript issue
williamstein May 26, 2025
ac73f2b
upgrade rspack
williamstein May 26, 2025
ff4f5b5
do not unset BASE_PATH
williamstein May 26, 2025
71f63d4
add ssl option for running hub
williamstein May 26, 2025
ea7caea
easy access to the core sync primitives from conat core client
williamstein May 26, 2025
cb1066f
typescript error
williamstein May 26, 2025
6550ead
do not show user as anonymous sometimes for a moment
williamstein May 26, 2025
acf73ee
conat: improve some logging
williamstein May 26, 2025
82d7d84
conat: eliminate account_id cookie
williamstein May 26, 2025
4931689
Revert "conat: eliminate account_id cookie"
williamstein May 27, 2025
4a956cd
conat auth: implementing it; added many unit tests
williamstein May 27, 2025
1f20fc3
conat: implement auth for hub
williamstein May 27, 2025
b956cf0
conat: implement auth
williamstein May 27, 2025
7305dcb
conat: just working on auth
williamstein May 27, 2025
312087a
conat core: do much more to surface permissions issues; specify inbox…
williamstein May 27, 2025
240ab55
project: generate project secret token in hub and set when starting p…
williamstein May 27, 2025
2748130
conat: make secret_token available (e.g., used by video chat)
williamstein May 27, 2025
3a5973d
conat: strip undefines before doing userQuery -- needed due to MsgPack
williamstein May 27, 2025
0753244
optimize opening files -- this makesit much faster, but is dangerous …
williamstein May 27, 2025
9c741bf
sync startup: bring back wait until ready in cases of no patches
williamstein May 27, 2025
e21a9ec
automatically fix the account_id cookie if it is not correct
williamstein May 27, 2025
be34ab2
terminal -- some renaming and don't ignore characters when disconnect…
williamstein May 27, 2025
88ab42e
conat: frontend standby timeout support
williamstein May 27, 2025
f61b10a
conat: add connection stats to the frontend
williamstein May 27, 2025
afce927
connection dialog: display messages sent/received and other info nicely
williamstein May 27, 2025
7e0f163
conats: add server stats collection about all connected clients
williamstein May 28, 2025
7a56d3e
conat core: fix some bugs revealed by testing; change dkv and dstream…
williamstein May 28, 2025
c451dba
make terminal start quicker in edge case, maybe
williamstein May 28, 2025
b6d424b
oops -- wrong unit
williamstein May 28, 2025
3f6afe3
conat core: figure out how to use service method and get access to me…
williamstein May 28, 2025
6137606
conat persist: rough draft of load balancer
williamstein May 28, 2025
4b80092
conat core server: fix logic for clearing subscriptions when there is…
williamstein May 28, 2025
e3a3a86
conat server id; use conat client for sign in info instead of old hub…
williamstein May 28, 2025
58b847e
frontend connection status
williamstein May 28, 2025
596f3b0
work in progress removing hub-websocket completely...
williamstein May 28, 2025
bc6f1f3
more work using conat instead of old hub websocket
williamstein May 28, 2025
282c7c1
frontend: removing old mesg_info tracking -- doesn't really make sense
williamstein May 28, 2025
cbe5e30
remove a bunch of old react billing code
williamstein May 28, 2025
7169875
remove syncdoc_history -- code all over, which of course can't possib…
williamstein May 28, 2025
0fc9693
rewrite remove blob ttls
williamstein May 28, 2025
6ad5f21
rewrite admin password reset
williamstein May 28, 2025
8aa8b8e
work in progress rewriting collab configuration in typescript
williamstein May 28, 2025
729059b
actually remove a collab
williamstein May 28, 2025
d6920f6
first draft of rewrite of add/remove/invite collabs to typescript
williamstein May 28, 2025
38f33b9
fix bug in project invite tokens (probably caused months ago when ant…
williamstein May 28, 2025
1ec0658
fix some typescript issues
williamstein May 28, 2025
7b8bb50
rewrite jupyter kernel/exec to be on conat
williamstein May 28, 2025
bafdb90
rewrite error tracking api
williamstein May 28, 2025
21c40ed
delete a bunch of old stripe api code that we're not using anymore
williamstein May 28, 2025
972972b
deleting more unused code
williamstein May 28, 2025
6dce128
change email address -- only use new api endpoint
williamstein May 29, 2025
94c28b4
delete old broken forgot password code from frontend
williamstein May 29, 2025
f5e9f7b
migrate sending verification email
williamstein May 29, 2025
5af0fae
rewrite unlink passport
williamstein May 29, 2025
140a0ed
rewrite set admin quotas
williamstein May 29, 2025
9c4891b
get rid of add/remove license that wasn't used
williamstein May 29, 2025
7f4ccd5
migrate to new copy path between projects code
williamstein May 29, 2025
f752234
delete all the "anonymous setup" stuff; I don't think it worked anymo…
williamstein May 29, 2025
6446526
delete app "create_account" functionality -- just complicates code, p…
williamstein May 29, 2025
acbec0e
delete a bunch of old code for working with upgrades that we no longe…
williamstein May 29, 2025
72a8eed
rewrite print to PDF for sagews
williamstein May 29, 2025
c7956b5
delete all use of primus, api v1, and the client.coffe from hub!
williamstein May 29, 2025
7b07e55
remove cookies endpoint -- that's not the right way to do this
williamstein May 29, 2025
6d2795e
remove symmetric channel, since we do not use it anywhere
williamstein May 29, 2025
b7d9beb
conat - work on "primus" connection
williamstein May 29, 2025
c83e33c
delete project_info primus websocket channel and backend server
williamstein May 30, 2025
ca3db98
conat: work in progress eliminating the project websocket
williamstein May 30, 2025
3b1e8bc
Merge branch 'master' into conat
williamstein May 30, 2025
aa85ac4
conat synctable clean up
williamstein May 30, 2025
b0c8ab0
final big rename: nats --> conat
williamstein May 30, 2025
559aae8
sync dkv save -- log ANY save error failure
williamstein May 30, 2025
dca17ac
better error message when fail to sign in using hub auth
williamstein May 30, 2025
48d82d9
rewrite project info to not use synctable; instead use conat pub/sub
williamstein May 30, 2025
2a55814
rewrite project status to use pub/sub
williamstein May 30, 2025
4367822
disable primus on frontend (for testing)
williamstein May 30, 2025
df2ad55
project usage info: complete rewrite
williamstein May 30, 2025
014ae98
remove lean
williamstein May 31, 2025
f4e6178
frontend primus websocket to project -- get rid of connection code
williamstein May 31, 2025
cac360f
remove more functionality supported by project websocket
williamstein May 31, 2025
26c20a5
deleting/removing most of the code for the old project-based sync imp…
williamstein May 31, 2025
1b3e086
handle bad license in project slightly better
williamstein May 31, 2025
2b805bd
conat: move pattern out of server object to own class so we can make …
williamstein May 31, 2025
8222ee8
starting work on fast subject matching algorithm
williamstein May 31, 2025
fdc01de
finish implementing fast nats pattern matching and use it by default
williamstein May 31, 2025
b58ec87
conat core pattern matching -- add some unit tests
williamstein May 31, 2025
98cad36
add retryTimes to core-stream.test.ts since it can timeout sometimes
williamstein May 31, 2025
69c4553
conat core: implement special 'sticky' queue group
williamstein May 31, 2025
a23f6ed
conat core -- use consistent hashing for selecting sticky target
williamstein May 31, 2025
9b6f366
conat persist: implement use of sticky queue group so that multiple s…
williamstein May 31, 2025
e1029d5
fix reconnect button broken
williamstein May 31, 2025
f63d19d
conat -- rewrite changefeeds to use sticky subscriptions
williamstein May 31, 2025
6b8fbe4
upgrade to the latest xterm (new @xterm/* packages); re-enable webgl …
williamstein May 31, 2025
9a6a9c3
disable progressive app service worker in dev mode since it doesn't w…
williamstein May 31, 2025
6cd9a98
improve some frontend logging
williamstein May 31, 2025
fdf4865
increase project log default load limits
williamstein May 31, 2025
aaa70ff
change requestMany to a subscription
williamstein May 31, 2025
4caf6b4
only pass exactly the query options on to user_query
williamstein May 31, 2025
b7f2733
default timeout for requestMany and publish; working on changefeeds
williamstein May 31, 2025
bc00fc5
subject socket - instantly disconnect client when server cleanly closes
williamstein May 31, 2025
09031c9
rewrite conat socket module to not use a separate control subject; th…
williamstein May 31, 2025
5e5697f
subject socket: add unit test of load balancing and automatic failover
williamstein May 31, 2025
226f81a
better subscribe error message
williamstein Jun 1, 2025
d3fd6ef
rename: hub-api --> hub/api
williamstein Jun 1, 2025
9cf864a
improve project file tabs when there are a large number
williamstein Jun 1, 2025
0917dd7
conat socket: make it server knows the subject the client connected o…
williamstein Jun 1, 2025
32a72da
conat subject socket: add support for headers
williamstein Jun 1, 2025
2cd17fa
conat: add reconnection logic, state, etc., for subject-socket
williamstein Jun 1, 2025
a2b67b0
conat: working on changfeeds and subject sockets -- this is completel…
williamstein Jun 1, 2025
bd5bd3d
support multiple distinct subject sockets between same client/server;…
williamstein Jun 1, 2025
747531b
improve async error handling for event iterator so ping failures are …
williamstein Jun 1, 2025
c41ee56
ts error
williamstein Jun 1, 2025
3ed496e
conat subject socket -- implement connection logic primarily using so…
williamstein Jun 1, 2025
c4f24a1
conat persist -- work in progress rewriting to use subject socket
williamstein Jun 1, 2025
f9101aa
conat: add full request/respond functionality to subject sockets
williamstein Jun 1, 2025
4a40bc0
work in progress rewriting persistence storage server to use subject …
williamstein Jun 1, 2025
281074d
rewrite persist server to use socket instead of requestMany -- still …
williamstein Jun 2, 2025
8fff34c
persist rewrite -- typescript works, but test suite horribly broken...
williamstein Jun 2, 2025
930b664
fix how headers are specified in subject socket to match client publi…
williamstein Jun 2, 2025
db13948
improve request/respond for subject socket so it works even if the se…
williamstein Jun 2, 2025
12ec180
stream rewrite to use sockets -- work in progress -- implement startup
williamstein Jun 2, 2025
5ca7cc6
add requestMany to subject socket
williamstein Jun 2, 2025
1846b52
persist rewrite again for getall -- rough draft (not working yet)
williamstein Jun 2, 2025
dd709e2
using new persist server api to make async stream much better
williamstein Jun 2, 2025
ab2243b
astream -- add setMany; writing more tests
williamstein Jun 2, 2025
dd4e15a
astream: more unit tests
williamstein Jun 2, 2025
1b47c10
rewrite core-stream tests so works with new persist server
williamstein Jun 2, 2025
bf6fe57
fix some more unit tests of core-stream
williamstein Jun 2, 2025
c6f1a35
more fixes to subject socket based on unit testing
williamstein Jun 2, 2025
dd0348f
conat: work in progress fixing and improving
williamstein Jun 3, 2025
914b48a
conat -- more fixing of the core sync stuff
williamstein Jun 3, 2025
ce46b42
more fixes
williamstein Jun 3, 2025
2b7d047
fix fallback conat client
williamstein Jun 3, 2025
43b2416
mainly make it so subject sockets also have an async end method.
williamstein Jun 3, 2025
013dd00
no need to log this "error" about the error reporter
williamstein Jun 3, 2025
4127617
Merge branch 'master' into conat
williamstein Jun 3, 2025
23c7694
tighter typescript
williamstein Jun 3, 2025
51f0fc2
terminals: make them not ephemeral; being ephemeral is actualy really…
williamstein Jun 3, 2025
cb0359d
working on ensuring socketio server restart doesn't break everything …
williamstein Jun 3, 2025
2ad7f9a
conat sockets: work in progress implementing reliability
williamstein Jun 3, 2025
4de4d4d
socket: first rough draft of tcp-style protocol to ensure exactly onc…
williamstein Jun 4, 2025
61c7cb4
getting TCP algorithm for socket to work
williamstein Jun 4, 2025
ebe7e12
typescript
williamstein Jun 4, 2025
6996a41
misc conat sync
williamstein Jun 4, 2025
f133d76
writing persist unit tests
williamstein Jun 4, 2025
51dc484
adding unit tests ot persist and restarting network and persist server
williamstein Jun 4, 2025
efe5ec1
conat - change definition of "connected" to mean (1) socketio connect…
williamstein Jun 4, 2025
7caf86f
conat -- slight socket code re-org
williamstein Jun 4, 2025
4fc5d5a
conat socket -- another little refactor
williamstein Jun 4, 2025
6fca2cd
conat: more socket refactoring
williamstein Jun 4, 2025
e840170
conat socket -- further refactoring
williamstein Jun 4, 2025
5695e63
socket: refactoring and eliminate sending init message with connect (…
williamstein Jun 4, 2025
b61ce60
socket: implement properly dealing with lost messages right when netw…
williamstein Jun 4, 2025
c9c4504
adding more socket reconnect unit tests
williamstein Jun 4, 2025
74fccbe
conat: fix some subtle issues with uncaught respond replies
williamstein Jun 4, 2025
e3dd51d
persist client -- restart if it is seriously broken
williamstein Jun 4, 2025
948483b
fix ts issue
williamstein Jun 4, 2025
5192116
conat: got all tests passing again
williamstein Jun 4, 2025
8a300d3
add cc to open-files (trivial)
williamstein Jun 5, 2025
eed2bd3
add a connectivity test involving both the network and the persist se…
williamstein Jun 5, 2025
50a0267
conat: fix changefeeds server breaking due to a bug in socket code an…
williamstein Jun 5, 2025
de6573a
we do want these events with sockets
williamstein Jun 5, 2025
8aede75
fix massive subscription leak in how I designed persist client
williamstein Jun 5, 2025
e001ce9
raise sub limit to 500
williamstein Jun 5, 2025
be4e0f2
do not require full subscription sync before considering connected
williamstein Jun 5, 2025
6dcd322
fix issue with sticky sockets
williamstein Jun 5, 2025
9aa8524
implement tcp state on reconnect of socket
williamstein Jun 5, 2025
ffd6b82
README for conat sockets
williamstein Jun 5, 2025
726411f
hit this edge case error in the console log
williamstein Jun 5, 2025
5bb7120
restarting a changefeed on reconnect (with core stream) should be con…
williamstein Jun 5, 2025
9a17ad2
core stream -- track and get any missing messages
williamstein Jun 5, 2025
56bec42
conat -- sockets and persist: subtle fixes to the semantics and imple…
williamstein Jun 5, 2025
4d7c664
conat socket: implement outgoing queue size; fix some unit tests
williamstein Jun 5, 2025
2ae33b2
re-enable all skiped conat tests, since they all work now
williamstein Jun 5, 2025
62f87ef
conat sockets -- implement keepalive for sockets
williamstein Jun 6, 2025
98a4952
add keepalive test in other direction
williamstein Jun 6, 2025
de0a4c2
adjust changefeed keepalive params
williamstein Jun 6, 2025
569cca3
listings failures to query db should return undefined not crash
williamstein Jun 6, 2025
4f20fcf
fix flyout terminal breaking on upgrade of @xterm (unrelated to conat)
williamstein Jun 6, 2025
be128ad
fix issue with keepalive and reduce some excessive logging
williamstein Jun 6, 2025
55988cc
ts fix
williamstein Jun 6, 2025
51b1078
conat: implement significantly enhanced subscription sync; also make …
williamstein Jun 6, 2025
9d8bc9f
ts
williamstein Jun 6, 2025
726e452
just call it force resize instead of kick
williamstein Jun 6, 2025
14d6f7f
fix bugs, tests and fallout from conat client sub sync
williamstein Jun 6, 2025
6db57f0
make terminal history be local to each frame and saved immediately
williamstein Jun 6, 2025
c3424d8
HISTFILE is relative path
williamstein Jun 6, 2025
60dc054
using a subdir for bash history is silly
williamstein Jun 6, 2025
22aa1cf
ts
williamstein Jun 6, 2025
df54854
special terminal env should overwrite parent env
williamstein Jun 6, 2025
2288b9d
conat: fix subscription counter
williamstein Jun 6, 2025
dab36a5
conat sync: fix some leaks in persist clients
williamstein Jun 6, 2025
5786fcc
dkv and dstream could try to save after they close -- fix
williamstein Jun 6, 2025
8354a2c
reducing leaks when closing projects in frontend
williamstein Jun 6, 2025
c122da0
project was initing compute server too much
williamstein Jun 7, 2025
e540868
close project actions if the tab is closed
williamstein Jun 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .github/workflows/make-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,4 @@ jobs:

- run: cd src && npm install -g pnpm
- run: cd src && pnpm run make
- run: cd src && pnpm nats-server-daemon
- run: cd src && pnpm run test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,5 @@ src/packages/frontend/i18n/trans/*.compiled.json
**/*.db

src/packages/project/nats/project-env.sh

**/*.bash_history
4 changes: 2 additions & 2 deletions src/compute/compute/lib/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
import { apiCall } from "@cocalc/api-client";
import sendFiles from "./send-files";
import getFiles from "./get-files";
// ensure that the nats client is initialized so that syncfs can connect to nats properly.
import "@cocalc/project/nats";
// ensure that the conat client is initialized so that syncfs can connect properly.
import "@cocalc/project/conat";

const logger = getLogger("compute:filesystem");

Expand Down
2 changes: 1 addition & 1 deletion src/compute/compute/lib/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The manager does the following:
*/

import debug from "debug";
import startProjectServers from "@cocalc/project/nats";
import startProjectServers from "@cocalc/project/conat";
import { pingProjectUntilSuccess, waitUntilFilesystemIsOfType } from "./util";
import { apiCall, project } from "@cocalc/api-client";

Expand Down
2 changes: 1 addition & 1 deletion src/compute/compute/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@cocalc/backend": "workspace:*",
"@cocalc/compute": "link:",
"@cocalc/jupyter": "workspace:*",
"@cocalc/nats": "workspace:*",
"@cocalc/conat": "workspace:*",
"@cocalc/project": "workspace:*",
"@cocalc/sync": "workspace:*",
"@cocalc/sync-client": "workspace:*",
Expand Down
1 change: 1 addition & 0 deletions src/compute/conat
1 change: 0 additions & 1 deletion src/compute/nats

This file was deleted.

6 changes: 3 additions & 3 deletions src/compute/pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions src/compute/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ packages:
- backend
- comm
- jupyter
- nats
- conat
- project
- sync
- sync-fs
- sync-client
- util
- terminal
- compute
- nats
- conat

onlyBuiltDependencies:
- '@cocalc/fuse-native'
Expand Down
11 changes: 2 additions & 9 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@
"test-parallel": "unset DEBUG && pnpm run version-check && cd packages && pnpm run -r --parallel test",
"test": "unset DEBUG && pnpm run version-check && cd packages && pnpm run -r test",
"prettier-all": "cd packages/",
"nats-server": "cd ${COCALC_ROOT:=$INIT_CWD}/packages/backend && node -e \"require('@cocalc/backend/nats/install').main()\" && node -e \"require('@cocalc/backend/nats/conf').main()\" && node -e \"require('@cocalc/backend/nats/server').main()\"",
"build-nats": "cd ${COCALC_ROOT:=$INIT_CWD}/packages/util && pnpm install && pnpm build && cd ${COCALC_ROOT:=$INIT_CWD}/packages/nats && pnpm install && pnpm build && cd ${COCALC_ROOT:=$INIT_CWD}/packages/backend && pnpm install && pnpm build",
"nats-server-ci": "pnpm run build-nats && cd ${COCALC_ROOT:=$INIT_CWD}/packages/backend && node -e \"require('@cocalc/backend/nats/install').main()\" && node -e \"require('@cocalc/backend/nats/conf').main()\" && node -e \"require('@cocalc/backend/nats/server').main()\"",
"nats-server-daemon": "cd ${COCALC_ROOT:=$INIT_CWD}/packages/backend && node -e \"require('@cocalc/backend/nats/install').main()\" && node -e \"require('@cocalc/backend/nats/conf').main()\" && node -e \"require('@cocalc/backend/nats/server').main({daemon:true})\"",
"nats-server-verbose": "cd ${COCALC_ROOT:=$INIT_CWD}/packages/backend && node -e \"require('@cocalc/backend/nats/install').main()\" && node -e \"require('@cocalc/backend/nats/conf').main()\" && node -e \"require('@cocalc/backend/nats/server').main({verbose:true})\"",
"nats-cli": "cd ${COCALC_ROOT:=$INIT_CWD}/packages/backend && node -e \"require('@cocalc/backend/nats/cli').main()\"",
"nats-sys": "cd ${COCALC_ROOT:=$INIT_CWD}/packages/backend && node -e \"require('@cocalc/backend/nats/cli').main({user:'sys'})\"",
"nats-tiered-storage": "cd ${COCALC_ROOT:=$INIT_CWD}/packages/server && DEBUG=cocalc:* DEBUG_CONSOLE=yes node -e \"require('@cocalc/server/nats/tiered-storage').init()\"",
"local-ci": "./scripts/ci.sh"
"local-ci": "./scripts/ci.sh",
"conat-server": "cd packages/server && pnpm conat-server"
},
"repository": {
"type": "git",
Expand Down
15 changes: 15 additions & 0 deletions src/packages/backend/auth/cookie-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,18 @@ export const ACCOUNT_ID_COOKIE_NAME = basePathCookieName({
basePath,
name: "account_id",
});

export const PROJECT_SECRET_COOKIE_NAME = basePathCookieName({
basePath,
name: "project_secret",
});

export const PROJECT_ID_COOKIE_NAME = basePathCookieName({
basePath,
name: "project_id",
});

export const HUB_PASSWORD_COOKIE_NAME = basePathCookieName({
basePath,
name: "hub_password",
});
10 changes: 10 additions & 0 deletions src/packages/backend/bin/conat-watch.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { conat } = require('@cocalc/backend/conat')

async function main() {
const subject = process.argv[2] ?? '>';
console.log("watching ", {subject})
const cn = await conat()
cn.watch(subject)
}

main();
17 changes: 17 additions & 0 deletions src/packages/backend/conat/conat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { conatPassword, conatServer } from "@cocalc/backend/data";
import { connect, Client, type ClientOptions } from "@cocalc/conat/core/client";
import { HUB_PASSWORD_COOKIE_NAME } from "@cocalc/backend/auth/cookie-names";
import { inboxPrefix } from "@cocalc/conat/names";

export type { Client };

export function conat(options?: ClientOptions): Client {
return connect({
address: conatServer,
inboxPrefix: inboxPrefix({ hub_id: "hub" }),
extraHeaders: {
Cookie: `${HUB_PASSWORD_COOKIE_NAME}=${conatPassword}`,
},
...options,
});
}
10 changes: 10 additions & 0 deletions src/packages/backend/conat/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import getLogger from "@cocalc/backend/logger";
import { setConatClient } from "@cocalc/conat/client";
import { conat } from "./conat";

export { conat };

export function init() {
setConatClient({ conat: async (opts?) => conat(opts), getLogger });
}
init();
29 changes: 29 additions & 0 deletions src/packages/backend/conat/persist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import "./index";
import betterSqlite3 from "better-sqlite3";
import { initContext } from "@cocalc/conat/persist/context";
import { compress, decompress } from "zstd-napi";
import { syncFiles } from "@cocalc/backend/data";
import ensureContainingDirectoryExists from "@cocalc/backend/misc/ensure-containing-directory-exists";

initContext({
betterSqlite3,
compress,
decompress,
syncFiles,
ensureContainingDirectoryExists,
});

export { pstream } from "@cocalc/conat/persist/storage";
import { server } from "@cocalc/conat/persist/server";
export { server };
import { conat } from "./conat";

let persistServer: any = undefined;

export function initPersistServer() {
persistServer = server({ client: conat() });
}
export function close() {
persistServer?.end(); // end is a bit more graceful
persistServer = undefined;
}
40 changes: 40 additions & 0 deletions src/packages/backend/conat/sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
dstream as createDstream,
type DStream,
type DStreamOptions as DstreamCreateOptions,
} from "@cocalc/conat/sync/dstream";
import { dkv as createDKV, type DKV, type DKVOptions } from "@cocalc/conat/sync/dkv";
import { dko as createDKO, type DKO } from "@cocalc/conat/sync/dko";
import { akv as createAKV, type AKV } from "@cocalc/conat/sync/akv";
import { astream as createAStream, type AStream } from "@cocalc/conat/sync/astream";
import { createOpenFiles, type OpenFiles } from "@cocalc/conat/sync/open-files";
export { inventory } from "@cocalc/conat/sync/inventory";
import "./index";

export type { DStream, DKV, DKO, AKV };

export async function dstream<T = any>(
opts: DstreamCreateOptions,
): Promise<DStream<T>> {
return await createDstream<T>(opts);
}

export function astream<T = any>(opts: DstreamCreateOptions): AStream<T> {
return createAStream<T>(opts);
}

export async function dkv<T = any>(opts: DKVOptions): Promise<DKV<T>> {
return await createDKV<T>(opts);
}

export function akv<T = any>(opts: DKVOptions): AKV<T> {
return createAKV<T>(opts);
}

export async function dko<T = any>(opts: DKVOptions): Promise<DKO<T>> {
return await createDKO(opts);
}

export async function openFiles(project_id: string, opts?): Promise<OpenFiles> {
return await createOpenFiles({ project_id, ...opts });
}
Loading
Loading