Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

WIP add backend messages serialization and frontend messages deserialization#946

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
prx0 wants to merge4 commits intorust-postgres:master
base:master
Choose a base branch
Loading
fromprx0:backend_serialization_frontend_deserialization

Conversation

prx0
Copy link

@prx0prx0 commentedAug 26, 2022
edited
Loading

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!

@prx0
Copy link
Author

Hi Max, I actually wanted to implement the same thing as I was inspired byhttps://github.com/jackc/pgproto3. You can get a lot of pointers for parsing the messages there

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. ^^'

@zain-kabani
Copy link

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

@prx0
Copy link
Author

prx0 commentedSep 15, 2022
edited
Loading

@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.
https://github.com/levkk/pgcat
Not a framework but a tool to manage sharding avec load balancing for postgres databases.

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 fromjackc/pgproto3.
The idea is to be able to modify each parameter of a frontend message.

Example for a BindBody

#[non_exaustive]pubenumMessage{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.gopubstructBindBody{pubdestination_portal:String,pubprepared_statement:String,pubparameter_format_codes:Vec<u16>,pubparameters:Vec<Vec<Bytes>>,pubresult_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.

@zain-kabani
Copy link

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.
Fun fact I'm actually an active contributor to the pgcat project, and built this with pgcat in mind.

Yes those are there temporarily as I still have to implement the logic of encoding/decoding them. (contributions are welcome!)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@prx0@zain-kabani

[8]ページ先頭

©2009-2025 Movatter.jp