docs: handshake documentation
This commit is contained in:
parent
eb8410718d
commit
c61b6021db
5 changed files with 28 additions and 3 deletions
|
|
@ -7,11 +7,15 @@ use crate::reader::frontend::FrontendProtoReader;
|
|||
use crate::writer::backend::BackendProtoWriter;
|
||||
use crate::writer::protowriter::ProtoFlush;
|
||||
|
||||
/// Performs server-side handshake with the client until ending it with `ReadyForQuery` message.
|
||||
/// For more info visit the [`55.2.1. Start-up`](https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-START-UP)
|
||||
pub async fn do_server_handshake(
|
||||
writer: &mut (impl BackendProtoWriter + ProtoFlush),
|
||||
reader: &mut impl FrontendProtoReader,
|
||||
response: HandshakeResponse,
|
||||
) -> Result<HandshakeRequest, ServerHandshakeError> {
|
||||
|
||||
// Check if client requested SSL
|
||||
match &reader.peek_special_message().await? {
|
||||
Some(msg @ SpecialMessage::SSLRequest) => {
|
||||
reader.consume_special_message(msg).await?;
|
||||
|
|
@ -23,6 +27,7 @@ pub async fn do_server_handshake(
|
|||
}
|
||||
}
|
||||
|
||||
// Wait for mandatory StartupMessage
|
||||
let startup_message = match &reader.peek_special_message().await? {
|
||||
Some(msg @ SpecialMessage::StartupMessage(data)) => {
|
||||
reader.consume_special_message(msg).await?;
|
||||
|
|
@ -33,15 +38,18 @@ pub async fn do_server_handshake(
|
|||
}
|
||||
};
|
||||
|
||||
// Authenticate client
|
||||
writer
|
||||
.write_proto(BackendMessage::from(AuthenticationOkData { status: 0 }))
|
||||
.await?;
|
||||
|
||||
// Send server parameters
|
||||
let messages: Vec<BackendMessage> = response.into();
|
||||
for message in messages {
|
||||
writer.write_proto(message).await?;
|
||||
}
|
||||
|
||||
// Finish the handshake
|
||||
writer
|
||||
.write_proto(BackendMessage::from(ReadyForQueryData { status: b'I' }))
|
||||
.await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue