-
Notifications
You must be signed in to change notification settings - Fork 35
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
XIP-5: Support different payload content types #68
Conversation
Deploying with Cloudflare Pages
|
015f18e
to
6c39a14
Compare
@@ -21,52 +25,86 @@ message PublicKey { | |||
} | |||
} | |||
|
|||
message PrivateKey { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is moved further down as this is not part of the protocol
bytes payload = 3; | ||
} | ||
oneof union { | ||
AES256GCM_HKDFSHA256 aes256GcmHkdfSha256 = 1; | ||
} | ||
} | ||
|
||
message PublicKeyBundle { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is moved up, next to the PublicKey definition to tidy up the file.
Writing the tests I grew to dislike the So I'm inclined to dump the MessageContent in favour of introducing another optional The changes this change would require can be seen in this commit 8d4466b PS: I just realized that I will also need to add an optional |
I've added support for |
3f3675f
to
128a397
Compare
Prototype of compression support is in 128a397. It is using the draft compression standard. Support for the draft is spotty, and Streams on Node are also different so I used this polyfill 🤷♂️. Examples of streaming bytes in memory seem scarce so I used a fairly naive approach to growing the stream buffer when it cannot accommodate the chunk being written to simply doubling it in size. The protocol change is small, just adding a Compression opens up an attack vector, where a message that is relatively small in transit can be expanded to huge on the recipient side, not sure if we want to do something about that (the growth strategy could simply throw if we reach some pre-set limit) |
// content allows attaching decoded content to the Message | ||
// the message receiving APIs need to return a Message to provide access to the header fields like sender/recipient | ||
contentType?: ContentTypeId | ||
content?: any // eslint-disable-line @typescript-eslint/no-explicit-any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that's really unfortunate is that this leads to so many any
types.
It would require a black-belt in Typescript (which I do not possess), but it should be possible to make this into a discriminated union type using the ContentType field. I can figure out how to do that with a fixed set of types, but I have a lot harder of a time imagining how that could be extended by developer's adding additional types. Even if we could have a discriminated union for our own types, and then fall back to any for unknown types, that would be a win for developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really want to get into this at this point. Should I make an issue to follow up on later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I think that's going to be hard to resolve.
I've decided this is too much of a risk and added configurable |
That seems sensible. I wonder how many valid use-cases there are for messages > 10mb even. I believe LibP2P limits messages to ~1MB at the PubSub level, so it would have to be extremely compressible content for a valid message to get anywhere close to those numbers. |
I figured that given that photos can be easily close to 10M today, that might be a bit low, but I'm just pulling a number out of thin air. Happy to be convinced otherwise, I don't feel strongly about this at all. |
be64978
to
f693717
Compare
Hrm, test:jsdom is failing in CI with |
Almost there :/ jsdom/jsdom#3200 |
One more thing that bothers me here is that the |
I think I've addressed all the feedback, the main changes are
|
src/Client.ts
Outdated
@@ -84,6 +125,12 @@ export default class Client { | |||
const keyStore = createNetworkPrivateKeyStore(wallet, waku) | |||
const keys = await loadOrCreateKeys(wallet, keyStore) | |||
const client = new Client(waku, keys) | |||
opts?.codecs?.forEach((codec) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're going to have to update this to be compatible with @jazzz's just-merged changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I just noticed, that #93 has impact on this, and I probably should have waited.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's OK I'll rebase and fix this up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebased and cleaned up.
25c20c3
to
951d4b5
Compare
1775f1f
to
3f01125
Compare
src/Client.ts
Outdated
opts?.codecs?.forEach((codec) => { | ||
client.registerCodec(codec) | ||
}) | ||
if (opts?.maxContentSize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Pebble] all parameters should be accessed through the options
configuration instead of the raw passed in opts
.
src/Client.ts
Outdated
|
||
// Set the maximum content size in bytes that is allowed by the Client. | ||
// Currently only checked when decompressing compressed content. | ||
maxContentSize?: number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Sand] Likely want to avoid optional parameters here in the future. We can increase clarity by making it a required value and providing a sensible default parameter in defaultOptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to do this, but TS is forcing me to set the default values in the Client constructor (given that they are declared fields on Client). Do we want to set the defaults twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I could do this for codecs, but I'll need to merge the two lists in defaultOptions()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I pushed a fix, I think this does look better, but I wasn't able to get rid of setting the _maxContentSize in both the constructor and defaultOptions. Is this good @jazzz ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 . It's unfortunate about having to set it twice, but imagine we'll fix that with an update to the constructor at somepoint. As we add more properties to Client we'll likely want to set the values in the constructor rather than afterwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see: #68 (comment)
keyStoreType: KeyStoreType.networkTopicStoreV1, | ||
env: 'testnet', | ||
waitForPeersTimeoutMs: 10000, | ||
codecs: [new TextCodec()], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having textCodec here in DefaultOptions makes sense if we want it to be possible for someone to disable it.
If it is required to be present, then I think it was fine baked into the object, as its not really an option/tunable parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way I wrote the merging logic below, they can override it, but they cannot remove it. I think that's what we want, if they have better codec, they are free to use it, but they cannot disable support for xmtp.org/text
altogether.
BREAKING CHANGE: The protocol format of messages is changing, old clients won't be able to decode new messages correctly and new clients won't be able to decode old messages correctly. The API changes are backward compatible.
774c341
to
f79cfe2
Compare
🎉 This PR is included in version 3.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Implements #54