Skip to content
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

Fix Frame Size Issue #690

Merged
merged 1 commit into from
Dec 19, 2018
Merged

Fix Frame Size Issue #690

merged 1 commit into from
Dec 19, 2018

Conversation

hayesgm
Copy link
Contributor

@hayesgm hayesgm commented Dec 1, 2018

When packets come in, sometimes they are incomplete. We previously handled packets that had a valid header but insufficient body size. This patch adds support for packets that don't even have complete headers. We queue the packet into queued data and wait for more data before processing.


if expected_frame_mac != frame_mac do
{:error, "Failed to match frame ingress mac"}
if byte_size(frame_rest) < frame_size + frame_padding_bytes + 16 do
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the 16 for here? Can we make it into a descriptive constant?

%{frame_secrets | ingress_mac: ingress_mac, decoder_stream: decoder_stream}
}
frame_enc::binary-size(frame_size),
frame_padding::binary-size(frame_padding_bytes),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this just be frame_enc_with_padding::binary-size(frame_size + frame_padding_bytes)? Looks like they're pattern matched separately only to be concatenated below and never used individually.

@InoMurko
Copy link
Member

InoMurko commented Dec 4, 2018

I've noticed that binary isn't a dependency of ex_wire, could you include it? {:binary, "~> 0.0.5"}

| {:error,
:insufficient_data
| :failed_to_match_header_ingress_mac
| :failed_to_match_frame_ingress_mac}
def unframe(
Copy link
Member

@InoMurko InoMurko Dec 4, 2018

Choose a reason for hiding this comment

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

if you included frame parsing in the header, as in

def unframe(<<header_enc::binary-size(16), header_mac::binary-size(16), frame_rest::binary()>>, frame_secrets = %Secrets{
          ingress_mac: ingress_mac,
          decoder_stream: decoder_stream,
          mac_encoder: mac_encoder,
          mac_secret: mac_secret
        })
def unframe(<<header_enc::binary-size(16), header_mac::binary-size(16), frame_rest::binary()>>, frame_secrets = %Secrets{
          ingress_mac: ingress_mac,
          decoder_stream: decoder_stream,
          mac_encoder: mac_encoder,
          mac_secret: mac_secret
        }) do 
...
end
def unframe(_, _), do: {:error, :insufficient_data}

You could avoid deep nested function.

When packets come in, sometimes they are incomplete. We previously handled packets that had a valid header but insufficient body size. This patch adds support for packets that don't even have complete headers. We queue the packet into queued data and wait for more data before processing.

Address PR feedback
@hayesgm
Copy link
Contributor Author

hayesgm commented Dec 19, 2018

I addressed the PR feedback, ready for merge.

@hayesgm hayesgm merged commit 9c3967a into master Dec 19, 2018
@hayesgm hayesgm deleted the hayesgm/frame-size-issue branch December 19, 2018 06:22
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.

3 participants