Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  network_config.rs

  Sprache: Rust
 

mod common;
use common::*;

use std::time::{Duration, Instant};

use happy_eyeballs::{
    AltSvc, ConnectionAttemptHttpVersions, FailureReason, HappyEyeballs, HttpVersion, HttpVersions,
    Id, NetworkConfig, Output,
};

#[test]
fn ip_host() {
    let now = Instant::now();
    let mut he = HappyEyeballs::new("[2001:0DB8::1]", PORT).unwrap();

    he.expect(vec![(None, Some(out_attempt_v6_h1_h2(Id::from(0))))], now);
}

#[test]
fn not_url_but_ip() {
    // Neither of these are a valid URL, but they are valid IP addresses.
    HappyEyeballs::new("::1", PORT).unwrap();
    HappyEyeballs::new("127.0.0.1", PORT).unwrap();
}

#[test]
fn alt_svc_construction() {
    let now = Instant::now();
    let config = NetworkConfig {
        alt_svc: vec![AltSvc {
            host: None,
            port: None,
            http_version: HttpVersion::H3,
        }],
        ..NetworkConfig::default()
    };
    let mut he = HappyEyeballs::new_with_network_config(HOSTNAME, PORT, config).unwrap();

    // Should still send DNS queries as normal
    he.expect(vec![(None, Some(out_send_dns_https(Id::from(0))))], now);
}

#[test]
fn alt_svc_used_immediately() {
    let now = Instant::now();
    let config = NetworkConfig {
        alt_svc: vec![AltSvc {
            host: None,
            port: None,
            http_version: HttpVersion::H3,
        }],
        ..NetworkConfig::default()
    };
    let mut he = HappyEyeballs::new_with_network_config(HOSTNAME, PORT, config).unwrap();

    // Alt-svc with H3 should make H3 available even without HTTPS DNS response
    he.expect(
        vec![
            (None, Some(out_send_dns_https(Id::from(0)))),
            (None, Some(out_send_dns_aaaa(Id::from(1)))),
            (None, Some(out_send_dns_a(Id::from(2)))),
            (
                Some(in_dns_https_negative(Id::from(0))),
                Some(out_resolution_delay()),
            ),
            // Alt-svc provided H3, so we should attempt H3 connection
            (
                Some(in_dns_aaaa_positive(Id::from(1))),
                Some(out_attempt_v6_h3(Id::from(3))),
            ),
        ],
        now,
    );
}

/// Alt-svc with a custom port: connections are attempted at both the alt-svc
/// port and the origin port.
///
/// No HTTPS records in this scenario. Alt-svc says H3 on port 8443.
/// Expected endpoint order:
///   alt-svc bucket  (port 8443): V6:H3, V4:H3
///   fallback bucket (port  443): V6:H2OrH1, V4:H2OrH1
#[test]
fn alt_svc_with_port() {
    let alt_port: u16 = CUSTOM_PORT;
    let config = NetworkConfig {
        alt_svc: vec![AltSvc {
            host: None,
            port: Some(alt_port),
            http_version: HttpVersion::H3,
        }],
        ..NetworkConfig::default()
    };
    let (mut now, mut he) = setup_with_config(config);

    he.expect(
        vec![
            (None, Some(out_send_dns_https(Id::from(0)))),
            (None, Some(out_send_dns_aaaa(Id::from(1)))),
            (None, Some(out_send_dns_a(Id::from(2)))),
            (
                Some(in_dns_https_negative(Id::from(0))),
                Some(out_resolution_delay()),
            ),
            // AAAA arrives, move-on met. First endpoint: alt-svc port V6:H3
            (
                Some(in_dns_aaaa_positive(Id::from(1))),
                Some(out_attempt(
                    Id::from(3),
                    V6_ADDR.into(),
                    alt_port,
                    ConnectionAttemptHttpVersions::H3,
                )),
            ),
            (
                Some(in_dns_a_positive(Id::from(2))),
                Some(out_connection_attempt_delay()),
            ),
        ],
        now,
    );

    he.expect_connection_attempts(
        &mut now,
        vec![
            // Alt-svc bucket (port 8443): V4:H3
            out_attempt(
                Id::from(4),
                V4_ADDR.into(),
                alt_port,
                ConnectionAttemptHttpVersions::H3,
            ),
            // Fallback bucket (port 443): V6:H2OrH1, V4:H2OrH1
            out_attempt(
                Id::from(5),
                V6_ADDR.into(),
                PORT,
                ConnectionAttemptHttpVersions::H2OrH1,
            ),
            out_attempt(
                Id::from(6),
                V4_ADDR.into(),
                PORT,
                ConnectionAttemptHttpVersions::H2OrH1,
            ),
        ],
    );

    // All connection attempts fail -> should report Failed(Connection)
    for id in 3..=5 {
        he.expect(
            vec![(Some(in_connection_result_negative(Id::from(id))), None)],
            now,
        );
    }
    he.expect(
        vec![(
            Some(in_connection_result_negative(Id::from(6))),
            Some(Output::Failed(FailureReason::Connection)),
        )],
        now,
    );
}

