Skip to content

Commit ee90afd

Browse files
authored
Merge pull request jonhoo#9 from datafuse-extras/fix-seq
Fix protocol seq
2 parents ab376b0 + 9c706a3 commit ee90afd

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

examples/serve_auth.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,11 @@ impl<W: io::Write> MysqlShim<W> for Backend {
5353
/// authenticate method for the specified plugin
5454
fn authenticate(
5555
&self,
56-
auth_plugin: &str,
56+
_auth_plugin: &str,
5757
username: &[u8],
58-
salt: &[u8],
59-
auth_data: &[u8],
58+
_salt: &[u8],
59+
_auth_data: &[u8],
6060
) -> bool {
61-
println!(
62-
"auth_plugin, {:?}, user: {:?} , salt: {:?}, auth_data:{:?}",
63-
auth_plugin, username, salt, auth_data
64-
);
65-
6661
username == "default".as_bytes()
6762
}
6863

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

10398
fn main() {
10499
let mut threads = Vec::new();
105-
let listener = net::TcpListener::bind("127.0.0.1:3306").unwrap();
100+
let listener = net::TcpListener::bind("0.0.0.0:3306").unwrap();
106101

107102
while let Ok((s, _)) = listener.accept() {
108-
println!("{:?}", "got one socket");
109103
threads.push(thread::spawn(move || {
110104
MysqlIntermediary::run_on_tcp(Backend, s).unwrap();
111105
}));

examples/serve_one.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ fn main() {
4141
let listener = net::TcpListener::bind("127.0.0.1:3306").unwrap();
4242

4343
while let Ok((s, _)) = listener.accept() {
44-
println!("{:?}", "got one socket");
4544
threads.push(thread::spawn(move || {
4645
MysqlIntermediary::run_on_tcp(Backend, s).unwrap();
4746
}));

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl<B: MysqlShim<W>, R: Read, W: Write> MysqlIntermediary<B, R, W> {
366366
self.writer.flush()?;
367367

368368
{
369-
let (seq, handshake) = self.reader.next()?.ok_or_else(|| {
369+
let (mut seq, handshake) = self.reader.next()?.ok_or_else(|| {
370370
io::Error::new(
371371
io::ErrorKind::ConnectionAborted,
372372
"peer terminated connection",
@@ -409,6 +409,7 @@ impl<B: MysqlShim<W>, R: Read, W: Write> MysqlIntermediary<B, R, W> {
409409
&& auth_response.is_empty()
410410
&& handshake.auth_plugin != auth_plugin_expect.as_bytes()
411411
{
412+
self.writer.set_seq(seq + 1);
412413
self.writer.write_all(&[0xfe])?;
413414
self.writer.write_all(auth_plugin_expect.as_bytes())?;
414415
self.writer.write_all(&[0x00])?;
@@ -417,13 +418,14 @@ impl<B: MysqlShim<W>, R: Read, W: Write> MysqlIntermediary<B, R, W> {
417418

418419
self.writer.flush()?;
419420
{
420-
let (_seq, auth_response_data) = self.reader.next()?.ok_or_else(|| {
421+
let (rseq, auth_response_data) = self.reader.next()?.ok_or_else(|| {
421422
io::Error::new(
422423
io::ErrorKind::ConnectionAborted,
423424
"peer terminated connection",
424425
)
425426
})?;
426427

428+
seq = rseq;
427429
auth_response = auth_response_data.to_vec();
428430
}
429431
}

0 commit comments

Comments
 (0)