mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
fix guest tls connection init
This commit is contained in:
parent
a63e05685c
commit
3791cbc4d0
2 changed files with 12 additions and 29 deletions
|
|
@ -74,10 +74,6 @@ impl Client {
|
|||
certificate: Option<TlsCertificate>,
|
||||
callback: impl Fn(Result<connection::Response, Error>) + 'static,
|
||||
) {
|
||||
// Toggle socket mode
|
||||
// * guest sessions will not work without!
|
||||
self.socket.set_tls(certificate.is_none());
|
||||
|
||||
// Begin new connection
|
||||
// * [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html) required for valid
|
||||
// [SNI](https://geminiprotocol.net/docs/protocol-specification.gmi#server-name-indication)
|
||||
|
|
|
|||
|
|
@ -14,8 +14,7 @@ use glib::{
|
|||
};
|
||||
|
||||
pub struct Connection {
|
||||
pub socket_connection: SocketConnection,
|
||||
pub tls_client_connection: Option<TlsClientConnection>, // is user certificate session
|
||||
pub tls_client_connection: TlsClientConnection,
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
|
|
@ -28,19 +27,18 @@ impl Connection {
|
|||
server_identity: Option<NetworkAddress>,
|
||||
) -> Result<Self, Error> {
|
||||
Ok(Self {
|
||||
tls_client_connection: match certificate {
|
||||
Some(ref certificate) => {
|
||||
match new_tls_client_connection(&socket_connection, server_identity.as_ref()) {
|
||||
Ok(tls_client_connection) => {
|
||||
tls_client_connection.set_certificate(certificate);
|
||||
Some(tls_client_connection)
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
tls_client_connection: match new_tls_client_connection(
|
||||
&socket_connection,
|
||||
server_identity.as_ref(),
|
||||
) {
|
||||
Ok(tls_client_connection) => {
|
||||
if let Some(ref certificate) = certificate {
|
||||
tls_client_connection.set_certificate(certificate);
|
||||
}
|
||||
tls_client_connection
|
||||
}
|
||||
None => None,
|
||||
Err(e) => return Err(e),
|
||||
},
|
||||
socket_connection,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -75,22 +73,11 @@ impl Connection {
|
|||
|
||||
// Getters
|
||||
|
||||
/// Cast [IOStream](https://docs.gtk.org/gio/class.IOStream.html)
|
||||
/// for [SocketConnection](https://docs.gtk.org/gio/class.SocketConnection.html)
|
||||
/// or [TlsClientConnection](https://docs.gtk.org/gio/iface.TlsClientConnection.html) (if available)
|
||||
/// Get [IOStream](https://docs.gtk.org/gio/class.IOStream.html)
|
||||
/// * compatible with user (certificate) and guest (certificate-less) connection type
|
||||
/// * useful to keep `Connection` reference active in async I/O context
|
||||
pub fn stream(&self) -> impl IsA<IOStream> {
|
||||
match self.tls_client_connection.is_some() {
|
||||
// is user session
|
||||
true => self
|
||||
.tls_client_connection
|
||||
.clone()
|
||||
.unwrap()
|
||||
.upcast::<IOStream>(),
|
||||
// is guest session
|
||||
false => self.socket_connection.clone().upcast::<IOStream>(),
|
||||
}
|
||||
self.tls_client_connection.clone().upcast::<IOStream>()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue