Compare commits

..

83 Commits

Author SHA1 Message Date
semantic-release-bot a021ad79fe chore(release): 0.1.0-develop.13 [skip ci]
# [0.1.0-develop.13](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.12...v0.1.0-develop.13) (2023-11-17)
2023-11-17 13:50:51 +00:00
Derrick Hammer 348614dbd0
Merge remote-tracking branch 'origin/develop' into develop 2023-11-17 08:49:58 -05:00
Derrick Hammer abca3a9b6c
dep: update libkernel 2023-11-17 08:49:53 -05:00
semantic-release-bot 8b85e59be8 chore(release): 0.1.0-develop.12 [skip ci]
# [0.1.0-develop.12](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.11...v0.1.0-develop.12) (2023-10-13)
2023-10-13 10:47:32 +00:00
Derrick Hammer 5f81ea2e8f
Merge remote-tracking branch 'origin/develop' into develop 2023-10-13 06:46:25 -04:00
Derrick Hammer 054ae79386
dep: update module hash 2023-10-13 06:46:20 -04:00
semantic-release-bot 0810b05074 chore(release): 0.1.0-develop.11 [skip ci]
# [0.1.0-develop.11](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.10...v0.1.0-develop.11) (2023-10-12)
2023-10-12 12:01:51 +00:00
Derrick Hammer 3a863c00de
Merge remote-tracking branch 'origin/develop' into develop 2023-10-12 08:00:46 -04:00
Derrick Hammer 6159a94a19
dep: update libkernel 2023-10-12 08:00:40 -04:00
semantic-release-bot 2f66337592 chore(release): 0.1.0-develop.10 [skip ci]
# [0.1.0-develop.10](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.9...v0.1.0-develop.10) (2023-09-09)
2023-09-09 11:44:50 +00:00
Derrick Hammer 273f351163
Merge remote-tracking branch 'origin/develop' into develop 2023-09-09 07:43:58 -04:00
Derrick Hammer 7856713abf
refactor: switch to using hexToBytes 2023-09-09 07:43:54 -04:00
semantic-release-bot e94b2a7f2e chore(release): 0.1.0-develop.9 [skip ci]
# [0.1.0-develop.9](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.8...v0.1.0-develop.9) (2023-09-03)
2023-09-03 04:35:27 +00:00
Derrick Hammer 81851d9595
Merge remote-tracking branch 'origin/develop' into develop 2023-09-03 00:34:18 -04:00
Derrick Hammer 34b807743f
dep: update module hash 2023-09-03 00:34:13 -04:00
semantic-release-bot 89fa1c31c2 chore(release): 0.1.0-develop.8 [skip ci]
# [0.1.0-develop.8](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.7...v0.1.0-develop.8) (2023-09-02)
2023-09-02 14:07:42 +00:00
Derrick Hammer f1841a8b0f
Merge remote-tracking branch 'origin/develop' into develop 2023-09-02 10:06:32 -04:00
Derrick Hammer 7ec1ec177e
dep: update module hash 2023-09-02 10:06:28 -04:00
semantic-release-bot 28670320ab chore(release): 0.1.0-develop.7 [skip ci]
# [0.1.0-develop.7](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.6...v0.1.0-develop.7) (2023-09-02)
2023-09-02 13:11:52 +00:00
Derrick Hammer 00f2b05ee4
dep: update libkernel 2023-09-02 09:10:56 -04:00
Derrick Hammer 3bffac2223
Merge remote-tracking branch 'origin/develop' into develop 2023-09-02 09:04:55 -04:00
Derrick Hammer 69a16dcc17
dep: update libkernel 2023-09-02 09:04:51 -04:00
semantic-release-bot 3959d7eddc chore(release): 0.1.0-develop.6 [skip ci]
# [0.1.0-develop.6](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.5...v0.1.0-develop.6) (2023-09-02)
2023-09-02 12:34:28 +00:00
Derrick Hammer a3c539df20
Merge remote-tracking branch 'origin/develop' into develop 2023-09-02 08:33:35 -04:00
Derrick Hammer e079063f94
dep: update module hash 2023-09-02 08:33:31 -04:00
semantic-release-bot 2e7c6f3d75 chore(release): 0.1.0-develop.5 [skip ci]
# [0.1.0-develop.5](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.4...v0.1.0-develop.5) (2023-07-29)
2023-07-29 04:35:13 +00:00
Derrick Hammer 84cbd1d164
dep: update module hash 2023-07-29 00:33:53 -04:00
semantic-release-bot 084138cff3 chore(release): 0.1.0-develop.4 [skip ci]
# [0.1.0-develop.4](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.3...v0.1.0-develop.4) (2023-07-24)
2023-07-24 17:34:11 +00:00
Derrick Hammer 5f6193dcf7
Merge remote-tracking branch 'origin/develop' into develop 2023-07-24 13:33:05 -04:00
Derrick Hammer fada2f8355
dep: update module hash 2023-07-24 13:33:02 -04:00
semantic-release-bot cc60ef4727 chore(release): 0.1.0-develop.3 [skip ci]
# [0.1.0-develop.3](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.2...v0.1.0-develop.3) (2023-07-23)

