Make connection setup a part of EppConnection interface

This commit is contained in:
Dirkjan Ochtman 2021-12-13 16:31:06 +01:00 committed by masalachai
parent 6695a20a18
commit 4f111fa8fe
2 changed files with 9 additions and 8 deletions

View File

@ -49,7 +49,7 @@ use crate::common::NoExtension;
use crate::config::EppClientConfig;
use crate::error;
use crate::hello::{Greeting, GreetingDocument, HelloDocument};
use crate::registry::{epp_connect, EppConnection};
use crate::registry::EppConnection;
use crate::request::{Command, Extension, Transaction};
use crate::response::Response;
use crate::xml::EppXml;
@ -73,10 +73,9 @@ impl EppClient {
None => return Err(format!("missing credentials for {}", registry).into()),
};
let stream = epp_connect(registry_creds).await?;
let connection = EppConnection::new(registry.to_string(), stream).await?;
Ok(EppClient { connection })
Ok(EppClient {
connection: EppConnection::connect(registry.to_string(), registry_creds).await?,
})
}
/// Executes an EPP Hello call and returns the response as an `Greeting`

View File

@ -26,10 +26,12 @@ pub struct EppConnection {
impl EppConnection {
/// Create an EppConnection instance with the stream to the registry
pub async fn new(
pub async fn connect(
registry: String,
mut stream: TlsStream<TcpStream>,
config: &RegistryConfig,
) -> Result<EppConnection, Box<dyn Error>> {
let mut stream = epp_connect(config).await?;
let mut buf = vec![0u8; 4096];
stream.read(&mut buf).await?;
let greeting = str::from_utf8(&buf[4..])?.to_string();
@ -118,7 +120,7 @@ impl EppConnection {
/// Establishes a TLS connection to a registry and returns a ConnectionStream instance containing the
/// socket stream to read/write to the connection
pub async fn epp_connect(
async fn epp_connect(
registry_creds: &RegistryConfig,
) -> Result<TlsStream<TcpStream>, error::Error> {
info!(