Skip to content

Commit 5f5936f

Browse files
committed
feat(example,data): pass data marshallers to outbound connection & add dummy pass in client ex
1 parent d86afd2 commit 5f5936f

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/server/src/connection/outbound.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use tokio::io;
22

33
use std::net::{IpAddr, SocketAddr};
4+
use std::sync::{Arc, Mutex};
45

56
use log::{error, info};
67

@@ -9,13 +10,15 @@ use openssl::rsa::{Padding, Rsa};
910

1011
use trust_dns_resolver::{TokioAsyncResolver};
1112
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
13+
use osp_data::registry::DataTypeRegistry;
1214

1315
use osp_protocol::{ConnectionType, OSPUrl, Protocol};
1416
use osp_protocol::packet::handshake::{HandshakePacketGuestToHost, HandshakePacketHostToGuest};
1517

1618
pub struct OutboundConnection<TState> {
1719
private_key: Rsa<Private>,
1820
hostname: String,
21+
data_marshallers: Arc<Mutex<DataTypeRegistry>>,
1922
addr: SocketAddr,
2023
state: TState
2124
}
@@ -27,7 +30,7 @@ pub struct HandshakeState {
2730
}
2831

2932
impl OutboundConnection<WaitingState> {
30-
pub async fn create(url: OSPUrl, private_key: Rsa<Private>, hostname: String) -> io::Result<Self> {
33+
pub async fn create(url: OSPUrl, private_key: Rsa<Private>, hostname: String, data_marshallers: Arc<Mutex<DataTypeRegistry>>) -> io::Result<Self> {
3134
info!("Resolving osp connection to {url}");
3235
let resolver = TokioAsyncResolver::tokio(ResolverConfig::default(), ResolverOpts::default());
3336

@@ -37,20 +40,22 @@ impl OutboundConnection<WaitingState> {
3740
Self::create_with_socket_addr(
3841
SocketAddr::new(IpAddr::from(ip.0), url.port),
3942
private_key,
40-
hostname
43+
hostname,
44+
data_marshallers,
4145
)
4246
} else {
4347
error!("Lookup failed");
4448
Err(io::Error::new(io::ErrorKind::NotConnected, format!("Failed to resolve address {}", url.domain)))
4549
}
4650
}
4751

48-
pub fn create_with_socket_addr(addr: SocketAddr, private_key: Rsa<Private>, hostname: String) -> io::Result<Self> {
52+
pub fn create_with_socket_addr(addr: SocketAddr, private_key: Rsa<Private>, hostname: String, data_marshallers: Arc<Mutex<DataTypeRegistry>>) -> io::Result<Self> {
4953
info!("Opening connection to {addr}");
5054

5155
Ok(Self {
5256
private_key,
5357
hostname,
58+
data_marshallers,
5459
addr,
5560
state: WaitingState {}
5661
})
@@ -61,6 +66,7 @@ impl OutboundConnection<WaitingState> {
6166
Ok(OutboundConnection {
6267
private_key: self.private_key.clone(),
6368
hostname: self.hostname.clone(),
69+
data_marshallers: self.data_marshallers.clone(),
6470
addr: self.addr.clone(),
6571
state: HandshakeState {
6672
protocol: Protocol::connect(self.addr).await?,

crates/server/src/node.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ impl OSProtocolNode<ConnectionState> {
134134
let mut conn = OutboundConnection::create(
135135
url,
136136
self.state.lock().unwrap().private_key.clone(),
137-
self.hostname.clone()
137+
self.hostname.clone(),
138+
self.data_marshallers.clone(),
138139
).await?;
139140
let mut conn_in_handshake = conn.begin().await?;
140141
conn_in_handshake.handshake().await

examples/test_server_implementation/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77

88
[dependencies]
99
# Internal Crates
10+
osp_data = { workspace = true }
1011
osp_protocol = { workspace = true }
1112
osp_server_sdk = { workspace = true }
1213

examples/test_server_implementation/src/bin/client_test.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fs;
2+
use std::sync::{Arc, Mutex};
23

34
use clap::Parser;
45

@@ -9,6 +10,7 @@ use openssl::rsa::Rsa;
910
use tokio::io;
1011

1112
use url::Url;
13+
use osp_data::registry::DataTypeRegistry;
1214

1315
use osp_protocol::OSPUrl;
1416
use osp_server_sdk::connection::outbound::OutboundConnection;
@@ -44,7 +46,12 @@ async fn main() -> io::Result<()> {
4446
let url = OSPUrl::from(reg_url);
4547

4648
info!("Starting outbound thread");
47-
let mut conn = OutboundConnection::create(url, key, args.hostname).await?;
49+
let mut conn = OutboundConnection::create(
50+
url,
51+
key,
52+
args.hostname,
53+
Arc::new(Mutex::new(DataTypeRegistry::new())) // standalone for testing TODO REPLACE THIS WITH SOMETHING PROPER DAMMIT
54+
).await?;
4855
let mut conn_in_handshake = conn.begin().await?;
4956
conn_in_handshake.handshake().await
5057
}

0 commit comments

Comments
 (0)