/// When the host is an IP address and alt-svc specifies a custom port,
/// endpoints should be attempted at both the alt-svc port and the origin port.
///
/// Expected endpoint order:
///   alt-svc bucket  (port 8443): V4_ADDR:H3
///   fallback bucket (port  443): V4_ADDR:H2OrH1
#[test]
fn ip_host_alt_svc_with_port() {
    let mut now = Instant::now();
    let config = NetworkConfig {
        alt_svc: vec![AltSvc {
            host: None,
            port: Some(CUSTOM_PORT),
            http_version: HttpVersion::H3,
        }],
        ..NetworkConfig::default()
    };
    let mut he =
        HappyEyeballs::new_with_network_config(&V4_ADDR.to_string(), PORT, config).unwrap();

    he.expect(
        vec![
            // Alt-svc bucket (port 8443): H3
            (
                None,
                Some(out_attempt(
                    Id::from(0),
                    V4_ADDR.into(),
                    CUSTOM_PORT,
                    ConnectionAttemptHttpVersions::H3,
                )),
            ),
            (None, Some(out_connection_attempt_delay())),
        ],
        now,
    );

    he.expect_connection_attempts(
        &mut now,
        vec![
            // Fallback bucket (port 443): H2OrH1
            out_attempt(
                Id::from(1),
                V4_ADDR.into(),
                PORT,
                ConnectionAttemptHttpVersions::H2OrH1,
            ),
        ],
    );
}

/// Custom resolution and connection attempt delays should be respected by
/// the state machine instead of the default constants.
#[test]
fn custom_delays() {
    let custom_resolution_delay = Duration::from_millis(10);
    let custom_connection_attempt_delay = Duration::from_millis(50);

    let (mut now, mut he) = setup_with_config(NetworkConfig {
        resolution_delay: custom_resolution_delay,
        connection_attempt_delay: custom_connection_attempt_delay,
        ..NetworkConfig::default()
    });

    he.expect(
        vec![
            (None, Some(out_send_dns_https(Id::from(0)))),
            (None, Some(out_send_dns_aaaa(Id::from(1)))),
            (None, Some(out_send_dns_a(Id::from(2)))),
            (
                Some(in_dns_a_positive(Id::from(2))),
                // Should use the custom resolution delay, not the default 50ms.
                Some(Output::Timer {
                    duration: custom_resolution_delay,
                }),
            ),
        ],
        now,
    );

    now += custom_resolution_delay;

    he.expect(
        vec![
            (None, Some(out_attempt_v4_h1_h2(Id::from(3)))),
            // Should use the custom connection attempt delay, not the default 250ms.
            (
                None,
                Some(Output::Timer {
                    duration: custom_connection_attempt_delay,
                }),
            ),
        ],
        now,
    );
}

/// Config with `version` disabled in `http_versions` and present as the sole alt-svc entry.
fn alt_svc_disabled_config(version: HttpVersion) -> NetworkConfig {
    let http_versions = match version {
        HttpVersion::H3 => HttpVersions {
            h3: false,
            ..Default::default()
        },
        HttpVersion::H2 => HttpVersions {
            h2: false,
            ..Default::default()
        },
        HttpVersion::H1 => HttpVersions {
            h1: false,
            ..Default::default()
        },
    };
    NetworkConfig {
        http_versions,
        alt_svc: vec![AltSvc {
            host: None,
            port: None,
            http_version: version,
        }],
        ..NetworkConfig::default()
    }
}

fn assert_alt_svc_version_disabled(
    version: HttpVersion,
    expected_fallback: ConnectionAttemptHttpVersions,
) {
    let now = Instant::now();
    let mut he = HappyEyeballs::new_with_network_config(
        &V4_ADDR.to_string(),
        PORT,
        alt_svc_disabled_config(version),
    )
    .unwrap();
    he.expect(
        vec![(
            None,
            Some(out_attempt(
                Id::from(0),
                V4_ADDR.into(),
                PORT,
                expected_fallback,
            )),
        )],
        now,
    );
}

/// Alt-svc H2 entry is filtered out when H2 is disabled in the network config.
#[test]
fn alt_svc_h2_disabled() {
    assert_alt_svc_version_disabled(HttpVersion::H2, ConnectionAttemptHttpVersions::H1);
}

/// Alt-svc H1 entry is filtered out when H1 is disabled in the network config.
#[test]
fn alt_svc_h1_disabled() {
    assert_alt_svc_version_disabled(HttpVersion::H1, ConnectionAttemptHttpVersions::H2);
}

Messung V0.5 in Prozent
C=94 H=99 G=96

¤ Dauer der Verarbeitung: 0.4 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002