ProxyHdrV2

Struct ProxyHdrV2 

Source
pub struct ProxyHdrV2<OPC: ProxyV2OpCode> { /* private fields */ }
Expand description

A Proxy Network packet composer.

Depending on the type of the generic OPC a different composing options are available.

OPC:

  • HdrV2OpLocal - a local operation as described in the proxy documentation.

  • HdrV2OpProxy - a proxy operation as described in the proxy documentation.

§Arguments

  • OPC - ProxyV2OpCode a proxy opcode. It is intentionally made as a generic to separate the options which are availabe for each type of HaProxy message.

§Example

// creating new instance
let mut comp = 
    ProxyHdrV2::<HdrV2OpProxy>::new(ProxyTransportFam::STREAM, addr).unwrap();
 
// aquiring the plts to set fields
let plts = comp.set_plts();
 
// adding ssl info
let mut ssl = plts.add_ssl(PP2TlvClient::PP2_CLIENT_SSL, 0).unwrap();
ssl.add_ssl_sub_version("TLSv1.2").unwrap();
     
// done writing ssl, returning the plts
let mut plts = ssl.done().unwrap();
 
// a custom TLV
let cust_plt = ProxyV2Dummy2::SomeTlvName(0x01020304, 0x05060708);
 
plts.add_tlv(cust_plt, Some(&[0xE0..=0xE0])).unwrap();
 
drop(plts);
 
// convert to vec of bytes
let pkt: Vec<u8> = comp.try_into().unwrap();

Implementations§

Source§

impl<OPC: ProxyV2OpCode> ProxyHdrV2<OPC>

Source

pub const HDR_MSG_LEN_OFFSET: u64 = 14u64

Offset to the message length field.

Source§

impl ProxyHdrV2<HdrV2OpLocal>

All functionality available for the opcode LOCAL.

Source

pub fn new() -> Vec<u8>

Creates a new message of type LOCAL HdrV2Command::LOCAL.

Source§

impl ProxyHdrV2<HdrV2OpProxy>

All functionality available for the opcode PROXY.

Source

pub fn new( transport: ProxyTransportFam, address: ProxyV2Addr, ) -> HaProxRes<Self>

Creates new message of type PROXY HdrV2Command::PROXY. A program should provide the type of the transport and address of the source and destination. The message compose instance is returned which already contains a prepared header.

§Arguments
§Returns

A HaProxRes is returned:

Examples found in repository?
examples/example_custom_composer.rs (line 61)
56fn main()
57{
58    let addr = ProxyV2Addr::try_from(("127.0.0.1:39754", "127.0.0.67:11883")).unwrap();
59        
60    let mut comp = 
61        ProxyHdrV2::<HdrV2OpProxy>::new(ProxyTransportFam::STREAM, addr).unwrap();
62
63    let plts = comp.set_plts();
64
65    let mut ssl = plts.add_ssl(PP2TlvClient::PP2_CLIENT_SSL, 0).unwrap();
66
67    ssl.add_ssl_sub_version("TLSv1.2").unwrap();
68    
69    let mut plts = ssl.done().unwrap();
70
71
72    let cust_plt = ProxyV2Dummy2::SomeTlvName(0x01020304, 0x05060708);
73
74    plts.add_tlv(cust_plt, Some(&[0xE0..=0xE0])).unwrap();
75
76    drop(plts);
77
78    let pkt: Vec<u8> = comp.try_into().unwrap();
79
80    let ctrl = 
81b"\x0d\x0a\x0d\x0a\x00\x0d\x0a\x51\x55\x49\x54\x0a\x21\x11\x00\x29\
82\x7f\x00\x00\x01\x7f\x00\x00\x43\x9b\x4a\x2e\x6b\x20\x00\x0f\x01\
83\x00\x00\x00\x00\x21\x00\x07\x54\x4c\x53\x76\x31\x2e\x32\xE0\x00\
84\x08\x01\x02\x03\x04\x05\x06\x07\x08";
85
86    assert_eq!(pkt.as_slice(), ctrl.as_slice());
87}
Source

pub fn set_plts<'s>(&'s mut self) -> TlType<'s>

Provides functionality to add the TLV to the payload of the message.

Examples found in repository?
examples/example_custom_composer.rs (line 63)
56fn main()
57{
58    let addr = ProxyV2Addr::try_from(("127.0.0.1:39754", "127.0.0.67:11883")).unwrap();
59        
60    let mut comp = 
61        ProxyHdrV2::<HdrV2OpProxy>::new(ProxyTransportFam::STREAM, addr).unwrap();
62
63    let plts = comp.set_plts();
64
65    let mut ssl = plts.add_ssl(PP2TlvClient::PP2_CLIENT_SSL, 0).unwrap();
66
67    ssl.add_ssl_sub_version("TLSv1.2").unwrap();
68    
69    let mut plts = ssl.done().unwrap();
70
71
72    let cust_plt = ProxyV2Dummy2::SomeTlvName(0x01020304, 0x05060708);
73
74    plts.add_tlv(cust_plt, Some(&[0xE0..=0xE0])).unwrap();
75
76    drop(plts);
77
78    let pkt: Vec<u8> = comp.try_into().unwrap();
79
80    let ctrl = 
81b"\x0d\x0a\x0d\x0a\x00\x0d\x0a\x51\x55\x49\x54\x0a\x21\x11\x00\x29\
82\x7f\x00\x00\x01\x7f\x00\x00\x43\x9b\x4a\x2e\x6b\x20\x00\x0f\x01\
83\x00\x00\x00\x00\x21\x00\x07\x54\x4c\x53\x76\x31\x2e\x32\xE0\x00\
84\x08\x01\x02\x03\x04\x05\x06\x07\x08";
85
86    assert_eq!(pkt.as_slice(), ctrl.as_slice());
87}

Trait Implementations§

Source§

impl<OPC: Clone + ProxyV2OpCode> Clone for ProxyHdrV2<OPC>

Source§

fn clone(&self) -> ProxyHdrV2<OPC>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<OPC: Debug + ProxyV2OpCode> Debug for ProxyHdrV2<OPC>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl TryFrom<ProxyHdrV2<HdrV2OpProxy>> for Vec<u8>

Converts the instance to the vector. The message will be finalized i.e length recalculated, CRC updated.

Source§

type Error = HaProxErr

The type returned in the event of a conversion error.
Source§

fn try_from(value: ProxyHdrV2<HdrV2OpProxy>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<OPC> Freeze for ProxyHdrV2<OPC>

§

impl<OPC> RefUnwindSafe for ProxyHdrV2<OPC>
where OPC: RefUnwindSafe,

§

impl<OPC> Send for ProxyHdrV2<OPC>
where OPC: Send,

§

impl<OPC> Sync for ProxyHdrV2<OPC>
where OPC: Sync,

§

impl<OPC> Unpin for ProxyHdrV2<OPC>
where OPC: Unpin,

§

impl<OPC> UnwindSafe for ProxyHdrV2<OPC>
where OPC: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.