-
-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP add backend messages serialization and frontend messages deserialization #946
base: master
Are you sure you want to change the base?
WIP add backend messages serialization and frontend messages deserialization #946
Conversation
Hello! Thank you. I use already pgproto3 in my company but I still want to continue this PR because I would like to work with Rust. I'll check out the source code of pgproto3 to get some help. Backend serialization is quite easy. But frontend deserialization is not. I need some motivations and time, but I promess I'll finish this PR. ^^' |
Hi I've been working on a project to make creating postgres proxies easier in rust. I've just gotten started on it and welcome any contributions to it! https://github.com/zain-kabani/postgres-proto-rs |
@zain-kabani that's great! I noticed that you've started to implement deserialization for frontend messages. That's what I try to do here. (also be careful you didn't specify any license in your project) I don't know if it's a good idea to create another crate to add postgres protocol parsing because the rust-postgres crate made by @sfackler do this already. rust-postgres is a dependency of the postgres crate which is massively used. It would be great to add deserialization and serialization into rust-postgres in order to add functionnalities for existing projects based on this crate. I think it would be awesome to create a framework for making progresql proxies with rust-postgres as dependency. pgcat is another inspiring project. EDIT: your frontend messages are mainly struct with a ByteMut attribute called message_byte. That's a simple approach I like. In my case I would like to implement something more like the structs from jackc/pgproto3. Example for a BindBody #[non_exaustive]
pub enum Message {
Bind(BindBody),
Close(CloseBody),
CopyFail(CopyFailBody),
Descibe(DescribeBody),
Execute(ExecuteBody),
Flush(FlushBody),
FunctionCall(FunctionCall),
GSSENCRequest(GSSENCRequestBody),
GSSResponse(GSSResponseBody),
Parse(ParseBody),
PasswordMessage(PasswordMessageBody),
Query(QueryBody),
SASLInitialResponse(SASLInitialResponseBody),
SASLResponse(SASLResponseBody),
SSLRequest(SSLRequestBody),
StartupMessage(StartupMessageBody),
Sync(SyncBody),
Terminate(TerminateBody),
}
// highly based on https://github.com/jackc/pgproto3/blob/master/bind.go
pub struct BindBody {
pub destination_portal: String,
pub prepared_statement: String,
pub parameter_format_codes: Vec<u16>,
pub parameters: Vec<Vec<Bytes>>,
pub result_format_codes: Vec<u16>,
} I don't know if it's a good idea to go into such details than using a simple attribute which do the job. |
Hi Max, yeah I considered adding to this repo too but didn't want to rock the boat too much here and decided to just create a separate project. Yes those are there temporarily as I still have to implement the logic of encoding/decoding them. (contributions are welcome!) |
PR related to #942
The goal is to allow serialization of backend message into bytes and deserialization of frontend message into rust object that we can handle.
It could be useful for making a proxy or a fake postgresql server. (honeypot)
I've still lot of work to do here. My approach for backend message serialization is to implement TryFrom for Message in order to convert them into bytes.
I'm open to suggestions if you know a better way to do this of course.
Postgresql message flow documentation: https://www.postgresql.org/docs/current/protocol-message-formats.html
Thank you!