Skip to content
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

feat: MapeoRPC -> LocalPeers #356

Merged
merged 9 commits into from
Oct 30, 2023
Merged

feat: MapeoRPC -> LocalPeers #356

merged 9 commits into from
Oct 30, 2023

Conversation

gmaclennan
Copy link
Member

@gmaclennan gmaclennan commented Oct 26, 2023

Rename, make device info handling internal, add connectedAt and disconnectedAt properties, and expose the peer protomux connection to be used by sync.

This mainly is about renaming things to be more consistent, but also tweaking the API to add features needed for sync integration work. Fixes #355 and also #316

gmaclennan added a commit that referenced this pull request Oct 27, 2023
For now this simplifies the API (because we are only supporting local
sync, not remote sync over the internet) to:

- `project.$sync.getState()`
- `project.$sync.start()`
- `project.$sync.stop()`
- Events
    - `sync-state`

It's currently not possible to stop local discovery, nor is it possible
to stop sync of the metadata namespaces (auth, config, blobIndex). The
start and stop methods stop the sync of the data and blob namespaces.

Fixes #134. Stacked on #360, #358 and #356.
gmaclennan added a commit that referenced this pull request Oct 27, 2023
For now this simplifies the API (because we are only supporting local
sync, not remote sync over the internet) to:

- `project.$sync.getState()`
- `project.$sync.start()`
- `project.$sync.stop()`
- Events
    - `sync-state`

It's currently not possible to stop local discovery, nor is it possible
to stop sync of the metadata namespaces (auth, config, blobIndex). The
start and stop methods stop the sync of the data and blob namespaces.

Fixes #134. Stacked on #360, #358 and #356.
Copy link
Member

@achou11 achou11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a non-blocking comment but overall changes make sense 👍

