1
1
use tokio:: io;
2
2
3
3
use std:: net:: { IpAddr , SocketAddr } ;
4
+ use std:: sync:: { Arc , Mutex } ;
4
5
5
6
use log:: { error, info} ;
6
7
@@ -9,13 +10,15 @@ use openssl::rsa::{Padding, Rsa};
9
10
10
11
use trust_dns_resolver:: { TokioAsyncResolver } ;
11
12
use trust_dns_resolver:: config:: { ResolverConfig , ResolverOpts } ;
13
+ use osp_data:: registry:: DataTypeRegistry ;
12
14
13
15
use osp_protocol:: { ConnectionType , OSPUrl , Protocol } ;
14
16
use osp_protocol:: packet:: handshake:: { HandshakePacketGuestToHost , HandshakePacketHostToGuest } ;
15
17
16
18
pub struct OutboundConnection < TState > {
17
19
private_key : Rsa < Private > ,
18
20
hostname : String ,
21
+ data_marshallers : Arc < Mutex < DataTypeRegistry > > ,
19
22
addr : SocketAddr ,
20
23
state : TState
21
24
}
@@ -27,7 +30,7 @@ pub struct HandshakeState {
27
30
}
28
31
29
32
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 > {
31
34
info ! ( "Resolving osp connection to {url}" ) ;
32
35
let resolver = TokioAsyncResolver :: tokio ( ResolverConfig :: default ( ) , ResolverOpts :: default ( ) ) ;
33
36
@@ -37,20 +40,22 @@ impl OutboundConnection<WaitingState> {
37
40
Self :: create_with_socket_addr (
38
41
SocketAddr :: new ( IpAddr :: from ( ip. 0 ) , url. port ) ,
39
42
private_key,
40
- hostname
43
+ hostname,
44
+ data_marshallers,
41
45
)
42
46
} else {
43
47
error ! ( "Lookup failed" ) ;
44
48
Err ( io:: Error :: new ( io:: ErrorKind :: NotConnected , format ! ( "Failed to resolve address {}" , url. domain) ) )
45
49
}
46
50
}
47
51
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 > {
49
53
info ! ( "Opening connection to {addr}" ) ;
50
54
51
55
Ok ( Self {
52
56
private_key,
53
57
hostname,
58
+ data_marshallers,
54
59
addr,
55
60
state : WaitingState { }
56
61
} )
@@ -61,6 +66,7 @@ impl OutboundConnection<WaitingState> {
61
66
Ok ( OutboundConnection {
62
67
private_key : self . private_key . clone ( ) ,
63
68
hostname : self . hostname . clone ( ) ,
69
+ data_marshallers : self . data_marshallers . clone ( ) ,
64
70
addr : self . addr . clone ( ) ,
65
71
state : HandshakeState {
66
72
protocol : Protocol :: connect ( self . addr ) . await ?,
0 commit comments