skyfall 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +45 -22
- data/README.md +134 -30
- data/SECURITY.md +16 -0
- data/data/jetstream_zstd_dictionary +0 -0
- data/lib/skyfall/collection.rb +8 -1
- data/lib/skyfall/errors.rb +6 -0
- data/lib/skyfall/firehose/info_message.rb +1 -1
- data/lib/skyfall/firehose/message.rb +23 -6
- data/lib/skyfall/firehose/operation.rb +8 -8
- data/lib/skyfall/firehose/sync_message.rb +5 -0
- data/lib/skyfall/firehose.rb +2 -2
- data/lib/skyfall/jetstream/account_message.rb +4 -1
- data/lib/skyfall/jetstream/commit_message.rb +10 -2
- data/lib/skyfall/jetstream/identity_message.rb +3 -1
- data/lib/skyfall/jetstream/message.rb +35 -10
- data/lib/skyfall/jetstream/operation.rb +1 -1
- data/lib/skyfall/jetstream.rb +130 -44
- data/lib/skyfall/jetstream_v2/account_message.rb +41 -0
- data/lib/skyfall/jetstream_v2/commit_message.rb +51 -0
- data/lib/skyfall/jetstream_v2/identity_message.rb +37 -0
- data/lib/skyfall/jetstream_v2/info_message.rb +56 -0
- data/lib/skyfall/jetstream_v2/message.rb +213 -0
- data/lib/skyfall/jetstream_v2/sync_message.rb +64 -0
- data/lib/skyfall/jetstream_v2/unknown_message.rb +13 -0
- data/lib/skyfall/jetstream_v2.rb +257 -0
- data/lib/skyfall/version.rb +1 -1
- data/lib/skyfall.rb +2 -0
- metadata +27 -3
- data/sig/skyfall.rbs +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b953131060753aed24131f0ba3286a8d956d35c93d89b3400b2179b93cec3f7
|
|
4
|
+
data.tar.gz: 2227498a04c1a2611c905cd4a6a1b4bd7d12c7197154d266b9d94c36654225a0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 26d7ed43387432f24d6ac60081fd232973bc755f3d7afa99690814a31afc3b04fbf24be9d4964f6addfb94e3a419579d4d97e54e6b8f21372938ca259d1b4bb9
|
|
7
|
+
data.tar.gz: 51c8c92daba02ba2b48575323555fd9908cd9f6bb7f4a728a9cc027dedc4e39836a5db2a79df13263e33c6c793c5b3f69f29bb4532cdc8fdefbbade53ad73cbe
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
|
-
## [0.
|
|
1
|
+
## [0.8.0] – 2026-11-24
|
|
2
|
+
|
|
3
|
+
Added:
|
|
4
|
+
|
|
5
|
+
- added support for the Jetstream v2 API via `Skyfall::JetstreamV2` and related `Message` class family; `Skyfall::Jetstream` can also be used to connect to a v2 service, though it uses the `/subscribe` compatibility endpoint (`Skyfall::JetstreamV2` does not work with v1 services)
|
|
6
|
+
- added support for Zstd compression (`:compress => true`) in both Jetstream APIs
|
|
7
|
+
- added support for `:maxMessageSizeBytes` option in both Jetstream APIs
|
|
8
|
+
- added `#cursor` as an alias for `#seq` in `Message` classes
|
|
9
|
+
- added `#time_us` to `Skyfall::Firehose::Message`
|
|
10
|
+
- added `#rev` to `Skyfall::Jetstream::CommitMessage`
|
|
11
|
+
- `Skyfall::Jetstream` also accepts parameter names `dids` & `collections` as used in `Skyfall::JetstreamV2`
|
|
12
|
+
- added constants and symbol shortcodes for `app.bsky.actor.link`, `app.bsky.graph.referencelistoptout` and `app.bsky.actor.contentVisibilityDeclaration`
|
|
13
|
+
|
|
14
|
+
Changed:
|
|
15
|
+
|
|
16
|
+
- some stricter/improved validation in `Message` constructors and in parameter parsing
|
|
17
|
+
- don't reset `cursor` to nil when processing a `Skyfall::Firehose::InfoMessage`
|
|
18
|
+
|
|
19
|
+
Possibly breaking changes:
|
|
20
|
+
|
|
21
|
+
- when connecting to a Jetstream v2 service using `Skyfall::Jetstream` through the compatibility API, `#seq` and `#cursor` will now return a sequential number cursor from the `cursor` field instead of the `time_us` timestamp (both can be passed as the cursor when reconnecting)
|
|
22
|
+
- `Skyfall::Jetstream` and `Skyfall::JetstreamV2` will now reject `nil` and `[]` values passed as dids/collections/kinds filter
|
|
23
|
+
|
|
24
|
+
## [0.7.2] – 2026-08-17
|
|
2
25
|
|
|
3
26
|
- bumped up Oxygene dependency (see below under 0.7.1) to 0.1, with a stricter dependency rule
|
|
4
27
|
- includes various performance improvements for Base 32 en/decoding, CID & CAR parsing
|
|
@@ -10,12 +33,12 @@
|
|
|
10
33
|
- some minor optimizations
|
|
11
34
|
- added some unit tests
|
|
12
35
|
|
|
13
|
-
## [0.7.1]
|
|
36
|
+
## [0.7.1] – 2026-08-05
|
|
14
37
|
|
|
15
38
|
- extracted `CID` and `CarArchive` to a new gem "oxygene"
|
|
16
39
|
- added `CommitMessage#cid` as alias of `#commit`
|
|
17
40
|
|
|
18
|
-
## [0.7.0]
|
|
41
|
+
## [0.7.0] – 2026-02-13
|
|
19
42
|
|
|
20
43
|
The main change in this version is that inline [YARD documentation](https://rubydoc.info/gems/skyfall/) has been added. This was also a good opportunity to review some APIs and tweak some things in order to get Skyfall a bit closer to 1.0.
|
|
21
44
|
|
|
@@ -58,26 +81,26 @@ Additional validations and other changes:
|
|
|
58
81
|
- fixed the `require`s config in some files so they can be loaded in any order
|
|
59
82
|
|
|
60
83
|
|
|
61
|
-
## [0.6.1]
|
|
84
|
+
## [0.6.1] – 2026-01-08
|
|
62
85
|
|
|
63
86
|
- added `:bsky_notif_declaration` shortcode for `app.bsky.notification.declaration` collection
|
|
64
87
|
- throw error when trying to run two streams in one process (see b4a1514f5da28983205765e55724b5c4abe6c5e4 for details)
|
|
65
88
|
- added protected `#send_data` and `#socket` methods in `Stream` for use in `Stream` subclasses (currently for the Tapfall gem)
|
|
66
89
|
- added a way to customize headers sent when connecting in `Stream` subclasses through the `#request_headers` method
|
|
67
90
|
|
|
68
|
-
## [0.6.0]
|
|
91
|
+
## [0.6.0] – 2025-06-25
|
|
69
92
|
|
|
70
93
|
- significantly speeded up reading of events from the binary firehose (`Skyfall::Firehose`) – up to 4-5x faster than before
|
|
71
94
|
- removed the `Skyfall::Stream.new` constructor deprecated in 0.5.0
|
|
72
95
|
|
|
73
|
-
## [0.5.1]
|
|
96
|
+
## [0.5.1] – 2025-05-18
|
|
74
97
|
|
|
75
98
|
- added support for the new `#sync` message type
|
|
76
99
|
- added `#unknown?` helper in `Skyfall::Firehose::Message` and `Skyfall::Jetstream::Message`, which returns true if the message type is `UnknownMessage`
|
|
77
100
|
- added `:bsky_verification` and `:bsky_actor_status` lexicon type and shortcode
|
|
78
101
|
- added one missing require
|
|
79
102
|
|
|
80
|
-
## [0.5.0]
|
|
103
|
+
## [0.5.0] – 2024-11-15
|
|
81
104
|
|
|
82
105
|
Jetstream support! You can now connect to [Jetstream](https://github.com/bluesky-social/jetstream) sources using `Skyfall::Jetstream` (see readme).
|
|
83
106
|
|
|
@@ -92,17 +115,17 @@ In most cases, you should only need to update the `Skyfall::Stream` class name i
|
|
|
92
115
|
|
|
93
116
|
Also, small change to the user agent API: `Skyfall::Stream` now has an additional metod `version_string`, which will always return `Skyfall/0.x.y` – it's recommended to use that instead of `default_user_agent` to build your own user agent string that includes the library version. `default_user_agent` now passes through to `version_string`, but it could be changed in future to return something else.
|
|
94
117
|
|
|
95
|
-
## [0.4.1]
|
|
118
|
+
## [0.4.1] – 2024-10-04
|
|
96
119
|
|
|
97
120
|
- performance fix – don't decode CAR sections which aren't needed, which is most of them; this cuts the amount of memory that GC has to free up by about one third, and should speed up processing by around ~10%
|
|
98
121
|
|
|
99
|
-
## [0.4.0]
|
|
122
|
+
## [0.4.0] – 2024-09-23
|
|
100
123
|
|
|
101
124
|
- (re)added a "hearbeat" feature (removed earlier in 0.2.0) to fix the occasional issue when the websocket stops receiving data, but doesn't disconnect (not enabled by default, turn it on by setting `check_heartbeat` to true)
|
|
102
125
|
- added a way to set the user agent sent when connecting using the `user_agent` field (default is `"Skyfall/#{version}"`)
|
|
103
126
|
- added `app.bsky.feed.postgate` record type
|
|
104
127
|
|
|
105
|
-
## [0.3.1]
|
|
128
|
+
## [0.3.1] – 2024-06-28
|
|
106
129
|
|
|
107
130
|
- added `app.bsky.graph.starterpack` and `chat.bsky.actor.declaration` record types
|
|
108
131
|
- added `#account` event type (`AccountMessage`)
|
|
@@ -110,7 +133,7 @@ Also, small change to the user agent API: `Skyfall::Stream` now has an additiona
|
|
|
110
133
|
- fixed param validation on `Stream` initialization
|
|
111
134
|
- reverted the change that added Ruby stdlib dependencies explicitly to the gemspec, since this causes more problems than it's worth – only `base64` is left there, since it's the one now required to be listed
|
|
112
135
|
|
|
113
|
-
## [0.3.0]
|
|
136
|
+
## [0.3.0] – 2024-03-21
|
|
114
137
|
|
|
115
138
|
- added support for labeller firehose, served by labeller services at the `com.atproto.label.subscribeLabels` endpoint (aliased as `:subscribe_labels`)
|
|
116
139
|
- the `#labels` messages from the labeller firehose are parsed into a `LabelsMessage`, which includes a `labels` array of `Label` objects
|
|
@@ -118,11 +141,11 @@ Also, small change to the user agent API: `Skyfall::Stream` now has an additiona
|
|
|
118
141
|
- added default error handler to `Stream` which logs the error to `$stdout` – set `stream.on_error = nil` to disable
|
|
119
142
|
- added Ruby stdlib dependencies explicitly to the gemspec – fixes a warning in Ruby 3.3 when requiring `base64`, which will be extracted as an optional gem in 3.4
|
|
120
143
|
|
|
121
|
-
## [0.2.5]
|
|
144
|
+
## [0.2.5] – 2024-03-14
|
|
122
145
|
|
|
123
146
|
- added `:bsky_labeler` record type symbol & collection constant
|
|
124
147
|
|
|
125
|
-
## [0.2.4]
|
|
148
|
+
## [0.2.4] – 2024-02-27
|
|
126
149
|
|
|
127
150
|
- added support for `#identity` message type
|
|
128
151
|
- added `Operation#did` as an alias of `#repo`
|
|
@@ -131,24 +154,24 @@ Also, small change to the user agent API: `Skyfall::Stream` now has an additiona
|
|
|
131
154
|
- the `server` parameter in `Stream` initializer can be a full URL with scheme, which lets you connect to e.g. `ws://localhost` (since by default, `wss://` is used)
|
|
132
155
|
- tweaked `#inspect` output of `Stream` and `Operation`
|
|
133
156
|
|
|
134
|
-
## [0.2.3]
|
|
157
|
+
## [0.2.3] – 2023-09-28
|
|
135
158
|
|
|
136
159
|
- fixed encoding of image CIDs again (they should be wrapped in a `$link` object)
|
|
137
160
|
- binary strings are now correctly returned as `$bytes` objects
|
|
138
161
|
- added `list`, `listblock` and `threadgate` to record type symbols and collection constants
|
|
139
162
|
|
|
140
|
-
## [0.2.2]
|
|
163
|
+
## [0.2.2] – 2023-09-06
|
|
141
164
|
|
|
142
165
|
- fixed image CIDs returned in the record JSON as CBOR tag objects (they are now returned decoded to the string form)
|
|
143
166
|
|
|
144
|
-
## [0.2.1]
|
|
167
|
+
## [0.2.1] – 2023-08-19
|
|
145
168
|
|
|
146
169
|
- optimized `WebsocketMessage` parsing performance – lazy parsing of most properties (message decoding should be over 50% faster on average)
|
|
147
170
|
- added separate subclasses of `WebsocketMessage` for different message types
|
|
148
171
|
- added support for `#handle`, `#info` and `#tombstone` message types
|
|
149
172
|
- `UnknownMessage` is returned for unrecognized message types
|
|
150
173
|
|
|
151
|
-
## [0.2.0]
|
|
174
|
+
## [0.2.0] – 2023-07-24
|
|
152
175
|
|
|
153
176
|
- switched the websocket library from `websocket-client-simple` to `faye-websocket`, which should make event parsing up to ~30× faster (!)
|
|
154
177
|
- added `auto_reconnect` property to `Stream` (on by default) – if true, it will try to reconnect with an exponential backoff when the websocket disconnects, until you call `Stream#disconnect`
|
|
@@ -159,7 +182,7 @@ Note:
|
|
|
159
182
|
- the disconnect event no longer passes an error object in the argument
|
|
160
183
|
- there is currently no "heartbeat" feature as in 0.1.x that checks for a stuck connection – but it doesn't seem to be needed
|
|
161
184
|
|
|
162
|
-
## [0.1.3]
|
|
185
|
+
## [0.1.3] – 2023-07-04
|
|
163
186
|
|
|
164
187
|
- allow passing a previously saved cursor to websocket to replay any missed events
|
|
165
188
|
- the cursor is also kept in memory and automatically used when reconnecting
|
|
@@ -167,19 +190,19 @@ Note:
|
|
|
167
190
|
- fixed connecting to websocket when endpoint is given as a string
|
|
168
191
|
- improved error handling during parsing
|
|
169
192
|
|
|
170
|
-
## [0.1.2]
|
|
193
|
+
## [0.1.2] – 2023-06-15
|
|
171
194
|
|
|
172
195
|
- added rkey property for Operation
|
|
173
196
|
|
|
174
|
-
## [0.1.1]
|
|
197
|
+
## [0.1.1] – 2023-06-13
|
|
175
198
|
|
|
176
199
|
- added heartbeat thread to restart websocket if it stops responding
|
|
177
200
|
|
|
178
|
-
## [0.1.0]
|
|
201
|
+
## [0.1.0] – 2023-06-01
|
|
179
202
|
|
|
180
203
|
- connecting to the firehose websocket
|
|
181
204
|
|
|
182
|
-
## [0.0.1]
|
|
205
|
+
## [0.0.1] – 2023-05-31
|
|
183
206
|
|
|
184
207
|
Initial release:
|
|
185
208
|
|
data/README.md
CHANGED
|
@@ -12,7 +12,7 @@ A Ruby gem for streaming data from the Bluesky/ATProto firehose 🦋
|
|
|
12
12
|
|
|
13
13
|
Skyfall is a Ruby library for connecting to the *"[firehose](https://atproto.com/specs/event-stream)"* of the Bluesky social network, i.e. a websocket which streams all new posts and everything else happening on the Bluesky network in real time. The code connects to the websocket endpoint, decodes the messages which are encoded in some binary formats like DAG-CBOR, and returns the data as Ruby objects, which you can filter and save to some kind of database (e.g. in order to create a custom feed).
|
|
14
14
|
|
|
15
|
-
Since version 0.5, Skyfall also supports connecting to [Jetstream](https://github.com/bluesky-social/jetstream/) sources, which serve the same kind of stream, but as JSON messages instead of CBOR.
|
|
15
|
+
Since version 0.5, Skyfall also supports connecting to [Jetstream](https://github.com/bluesky-social/jetstream/) sources, which serve the same kind of stream, but as JSON messages instead of CBOR. Jetstream v2 API is supported since version 0.8.
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
## Installation
|
|
@@ -25,22 +25,25 @@ To install the gem, run the command:
|
|
|
25
25
|
|
|
26
26
|
Or add this to your app's `Gemfile`:
|
|
27
27
|
|
|
28
|
-
gem 'skyfall', '~> 0.
|
|
28
|
+
gem 'skyfall', '~> 0.8'
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
## Usage
|
|
32
32
|
|
|
33
33
|
### Standard ATProto firehose
|
|
34
34
|
|
|
35
|
-
To connect to the firehose, start by creating a `Skyfall::Firehose` object, specifying the server hostname and endpoint name:
|
|
35
|
+
To connect to the firehose, start by creating a `Skyfall::Firehose` object, specifying the server hostname and optionally an endpoint name:
|
|
36
36
|
|
|
37
37
|
```rb
|
|
38
38
|
require 'skyfall'
|
|
39
39
|
|
|
40
40
|
sky = Skyfall::Firehose.new('bsky.network', :subscribe_repos)
|
|
41
|
+
|
|
42
|
+
# or (:subscribe_repos is the default)
|
|
43
|
+
sky = Skyfall::Firehose.new('bsky.network')
|
|
41
44
|
```
|
|
42
45
|
|
|
43
|
-
The server name can be just a hostname, or a full URL with a `ws:` or `wss:` scheme, which is useful if you want to use a non-encrypted websocket connection, e.g. `"ws://localhost:8000"`. The endpoint can be either a full NSID string like `"com.atproto.sync.subscribeRepos"`, or one of the defined symbol shortcuts – you will almost always want to
|
|
46
|
+
The server name can be just a hostname, or a full URL with a `ws:` or `wss:` scheme, which is useful if you want to use a non-encrypted websocket connection, e.g. `"ws://localhost:8000"`. The endpoint can be either a full NSID string like `"com.atproto.sync.subscribeRepos"`, or one of the defined symbol shortcuts – you will almost always want to use `:subscribe_repos`.
|
|
44
47
|
|
|
45
48
|
Next, set up event listeners to handle incoming messages and get notified of errors. Here are all the available listeners (you will need at least either `on_message` or `on_raw_message`):
|
|
46
49
|
|
|
@@ -81,10 +84,16 @@ The `#connect` method blocks until the connection is explicitly closed with `#di
|
|
|
81
84
|
|
|
82
85
|
Alternatively, you can connect to a [Jetstream](https://github.com/bluesky-social/jetstream/) server. Jetstream is a firehose proxy that lets you stream data as simple JSON instead, which uses much less bandwidth, and allows you to pick only a subset of events that you're interested in, e.g. only posts or only from specific accounts. (See the [configuration section](#jetstream-filters) for more info on Jetstream filtering.)
|
|
83
86
|
|
|
84
|
-
|
|
87
|
+
There are two different versions of Jetstream:
|
|
88
|
+
|
|
89
|
+
* the [original Jetstream](https://github.com/bluesky-social/jetstream-legacy/) (v1); most community-run [Jetstream instances](https://pulsar.feeds.blue) out there are running this version. Use the `Skyfall::Jetstream` class to connect to those.
|
|
90
|
+
* the [Jetstream v2](https://github.com/bluesky-social/jetstream/), which uses a slightly different JSON structure, keeps a complete historical archive, and has APIs for backfilling historical data (not supported in Skyfall yet). Use the `Skyfall::JetstreamV2` class to connect to v2 instances, although `Skyfall::Jetstream` can also be used to connect to the v1 compatibility API. `Skyfall::JetstreamV2` will not work with v1 instances.
|
|
91
|
+
|
|
92
|
+
Both `Skyfall::Jetstream` and `Skyfall::JetstreamV2` have intentionally the same API as `Skyfall::Firehose` as much as possible:
|
|
85
93
|
|
|
86
94
|
```rb
|
|
87
|
-
sky = Skyfall::Jetstream.new('
|
|
95
|
+
sky = Skyfall::Jetstream.new('frankfurt.firehose.stream')
|
|
96
|
+
sky2 = Skyfall::JetstreamV2.new('jetstream.us-east.bsky.network')
|
|
88
97
|
|
|
89
98
|
sky.on_message { |msg| ... }
|
|
90
99
|
sky.on_error { |e| ... }
|
|
@@ -96,30 +105,49 @@ sky.connect
|
|
|
96
105
|
|
|
97
106
|
### Cursors
|
|
98
107
|
|
|
99
|
-
ATProto websocket endpoints implement a "*cursor*" feature to help you make sure that you don't miss anything if your connection is down for a bit (because of a network issue, server restart, deploy etc.). Each message includes a `seq` field, which is the sequence number of the event. You can keep track of the last seq you've seen, and when you reconnect, you pass that number as a cursor parameter – the server will then "replay" all events you might have missed since that last one. (
|
|
108
|
+
ATProto websocket endpoints implement a "*cursor*" feature to help you make sure that you don't miss anything if your connection is down for a bit (because of a network issue, server restart, deploy etc.). Each message includes a `seq` field, which is the sequence number of the event. You can keep track of the last seq you've seen, and when you reconnect, you pass that number as a cursor parameter – the server will then "replay" all events you might have missed since that last one. (Different relay and Jetstream servers have differently sized replay buffers depending on configuration, usually between 24 and 72 hours.)
|
|
100
109
|
|
|
101
|
-
To use a cursor when connecting to the firehose, pass it as the third parameter to `Skyfall::Firehose`. You should then regularly save the `seq` of the last event to some permanent storage, and then load it from there when reconnecting.
|
|
110
|
+
To use a cursor when connecting to the CBOR firehose, pass it as the third (or second) parameter to `Skyfall::Firehose`. You should then regularly save the `seq` of the last event (also aliased as `cursor`) to some permanent storage, and then load it from there when reconnecting.
|
|
102
111
|
|
|
103
112
|
A full-network firehose sends many hundreds of events per second, so depending on your use case, it might be enough if you save it every n events (e.g. every 100 or 1000) and on clean shutdown:
|
|
104
113
|
|
|
105
114
|
```rb
|
|
106
115
|
cursor = load_cursor
|
|
107
116
|
|
|
108
|
-
sky = Skyfall::Firehose.new('bsky.network',
|
|
117
|
+
sky = Skyfall::Firehose.new('bsky.network', cursor)
|
|
118
|
+
|
|
109
119
|
sky.on_message do |msg|
|
|
110
|
-
save_cursor(msg.
|
|
120
|
+
save_cursor(msg.cursor) if msg.cursor % 1000 == 0
|
|
111
121
|
process_message(msg)
|
|
112
122
|
end
|
|
113
123
|
```
|
|
114
124
|
|
|
115
|
-
Jetstream has a similar mechanism, except the cursor
|
|
125
|
+
Jetstream has a similar mechanism, except the cursor works a bit differently depending on the Jetstream client and server version:
|
|
126
|
+
|
|
127
|
+
* v1 servers include a `time_us` field, which is the Unix timestamp of the event in microseconds, which acts as a cursor. For a v1 service, `seq` and `cursor` methods in `Skyfall::Jetstream::Message` will both return this value.
|
|
128
|
+
* v2 servers include a `seq` field with a sequential number cursor like in the CBOR firehose. `seq` / `cursor` methods in `Skyfall::JetstreamV2::Message` return this sequential cursor value. For symmetry with `Skyfall::Jetstream::Message`, a `time_us` method is also provided here that returns the event time in microseconds.
|
|
129
|
+
* when a v1 client (`Skyfall::Jetstream`) connects to a v2 service, it uses a special v1 compatibility API there. In that API, the responses have a v1 JSON shape, *except* they also include a sequential cursor in a `cursor` field. In that case, `Skyfall::Jetstream::Message` will have a `time_us` with the timestamp field, but `seq` & `cursor` return that sequential cursor.
|
|
130
|
+
* in both APIs on a v2 service, either the sequential or the timestamp cursor can be passed when reconnecting.
|
|
131
|
+
* to simplify, in any combination of client and server API you can record & reuse the value returned from `message.cursor` and it should be accepted by the same server. You might need to take some more care with the cursor when switching between different instances.
|
|
132
|
+
|
|
133
|
+
Here's a table showing all combinations:
|
|
134
|
+
|
|
135
|
+
| | `seq` | `cursor` | `time_us` | `time` |
|
|
136
|
+
|---------------------|-------------------|-------------------|------------------|----------------------|
|
|
137
|
+
| CBOR firehose | seq cursor | seq cursor | `time` in µs | built from `time` |
|
|
138
|
+
| Jetstream v1 | timestamp cursor | timestamp cursor | timestamp cursor | built from `time_us` |
|
|
139
|
+
| v1 compat API on v2 | seq cursor | seq cursor | timestamp cursor | built from `time_us` |
|
|
140
|
+
| Jetstream v2 | seq cursor | seq cursor | `time` in µs | built from `time` |
|
|
141
|
+
|
|
142
|
+
For any cursor and Jetstream client version, you pass the cursor as a key in an options hash:
|
|
116
143
|
|
|
117
144
|
```rb
|
|
118
145
|
cursor = load_cursor
|
|
119
146
|
|
|
120
|
-
sky = Skyfall::Jetstream.new('
|
|
147
|
+
sky = Skyfall::Jetstream.new('london.firehose.stream', { cursor: cursor })
|
|
148
|
+
|
|
121
149
|
sky.on_message do |msg|
|
|
122
|
-
save_cursor(msg.
|
|
150
|
+
save_cursor(msg.cursor) unless msg.cursor.nil?
|
|
123
151
|
process_message(msg)
|
|
124
152
|
end
|
|
125
153
|
```
|
|
@@ -127,7 +155,7 @@ end
|
|
|
127
155
|
|
|
128
156
|
### Processing messages
|
|
129
157
|
|
|
130
|
-
Each message passed to `on_message` is an instance of a subclass of
|
|
158
|
+
Each message passed to `on_message` is an instance of a subclass of `Skyfall::Firehose::Message`, `Skyfall::Jetstream::Message`, or `Skyfall::JetstreamV2::Message`, depending on the selected source. For the CBOR firehose, the supported message types are:
|
|
131
159
|
|
|
132
160
|
- `CommitMessage` (`#commit`) – represents a change in a user's repo; most messages are of this type
|
|
133
161
|
- `IdentityMessage` (`#identity`) – notifies about a change in user's DID document, e.g. a handle change or a migration to a new PDS
|
|
@@ -137,36 +165,46 @@ Each message passed to `on_message` is an instance of a subclass of either `Skyf
|
|
|
137
165
|
- `InfoMessage` (`#info`) – a protocol error message, e.g. about an invalid cursor parameter
|
|
138
166
|
- `UnknownMessage` is used for other unrecognized message types
|
|
139
167
|
|
|
140
|
-
`Skyfall::
|
|
168
|
+
`Skyfall::Jetstream` and `Skyfall::JetstreamV2` have their own message class families which mirror these and have more or less the same interface, except when a given field or message type is not included in one of the formats:
|
|
169
|
+
|
|
170
|
+
- Jetstream has: `AccountMessage`, `CommitMessage`, `IdentityMessage` and `UnknownMessage`
|
|
171
|
+
- JetstreamV2 has: `AccountMessage`, `CommitMessage`, `IdentityMessage`, `SyncMessage`, `InfoMessage` and `UnknownMessage`
|
|
141
172
|
|
|
142
173
|
All message objects have the following shared properties:
|
|
143
174
|
|
|
144
|
-
- `type` (symbol) – the message type identifier, e.g. `:commit`
|
|
145
|
-
- `seq` (integer) –
|
|
175
|
+
- `type` or `kind` (symbol) – the message type identifier, e.g. `:commit`
|
|
176
|
+
- `seq` or `cursor` (integer) – the cursor value to pass when reconnecting; either a sequential index of the message, or a Unix timestamp in microseconds for Jetstream v1 servers
|
|
146
177
|
- `repo` or `did` (string) – DID of the repository (user account)
|
|
147
178
|
- `time` (Time) – timestamp of the described action
|
|
179
|
+
- `time_us` (integer) – timestamp in Unix microseconds (for Jetstream v1/v2 can be used as a cursor)
|
|
148
180
|
|
|
149
181
|
All properties except `type` may be nil for some message types that aren't related to a specific user, like `#info`.
|
|
150
182
|
|
|
151
|
-
Commit messages additionally
|
|
183
|
+
Commit messages additionally include (depending on the version):
|
|
152
184
|
|
|
153
|
-
- `commit` – CID of the commit
|
|
154
|
-
- `operations` – list of operations (usually one)
|
|
185
|
+
- `commit` or `cid` – CID of the commit
|
|
186
|
+
- `operations` or `ops` – list of operations (usually one for CBOR, always one for Jetstream)
|
|
187
|
+
- `operation` or `op` – in Jetstream only
|
|
188
|
+
- `rev` – current revision identifier of the repo
|
|
189
|
+
- `since` – revision of the previous commit
|
|
190
|
+
- `blocks` – commit data as a parsed CAR archive
|
|
155
191
|
|
|
156
|
-
|
|
192
|
+
Identity messages additionally include:
|
|
157
193
|
|
|
158
194
|
- `handle` – the new handle assigned to the DID
|
|
159
195
|
|
|
160
|
-
Account messages additionally
|
|
196
|
+
Account messages additionally include:
|
|
161
197
|
|
|
162
198
|
- `active?` – whether the account is active, or inactive for any reason
|
|
163
199
|
- `status` – if not active, shows the status of the account (`:deactivated`, `:deleted`, `:takendown`)
|
|
164
200
|
|
|
165
|
-
Info messages additionally
|
|
201
|
+
Info messages additionally include:
|
|
166
202
|
|
|
167
203
|
- `name` – identifier of the message/error
|
|
168
204
|
- `message` – a human-readable description
|
|
169
205
|
|
|
206
|
+
See the [YARD API docs](https://rubydoc.info/gems/skyfall/) for more details on what specific message classes are available and what fields each one has.
|
|
207
|
+
|
|
170
208
|
|
|
171
209
|
### Commit operations
|
|
172
210
|
|
|
@@ -213,7 +251,7 @@ Do not however check if such operations have a `type` equal to `:unknown` first
|
|
|
213
251
|
|
|
214
252
|
## Reconnection logic
|
|
215
253
|
|
|
216
|
-
In a perfect world, the websocket would never disconnect until you disconnect it, but unfortunately we don't live in a perfect world. The socket sometimes disconnects or stops responding, and Skyfall has some built-in protections to make sure it can operate without much oversight.
|
|
254
|
+
In a perfect world, the websocket would never disconnect until you disconnect it, but unfortunately we don't live in a perfect world. The socket sometimes disconnects or stops responding, and Skyfall has some built-in protections to make sure it can operate without much oversight. (This section applies to all three stream types.)
|
|
217
255
|
|
|
218
256
|
|
|
219
257
|
### Broken connections
|
|
@@ -252,7 +290,9 @@ To connect to a labeller, pass `:subscribe_labels` as the endpoint name to `Skyf
|
|
|
252
290
|
|
|
253
291
|
```rb
|
|
254
292
|
cursor = load_cursor(service)
|
|
293
|
+
|
|
255
294
|
sky = Skyfall::Firehose.new(service, :subscribe_labels, cursor)
|
|
295
|
+
|
|
256
296
|
sky.on_message do |msg|
|
|
257
297
|
if msg.type == :labels
|
|
258
298
|
msg.labels.each do |l|
|
|
@@ -279,12 +319,12 @@ sky.user_agent = "NewsBot (@news.bot) #{sky.version_string}"
|
|
|
279
319
|
|
|
280
320
|
### Jetstream filters
|
|
281
321
|
|
|
282
|
-
Jetstream allows you to specify [filters](https://
|
|
322
|
+
Jetstream allows you to specify [filters](https://bsky.network/docs/jetstream#filtering-ask-for-just-your-slice) of collection types and/or tracked DIDs when you connect, so it will send you only the events you're interested in. You can e.g. ask only for posts and ignore likes, or only profile events and ignore everything else, or only listen for posts from a few specific accounts.
|
|
283
323
|
|
|
284
|
-
To use these filters, pass the "wantedCollections" and/or "wantedDids" parameters in the options hash when initializing `Skyfall::Jetstream`. You can use the original JavaScript param names, or a more Ruby-like snake_case form:
|
|
324
|
+
To use these filters, pass the "wantedCollections" and/or "wantedDids" parameters in the options hash when initializing `Skyfall::Jetstream`. You can use the original JavaScript param names, or a more Ruby-like snake_case form, with a single value or an array:
|
|
285
325
|
|
|
286
326
|
```rb
|
|
287
|
-
sky = Skyfall::Jetstream.new('
|
|
327
|
+
sky = Skyfall::Jetstream.new('nyc.firehose.stream', {
|
|
288
328
|
wanted_collections: 'app.bsky.feed.post',
|
|
289
329
|
wanted_dids: @dids
|
|
290
330
|
})
|
|
@@ -293,15 +333,79 @@ sky = Skyfall::Jetstream.new('jetstream2.us-east.bsky.network', {
|
|
|
293
333
|
For collections, you can also use the symbol codes used in `Operation#type`, e.g. `:bsky_post`:
|
|
294
334
|
|
|
295
335
|
```rb
|
|
296
|
-
sky = Skyfall::Jetstream.new('
|
|
336
|
+
sky = Skyfall::Jetstream.new('nyc.firehose.stream', {
|
|
297
337
|
wanted_collections: [:bsky_post]
|
|
298
338
|
})
|
|
299
339
|
```
|
|
300
340
|
|
|
301
|
-
|
|
341
|
+
The parameters are named `collections` and `dids` respectively in the Jetstream v2 API, but you can use any variant in either of the client versions here.
|
|
342
|
+
|
|
343
|
+
Jetstream v2 additionally allows you to filter by event kinds. Pass one or more event types as the `kinds` option – note that `collections` can be combined with `kinds`, but only if `kinds` includes `commit`:
|
|
344
|
+
|
|
345
|
+
```rb
|
|
346
|
+
sky = Skyfall::JetstreamV2.new('jetstream.us-east.bsky.network', {
|
|
347
|
+
collections: [:bsky_post, :bsky_like],
|
|
348
|
+
kinds: [:commit, :identity]
|
|
349
|
+
})
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
See [Jetstream docs](https://bsky.network/docs/jetstream#filtering-ask-for-just-your-slice) for more info on available filters.
|
|
302
353
|
|
|
303
354
|
> [!NOTE]
|
|
304
|
-
> The `
|
|
355
|
+
> The `requireHello` option and "subscriber sourced messages" from the Jetstream v1 aren't currently supported (and probably won't be).
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
### Jetstream compression
|
|
359
|
+
|
|
360
|
+
Both Jetstream v1 and v2 support optional Zstd compression (off by default), using a pre-shared compression dictionary. For Jetstream v1 there is a single hardcoded dictionary, for v2 the currently used dictionary is fetched from the server before making a connection.
|
|
361
|
+
|
|
362
|
+
In both versions, enable compression by adding a `compress: true` option:
|
|
363
|
+
|
|
364
|
+
```rb
|
|
365
|
+
sky = Skyfall::Jetstream.new('nyc.firehose.stream', {
|
|
366
|
+
wanted_collections: [:bsky_post],
|
|
367
|
+
compress: true
|
|
368
|
+
})
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
The decompression and dictionary handling happens automatically. Note that if compression is enabled, `on_raw_message` callbacks will receive the original compressed message bytes; `on_message` receives a parsed `Message` object as before.
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
### Jetstream message size limit
|
|
375
|
+
|
|
376
|
+
Another Jetstream option is `maxMessageSizeBytes`, available in both v1 and v2, which sets a limit in bytes on how large events will be sent to the client; events larger than the limit are silently dropped.
|
|
377
|
+
|
|
378
|
+
Note: when compression is also enabled, the value is interpreted differently in Jetstream v1 and v2:
|
|
379
|
+
|
|
380
|
+
* Jetstream v1 uses the value as the max *compressed* event size
|
|
381
|
+
* Jetstream v2 servers, including the v1 compatibility API, use the value as the max *uncompressed* event size
|
|
382
|
+
|
|
383
|
+
Pass the limit as a number in bytes to `:maxMessageSizeBytes` or `:max_message_size_bytes` (0 will be interpreted as no limit):
|
|
384
|
+
|
|
385
|
+
```rb
|
|
386
|
+
sky = Skyfall::Jetstream.new('nyc.firehose.stream', { max_message_size_bytes: 1_000_000 })
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
## Available servers
|
|
390
|
+
|
|
391
|
+
Bluesky PBC currently runs these official firehose and Jetstream servers:
|
|
392
|
+
|
|
393
|
+
Relay:
|
|
394
|
+
|
|
395
|
+
- `bsky.network`
|
|
396
|
+
|
|
397
|
+
Jetstream v2:
|
|
398
|
+
|
|
399
|
+
- `jetstream.us-west.bsky.network`
|
|
400
|
+
- `jetstream.us-east.bsky.network`
|
|
401
|
+
|
|
402
|
+
The ATProto developer community is running a number of independent relays and Jetstream v1 instances, including:
|
|
403
|
+
|
|
404
|
+
- the [firehose.network](https://firehose.network) relays and [firehose.stream](https://firehose.stream) Jetstream servers run by [@sri.xyz](https://bsky.app/profile/did:plc:7gm5ejhut7kia2kzglqfew5b)
|
|
405
|
+
- the [Microcosm relays](https://www.microcosm.blue/#infra) run by [@bad-example.com](https://bsky.app/profile/did:plc:hdhoaan3xa3jiuq4fg4mefid)
|
|
406
|
+
- the [Blacksky](https://blackskyweb.xyz) and [Eurosky](https://eurosky.tech) infrastructure
|
|
407
|
+
|
|
408
|
+
I'm running a tool named [Pulsar](https://pulsar.feeds.blue) at [pulsar.feeds.blue](https://pulsar.feeds.blue) which lists all of those and more, and tracks their uptime and network coverage statistics.
|
|
305
409
|
|
|
306
410
|
|
|
307
411
|
## Other resources
|
data/SECURITY.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## How To Report a Vulnerability
|
|
4
|
+
|
|
5
|
+
If you find a potential vulnerability in one of my projects, it's recommended not to report it through a standard publicly-readable issue report, in order to avoid giving possible clues to any potential attackers who could abuse it before it's fixed (see: ["Just a rumour of a bug is enough to find a security exploit these days"](https://anil.recoil.org/notes/rumour-is-the-exploit)).
|
|
6
|
+
|
|
7
|
+
You can use one of these to contact me instead:
|
|
8
|
+
|
|
9
|
+
- [@mackuba.eu](https://bsky.app/profile/did:plc:oio4hkxaop4ao4wz2pp3f4cr) on Bluesky (my DMs should be open, or mention me discretely with a request for contact)
|
|
10
|
+
- [@mackuba@martianbase.net](https://martianbase.net/@mackuba) on Mastodon (my personal instance)
|
|
11
|
+
- email: mackuba `@` protonmail.ch (optionally with [this PGP key](https://mail-api.proton.me/pks/lookup?op=get&search=mackuba@protonmail.ch))
|
|
12
|
+
- ["Report a vulnerability"](https://github.com/mackuba/skyfall/security/advisories/new) form on GitHub
|
|
13
|
+
|
|
14
|
+
I do not check my Twitter/X or LinkedIn accounts regularly.
|
|
15
|
+
|
|
16
|
+
Note: please don't submit AI-reported issues that have not been verified manually :)
|
|
Binary file
|
data/lib/skyfall/collection.rb
CHANGED
|
@@ -9,6 +9,7 @@ module Skyfall
|
|
|
9
9
|
#
|
|
10
10
|
|
|
11
11
|
module Collection
|
|
12
|
+
BSKY_ACTOR_LINK = "app.bsky.actor.link"
|
|
12
13
|
BSKY_PROFILE = "app.bsky.actor.profile"
|
|
13
14
|
BSKY_ACTOR_STATUS = "app.bsky.actor.status"
|
|
14
15
|
BSKY_FEED = "app.bsky.feed.generator"
|
|
@@ -22,16 +23,20 @@ module Skyfall
|
|
|
22
23
|
BSKY_LIST = "app.bsky.graph.list"
|
|
23
24
|
BSKY_LISTBLOCK = "app.bsky.graph.listblock"
|
|
24
25
|
BSKY_LISTITEM = "app.bsky.graph.listitem"
|
|
26
|
+
BSKY_LIST_OPTOUT = "app.bsky.graph.referencelistoptout"
|
|
25
27
|
BSKY_STARTERPACK = "app.bsky.graph.starterpack"
|
|
26
28
|
BSKY_VERIFICATION = "app.bsky.graph.verification"
|
|
27
29
|
BSKY_LABELER = "app.bsky.labeler.service"
|
|
28
30
|
|
|
29
31
|
BSKY_NOTIF_DECLARATION = "app.bsky.notification.declaration"
|
|
30
32
|
BSKY_CHAT_DECLARATION = "chat.bsky.actor.declaration"
|
|
33
|
+
BSKY_VISIBILITY_DECLARATION = "app.bsky.actor.contentVisibilityDeclaration"
|
|
34
|
+
|
|
31
35
|
|
|
32
36
|
# Mapping of NSID collection names to symbol short codes
|
|
33
37
|
|
|
34
38
|
SHORT_CODES = {
|
|
39
|
+
BSKY_ACTOR_LINK => :bsky_actor_link,
|
|
35
40
|
BSKY_ACTOR_STATUS => :bsky_actor_status,
|
|
36
41
|
BSKY_BLOCK => :bsky_block,
|
|
37
42
|
BSKY_FEED => :bsky_feed,
|
|
@@ -41,6 +46,7 @@ module Skyfall
|
|
|
41
46
|
BSKY_LIST => :bsky_list,
|
|
42
47
|
BSKY_LISTBLOCK => :bsky_listblock,
|
|
43
48
|
BSKY_LISTITEM => :bsky_listitem,
|
|
49
|
+
BSKY_LIST_OPTOUT => :bsky_list_optout,
|
|
44
50
|
BSKY_POST => :bsky_post,
|
|
45
51
|
BSKY_POSTGATE => :bsky_postgate,
|
|
46
52
|
BSKY_PROFILE => :bsky_profile,
|
|
@@ -49,7 +55,8 @@ module Skyfall
|
|
|
49
55
|
BSKY_THREADGATE => :bsky_threadgate,
|
|
50
56
|
BSKY_VERIFICATION => :bsky_verification,
|
|
51
57
|
BSKY_CHAT_DECLARATION => :bsky_chat_declaration,
|
|
52
|
-
BSKY_NOTIF_DECLARATION => :bsky_notif_declaration
|
|
58
|
+
BSKY_NOTIF_DECLARATION => :bsky_notif_declaration,
|
|
59
|
+
BSKY_VISIBILITY_DECLARATION => :bsky_visibility_declaration
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
# Returns a symbol short code for a given collection NSID, or `:unknown`
|
data/lib/skyfall/errors.rb
CHANGED
|
@@ -19,6 +19,12 @@ module Skyfall
|
|
|
19
19
|
class DecodeError < Error
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
#
|
|
23
|
+
# Raised when the Zstd compression dictionary used for Jetstream can't be loaded or is invalid.
|
|
24
|
+
#
|
|
25
|
+
class DictionaryError < Error
|
|
26
|
+
end
|
|
27
|
+
|
|
22
28
|
#
|
|
23
29
|
# Raised when {Stream#connect} is called and there's already another instance of {Stream} or its
|
|
24
30
|
# subclass like {Firehose} that's connected to another websocket.
|
|
@@ -38,6 +38,7 @@ module Skyfall
|
|
|
38
38
|
# @return [Integer, nil]
|
|
39
39
|
attr_reader :seq
|
|
40
40
|
|
|
41
|
+
alias cursor seq
|
|
41
42
|
alias repo did
|
|
42
43
|
alias kind type
|
|
43
44
|
|
|
@@ -125,6 +126,10 @@ module Skyfall
|
|
|
125
126
|
# might differ a lot from the `created_at` time saved in the record data, e.g. if user's local
|
|
126
127
|
# time is set incorrectly, or if an archive of existing posts was imported from another platform.
|
|
127
128
|
#
|
|
129
|
+
# If streaming from a relay, this timestamp might also differ a lot from the time when the relay
|
|
130
|
+
# received and stored the event, e.g. if the PDS has streamed some events buffered on its side
|
|
131
|
+
# after a period of being disconnected from the relay.
|
|
132
|
+
#
|
|
128
133
|
# @return [Time, nil]
|
|
129
134
|
#
|
|
130
135
|
def time
|
|
@@ -139,6 +144,15 @@ module Skyfall
|
|
|
139
144
|
end
|
|
140
145
|
end
|
|
141
146
|
|
|
147
|
+
# Timestamp of the event in Unix microseconds. Added for symmetry with {Skyfall::Jetstream::Message},
|
|
148
|
+
# although here it doesn't serve a role of a cursor.
|
|
149
|
+
#
|
|
150
|
+
# @return [Integer, nil]
|
|
151
|
+
#
|
|
152
|
+
def time_us
|
|
153
|
+
time && (time.to_r * 1_000_000).to_i
|
|
154
|
+
end
|
|
155
|
+
|
|
142
156
|
# Returns a string with a representation of the object for debugging purposes.
|
|
143
157
|
# @return [String]
|
|
144
158
|
def inspect
|
|
@@ -186,17 +200,20 @@ module Skyfall
|
|
|
186
200
|
type, data = objects
|
|
187
201
|
|
|
188
202
|
raise DecodeError.new("Invalid object type: #{type.inspect}") unless type.is_a?(Hash)
|
|
189
|
-
raise DecodeError.new("Missing data: #{type.inspect}") unless type['op'] && type['t']
|
|
190
|
-
raise DecodeError.new("Invalid object type: #{type['op'].inspect}") unless type['op'].is_a?(Integer)
|
|
191
|
-
raise DecodeError.new("Invalid object type: #{type['t'].inspect}") unless type['t'].is_a?(String)
|
|
192
|
-
raise DecodeError.new("Invalid message type: #{type['t'].inspect}") unless type['t'].start_with?('#')
|
|
193
|
-
raise UnsupportedError.new("Unsupported version: #{type['op']}") unless type['op'] == 1
|
|
194
203
|
raise DecodeError.new("Invalid object type: #{data.inspect}") unless data.is_a?(Hash)
|
|
204
|
+
raise DecodeError.new("Missing data: #{type.inspect}") unless type['op']
|
|
205
|
+
raise DecodeError.new("Invalid object type: #{type['op'].inspect}") unless type['op'].is_a?(Integer)
|
|
195
206
|
|
|
196
|
-
if data['error']
|
|
207
|
+
if type['op'] == -1 && data['error']
|
|
197
208
|
raise SubscriptionError.new(data['error'], data['message'])
|
|
209
|
+
elsif type['op'] != 1
|
|
210
|
+
raise UnsupportedError.new("Unexpected version: #{type['op']}")
|
|
198
211
|
end
|
|
199
212
|
|
|
213
|
+
raise DecodeError.new("Missing data: #{type.inspect}") unless type['t']
|
|
214
|
+
raise DecodeError.new("Invalid object type: #{type['t'].inspect}") unless type['t'].is_a?(String)
|
|
215
|
+
raise DecodeError.new("Invalid message type: #{type['t'].inspect}") unless type['t'].start_with?('#')
|
|
216
|
+
|
|
200
217
|
[type, data]
|
|
201
218
|
end
|
|
202
219
|
|