Giter VIP home page Giter VIP logo

Comments (7)

anecdata avatar anecdata commented on September 4, 2024 1

hashlib seems to be used for web sockets. If you're not using web sockets, I think you could comment it out.

edit: ah, I see you did it :-)

Raspberry Pi Pico W has hashlib, so it may just be a build config that could be changed to include hashlib in the builds for the WIZnet Pico boards (5100S, 5500, 6100).

edit: looks like a one-line addition needed in the circuitpython repo in each board's mpconfigboard.mk file:
CIRCUITPY_HASHLIB = 1

edit 2: This library should probably adopt your change. The websocket example in this repo expects native wifi, not sure offhand if it works on Ethernet. If it does, the core change noted above could be made.

from adafruit_circuitpython_httpserver.

michalpokusa avatar michalpokusa commented on September 4, 2024 1

I think it's worth adding the try/except even if we can enable hashlib on the currently remaining devices that don't have it. We have adafruit_hashlib as a python level lib so in the event that any boards are released that actually don't (or can't) support the native hashlib it'll be nice to have this as a fallback.

Makes sense. I will make a PR later in the day.

If I am correct, hashlib is only used for Websockets, so maybe it both hashlib and adafruit_hashlib are not present, we could print a warning that Websockets will not work and not require everyone to install it, it they are only using the standard HTTP communication.

So maybe something like this:

try:
    import hashlib
except ImportError:
    try:
        import adafruit_hashlib as hashlib
    except ImportError:
        print("Warning...")

What do you think?

from adafruit_circuitpython_httpserver.

anecdata avatar anecdata commented on September 4, 2024 1

I agree it makes sense to import flexibly here. It's even conceivable that this library is used with a main board without hashlib with an ethernet feathering (or other compatible ethernet peripheral).

I started a PR for the core changes, but didn't have all the pieces to test it on an EVB-Pico. I can put it through and leave testing open.

There's about an order of magnitude improvement with the core module over the library:

EXPAND...
import time

GUID = b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
ITERATIONS = 10_000

def hashme():
    key = "dGhlIHNhbXBsZSBub25jZQ=="
    start = time.monotonic_ns()
    for _ in range(0, ITERATIONS):
        response_key = hashlib.new("sha1", key.encode())
        response_key.update(GUID)
    return time.monotonic_ns() - start

import hashlib
duration = hashme()
print(f"{ITERATIONS} iterations in {duration} ns - hashlib")
import adafruit_hashlib as hashlib
duration = hashme()
print(f"{ITERATIONS} iterations in {duration} ns - adafruit_hashlib")
10000 iterations in 500976562 ns - hashlib
10000 iterations in 6370117187 ns - adafruit_hashlib

Addendum: circuitpython PR adafruit/circuitpython#8719 but there's not enough space on some language builds and there are no other optional modules to remove to make space, I'll see if one of the core devs has an idea

Addendum 2: it wasn't a space issue, seems more like a build dependency issue from using mbedtls for hashlib, details in the PR

from adafruit_circuitpython_httpserver.

anecdata avatar anecdata commented on September 4, 2024 1

There's a native solution at this core PR:
adafruit/circuitpython#8749
If someone is set up to test, please comment there.

from adafruit_circuitpython_httpserver.

Akkiesoft avatar Akkiesoft commented on September 4, 2024

I replaced import hashlib line in the adafruit_httpserver/response.py with following code and it workaround works for me.
However I just want to run web server, so I haven't tested about the WebSocket functions (sorry...).

try:
    import hashlib
except ImportError:
    import adafruit_hashlib as hashlib

from adafruit_circuitpython_httpserver.

michalpokusa avatar michalpokusa commented on September 4, 2024

@Akkiesoft Could you please check if the websocket example works WIZnet Pico boards you have?

@anecdata Do you think adding the try/except to import si the way to go, or should it be solved using by adding hashlib during build to boards that do not have it now?

from adafruit_circuitpython_httpserver.

FoamyGuy avatar FoamyGuy commented on September 4, 2024

I think it's worth adding the try/except even if we can enable hashlib on the currently remaining devices that don't have it. We have adafruit_hashlib as a python level lib so in the event that any boards are released that actually don't (or can't) support the native hashlib it'll be nice to have this as a fallback.

from adafruit_circuitpython_httpserver.

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.