mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 19:17:38 +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)
|
pkt.Payload, err = pkt.DecryptPayload(c.ecdh.InitialShareKey, c.RandomKey, c.sigInfo.wtSessionTicketKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Error("decrypt payload error: %v", err)
|
c.Error("decrypt payload error: %v", err)
|
||||||
|
if errors.Is(err, packets.ErrUnknownFlag) {
|
||||||
|
go c.quickReconnect()
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
type TCPListener struct {
|
type TCPListener struct {
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
|
connected bool
|
||||||
plannedDisconnect func(*TCPListener)
|
plannedDisconnect func(*TCPListener)
|
||||||
unexpectedDisconnect func(*TCPListener, error)
|
unexpectedDisconnect func(*TCPListener, error)
|
||||||
}
|
}
|
||||||
@ -42,6 +43,7 @@ func (t *TCPListener) Connect(addr *net.TCPAddr) error {
|
|||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
t.conn = conn
|
t.conn = conn
|
||||||
|
t.connected = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,16 +105,18 @@ func (t *TCPListener) close() {
|
|||||||
func (t *TCPListener) invokePlannedDisconnect() {
|
func (t *TCPListener) invokePlannedDisconnect() {
|
||||||
t.lock.RLock()
|
t.lock.RLock()
|
||||||
defer t.lock.RUnlock()
|
defer t.lock.RUnlock()
|
||||||
if t.plannedDisconnect != nil {
|
if t.plannedDisconnect != nil && t.connected {
|
||||||
go t.plannedDisconnect(t)
|
go t.plannedDisconnect(t)
|
||||||
|
t.connected = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TCPListener) invokeUnexpectedDisconnect(err error) {
|
func (t *TCPListener) invokeUnexpectedDisconnect(err error) {
|
||||||
t.lock.RLock()
|
t.lock.RLock()
|
||||||
defer t.lock.RUnlock()
|
defer t.lock.RUnlock()
|
||||||
if t.unexpectedDisconnect != nil {
|
if t.unexpectedDisconnect != nil && t.connected {
|
||||||
go t.unexpectedDisconnect(t, err)
|
go t.unexpectedDisconnect(t, err)
|
||||||
|
t.connected = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user