Skip to content

Commit

Permalink
Merge pull request jonhoo#9 from datafuse-extras/fix-seq
Browse files Browse the repository at this point in the history
Fix protocol seq
  • Loading branch information
BohuTANG authored Sep 20, 2021
2 parents ab376b0 + 9c706a3 commit ee90afd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
14 changes: 4 additions & 10 deletions examples/serve_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,11 @@ impl<W: io::Write> MysqlShim<W> for Backend {
/// authenticate method for the specified plugin
fn authenticate(
&self,
auth_plugin: &str,
_auth_plugin: &str,
username: &[u8],
salt: &[u8],
auth_data: &[u8],
_salt: &[u8],
_auth_data: &[u8],
) -> bool {
println!(
"auth_plugin, {:?}, user: {:?} , salt: {:?}, auth_data:{:?}",
auth_plugin, username, salt, auth_data
);

username == "default".as_bytes()
}

Expand Down Expand Up @@ -102,10 +97,9 @@ impl<W: io::Write> MysqlShim<W> for Backend {

fn main() {
let mut threads = Vec::new();
let listener = net::TcpListener::bind("127.0.0.1:3306").unwrap();
let listener = net::TcpListener::bind("0.0.0.0:3306").unwrap();

while let Ok((s, _)) = listener.accept() {
println!("{:?}", "got one socket");
threads.push(thread::spawn(move || {
MysqlIntermediary::run_on_tcp(Backend, s).unwrap();
}));
Expand Down
1 change: 0 additions & 1 deletion examples/serve_one.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ fn main() {
let listener = net::TcpListener::bind("127.0.0.1:3306").unwrap();

while let Ok((s, _)) = listener.accept() {
println!("{:?}", "got one socket");
threads.push(thread::spawn(move || {
MysqlIntermediary::run_on_tcp(Backend, s).unwrap();
}));
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl<B: MysqlShim<W>, R: Read, W: Write> MysqlIntermediary<B, R, W> {
self.writer.flush()?;

{
let (seq, handshake) = self.reader.next()?.ok_or_else(|| {
let (mut seq, handshake) = self.reader.next()?.ok_or_else(|| {
io::Error::new(
io::ErrorKind::ConnectionAborted,
"peer terminated connection",
Expand Down Expand Up @@ -409,6 +409,7 @@ impl<B: MysqlShim<W>, R: Read, W: Write> MysqlIntermediary<B, R, W> {
&& auth_response.is_empty()
&& handshake.auth_plugin != auth_plugin_expect.as_bytes()
{
self.writer.set_seq(seq + 1);
self.writer.write_all(&[0xfe])?;
self.writer.write_all(auth_plugin_expect.as_bytes())?;
self.writer.write_all(&[0x00])?;
Expand All @@ -417,13 +418,14 @@ impl<B: MysqlShim<W>, R: Read, W: Write> MysqlIntermediary<B, R, W> {

self.writer.flush()?;
{
let (_seq, auth_response_data) = self.reader.next()?.ok_or_else(|| {
let (rseq, auth_response_data) = self.reader.next()?.ok_or_else(|| {
io::Error::new(
io::ErrorKind::ConnectionAborted,
"peer terminated connection",
)
})?;

seq = rseq;
auth_response = auth_response_data.to_vec();
}
}
Expand Down

0 comments on commit ee90afd

Please sign in to comment.