src/local-peers.js Show resolved Hide resolved
@gmaclennan gmaclennan merged commit 1f4abac into main Oct 30, 2023
7 checks passed
gmaclennan added a commit that referenced this pull request Nov 9, 2023
* main:
  feat: integrate LocalDiscovery & LocalPeers (#358)
  implement IconApi (#335)
  feat: MapeoRPC -> LocalPeers (#356)
  chore: update @mapeo/schema and @mapeo/sqlite-indexer (#357)
gmaclennan added a commit that referenced this pull request Nov 9, 2023
* main:
  feat: `listLocalPeers()` & `local-peers` event (#360)
  feat: integrate LocalDiscovery & LocalPeers (#358)
  implement IconApi (#335)
  feat: MapeoRPC -> LocalPeers (#356)
  chore: update @mapeo/schema and @mapeo/sqlite-indexer (#357)
gmaclennan added a commit that referenced this pull request Nov 9, 2023
* WIP initial work

* rename Rpc to LocalPeers

* Handle deviceInfo internally, id -> deviceId

* Tests for stream error handling

* remove unnecessary constructor

* return replication stream

* Attach protomux instance to peer info

* rename and re-organize

* revert changes outside scope of PR

* WIP initial work

* Tie everything together

* rename getProjectInstance

* feat: client.listLocalPeers() & `local-peers` evt

* feat: add $sync API methods

For now this simplifies the API (because we are only supporting local
sync, not remote sync over the internet) to:

- `project.$sync.getState()`
- `project.$sync.start()`
- `project.$sync.stop()`
- Events
    - `sync-state`

It's currently not possible to stop local discovery, nor is it possible
to stop sync of the metadata namespaces (auth, config, blobIndex). The
start and stop methods stop the sync of the data and blob namespaces.

Fixes #134. Stacked on #360, #358 and #356.
gmaclennan added a commit that referenced this pull request Nov 9, 2023
* main:
  feat: add `$sync` API methods (#361)
  feat: `listLocalPeers()` & `local-peers` event (#360)
  feat: integrate LocalDiscovery & LocalPeers (#358)
  implement IconApi (#335)
  feat: MapeoRPC -> LocalPeers (#356)
  chore: update @mapeo/schema and @mapeo/sqlite-indexer (#357)
@gmaclennan gmaclennan deleted the feat/local-peers branch November 9, 2023 07:22
gmaclennan added a commit that referenced this pull request Nov 28, 2023
* WIP initial work

* rename Rpc to LocalPeers

* Handle deviceInfo internally, id -> deviceId

* Tests for stream error handling

* remove unnecessary constructor

* return replication stream

* Attach protomux instance to peer info

* rename and re-organize

* revert changes outside scope of PR

* WIP initial work

* Tie everything together

* rename getProjectInstance

* feat: client.listLocalPeers() & `local-peers` evt

* feat: add $sync API methods

For now this simplifies the API (because we are only supporting local
sync, not remote sync over the internet) to:

- `project.$sync.getState()`
- `project.$sync.start()`
- `project.$sync.stop()`
- Events
    - `sync-state`

It's currently not possible to stop local discovery, nor is it possible
to stop sync of the metadata namespaces (auth, config, blobIndex). The
start and stop methods stop the sync of the data and blob namespaces.

Fixes #134. Stacked on #360, #358 and #356.

* feat: Add project.$waitForInitialSync() method

Fixes Add project method to download auth + config cores #233

Rather than call this inside the `client.addProject()` method, instead I
think it is better for the API consumer to call
`project.$waitForInitialSync()` after adding a project, since this
allows the implementer to give user feedback about what is happening.

* Wait for initial sync within  addProject()

* fix: don't add core bitfield until core is ready

* feat: expose deviceId on coreManager

* fix: wait for project.ready() in waitForInitialSync

* fix: skip waitForSync in tests

* don't enable/disable namespace if not needed

* start core download when created via sparse: false

* Add debug logging

This was a big lift, but necessary to be able to debug sync issues since
temporarily adding console.log statements was too much work, and
debugging requires knowing the deviceId associated with each message.

* fix timeout

* fix: Add new cores to the indexer (!!!)

This caused a day of work: a bug from months back

* remove unnecessary log stmt

* get capabilities.getMany() to include creator

* fix invite test

* keep blob cores sparse

* optional param for LocalPeers

* re-org sync and replication

Removes old replication code attached to CoreManager
Still needs tests to be updated

* update package-lock

* chore: Add debug logging

* Add new logger to discovery + dnssd

* Get invite test working

* fix manager logger

* cleanup invite test (and make it fail :(

* fix: handle duplicate connections to LocalPeers

* fix stream close before channel open

* send invite to non-existent peer

* fixed fake timers implementation for tests

* new tests for duplicate connections

* cleanup and small fix

* Better state debug logging

* chain of invites test

* fix max listeners and add skipped test

* fix: only request a core key from one peer

Reduces the number of duplicate requests for the same keys.

* cleanup members tests with new helprs

* wait for project ready when adding

* only create 4 clients for chain of invites test

* add e2e sync tests

* add published @mapeo/mock-data

* fix: don't open cores in sparse mode

Turns out this changes how core.length etc. work, which confuses things

* fix: option to skip auto download for tests

* e2e test for stop-start sync

* fix coreManager unit tests

* fix blob store tests

* fix discovery-key event

* add coreCount to sync state

* test sync with blocked peer & fix bugs

* fix datatype unit tests

* fix blobs server unit tests

* remote peer-sync-controller unit test

This is now tested in e2e tests

* fix type issues caused by bad lockfile

* ignore debug type errors

* fixes for review comments

* move utils-new into utils

* Add debug info to test that sometimes fails

* Update package-lock.json version

---------

Co-authored-by: Andrew Chou <[email protected]>
gmaclennan added a commit that referenced this pull request Nov 28, 2023
* remove project.ready() (breaks things)

* wait for coreOwnership write before returning

* feat: integrate sync and project invites (#362)

* WIP initial work

* rename Rpc to LocalPeers

* Handle deviceInfo internally, id -> deviceId

* Tests for stream error handling

* remove unnecessary constructor

* return replication stream

* Attach protomux instance to peer info

* rename and re-organize

* revert changes outside scope of PR

* WIP initial work

* Tie everything together

* rename getProjectInstance

* feat: client.listLocalPeers() & `local-peers` evt

* feat: add $sync API methods

For now this simplifies the API (because we are only supporting local
sync, not remote sync over the internet) to:

- `project.$sync.getState()`
- `project.$sync.start()`
- `project.$sync.stop()`
- Events
    - `sync-state`

It's currently not possible to stop local discovery, nor is it possible
to stop sync of the metadata namespaces (auth, config, blobIndex). The
start and stop methods stop the sync of the data and blob namespaces.

Fixes #134. Stacked on #360, #358 and #356.

* feat: Add project.$waitForInitialSync() method

Fixes Add project method to download auth + config cores #233

Rather than call this inside the `client.addProject()` method, instead I
think it is better for the API consumer to call
`project.$waitForInitialSync()` after adding a project, since this
allows the implementer to give user feedback about what is happening.

* Wait for initial sync within  addProject()

* fix: don't add core bitfield until core is ready

* feat: expose deviceId on coreManager

* fix: wait for project.ready() in waitForInitialSync

* fix: skip waitForSync in tests

* don't enable/disable namespace if not needed

* start core download when created via sparse: false

* Add debug logging

This was a big lift, but necessary to be able to debug sync issues since
temporarily adding console.log statements was too much work, and
debugging requires knowing the deviceId associated with each message.

* fix timeout

* fix: Add new cores to the indexer (!!!)

This caused a day of work: a bug from months back

* remove unnecessary log stmt

* get capabilities.getMany() to include creator

* fix invite test

* keep blob cores sparse

* optional param for LocalPeers

* re-org sync and replication

Removes old replication code attached to CoreManager
Still needs tests to be updated

* update package-lock

* chore: Add debug logging

* Add new logger to discovery + dnssd

* Get invite test working

* fix manager logger

* cleanup invite test (and make it fail :(

* fix: handle duplicate connections to LocalPeers

* fix stream close before channel open

* send invite to non-existent peer

* fixed fake timers implementation for tests

* new tests for duplicate connections

* cleanup and small fix

* Better state debug logging

* chain of invites test

* fix max listeners and add skipped test

* fix: only request a core key from one peer

Reduces the number of duplicate requests for the same keys.

* cleanup members tests with new helprs

* wait for project ready when adding

* only create 4 clients for chain of invites test

* add e2e sync tests

* add published @mapeo/mock-data

* fix: don't open cores in sparse mode

Turns out this changes how core.length etc. work, which confuses things

* fix: option to skip auto download for tests

* e2e test for stop-start sync

* fix coreManager unit tests

* fix blob store tests

* fix discovery-key event

* add coreCount to sync state

* test sync with blocked peer & fix bugs

* fix datatype unit tests

* fix blobs server unit tests

* remote peer-sync-controller unit test

This is now tested in e2e tests

* fix type issues caused by bad lockfile

* ignore debug type errors

* fixes for review comments

* move utils-new into utils

* Add debug info to test that sometimes fails

* Update package-lock.json version

---------

Co-authored-by: Andrew Chou <[email protected]>

---------

Co-authored-by: Andrew Chou <[email protected]>
gmaclennan added a commit that referenced this pull request Nov 28, 2023
* WIP initial work

* rename Rpc to LocalPeers

* Handle deviceInfo internally, id -> deviceId

* Tests for stream error handling

* remove unnecessary constructor

* return replication stream

* Attach protomux instance to peer info

* rename and re-organize

* revert changes outside scope of PR

* WIP initial work

* Tie everything together

* rename getProjectInstance

* feat: client.listLocalPeers() & `local-peers` evt

* feat: add $sync API methods

For now this simplifies the API (because we are only supporting local
sync, not remote sync over the internet) to:

- `project.$sync.getState()`
- `project.$sync.start()`
- `project.$sync.stop()`
- Events
    - `sync-state`

It's currently not possible to stop local discovery, nor is it possible
to stop sync of the metadata namespaces (auth, config, blobIndex). The
start and stop methods stop the sync of the data and blob namespaces.

Fixes #134. Stacked on #360, #358 and #356.

* feat: Add project.$waitForInitialSync() method

Fixes Add project method to download auth + config cores #233

Rather than call this inside the `client.addProject()` method, instead I
think it is better for the API consumer to call
`project.$waitForInitialSync()` after adding a project, since this
allows the implementer to give user feedback about what is happening.

* Wait for initial sync within  addProject()

* fix: don't add core bitfield until core is ready

* feat: expose deviceId on coreManager

* fix: wait for project.ready() in waitForInitialSync

* fix: skip waitForSync in tests

* don't enable/disable namespace if not needed

* start core download when created via sparse: false

* Add debug logging

This was a big lift, but necessary to be able to debug sync issues since
temporarily adding console.log statements was too much work, and
debugging requires knowing the deviceId associated with each message.

* fix timeout

* fix: Add new cores to the indexer (!!!)

This caused a day of work: a bug from months back

* remove unnecessary log stmt

* get capabilities.getMany() to include creator

* fix invite test

* keep blob cores sparse

* optional param for LocalPeers

* re-org sync and replication

Removes old replication code attached to CoreManager
Still needs tests to be updated

* update package-lock

* chore: Add debug logging

* Add new logger to discovery + dnssd

* Get invite test working

* fix manager logger

* cleanup invite test (and make it fail :(

* fix: handle duplicate connections to LocalPeers

* fix stream close before channel open

* send invite to non-existent peer

* fixed fake timers implementation for tests

* new tests for duplicate connections

* cleanup and small fix

* Better state debug logging

* chain of invites test

* fix max listeners and add skipped test

* fix: only request a core key from one peer

Reduces the number of duplicate requests for the same keys.

* cleanup members tests with new helprs

* wait for project ready when adding

* only create 4 clients for chain of invites test

* add e2e sync tests

* add published @mapeo/mock-data

* fix: don't open cores in sparse mode

Turns out this changes how core.length etc. work, which confuses things

* fix: option to skip auto download for tests

* e2e test for stop-start sync

* fix coreManager unit tests

* fix blob store tests

* fix discovery-key event

* add coreCount to sync state

* test sync with blocked peer & fix bugs

* fix datatype unit tests

* fix blobs server unit tests

* remote peer-sync-controller unit test

This is now tested in e2e tests

* fix type issues caused by bad lockfile

* ignore debug type errors

* fixes for review comments

* move utils-new into utils

* Add debug info to test that sometimes fails

* Update package-lock.json version

* remove project.ready() (breaks things)

* wait for coreOwnership write before returning

---------

Co-authored-by: Andrew Chou <[email protected]>
gmaclennan added a commit that referenced this pull request Nov 28, 2023
* WIP initial work

* rename Rpc to LocalPeers

* Handle deviceInfo internally, id -> deviceId

* Tests for stream error handling

* remove unnecessary constructor

* return replication stream

* Attach protomux instance to peer info

* rename and re-organize

* revert changes outside scope of PR

* WIP initial work

* Tie everything together

* rename getProjectInstance

* feat: client.listLocalPeers() & `local-peers` evt

* feat: add $sync API methods

For now this simplifies the API (because we are only supporting local
sync, not remote sync over the internet) to:

- `project.$sync.getState()`
- `project.$sync.start()`
- `project.$sync.stop()`
- Events
    - `sync-state`

It's currently not possible to stop local discovery, nor is it possible
to stop sync of the metadata namespaces (auth, config, blobIndex). The
start and stop methods stop the sync of the data and blob namespaces.

Fixes #134. Stacked on #360, #358 and #356.

* feat: Add project.$waitForInitialSync() method

Fixes Add project method to download auth + config cores #233

Rather than call this inside the `client.addProject()` method, instead I
think it is better for the API consumer to call
`project.$waitForInitialSync()` after adding a project, since this
allows the implementer to give user feedback about what is happening.

* Wait for initial sync within  addProject()

* fix: don't add core bitfield until core is ready

* feat: expose deviceId on coreManager

* fix: wait for project.ready() in waitForInitialSync

* fix: skip waitForSync in tests

* don't enable/disable namespace if not needed

* start core download when created via sparse: false

* Add debug logging

This was a big lift, but necessary to be able to debug sync issues since
temporarily adding console.log statements was too much work, and
debugging requires knowing the deviceId associated with each message.

* fix timeout

* fix: Add new cores to the indexer (!!!)

This caused a day of work: a bug from months back

* remove unnecessary log stmt

* get capabilities.getMany() to include creator

* fix invite test

* keep blob cores sparse

* optional param for LocalPeers

* re-org sync and replication

Removes old replication code attached to CoreManager
Still needs tests to be updated

* update package-lock

* chore: Add debug logging

* Add new logger to discovery + dnssd

* Get invite test working

* fix manager logger

* cleanup invite test (and make it fail :(

* fix: handle duplicate connections to LocalPeers

* fix stream close before channel open

* send invite to non-existent peer

* fixed fake timers implementation for tests

* new tests for duplicate connections

* cleanup and small fix

* Better state debug logging

* chain of invites test

* fix max listeners and add skipped test

* fix: only request a core key from one peer

Reduces the number of duplicate requests for the same keys.

* cleanup members tests with new helprs

* wait for project ready when adding

* only create 4 clients for chain of invites test

* add e2e sync tests

* add published @mapeo/mock-data

* fix: don't open cores in sparse mode

Turns out this changes how core.length etc. work, which confuses things

* fix: option to skip auto download for tests

* e2e test for stop-start sync

* fix coreManager unit tests

* fix blob store tests

* fix discovery-key event

* add coreCount to sync state

* test sync with blocked peer & fix bugs

* fix datatype unit tests

* fix blobs server unit tests

* remote peer-sync-controller unit test

This is now tested in e2e tests

* fix type issues caused by bad lockfile

* ignore debug type errors

* fixes for review comments

* move utils-new into utils

* Add debug info to test that sometimes fails

* Update package-lock.json version

* remove project.ready() (breaks things)

* wait for coreOwnership write before returning

* use file storage in tests (breaks things)

* Catch race condition in CRUD tests

* fix race condition with parallel writes

* fix tests for new createManagers syntax

* fix flakey test

This test relied on `peer.connectedAt` changing in order to distinguish
connections, but sometimes `connectedAt` was the same for both peers.
This adds a 1ms delay before making the second connection, to attempt to
stop the flakiness.

---------

Co-authored-by: Andrew Chou <[email protected]>
gmaclennan added a commit that referenced this pull request Nov 28, 2023
* WIP initial work

* rename Rpc to LocalPeers

* Handle deviceInfo internally, id -> deviceId

* Tests for stream error handling

* remove unnecessary constructor

* return replication stream

* Attach protomux instance to peer info

* rename and re-organize

* revert changes outside scope of PR

* WIP initial work

* Tie everything together

* rename getProjectInstance

* feat: client.listLocalPeers() & `local-peers` evt

* feat: add $sync API methods

For now this simplifies the API (because we are only supporting local
sync, not remote sync over the internet) to:

- `project.$sync.getState()`
- `project.$sync.start()`
- `project.$sync.stop()`
- Events
    - `sync-state`

It's currently not possible to stop local discovery, nor is it possible
to stop sync of the metadata namespaces (auth, config, blobIndex). The
start and stop methods stop the sync of the data and blob namespaces.

Fixes #134. Stacked on #360, #358 and #356.

* feat: Add project.$waitForInitialSync() method

Fixes Add project method to download auth + config cores #233

Rather than call this inside the `client.addProject()` method, instead I
think it is better for the API consumer to call
`project.$waitForInitialSync()` after adding a project, since this
allows the implementer to give user feedback about what is happening.

* Wait for initial sync within  addProject()

* fix: don't add core bitfield until core is ready

* feat: expose deviceId on coreManager

* fix: wait for project.ready() in waitForInitialSync

* fix: skip waitForSync in tests

* don't enable/disable namespace if not needed

* start core download when created via sparse: false

* Add debug logging

This was a big lift, but necessary to be able to debug sync issues since
temporarily adding console.log statements was too much work, and
debugging requires knowing the deviceId associated with each message.

* fix timeout

* fix: Add new cores to the indexer (!!!)

This caused a day of work: a bug from months back

* remove unnecessary log stmt

* get capabilities.getMany() to include creator

* fix invite test

* keep blob cores sparse

* optional param for LocalPeers

* re-org sync and replication

Removes old replication code attached to CoreManager
Still needs tests to be updated

* update package-lock

* chore: Add debug logging

* Add new logger to discovery + dnssd

* Get invite test working

* fix manager logger

* cleanup invite test (and make it fail :(

* fix: handle duplicate connections to LocalPeers

* fix stream close before channel open

* send invite to non-existent peer

* fixed fake timers implementation for tests

* new tests for duplicate connections

* cleanup and small fix

* Better state debug logging

* chain of invites test

* fix max listeners and add skipped test

* fix: only request a core key from one peer

Reduces the number of duplicate requests for the same keys.

* cleanup members tests with new helprs

* wait for project ready when adding

* only create 4 clients for chain of invites test

* add e2e sync tests

* add published @mapeo/mock-data

* fix: don't open cores in sparse mode

Turns out this changes how core.length etc. work, which confuses things

* fix: option to skip auto download for tests

* e2e test for stop-start sync

* fix coreManager unit tests

* fix blob store tests

* fix discovery-key event

* add coreCount to sync state

* test sync with blocked peer & fix bugs

* fix datatype unit tests

* fix blobs server unit tests

* remote peer-sync-controller unit test

This is now tested in e2e tests

* fix type issues caused by bad lockfile

* ignore debug type errors

* fixes for review comments

* move utils-new into utils

* Add debug info to test that sometimes fails

* Update package-lock.json version

* remove project.ready() (breaks things)

* wait for coreOwnership write before returning

* use file storage in tests (breaks things)

* Catch race condition in CRUD tests

* fix race condition with parallel writes

* fix tests for new createManagers syntax

* fix flakey test

This test relied on `peer.connectedAt` changing in order to distinguish
connections, but sometimes `connectedAt` was the same for both peers.
This adds a 1ms delay before making the second connection, to attempt to
stop the flakiness.

* fix: wait for index idle before returning data

* temp fixes to run CI

* small fix for failing test

* update to published multi-core-indexer

---------

Co-authored-by: Andrew Chou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expand MapeoRPC to handle connections to local peers, and rename to LocalPeers
2 participants