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

feat: Shuffle the client Initial crypto data #2228

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

larseggert
Copy link
Collaborator

@larseggert larseggert commented Nov 13, 2024

Reorder data into chunks roughly delimited by the midpoints of ASCII "LDHD" (letters, digits, hyphens, dots) sequences.

Look for the n longest ranges of ASCII "LDHD" characters in data. Create split points halfway into each range. Chunk the data based on those split points, shuffle the chunks and return them.

CC @martinthomson @dennisjackson

Look for ranges of `N` or more bytes of graphical ASCII data in `data`.
Create at least one split point for each range, multiple ones each `N`
bytes if the range is long enough. Create data chunks based on those
split points. Shuffle the chunks and return them.

CC @martinthomson @dennisjackson
Copy link

github-actions bot commented Nov 13, 2024

Failed Interop Tests

QUIC Interop Runner, client vs. server

neqo-latest as client

neqo-latest as server

All results

Succeeded Interop Tests

QUIC Interop Runner, client vs. server

neqo-latest as client

neqo-latest as server

Unsupported Interop Tests

QUIC Interop Runner, client vs. server

neqo-latest as client

neqo-latest as server

@larseggert larseggert marked this pull request as ready for review November 14, 2024 14:37
Copy link

codecov bot commented Nov 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.40%. Comparing base (f3d0191) to head (cb63418).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2228      +/-   ##
==========================================
+ Coverage   95.37%   95.40%   +0.02%     
==========================================
  Files         112      113       +1     
  Lines       36569    36750     +181     
==========================================
+ Hits        34879    35061     +182     
+ Misses       1690     1689       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Copy link

github-actions bot commented Nov 15, 2024

Benchmark results

Performance differences relative to f3d0191.

coalesce_acked_from_zero 1+1 entries: 💔 Performance has regressed.
       time:   [104.93 ns 105.27 ns 105.62 ns]
       change: [+17.767% +18.446% +19.100%] (p = 0.00 < 0.05)

Found 14 outliers among 100 measurements (14.00%)
11 (11.00%) high mild
3 (3.00%) high severe

coalesce_acked_from_zero 3+1 entries: 💔 Performance has regressed.
       time:   [120.56 ns 120.88 ns 121.23 ns]
       change: [+20.871% +21.601% +22.224%] (p = 0.00 < 0.05)

Found 16 outliers among 100 measurements (16.00%)
1 (1.00%) low severe
1 (1.00%) low mild
4 (4.00%) high mild
10 (10.00%) high severe

coalesce_acked_from_zero 10+1 entries: 💔 Performance has regressed.
       time:   [120.50 ns 121.13 ns 121.85 ns]
       change: [+22.039% +22.577% +23.126%] (p = 0.00 < 0.05)

Found 19 outliers among 100 measurements (19.00%)
2 (2.00%) low severe
7 (7.00%) low mild
1 (1.00%) high mild
9 (9.00%) high severe

coalesce_acked_from_zero 1000+1 entries: 💔 Performance has regressed.
       time:   [100.08 ns 100.22 ns 100.39 ns]
       change: [+21.662% +23.086% +24.354%] (p = 0.00 < 0.05)

Found 8 outliers among 100 measurements (8.00%)
4 (4.00%) high mild
4 (4.00%) high severe

RxStreamOrderer::inbound_frame(): Change within noise threshold.
       time:   [111.40 ms 111.46 ms 111.52 ms]
       change: [+0.0818% +0.1568% +0.2254%] (p = 0.00 < 0.05)

Found 10 outliers among 100 measurements (10.00%)
9 (9.00%) low mild
1 (1.00%) high mild

transfer/pacing-false/varying-seeds: No change in performance detected.
       time:   [27.305 ms 28.462 ms 29.636 ms]
       change: [-2.2698% +3.2180% +8.9672%] (p = 0.26 > 0.05)
transfer/pacing-true/varying-seeds: No change in performance detected.
       time:   [35.271 ms 37.145 ms 39.046 ms]
       change: [-2.6502% +3.9287% +11.367%] (p = 0.28 > 0.05)

Found 4 outliers among 100 measurements (4.00%)
1 (1.00%) low mild
3 (3.00%) high mild

