mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
fix: reconnect on decrypt flag error
This commit is contained in:
parent
355fe4a410
commit
2d17133a7b
@ -311,6 +311,9 @@ func (c *QQClient) netLoop() {
|
||||
pkt.Payload, err = pkt.DecryptPayload(c.ecdh.InitialShareKey, c.RandomKey, c.sigInfo.wtSessionTicketKey)
|
||||
if err != nil {
|
||||
c.Error("decrypt payload error: %v", err)
|
||||
if errors.Is(err, packets.ErrUnknownFlag) {
|
||||
go c.quickReconnect()
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
type TCPListener struct {
|
||||
lock sync.RWMutex
|
||||
conn net.Conn
|
||||
connected bool
|
||||
plannedDisconnect func(*TCPListener)
|
||||
unexpectedDisconnect func(*TCPListener, error)
|
||||
}
|
||||
@ -42,6 +43,7 @@ func (t *TCPListener) Connect(addr *net.TCPAddr) error {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
t.conn = conn
|
||||
t.connected = true
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -103,16 +105,18 @@ func (t *TCPListener) close() {
|
||||
func (t *TCPListener) invokePlannedDisconnect() {
|
||||
t.lock.RLock()
|
||||
defer t.lock.RUnlock()
|
||||
if t.plannedDisconnect != nil {
|
||||
if t.plannedDisconnect != nil && t.connected {
|
||||
go t.plannedDisconnect(t)
|
||||
t.connected = false
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TCPListener) invokeUnexpectedDisconnect(err error) {
|
||||
t.lock.RLock()
|
||||
defer t.lock.RUnlock()
|
||||
if t.unexpectedDisconnect != nil {
|
||||
if t.unexpectedDisconnect != nil && t.connected {
|
||||
go t.unexpectedDisconnect(t, err)
|
||||
t.connected = false
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user