### Features

* add setKeepAlive method ([19dceed](19dceedab2))
2023-07-23 18:40:45 +00:00
Derrick Hammer e6dd89b347
Merge remote-tracking branch 'origin/develop' into develop 2023-07-23 14:39:48 -04:00
Derrick Hammer 19dceedab2
feat: add setKeepAlive method 2023-07-23 14:39:42 -04:00
Derrick Hammer 88586ca65a
dep: update module hash 2023-07-23 14:38:58 -04:00
semantic-release-bot b90f616cad chore(release): 0.1.0-develop.2 [skip ci]
# [0.1.0-develop.2](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.1...v0.1.0-develop.2) (2023-07-23)
2023-07-23 00:13:53 +00:00
Derrick Hammer 712bf44d83
Merge remote-tracking branch 'origin/develop' into develop 2023-07-22 20:12:53 -04:00
Derrick Hammer e0735052a0
dep: update module hash 2023-07-22 20:12:48 -04:00
semantic-release-bot 3669528c56 chore(release): 0.1.0-develop.1 [skip ci]
# [0.1.0-develop.1](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.14...v0.1.0-develop.1) (2023-07-22)

### Features

* add getListeners method to Socket ([0ec1dd1](0ec1dd1aac))
2023-07-22 14:15:11 +00:00
Derrick Hammer 61cee154e5
Merge remote-tracking branch 'origin/develop' into develop 2023-07-22 10:14:08 -04:00
Derrick Hammer 0ec1dd1aac
feat: add getListeners method to Socket 2023-07-22 10:14:01 -04:00
Derrick Hammer 8c6b038f89
dep: update module hash 2023-07-22 10:11:15 -04:00
semantic-release-bot 616dc63bcf chore(release): 0.0.2-develop.14 [skip ci]
## [0.0.2-develop.14](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.13...v0.0.2-develop.14) (2023-07-22)

### Bug Fixes

* missing return ([8380254](8380254638))
2023-07-22 12:32:58 +00:00
Derrick Hammer 84ab91442a
Merge remote-tracking branch 'origin/develop' into develop 2023-07-22 08:32:03 -04:00
Derrick Hammer 8380254638
fix: missing return 2023-07-22 08:31:59 -04:00
semantic-release-bot 1c0d11ccb0 chore(release): 0.0.2-develop.13 [skip ci]
## [0.0.2-develop.13](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.12...v0.0.2-develop.13) (2023-07-22)

### Bug Fixes

* on write and end, log errors if we are trying to use a closed socket ([57efedd](57efedd0af))
2023-07-22 11:12:45 +00:00
Derrick Hammer 0747c0b31f
Merge remote-tracking branch 'origin/develop' into develop 2023-07-22 07:11:52 -04:00
Derrick Hammer 57efedd0af
fix: on write and end, log errors if we are trying to use a closed socket 2023-07-22 07:11:48 -04:00
semantic-release-bot 807d9376a0 chore(release): 0.0.2-develop.12 [skip ci]
## [0.0.2-develop.12](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.11...v0.0.2-develop.12) (2023-07-22)

### Bug Fixes