transfer/pacing-false/same-seed: No change in performance detected.
       time:   [25.636 ms 26.461 ms 27.287 ms]
       change: [-3.7859% +0.7352% +5.6287%] (p = 0.76 > 0.05)
transfer/pacing-true/same-seed: No change in performance detected.
       time:   [40.711 ms 42.642 ms 44.591 ms]
       change: [-5.7983% +0.2364% +7.0996%] (p = 0.95 > 0.05)
1-conn/1-100mb-resp/mtu-1504 (aka. Download)/client: No change in performance detected.
       time:   [920.00 ms 929.07 ms 938.27 ms]
       thrpt:  [106.58 MiB/s 107.63 MiB/s 108.70 MiB/s]
change:
       time:   [-1.6896% -0.2539% +1.1341%] (p = 0.73 > 0.05)
       thrpt:  [-1.1214% +0.2545% +1.7187%]
1-conn/10_000-parallel-1b-resp/mtu-1504 (aka. RPS)/client: No change in performance detected.
       time:   [321.10 ms 324.14 ms 327.33 ms]
       thrpt:  [30.550 Kelem/s 30.851 Kelem/s 31.143 Kelem/s]
change:
       time:   [-0.3991% +0.9753% +2.3411%] (p = 0.16 > 0.05)
       thrpt:  [-2.2876% -0.9659% +0.4007%]

Found 3 outliers among 100 measurements (3.00%)
2 (2.00%) high mild
1 (1.00%) high severe

1-conn/1-1b-resp/mtu-1504 (aka. HPS)/client: Change within noise threshold.
       time:   [33.846 ms 34.084 ms 34.345 ms]
       thrpt:  [29.116  elem/s 29.340  elem/s 29.546  elem/s]
change:
       time:   [+0.2959% +1.1950% +2.1887%] (p = 0.01 < 0.05)
       thrpt:  [-2.1418% -1.1809% -0.2950%]

Found 10 outliers among 100 measurements (10.00%)
2 (2.00%) low mild
5 (5.00%) high mild
3 (3.00%) high severe

1-conn/1-100mb-resp/mtu-1504 (aka. Upload)/client: Change within noise threshold.
       time:   [1.6421 s 1.6602 s 1.6785 s]
       thrpt:  [59.577 MiB/s 60.234 MiB/s 60.899 MiB/s]
change:
       time:   [+0.4478% +2.2664% +4.0194%] (p = 0.01 < 0.05)
       thrpt:  [-3.8641% -2.2162% -0.4458%]

Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high mild

Client/server transfer results

Transfer of 33554432 bytes over loopback.

Client Server CC Pacing MTU Mean [ms] Min [ms] Max [ms]
gquiche gquiche 1504 581.9 ± 136.6 501.0 933.6
neqo gquiche reno on 1504 803.9 ± 83.8 745.4 1011.3
neqo gquiche reno 1504 790.3 ± 37.9 755.9 887.7
neqo gquiche cubic on 1504 819.9 ± 156.5 731.5 1248.3
neqo gquiche cubic 1504 843.4 ± 127.1 767.2 1186.8
msquic msquic 1504 194.0 ± 121.4 101.7 554.3
neqo msquic reno on 1504 305.2 ± 104.0 211.4 505.8
neqo msquic reno 1504 249.1 ± 64.0 204.7 451.5
neqo msquic cubic on 1504 253.9 ± 81.0 204.6 466.7
neqo msquic cubic 1504 338.1 ± 148.2 211.6 689.8
gquiche neqo reno on 1504 755.0 ± 112.0 599.4 923.4
gquiche neqo reno 1504 750.3 ± 114.2 570.9 888.3
gquiche neqo cubic on 1504 821.4 ± 146.1 611.7 1144.0
gquiche neqo cubic 1504 769.2 ± 146.4 614.0 1133.6
msquic neqo reno on 1504 693.7 ± 17.8 658.8 719.6
msquic neqo reno 1504 723.7 ± 25.4 704.0 787.5
msquic neqo cubic on 1504 736.3 ± 76.6 678.9 901.5
msquic neqo cubic 1504 732.1 ± 36.8 692.0 826.0
neqo neqo reno on 1504 682.4 ± 72.0 601.0 861.5
neqo neqo reno 1504 647.8 ± 58.3 494.0 720.8
neqo neqo cubic on 1504 732.1 ± 182.4 634.8 1095.6
neqo neqo cubic 1504 632.4 ± 26.8 605.9 698.6

