Skip to content

Commit 8901bec

Browse files
committed
chore: removed ohttp handling from directory
1 parent 43b12a9 commit 8901bec

9 files changed

Lines changed: 72 additions & 193 deletions

File tree

Cargo-minimal.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,6 @@ name = "payjoin-directory"
26332633
version = "0.0.3"
26342634
dependencies = [
26352635
"anyhow",
2636-
"bhttp",
26372636
"bitcoin 0.32.8",
26382637
"bitcoin-ohttp",
26392638
"clap",
@@ -2693,7 +2692,6 @@ dependencies = [
26932692
"anyhow",
26942693
"axum",
26952694
"axum-server",
2696-
"bhttp",
26972695
"bitcoin-ohttp",
26982696
"clap",
26992697
"config",

Cargo-recent.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,6 @@ name = "payjoin-directory"
26332633
version = "0.0.3"
26342634
dependencies = [
26352635
"anyhow",
2636-
"bhttp",
26372636
"bitcoin 0.32.8",
26382637
"bitcoin-ohttp",
26392638
"clap",
@@ -2693,7 +2692,6 @@ dependencies = [
26932692
"anyhow",
26942693
"axum",
26952694
"axum-server",
2696-
"bhttp",
26972695
"bitcoin-ohttp",
26982696
"clap",
26992697
"config",

ohttp-relay/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ws-bootstrap = ["futures", "rustls", "tokio-tungstenite"]
2020
_test-util = []
2121

2222
[dependencies]
23+
bhttp = { version = "0.6.1", features = ["http"] }
2324
byteorder = "1.5.0"
2425
bytes = "1.10.1"
2526
futures = { version = "0.3.31", optional = true }
@@ -33,6 +34,7 @@ hyper-rustls = { version = "0.27.7", default-features = false, features = [
3334
"ring",
3435
] }
3536
hyper-util = { version = "0.1.16", features = ["client-legacy", "service"] }
37+
ohttp = { package = "bitcoin-ohttp", version = "0.6" }
3638
rustls = { version = "0.23.31", optional = true, default-features = false, features = [
3739
"ring",
3840
] }
@@ -47,8 +49,6 @@ tokio-util = { version = "0.7.16", features = ["net", "codec"] }
4749
tower = "0.5"
4850
tracing = "0.1.41"
4951
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
50-
ohttp = { package = "bitcoin-ohttp", version = "0.6" }
51-
bhttp = { version = "0.6.1", features = ["http"] }
5252

5353
[dev-dependencies]
5454
mockito = "1.7.0"

ohttp-relay/src/gateway_helpers.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::io::Cursor;
22

33
pub const CHACHA20_POLY1305_NONCE_LEN: usize = 32;
44
pub const POLY1305_TAG_SIZE: usize = 16;
5-
pub const ENCAPSULATED_MESSAGE_BYTES: usize = 65536;
6-
pub const BHTTP_REQ_BYTES: usize =
7-
ENCAPSULATED_MESSAGE_BYTES - (CHACHA20_POLY1305_NONCE_LEN + POLY1305_TAG_SIZE);
5+
pub const OHTTP_OVERHEAD: usize = CHACHA20_POLY1305_NONCE_LEN + POLY1305_TAG_SIZE;
6+
pub const ENCAPSULATED_MESSAGE_BYTES: usize = 8192;
7+
pub const BHTTP_REQ_BYTES: usize = ENCAPSULATED_MESSAGE_BYTES - OHTTP_OVERHEAD;
88

99
#[derive(Debug)]
1010
pub enum GatewayError {
@@ -25,7 +25,6 @@ impl std::fmt::Display for GatewayError {
2525

2626
impl std::error::Error for GatewayError {}
2727

28-
/// Represents the decapsulated HTTP request extracted from OHTTP
2928
pub struct DecapsulatedRequest {
3029
pub method: String,
3130
pub uri: String,
@@ -90,18 +89,27 @@ pub fn encapsulate_ohttp_response(
9089
GatewayError::InternalServerError(format!("BHTTP serialization failed: {}", e))
9190
})?;
9291

92+
if bhttp_bytes.len() > BHTTP_REQ_BYTES {
93+
return Err(GatewayError::InternalServerError(format!(
94+
"BHTTP response too large: {} > {}",
95+
bhttp_bytes.len(),
96+
BHTTP_REQ_BYTES
97+
)));
98+
}
99+
93100
bhttp_bytes.resize(BHTTP_REQ_BYTES, 0);
94101

95102
let ohttp_res = res_ctx.encapsulate(&bhttp_bytes).map_err(|e| {
96103
GatewayError::InternalServerError(format!("OHTTP encapsulation failed: {}", e))
97104
})?;
98105

99-
assert!(
100-
ohttp_res.len() == ENCAPSULATED_MESSAGE_BYTES,
101-
"Unexpected OHTTP response size: {} != {}",
102-
ohttp_res.len(),
103-
ENCAPSULATED_MESSAGE_BYTES
104-
);
106+
if ohttp_res.len() != ENCAPSULATED_MESSAGE_BYTES {
107+
return Err(GatewayError::InternalServerError(format!(
108+
"Unexpected OHTTP response size: {} != {}",
109+
ohttp_res.len(),
110+
ENCAPSULATED_MESSAGE_BYTES
111+
)));
112+
}
105113

106114
Ok(ohttp_res)
107115
}

ohttp-relay/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ pub mod sentinel;
3838
pub use sentinel::SentinelTag;
3939
pub mod gateway_helpers;
4040

41-
pub use gateway_helpers::{
42-
decapsulate_ohttp_request, encapsulate_ohttp_response, BHTTP_REQ_BYTES,
43-
ENCAPSULATED_MESSAGE_BYTES,
44-
};
41+
pub use gateway_helpers::{decapsulate_ohttp_request, encapsulate_ohttp_response};
4542

4643
use crate::error::{BoxError, Error};
4744

payjoin-directory/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ acme = ["tokio-rustls-acme"]
2020

2121
[dependencies]
2222
anyhow = "1.0.99"
23-
bhttp = { version = "0.6.1", features = ["http"] }
2423
bitcoin = { version = "0.32.7", features = ["base64", "rand-std"] }
2524
clap = { version = "4.5.45", features = ["derive", "env"] }
2625
config = "0.15.14"

0 commit comments

Comments
 (0)