* change on to always return an instance of emittery unsubscribe function ([0c18c92](0c18c92521))
* return type required ([7eabf6a](7eabf6a05d))
2023-07-22 10:12:23 +00:00
Derrick Hammer 7eabf6a05d
fix: return type required 2023-07-22 06:11:18 -04:00
Derrick Hammer 50335dd062
Merge remote-tracking branch 'origin/develop' into develop 2023-07-22 06:03:48 -04:00
Derrick Hammer 0c18c92521
fix: change on to always return an instance of emittery unsubscribe function 2023-07-22 06:03:44 -04:00
semantic-release-bot 82d83c20fd chore(release): 0.0.2-develop.11 [skip ci]
## [0.0.2-develop.11](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.10...v0.0.2-develop.11) (2023-07-22)
2023-07-22 01:44:18 +00:00
Derrick Hammer 5691c7a488
Merge remote-tracking branch 'origin/develop' into develop 2023-07-21 21:43:23 -04:00
Derrick Hammer 720b7a60d9
dep: update module hash 2023-07-21 21:43:19 -04:00
semantic-release-bot a490281514 chore(release): 0.0.2-develop.10 [skip ci]
## [0.0.2-develop.10](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.9...v0.0.2-develop.10) (2023-07-22)
2023-07-22 00:35:45 +00:00
Derrick Hammer cbdf0a3ffa
refactor: update socket event handling
* update event handling to use a Map
* enable off to remove and close just one event, vs closing out all of them (possible bug)
* have on skip adding hook if it's in the eventUpdates already
2023-07-21 20:34:32 -04:00
Derrick Hammer 11ee1d687a
refactor: mutex no longer needed 2023-07-21 20:10:14 -04:00
semantic-release-bot d870170aa1 chore(release): 0.0.2-develop.9 [skip ci]
## [0.0.2-develop.9](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.8...v0.0.2-develop.9) (2023-07-12)
2023-07-12 10:32:48 +00:00
Derrick Hammer bbdb6d5848
dep: update module hash 2023-07-12 06:31:53 -04:00
semantic-release-bot 4ff2d1d09e chore(release): 0.0.2-develop.8 [skip ci]
## [0.0.2-develop.8](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.7...v0.0.2-develop.8) (2023-07-08)
2023-07-08 11:34:40 +00:00
Derrick Hammer 3ec590aaa2
Merge remote-tracking branch 'origin/develop' into develop 2023-07-08 07:33:25 -04:00
Derrick Hammer 296a23a3ce
dep: update module hash 2023-07-08 07:33:20 -04:00
semantic-release-bot a119226840 chore(release): 0.0.2-develop.7 [skip ci]
## [0.0.2-develop.7](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.6...v0.0.2-develop.7) (2023-07-08)
2023-07-08 08:08:28 +00:00
Derrick Hammer 86bbe98ef8
Merge remote-tracking branch 'origin/develop' into develop 2023-07-08 04:07:31 -04:00
Derrick Hammer fa071d53a7
dep: update module hash 2023-07-08 04:07:24 -04:00
semantic-release-bot 34b5ccf77a chore(release): 0.0.2-develop.6 [skip ci]
## [0.0.2-develop.6](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.5...v0.0.2-develop.6) (2023-07-05)
2023-07-05 03:15:30 +00:00
Derrick Hammer 07d1fc514b
Merge remote-tracking branch 'origin/develop' into develop 2023-07-04 23:14:20 -04:00
Derrick Hammer a03e775060
dep: update module hash 2023-07-04 23:14:15 -04:00
semantic-release-bot 252e0007d6 chore(release): 0.0.2-develop.5 [skip ci]
## [0.0.2-develop.5](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.4...v0.0.2-develop.5) (2023-07-05)
2023-07-05 01:02:47 +00:00
Derrick Hammer b337aee1ab
Merge remote-tracking branch 'origin/develop' into develop 2023-07-04 21:01:56 -04:00
Derrick Hammer 2a20232269
dep: update module hash 2023-07-04 21:01:52 -04:00
semantic-release-bot 8dfd7e5bef chore(release): 0.0.2-develop.4 [skip ci]
## [0.0.2-develop.4](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.3...v0.0.2-develop.4) (2023-07-04)
2023-07-04 15:21:59 +00:00
Derrick Hammer bd50637c14
Merge remote-tracking branch 'origin/develop' into develop 2023-07-04 11:20:37 -04:00
Derrick Hammer e47fe353aa
dep: update module hash 2023-07-04 11:20:31 -04:00
semantic-release-bot 4cdaa8caab chore(release): 0.0.2-develop.3 [skip ci]
## [0.0.2-develop.3](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.2...v0.0.2-develop.3) (2023-07-04)
2023-07-04 14:11:59 +00:00
Derrick Hammer 47ad52a358
Merge remote-tracking branch 'origin/develop' into develop 2023-07-04 10:10:55 -04:00
Derrick Hammer 612aa1a0a0
dep: backoff.js is missing 2023-07-04 10:10:50 -04:00
semantic-release-bot c8746c001d chore(release): 0.0.2-develop.2 [skip ci]
## [0.0.2-develop.2](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.1...v0.0.2-develop.2) (2023-07-01)
2023-07-01 20:40:22 +00:00
Derrick Hammer 608cd614a4
Merge remote-tracking branch 'origin/develop' into develop 2023-07-01 16:39:32 -04:00
Derrick Hammer 8141edeb79
dep: update module hash 2023-07-01 16:39:25 -04:00
semantic-release-bot 11034dc7a8 chore(release): 0.0.2-develop.1 [skip ci]
## [0.0.2-develop.1](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.1...v0.0.2-develop.1) (2023-07-01)

### Reverts

* Revert "*Change end to close" ([b5a81d5](b5a81d51ab))
2023-07-01 20:07:12 +00:00
Derrick Hammer 009dc4e003
refactor: switch to emittery 2023-07-01 16:06:03 -04:00
Derrick Hammer d22b636889
refactor: use new sdks and portal system 2023-07-01 05:36:28 -04:00
10 changed files with 18473 additions and 316 deletions

