Giter Club home page Giter Club logo

Comments (6)

barkyq avatar barkyq commented on June 11, 2024

Or perhaps it is allowed to send multiple nostr messages in a single websocket message payload? I did not think this was the case, but the NIP-01 document is a bit vague on the details.

from strfry.

hoytech avatar hoytech commented on June 11, 2024

In websockets terminology, "per-message" means that you can optionally compress some messages and not others. Each message has a flag that says whether it's compressed, basically. This is partly because it's not worthwhile to compress small messages, and also partly because of security reasons, where mixing attacker-provided data with secret data in the same compression context can leak the secret data (ie see the CRIME attack: https://security.stackexchange.com/questions/19911/crime-how-to-beat-the-beast-successor/19914#19914 )

The actual compression is specified as the DEFLATE (aka LZ77) algorithm (basically gzip without some headers and checksums).

When the websocket connection is started, clients and servers negotiate how the compression will happen. Either each message can use an empty DEFLATE buffer, or the buffer can be populated by previous messages over the same websocket connection. This is called a "sliding window" and achieves cross-message compression. Whoever told you this is not possible hasn't read the websocket compression RFC. It's is all described in detail here:

https://www.rfc-editor.org/rfc/rfc7692#section-7.1

The websocket sliding window system is not perfect though. First of all there are much better algorithms nowdays (ie zstd). The sliding window is limited to 32k max, and there is no way to pre-populate a dictionary and/or use a static dictionary for each message. Still, IMO the calculus for nostr is pretty clear that this is beneficial, which is why strfry enables it by default. You can see in the logs how effective the compression is for each connection.

from strfry.

barkyq avatar barkyq commented on June 11, 2024

Cool thanks! I read a bit more and learned that the "context takeover" headers are the relevant ones. I was a bit confused. Thanks for the answer!

from strfry.

hoytech avatar hoytech commented on June 11, 2024

No worries! FWIW, I find the *_context_takeover terminology confusing too. I think that RFC could've benefited from some significant editorial work.

from strfry.

barkyq avatar barkyq commented on June 11, 2024

Yes I was testing strfry but I was sending the server_no_context_takeover extension parameter. The compression was still pretty good (according to the helpful strfry logs). I am excited to see what happens if I don't send the server_no_context_takeover extension parameter. I need to figure out how to handle the received messages though. Anyways, thanks again for taking the time to answer my silly question.

PS. I was playing around with quadrable in the strfry directory:

quadb --db=./strfry-db dumpTree

Pretty cool stuff!

from strfry.

hoytech avatar hoytech commented on June 11, 2024

Thanks! The merkle tree stuff is going to have some pretty fun applications, I'm looking forward to writing up some more details on that. :)

For testing the sliding windows, I mostly use web browsers since this isn't a widely implemented feature for command-line clients. However, pretty much every browser negotiates the full window. The easiest way to see the effect is to do a query with sliding window enabled in the strfry config, then turn it off and do the same query. I think you have to restart the relay for this currently. That's not an inherent limitation, I just haven't got around to making that hot-changeable.

from strfry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.