-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathprotocol_pack.rs
More file actions
59 lines (54 loc) · 2.11 KB
/
protocol_pack.rs
File metadata and controls
59 lines (54 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2019, MASQ (https://masq.ai) and/or its affiliates. All rights reserved.
use crate::proxy_server::http_protocol_pack::HttpProtocolPack;
use crate::proxy_server::tls_protocol_pack::TlsProtocolPack;
use crate::sub_lib::cryptde::PlainData;
use crate::sub_lib::dispatcher::InboundClientData;
use crate::sub_lib::host::Host;
use crate::sub_lib::proxy_server::ProxyProtocol;
use masq_lib::constants::{HTTP_PORT, TLS_PORT};
pub trait ProtocolPack: Send + Sync {
fn proxy_protocol(&self) -> ProxyProtocol;
fn standard_port(&self) -> u16;
fn find_host(&self, data: &PlainData) -> Option<Host>;
fn server_impersonator(&self) -> Box<dyn ServerImpersonator>;
fn describe_packet(&self, data: &PlainData) -> String;
}
pub fn from_protocol(protocol: ProxyProtocol) -> Box<dyn ProtocolPack> {
match protocol {
ProxyProtocol::HTTP => Box::new(HttpProtocolPack {}),
ProxyProtocol::TLS => Box::new(TlsProtocolPack {}),
}
}
pub fn from_standard_port(standard_port: u16) -> Option<Box<dyn ProtocolPack>> {
match standard_port {
HTTP_PORT => Some(Box::new(HttpProtocolPack {})),
TLS_PORT => Some(Box::new(TlsProtocolPack {})),
_ => None,
}
}
pub fn from_ibcd(ibcd: &InboundClientData) -> Result<Box<dyn ProtocolPack>, String> {
let origin_port = match ibcd.reception_port_opt {
None => {
return Err(format!(
"No origin port specified with {}-byte non-clandestine packet: {:?}",
ibcd.data.len(),
ibcd.data
))
}
Some(origin_port) => origin_port,
};
match from_standard_port(origin_port) {
Some(pp) => Ok(pp),
None => Err(format!(
"No protocol associated with origin port {} for {}-byte non-clandestine packet: {:?}",
origin_port,
ibcd.data.len(),
&ibcd.data
)),
}
}
pub trait ServerImpersonator {
fn route_query_failure_response(&self, server_name: &str) -> Vec<u8>;
fn dns_resolution_failure_response(&self, server_name: String) -> Vec<u8>;
fn consuming_wallet_absent(&self) -> Vec<u8>;
}