douzhai1182 2016-08-20 14:08
浏览 108

代理数据包时如何使请求与响应匹配?

I'm working on MySQL proxy with browser based GUI. Core of an app looks like:

//Trying to connect to server
rightConn, err := net.Dial("tcp", l.rightAddr)
if err != nil {
    return
}
defer rightConn.Close()

wg.Add(2)
//Start passing packets from client to server
go func() {
    defer wg.Done()
    l.Pipe(leftConn, rightConn)
}()

//Start passing packets from server to client
go func() {
    defer wg.Done()
    l.Pipe(rightConn, leftConn)
}()
wg.Wait()

And here's definition of Pipe:

func (l *Lottip) Pipe(right, left net.Conn) {
for {
    pkt, err := mysql.ReadPacket(right)
    if err != nil {
        break
    }

    if _, err = mysql.WritePacket(pkt, left); err != nil {
        break
    }
}

}

The reason i'm using my custom proxy function instead of

go io.Copy(left, right)
go io.Copy(right, left)

is i have to parse each MySQL's Request/Response packet and prepare it for further processing.

As we all know MySQL client can send a lot of queries and get responses in random order.

The problem is i cannot get how to match request to it's response. While i'm piping using 2 goroutines(1 per direction) i can easily read server response but i don't know to what request it responding.

I've examined request/response between MySQL client and server via Wireshark and found no mention for packet_id or query_id or similar

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题