-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Added CoAP socket #4334
base: master
Are you sure you want to change the base?
Added CoAP socket #4334
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4334 +/- ##
==========================================
- Coverage 81.90% 81.53% -0.38%
==========================================
Files 330 356 +26
Lines 76380 85140 +8760
==========================================
+ Hits 62561 69416 +6855
- Misses 13819 15724 +1905
|
245e388
to
7ee64b2
Compare
Any idea on how I can fix these failed tests? |
Tests are failing on versions older than 3.9. You're using 3.9+ specific features. Scapy should work with anything starting from 3.7, so this probably needs to be updated. |
Fixing response payload Some docstring and bug fixes. Finished CoAP server logic implementation Added client interaction Client/Server done. Added delayed response handling Fixing small problems Unit tests Documentation
@gpotter2 Thanks for the insights, it is ready for reviews :D |
- Moved the defines/enumerators to coap.py - Changed the send() function to match the SuperSocket declaration - Updated unit tests
Could you please implement a select function for your socket, so that sr, sr1 and sniff will work. Could you please also provide unit tests for these functions. |
Hello, thanks for the review, I updated the code to include a select function, I'm not sure about the error in the macos tests. About the changes, I'm not sure if those can be considered "correct", it feels like workarounds. Because:
Is there a better way of doing this? Thanks so far :) |
Thanks for the update. I'll review soon. |
def hashret(self): | ||
return struct.pack('I', self.msg_id) + self.token | ||
|
||
def answers(self, other): |
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.
Wouldn't it make sense to implement the answers function based on coap_codes / the field "code"
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 added a simple verification where any kind of answer is accepted (within the response codes in the RFC's section 5.9), except if you are trying to answer with another request.
I did this way because I don't want to put too much constraints for the user.
scapy/contrib/coap_socket.py
Outdated
return len(x) | ||
|
||
def sr(self, *args, **kargs): | ||
args[0].sport = self.impl.port |
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.
since you want to operate on the packet you get here, I suggest to change the function signature:
def sr(pkt, *args, **kargs):
pkt[UDP].sport = ...
...
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.
Hopefully I got this correct, did you mean:
def sr(self, pkt, *args, **kargs):
pkt[UDP] ...
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.
Looks good. Unfortunately I’m not fully done with the review. I try to find some time as soon as possible.
- Implemented coap.answers function - Fixed some types - Remove unnecessary override - Changed sr and sr1 functions signatures.
Description
This PR implements a CoAP socket, pretty similar on how ISOTPSoftSocket works.
I implemented the basic message exchange, mostly based on the RFC-7252.
Known-limitations
General comments
It has a dependency for
from scapy.contrib.isotp.isotp_soft_socket import TimeoutScheduler
, I found nice how this is implemented, so I just used it, I didn't want to copy/paste again.Also I added some unit tests for the basic cases.
Quick usage