-
Notifications
You must be signed in to change notification settings - Fork 298
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
Truncate and sample #898
Truncate and sample #898
Conversation
function Truncate:push() | ||
for _ = 1, link.nreadable(self.input.input) do | ||
local p = receive(self.input.input) | ||
ffi.fill(p.data, math.min(0, self.n - p.length)) |
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.
Please don't use the packet fields directly and use the public functions packet.data
and packet.length
instead. It's a bit more verbose, but as of now the fields are not really part of the public API.
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.
Can you point to documentation for this @eugeneia? To me it is useful to know that a packet is just a data and a length, and part of the core Snabb value proposition. I haven't seen a PR that goes by that changes this, though I could have missed something :)
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.
http://snabbco.github.io/#packet-core.packet describes the core.packet
API. It doesn't mention the actual packet structure which is why I am uneasy about using the fields directly instead of going through the API functions.
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.
Yeah I know what you mean. Still, Luke has given several presentations with a lovely slide that's just
// The maximum amount of payload in any given packet.
enum { PACKET_PAYLOAD_SIZE = 10*1024 };
// Packet of network data, with associated metadata.
struct packet {
unsigned char data[PACKET_PAYLOAD_SIZE];
uint16_t length; // data payload length
};
and so I dunno, it's part of the public messaging. There are quite a lot of uses out there already fwiw, and many of them introduced since you made the data/length functions in January last year.
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 am in favor of documenting our ABI i.e. the memory layout of these structures.
These basic data structures like packet
and link
need to be usable by e.g. assembler code and this does not seem compatible with defining them via an abstract Lua API.
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 think documenting the ABI is a separate issue, since that would not define the FFI field names (data
/length
) if I understand correctly(?).
One advantage (imho) of the API functions is that they are read-only. I am fine with documenting the field names as well and encouraging their use, or even getting rid of the API functions. Either way, I would like that API to be defined before I recommend its use.
I have encountered direct uses of the fields before as well, but considered them as semi-bugs until now.
A quick and dirty (so take with a pinch of salt) grep of the source code shows ~10 uses of |
I don't see any significant safety consideration, for what it's worth, by using well-known names for fields of a struct with a stable, documented ABI, especially considering that we need to access the packet data directly without any out-of-bounds-checking machinery. YMMV of course :) |
To avoid stalling this PR I will merge it as is and open a separate PR to discuss the issue at hand. |
…ypes Comment not supported data types
2 very basic apps useful for monitoring rather than forwarding traffic.