13
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,13 @@
name: Build/Publish
on:
push:
branches:
- master
- develop
- develop-*
jobs:
main:
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
secrets: inherit

5
.presetterrc.json Normal file
View File

@ -0,0 +1,5 @@
{
"preset": [
"@lumeweb/node-library-preset"
]
}

84
CHANGELOG.md Normal file
View File

@ -0,0 +1,84 @@
# [0.1.0-develop.13](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.12...v0.1.0-develop.13) (2023-11-17)
# [0.1.0-develop.12](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.11...v0.1.0-develop.12) (2023-10-13)
# [0.1.0-develop.11](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.10...v0.1.0-develop.11) (2023-10-12)
# [0.1.0-develop.10](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.9...v0.1.0-develop.10) (2023-09-09)
# [0.1.0-develop.9](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.8...v0.1.0-develop.9) (2023-09-03)
# [0.1.0-develop.8](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.7...v0.1.0-develop.8) (2023-09-02)
# [0.1.0-develop.7](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.6...v0.1.0-develop.7) (2023-09-02)
# [0.1.0-develop.6](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.5...v0.1.0-develop.6) (2023-09-02)
# [0.1.0-develop.5](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.4...v0.1.0-develop.5) (2023-07-29)
# [0.1.0-develop.4](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.3...v0.1.0-develop.4) (2023-07-24)
# [0.1.0-develop.3](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.2...v0.1.0-develop.3) (2023-07-23)
### Features
* add setKeepAlive method ([19dceed](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/commit/19dceedab299c1cd35563c5c88a3f608cfc56deb))
# [0.1.0-develop.2](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.1.0-develop.1...v0.1.0-develop.2) (2023-07-23)
# [0.1.0-develop.1](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.14...v0.1.0-develop.1) (2023-07-22)
### Features
* add getListeners method to Socket ([0ec1dd1](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/commit/0ec1dd1aacdce1e85d6250db9b61a3edccfaafa7))
## [0.0.2-develop.14](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.13...v0.0.2-develop.14) (2023-07-22)
### Bug Fixes
* missing return ([8380254](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/commit/8380254638dde806ce38d3406ea6b4127cb2444b))
## [0.0.2-develop.13](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.12...v0.0.2-develop.13) (2023-07-22)
### Bug Fixes
* on write and end, log errors if we are trying to use a closed socket ([57efedd](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/commit/57efedd0affd5e647db185aff0ba1be2a137aef3))
## [0.0.2-develop.12](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.11...v0.0.2-develop.12) (2023-07-22)
### Bug Fixes
* change on to always return an instance of emittery unsubscribe function ([0c18c92](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/commit/0c18c92521de8b8685882b88ad8efa74a76617c6))
* return type required ([7eabf6a](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/commit/7eabf6a05da9dcd833b55f386896a70fa6ec736d))
## [0.0.2-develop.11](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.10...v0.0.2-develop.11) (2023-07-22)
## [0.0.2-develop.10](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.9...v0.0.2-develop.10) (2023-07-22)
## [0.0.2-develop.9](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.8...v0.0.2-develop.9) (2023-07-12)
## [0.0.2-develop.8](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.7...v0.0.2-develop.8) (2023-07-08)
## [0.0.2-develop.7](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.6...v0.0.2-develop.7) (2023-07-08)
## [0.0.2-develop.6](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.5...v0.0.2-develop.6) (2023-07-05)
## [0.0.2-develop.5](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.4...v0.0.2-develop.5) (2023-07-05)
## [0.0.2-develop.4](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.3...v0.0.2-develop.4) (2023-07-04)
## [0.0.2-develop.3](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.2...v0.0.2-develop.3) (2023-07-04)
## [0.0.2-develop.2](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.2-develop.1...v0.0.2-develop.2) (2023-07-01)
## [0.0.2-develop.1](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/compare/v0.0.1...v0.0.2-develop.1) (2023-07-01)
### Reverts
* Revert "*Change end to close" ([b5a81d5](https://git.lumeweb.com/LumeWeb/kernel-swarm-client/commit/b5a81d51ab490e5e8f405a18a5859f624d7b0b93))

52
dist/index.d.ts vendored
View File

@ -1,52 +0,0 @@
/// <reference types="node" />
import { Buffer } from "buffer";
import { Client } from "@lumeweb/libkernel-universal";
import { ErrTuple } from "@siaweb/libweb";
import type { eventNS, event, ListenerFn, OnOptions, Listener } from "eventemitter2";
export declare class SwarmClient extends Client {
private useDefaultSwarm;
private id;
private _autoReconnect;
private _connectBackoff;
private _ready?;
private _connectionListener?;
private _topics;
private _sockets;
get dht(): {
ready(): Promise<void>;
};
constructor(useDefaultDht?: boolean, autoReconnect?: boolean);
get swarm(): number | undefined;
connect(pubkey: string | Uint8Array): Promise<Socket>;
init(): Promise<ErrTuple>;
ready(): Promise<void>;
start(): Promise<void>;
private _listen;
addRelay(pubkey: string): Promise<void>;
removeRelay(pubkey: string): Promise<void>;
clearRelays(): Promise<void>;
getRelays(): Promise<string[]>;
join(topic: Buffer | Uint8Array | string): Promise<void>;
}
export declare class Socket extends Client {
private id;
private eventUpdates;
private syncMutex;
private swarm;
private userData?;
constructor(id: number, swarm: SwarmClient);
private _remotePublicKey?;
get remotePublicKey(): Uint8Array;
private _rawStream?;
get rawStream(): Uint8Array;
setup(): Promise<void>;
on(event: event | eventNS, listener: ListenerFn, options?: boolean | OnOptions): this | Listener;
off(event: event | eventNS, listener: ListenerFn): this;
write(message: string | Buffer): void;
end(): void;
private ensureEvent;
private trackEvent;
}
export declare const MODULE = "_AU-CzTIzrnnJSoVjfWG_d3cAb8_hONuZ1XaqbFlygrFlg";
export declare const createClient: (...args: any) => SwarmClient;
//# sourceMappingURL=index.d.ts.map

1
dist/index.d.ts.map vendored
View File

@ -1 +0,0 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,MAAM,EAAW,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAU,QAAQ,EAAY,MAAM,gBAAgB,CAAC;AAU5D,OAAO,KAAK,EACV,OAAO,EACP,KAAK,EACL,UAAU,EACV,SAAS,EACT,QAAQ,EACT,MAAM,eAAe,CAAC;AAEvB,qBAAa,WAAY,SAAQ,MAAM;IACrC,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,cAAc,CAAU;IAChC,OAAO,CAAC,eAAe,CAAM;IAE7B,OAAO,CAAC,MAAM,CAAC,CAAgB;IAC/B,OAAO,CAAC,mBAAmB,CAAC,CAG1B;IAEF,OAAO,CAAC,OAAO,CAA0C;IACzD,OAAO,CAAC,QAAQ,CAAkD;IAElE,IAAI,GAAG;;MAON;gBAEW,aAAa,UAAO,EAAE,aAAa,UAAQ;IAcvD,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAE9B;IAEY,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAiB5D,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC;IAIzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAMd,OAAO;IA2BR,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,SAAS,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAI9B,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAQtE;AAQD,qBAAa,MAAO,SAAQ,MAAM;IAChC,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,YAAY,CAAqC;IAEzD,OAAO,CAAC,SAAS,CAAe;IAEhC,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,QAAQ,CAAC,CAAa;gBAElB,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW;IAM1C,OAAO,CAAC,gBAAgB,CAAC,CAAa;IAEtC,IAAI,eAAe,IAAI,UAAU,CAEhC;IAED,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC,IAAI,SAAS,IAAI,UAAU,CAE1B;IAEK,KAAK;IAQX,EAAE,CACA,KAAK,EAAE,KAAK,GAAG,OAAO,EACtB,QAAQ,EAAE,UAAU,EACpB,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,GAC5B,IAAI,GAAG,QAAQ;IAiBlB,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,EAAE,QAAQ,EAAE,UAAU,GAAG,IAAI;IASvD,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIrC,GAAG,IAAI,IAAI;IAUX,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,UAAU;CAInB;AAED,eAAO,MAAM,MAAM,mDAAmD,CAAC;AAEvE,eAAO,MAAM,YAAY,+BAA4C,CAAC"}

179
dist/index.js vendored
View File

@ -1,179 +0,0 @@
import { Client, factory } from "@lumeweb/libkernel-universal";
import { hexToBuf } from "@siaweb/libweb";
import { blake2b } from "@noble/hashes/blake2b";
import b4a from "b4a";
// @ts-ignore
import Backoff from "backoff.js";
import { Mutex } from "async-mutex";
export class SwarmClient extends Client {
useDefaultSwarm;
id = 0;
_autoReconnect;
_connectBackoff;
_ready;
_connectionListener;
_topics = new Set();
_sockets = new Map();
get dht() {
const self = this;
return {
async ready() {
return self.ready();
},
};
}
constructor(useDefaultDht = true, autoReconnect = false) {
super();
this.useDefaultSwarm = useDefaultDht;
this._autoReconnect = autoReconnect;
this._connectBackoff = new Backoff({
strategy: "fibo",
maxAttempts: Number.MAX_SAFE_INTEGER,
});
this._connectBackoff.on("retry", (error) => {
this.logErr(error);
});
}
get swarm() {
return this.useDefaultSwarm ? undefined : this.id;
}
async connect(pubkey) {
if (typeof pubkey === "string") {
const buf = hexToBuf(pubkey);
pubkey = this.handleErrorOrReturn(buf);
}
let existing = Array.from(this._sockets.values()).filter((socket) => {
return b4a.equals(socket.remotePublicKey, pubkey);
});
if (existing.length) {
return existing[0];
}
throw new Error("not implemented");
}
async init() {
return await this.callModuleReturn("init", { swarm: this.swarm });
}
async ready() {
if (this._ready) {
return this._ready;
}
this._listen();
this._ready = this.callModuleReturn("ready", { swarm: this.swarm });
await this._ready;
this._ready = undefined;
for (const topic of this._topics) {
await this.join(topic);
}
}
async start() {
await this._connectBackoff.run(() => this.init());
await this.ready();
}
async _listen() {
if (!this._connectionListener) {
this._connectionListener = this.connectModule("listenConnections", { swarm: this.swarm }, async (socketId) => {
const socket = this._sockets.get(socketId) ?? (await createSocket(socketId, this));
socket.on("close", () => {
this._sockets.delete(socketId);
});
if (!this._sockets.has(socketId)) {
this._sockets.set(socketId, socket);
}
this.emit("connection", socket);
});
}
await this._connectionListener[1];
this._connectionListener = undefined;
this.start();
}
async addRelay(pubkey) {
return this.callModuleReturn("addRelay", { pubkey, swarm: this.swarm });
}
async removeRelay(pubkey) {
return this.callModuleReturn("removeRelay", { pubkey, swarm: this.swarm });
}
async clearRelays() {
return this.callModuleReturn("clearRelays", { swarm: this.swarm });
}
async getRelays() {
return this.callModuleReturn("getRelays", { swarm: this.swarm });
}
async join(topic) {
if (typeof topic === "string") {
topic = blake2b(topic, { dkLen: 32 });
}
this._topics.add(topic);
this.callModule("join", { id: this.id, topic });
}
}
export class Socket extends Client {
id;
eventUpdates = {};
syncMutex = new Mutex();
swarm;
userData = null;
constructor(id, swarm) {
super();
this.id = id;
this.swarm = swarm;
}
_remotePublicKey;
get remotePublicKey() {
return this._remotePublicKey;
}
_rawStream;
get rawStream() {
return this._rawStream;
}
async setup() {
let info = await this.callModuleReturn("socketGetInfo", { id: this.id });
this._remotePublicKey = info.remotePublicKey;
this._rawStream = info.rawStream;
await this.swarm.emitAsync("setup", this);
}
on(event, listener, options) {
const [update, promise] = this.connectModule("socketListenEvent", { id: this.id, event: event }, (data) => {
this.emit(event, data);
});
this.trackEvent(event, update);
promise.then(() => {
this.off(event, listener);
});
return super.on(event, listener, options);
}
off(event, listener) {
const updates = [...this.eventUpdates[event]];
this.eventUpdates[event] = [];
for (const func of updates) {
func();
}
return super.off(event, listener);
}
write(message) {
this.callModule("socketWrite", { id: this.id, message });
}
end() {
this.callModule("socketExists", { id: this.id }).then(([exists]) => {
if (exists) {
this.callModule("socketClose", { id: this.id });
}
});
}
ensureEvent(event) {
if (!(event in this.eventUpdates)) {
this.eventUpdates[event] = [];
}
}
trackEvent(event, update) {
this.ensureEvent(event);
this.eventUpdates[event].push(update);
}
}
export const MODULE = "_AU-CzTIzrnnJSoVjfWG_d3cAb8_hONuZ1XaqbFlygrFlg";
export const createClient = factory(SwarmClient, MODULE);
const socketFactory = factory(Socket, MODULE);
const createSocket = async (...args) => {
const socket = socketFactory(...args);
await socket.setup();
return socket;
};

18279
npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +1,33 @@
{ {
"name": "@lumeweb/kernel-swarm-client", "name": "@lumeweb/kernel-swarm-client",
"version": "0.1.0", "version": "0.1.0-develop.13",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "lib/index.js",
"dependencies": { "repository": {
"@lumeweb/libkernel-universal": "git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git", "type": "git",
"@noble/hashes": "^1.3.0", "url": "gitea@git.lumeweb.com:LumeWeb/kernel-swarm-client.git"
"@siaweb/libweb": "git+https://git.lumeweb.com/LumeWeb/libsiaweb.git",
"async-mutex": "^0.4.0",
"b4a": "^1.6.3",
"backoff.js": "^1.0.4",
"p-defer": "^4.0.0",
"protomux": "git+https://git.lumeweb.com/LumeWeb/protomux.git"
}, },
"devDependencies": { "devDependencies": {
"@lumeweb/node-library-preset": "^0.2.7",
"@types/b4a": "^1.6.0", "@types/b4a": "^1.6.0",
"@types/node": "^18.15.11", "presetter": "*"
"eventemitter2": "^6.4.9", },
"prettier": "^2.8.7", "readme": "ERROR: No README data found!",
"pretty": "^2.0.0", "scripts": {
"typescript": "^4.9.5" "prepare": "presetter bootstrap",
"build": "run build",
"semantic-release": "semantic-release"
},
"dependencies": {
"@lumeweb/libkernel": "^0.1.0-develop.68",
"async-mutex": "^0.4.0",
"b4a": "^1.6.4",
"backoff.js": "^1.0.4"
},
"files": [
"lib/**"
],
"publishConfig": {
"access": "public"
} }
} }

View File

@ -1,22 +1,15 @@
import { Buffer } from "buffer"; import { Buffer } from "buffer";
import { Client, factory } from "@lumeweb/libkernel-universal"; import { Client, factory } from "@lumeweb/libkernel/module";
import { DataFn, ErrTuple, hexToBuf } from "@siaweb/libweb"; import { DataFn, ErrTuple, logErr } from "@lumeweb/libkernel";
import { hexToBytes } from "@lumeweb/libweb";
import { blake2b } from "@noble/hashes/blake2b"; import { blake2b } from "@noble/hashes/blake2b";
import b4a from "b4a"; import b4a from "b4a";
// @ts-ignore // @ts-ignore
import Backoff from "backoff.js"; import Backoff from "backoff.js";
import { Mutex } from "async-mutex";
// @ts-ignore // @ts-ignore
import Protomux from "protomux"; import Protomux from "protomux";
import { UnsubscribeFn } from "emittery";
import type {
eventNS,
event,
ListenerFn,
OnOptions,
Listener,
} from "eventemitter2";
export class SwarmClient extends Client { export class SwarmClient extends Client {
private useDefaultSwarm: boolean; private useDefaultSwarm: boolean;
@ -27,7 +20,7 @@ export class SwarmClient extends Client {
private _ready?: Promise<void>; private _ready?: Promise<void>;
private _connectionListener?: [ private _connectionListener?: [
sendUpdate: DataFn, sendUpdate: DataFn,
response: Promise<ErrTuple> response: Promise<ErrTuple>,
]; ];
private _topics: Set<Uint8Array> = new Set<Uint8Array>(); private _topics: Set<Uint8Array> = new Set<Uint8Array>();
@ -42,8 +35,8 @@ export class SwarmClient extends Client {
}; };
} }
constructor(useDefaultDht = true, autoReconnect = false) { constructor(module: string, useDefaultDht = true, autoReconnect = false) {
super(); super(module);
this.useDefaultSwarm = useDefaultDht; this.useDefaultSwarm = useDefaultDht;
this._autoReconnect = autoReconnect; this._autoReconnect = autoReconnect;
this._connectBackoff = new Backoff({ this._connectBackoff = new Backoff({
@ -52,7 +45,7 @@ export class SwarmClient extends Client {
}); });
this._connectBackoff.on("retry", (error: any) => { this._connectBackoff.on("retry", (error: any) => {
this.logErr(error); logErr(error);
}); });
} }
@ -62,8 +55,7 @@ export class SwarmClient extends Client {
public async connect(pubkey: string | Uint8Array): Promise<Socket> { public async connect(pubkey: string | Uint8Array): Promise<Socket> {
if (typeof pubkey === "string") { if (typeof pubkey === "string") {
const buf = hexToBuf(pubkey); pubkey = hexToBytes(pubkey);
pubkey = this.handleErrorOrReturn(buf);
} }
let existing = Array.from(this._sockets.values()).filter((socket) => { let existing = Array.from(this._sockets.values()).filter((socket) => {
@ -123,7 +115,7 @@ export class SwarmClient extends Client {
} }
this.emit("connection", socket); this.emit("connection", socket);
} },
); );
} }
@ -166,15 +158,13 @@ interface SocketRawStream {
export class Socket extends Client { export class Socket extends Client {
private id: number; private id: number;
private eventUpdates: { [event: string]: DataFn[] } = {}; private eventUpdates: { [event: string]: Map<Function, DataFn> } = {};
private syncMutex = new Mutex();
private swarm: SwarmClient; private swarm: SwarmClient;
private userData?: any = null; private userData?: any = null;
constructor(id: number, swarm: SwarmClient) { constructor(module: string, id: number, swarm: SwarmClient) {
super(); super(module);
this.id = id; this.id = id;
this.swarm = swarm; this.swarm = swarm;
} }
@ -196,69 +186,101 @@ export class Socket extends Client {
this._remotePublicKey = info.remotePublicKey; this._remotePublicKey = info.remotePublicKey;
this._rawStream = info.rawStream; this._rawStream = info.rawStream;
await this.swarm.emitAsync("setup", this); await this.swarm.emit("setup", this);
} }
on( on(event: any, listener: any): UnsubscribeFn {
event: event | eventNS, const parentOn = super.on(event, listener);
listener: ListenerFn, if (this.eventUpdates[event]?.has(listener)) {
options?: boolean | OnOptions return parentOn;
): this | Listener { }
const [update, promise] = this.connectModule( const [update, promise] = this.connectModule(
"socketListenEvent", "socketListenEvent",
{ id: this.id, event: event }, { id: this.id, event: event },
(data: any) => { (data: any) => {
this.emit(event, data); this.emit(event, data);
} },
); );
this.trackEvent(event as string, update); this.trackEvent(event as string, listener, update);
promise.then(() => { promise.then(() => {
this.off(event as string, listener); this.off(event as string, listener);
}); });
return super.on(event, listener, options); return parentOn;
} }
off(event: event | eventNS, listener: ListenerFn): this { off(event: any, listener: any): this {
const updates = [...this.eventUpdates[event as string]]; if (listener) {
this.eventUpdates[event as string] = []; const updates = this.eventUpdates[event];
for (const func of updates) { updates?.get(listener)?.();
func(); updates?.delete(listener);
return this;
} }
return super.off(event, listener);
const updates = [...this.eventUpdates[event as string].values()];
this.eventUpdates[event as string] = new Map<Function, DataFn>();
updates.forEach((update) => update());
super.off(event, listener);
return this;
} }
write(message: string | Buffer): void { write(message: string | Buffer): void {
this.callModule("socketExists", { id: this.id }).then(
([exists]: ErrTuple) => {
if (!exists) {
logErr("tried to write to closed socket");
return;
}
this.callModule("socketWrite", { id: this.id, message });
},
);
this.callModule("socketWrite", { id: this.id, message }); this.callModule("socketWrite", { id: this.id, message });
} }
end(): void { end(): void {
this.callModule("socketExists", { id: this.id }).then( this.callModule("socketExists", { id: this.id }).then(
([exists]: ErrTuple) => { ([exists]: ErrTuple) => {
if (exists) { if (!exists) {
this.callModule("socketClose", { id: this.id }); logErr("tried to close a closed socket");
return;
} }
} this.callModule("socketClose", { id: this.id });
},
); );
} }
async getListeners() {
return this.callModuleReturn("socketListeners", { id: this.id });
}
public setKeepAlive(ms: number) {
this.callModuleReturn("socketSetKeepAlive", {
id: this.id,
alive: ms,
});
}
private ensureEvent(event: string): void { private ensureEvent(event: string): void {
if (!(event in this.eventUpdates)) { if (!(event in this.eventUpdates)) {
this.eventUpdates[event] = []; this.eventUpdates[event] = new Map<Function, DataFn>();
} }
} }
private trackEvent(event: string, update: DataFn): void { private trackEvent(event: string, listener: Function, update: DataFn): void {
this.ensureEvent(event as string); this.ensureEvent(event as string);
this.eventUpdates[event].push(update); this.eventUpdates[event].set(listener, update);
} }
} }
export const MODULE = "_AU-CzTIzrnnJSoVjfWG_d3cAb8_hONuZ1XaqbFlygrFlg"; export const MODULE = "zrjTDyEX8Mh2PdDdRj5YL2byFGrYe1ksczRwPaTRFaCGSMG";
export const createClient = factory<SwarmClient>(SwarmClient, MODULE); export const createClient = factory<SwarmClient>(SwarmClient, MODULE);
// @ts-ignore
const socketFactory = factory<Socket>(Socket, MODULE); const socketFactory = factory<Socket>(Socket, MODULE);
const createSocket = async (...args: any): Promise<Socket> => { const createSocket = async (...args: any): Promise<Socket> => {
const socket = socketFactory(...args); const socket = socketFactory(...args);

View File

@ -1,23 +0,0 @@
{
"compilerOptions": {
"declaration": true,
"strict": true,
"module": "esnext",
"target": "esnext",
"esModuleInterop": true,
"sourceMap": false,
"rootDir": "src",
"outDir": "dist",
"typeRoots": [
"node_modules/@types",
],
"moduleResolution": "node",
"declarationMap": true,
"declarationDir": "dist",
"emitDeclarationOnly": false,
"allowJs": true
},
"include": [
"src"
]
}