⬇️ Download logs

@larseggert larseggert changed the title feat: Mix up the Initial crypto data a bit feat: Shuffle the client Initial crypto data Nov 15, 2024
neqo-transport/src/crypto.rs Outdated Show resolved Hide resolved
neqo-transport/src/crypto.rs Outdated Show resolved Hide resolved
neqo-transport/src/crypto.rs Show resolved Hide resolved
neqo-transport/src/crypto.rs Outdated Show resolved Hide resolved
neqo-transport/src/crypto.rs Outdated Show resolved Hide resolved
neqo-transport/src/crypto.rs Outdated Show resolved Hide resolved
neqo-transport/src/crypto.rs Outdated Show resolved Hide resolved
neqo-transport/src/crypto.rs Outdated Show resolved Hide resolved
neqo-transport/src/crypto.rs Outdated Show resolved Hide resolved
neqo-transport/src/crypto.rs Outdated Show resolved Hide resolved
Copy link
Member

@martinthomson martinthomson left a comment

Choose a reason for hiding this comment

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

I spent a few minutes writing some code that might be a good replacement for this if you only care about splitting at a useful point. This would be used by drawing a random value in the range (r.start + 1..end - 1) to split on. It's a lot less code...

/// Finds the range where the SNI extension lives.
/// If this isn't a ClientHello, then return the whole message.
fn find_sni_split(mut buf: &[u8]) -> Range<usize> {
    fn read_len(buf: &[u8]) -> usize {
        let mut len = 0;
        for v in buf {
            len = len << 8 & usize::from(v);
        }
        len
    }
    fn skip_vec<const N: usize>(i: usize, buf: &[u8]) -> usize {
        i + N + read_len(&buf[i..i + N])
    }

    // ClientHello == 1
    if buf[0] == 1 {
        let mut i = 1 + 3 + 2 + 32; // msg_type, length, version, random
        i = skip_vec::<1>(i, buf); // session_id
        i = skip_vec::<2>(i, buf); // cipher_suites
        i = skip_vec::<1>(i, buf); // compression_methods
        i += 2; // extensions length
        while i < buf.len() {
            if buf[i] == 0 || buf[i + 1] == 0 {
                // SNI!
                return i..i + 4 + read_len(buf[i + 2..i + 4]);
            }
        }
    }
    0..buf.len()
}


/// Find the ranges of all sequences of two or more ASCII "LDHD" (letters, digits, hyphens, dots)
/// bytes in `data`, and return the `n` longest ones in ascending order by start index.
fn ascii_sequences(data: &[u8], n: usize) -> impl Iterator<Item = Range<usize>> {
Copy link
Member

Choose a reason for hiding this comment

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

I'm still not that enthusiastic about this approach, but here's a way to improve it some.

Change the signature to fn ascii_sequences<const N: usize>(data: &[u8]) -> impl Interator....

Then collect the value into an array ([_; N]) for sorting rather than a Vec. You might have to unwrap, but that's not so bad.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did this in e9f3b58.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But I don't think I can collect into an array, because there might be fewer than N ranges. I could collect into an array with Option<Range<usize>> and have some of them be None in that case - is that worth it?

@larseggert
Copy link
Collaborator Author

I spent a few minutes writing some code that might be a good replacement for this if you only care about splitting at a useful point.

Thanks for this, but I think it needs more work? I don't think this handles invalid crypto data well, skip_vec seems to easily read beyond the end of the buffer.

@martinthomson
Copy link
Member

Fair. It was only a few minutes of work. Adding bounds checks will complicate it a little, but not overmuch. Of course, you could take the attitude I did, which is that the TLS stack should not be producing invalid messages, so panicking in that case is justified.

@larseggert
Copy link
Collaborator Author

I am nervous about making assumptions about the input. But let me play with it and see how much complexity bounds checking adds.

@larseggert
Copy link
Collaborator Author

@martinthomson is your code taking SSL_ENABLE_CH_EXTENSION_PERMUTATION into account? Because the range it returns isn't the SNI...

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