1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-08 01:24:57 +08:00

fix(tcp): del broken conn from peers

This commit is contained in:
源文雨
2024-07-17 01:14:15 +09:00
parent 4ffacafb23
commit 04a3c9a10b
3 changed files with 14 additions and 3 deletions

2
go.mod
View File

@@ -3,7 +3,7 @@ module github.com/fumiama/WireGold
go 1.20
require (
github.com/FloatTech/ttl v0.0.0-20240715074357-190755f3fece
github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
github.com/fumiama/blake2b-simd v0.0.0-20220412110131-4481822068bb
github.com/fumiama/go-base16384 v1.7.0

4
go.sum
View File

@@ -1,5 +1,5 @@
github.com/FloatTech/ttl v0.0.0-20240715074357-190755f3fece h1:RIrGO+hIOoXxUh0T3TDaWNvinkXH9S2i12cWivT2MZ4=
github.com/FloatTech/ttl v0.0.0-20240715074357-190755f3fece/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 h1:snfw7FNFym1eNnLrQ/VCf80LiQo9C7jHgrunZDwiRcY=
github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 h1:S/ferNiehVjNaBMNNBxUjLtVmP/YWD6Yh79RfPv4ehU=
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View File

@@ -136,6 +136,7 @@ func (conn *Conn) receive(tcpconn *net.TCPConn, hasvalidated bool) {
peerstimeout = time.Second * 30
}
peerstimeout *= 2
defer conn.peers.Delete(ep.String())
for {
r := &connrecv{addr: ep}
if conn.addr == nil || conn.lstn == nil || conn.peers == nil || conn.recv == nil {
@@ -234,7 +235,9 @@ func (conn *Conn) WriteToPeer(b []byte, ep p2p.EndPoint) (n int, err error) {
if blen >= 65536 {
return 0, errors.New("data size " + strconv.Itoa(blen) + " is too large")
}
retried := false
tcpconn := conn.peers.Get(tcpep.String())
RECONNECT:
if tcpconn == nil {
dialtimeout := tcpep.dialtimeout
if dialtimeout < time.Second {
@@ -269,5 +272,13 @@ func (conn *Conn) WriteToPeer(b []byte, ep p2p.EndPoint) (n int, err error) {
len: uint16(blen),
dat: b,
})
if err != nil {
conn.peers.Delete(tcpep.String())
if !retried {
retried = true
tcpconn = nil
goto RECONNECT
}
}
return int(cnt) - 3, err
}