-
Notifications
You must be signed in to change notification settings - Fork 35
Implement DHCP lease maintenance with renew / rebind. #36
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Now can use `socket.bind` to set source port to be consistent with CPython socket behavior. - DHCP object is now persistent in `WIZNET5K` because we want to keep it around to automatically renew and rebind. - Added `maintain_dhcp_lease` to `WIZNET5K` to properly maintain the DHCP lease with renew / rebind behavior. - Implement correct DHCP transaction ID behavior so we don't accidentally grab an IP that was supposed to be assigned to another device. - Now keeps track of automatically assigned source ports to prevent duplication. - Renamed `WIZNET5K._src_port` to `WIZNET5K.src_port` because it's externally accessed from `socket.connect`. - Removed setting source port for DNS lookup, moved to `bind` before socket connect. - `WIZNET5K.get_socket` now only returns fully closed sockets. Previous behavior caused problems with stray old data from previous connections confusing new connections when the socket wasn't fully closed yet. - Improved WSGI server in how it deals with socket removal and allocation. - Fixed some bugs and comments.
Closed
If `socket_listen` was called, and a connection was made right away, it was possible that the state of the socket would change to `SNSR_SOCK_ESTABLISHED` before the check ever saw it enter `SNSR_SOCK_LISTEN`, and the code would be stuck in an endless loop. This fixes the issue by accepting both `SNSR_SOCK_LISTEN` and `SNSR_SOCK_ESTABLISHED` as valid states to continue.
@xorbit Great work and thank you for the PR, I'll review and test on hardware this week. |
README example now shows `maintain_dhcp_lease` function and a full detailed example showing other features was added to the `examples` directory.
brentru
requested changes
May 5, 2021
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.
@xorbit Thank you for the PR, I tested the WSGI and BTC handler locally with an Ethernet FeatherWing and it works great!
Had to catch exception when creating I2C device for boards that have no I2C pull-ups.
brentru
approved these changes
May 6, 2021
adafruit-adabot
added a commit
to adafruit/Adafruit_CircuitPython_Bundle
that referenced
this pull request
May 11, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_AS7341 to 1.1.2 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_AS7341#17 from jposada202020/replacing_named_tuple Updating https://github.com/adafruit/Adafruit_CircuitPython_BMP3XX to 1.3.6 from 1.3.5: > Merge pull request adafruit/Adafruit_CircuitPython_BMP3XX#17 from jposada202020/adding_waitingtime_as_option Updating https://github.com/adafruit/Adafruit_CircuitPython_DPS310 to 1.2.5 from 1.2.4: > Merge pull request adafruit/Adafruit_CircuitPython_DPS310#13 from jposada202020/adding_readme_note Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM9DS1 to 2.1.9 from 2.1.8: > Merge pull request adafruit/Adafruit_CircuitPython_LSM9DS1#30 from jposada202020/returning_correct_units_gyro Updating https://github.com/adafruit/Adafruit_CircuitPython_MPU6050 to 1.1.8 from 1.1.7: > Merge pull request adafruit/Adafruit_CircuitPython_MPU6050#17 from jposada202020/correcting_returning_units_gyro Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 1.10.0 from 1.9.3: > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#36 from xorbit/master Updating https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO to 5.3.0 from 5.2.5: > Merge pull request adafruit/Adafruit_CircuitPython_AdafruitIO#70 from rodrigoargumedo/create-multiple-records Updating https://github.com/adafruit/Adafruit_CircuitPython_MatrixPortal to 3.0.1 from 3.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_MatrixPortal#78 from flavio-fernandes/fix.issue.77
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After initializing everything, the DHCP lease can now be maintained from the main loop by calling
eth.maintain_dhcp_lease()
. An example main loop for a WSGI web server + DHCP maintenance can look like this:socket.bind
to set source port to be consistent with CPython socket behavior.WIZNET5K
because we want to keep it around to automatically renew and rebind.maintain_dhcp_lease
toWIZNET5K
to properly maintain the DHCP lease with renew / rebind behavior.WIZNET5K._src_port
toWIZNET5K.src_port
because it's externally accessed fromsocket.connect
.bind
before socket connect.WIZNET5K.get_socket
now only returns fully closed sockets. Previous behavior caused problems with stray old data from previous connections confusing new connections when the socket wasn't fully closed yet.