Skip to content

added in/outdev getters and performance improvements.#87

Closed
DOWRIGHTTV wants to merge 1 commit intooremanj:masterfrom
DOWRIGHTTV:out-indev
Closed

added in/outdev getters and performance improvements.#87
DOWRIGHTTV wants to merge 1 commit intooremanj:masterfrom
DOWRIGHTTV:out-indev

Conversation

@DOWRIGHTTV
Copy link

No description provided.

Copy link
Owner

@oremanj oremanj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I left some comments below; please also update the API reference in the README file to match this change.

"""

# Constants for module users
import Cython
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imports are placed awkwardly relative to the comment that is now above them but describes the constants below

Copyright: (c) 2011, Kerkhoff Technologies Inc.
License: MIT; see LICENSE.txt

Expanded features and performance improvements from downstream development
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that something like this be more specific about what you changed; this is a fairly small change and I think the description makes it sound bigger than it is.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh, i dont really care about the formalities. some of this stuff was a side effect of my heavily worked on fork where i removed the gil and some other things.

return 1
packet = Packet()

# skipping call to __init__.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the init method is inherently called when instantiating the Packet class and is a pure python method. calling new will return a new instance while reducing unnecessary code execution.

see: https://cython.readthedocs.io/en/latest/src/userguide/special_methods.html?highlight=performance

cdef nfqnl_msg_packet_hw *hw
cdef nfqnl_msg_packet_hdr *hdr

self._nfa = nfa
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not safe; the nfq_data pointer only lives as long as the callback, but the Packet object can be retained longer. Not saving nfa to the object is a deliberate choice. You should instead extract the in/out device numbers here (and convert them to names only if requested, since that part is likely to be slower).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the way i did this was for performance. this will not punish users who dont care about the in/out interfaces.

also, i dont feel the safety is relevant here. the intention is for the callback to store the in/out values on their side.

once the callback is called, the user can decide what information they want to query and store the returns locally in callback. this makes everything inherently safe because we dont need to rely on dead pointers and subsequent calls dont need to reach into Cython.


self._verdict_is_set = True

cpdef get_indev(self, bint name=False):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be two functions, one to get the index and one to get the name. (Or an attribute for the index and a function for the name, which might make more sense especially if you're saving the indices on the object anyway like I suggested above.) Parameters that change the return type of a function are awkward; they'll almost certainly be passed as constants, and they create a hazard for calling code to not name the parameter resulting in difficult-to-understand things like packet.get_indev(True).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh, i dont use the name functionality. i added that to make it more complete as a lib.

@DOWRIGHTTV
Copy link
Author

here is an example of what i am talking about. it is a derivative work of this repo from last year that actually takes on the basic protocol parsing for the user and releases the GIL prior to parsing. https://github.com/DOWRIGHTTV/dnx_nfqueue/blob/master/dnx_nfqueue.pyx

@oremanj
Copy link
Owner

oremanj commented Mar 1, 2023

I recently added indev/outdev attributes using a different approach. Closing this since you didn't respond to my comments.

@oremanj oremanj closed this Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants