Skip to content

Commit

Permalink
fix(tcp): set conn on peer's endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Jul 16, 2024
1 parent c7bbcb9 commit 39d8d5b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gold/p2p/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (ep *EndPoint) Listen() (p2p.Conn, error) {

type connrecv struct {
addr *EndPoint // cast from tcpconn.RemoteAddr()
conn *net.TCPConn
pckt packet
}

Expand Down Expand Up @@ -121,6 +122,7 @@ func (conn *Conn) receive(ep *EndPoint) {
if tcpconn == nil {
return
}
r.conn = tcpconn
_, err := io.Copy(&r.pckt, tcpconn)
if err != nil {
logrus.Debugln("[tcp] recv from", ep, "err:", err)
Expand Down Expand Up @@ -163,6 +165,7 @@ func (conn *Conn) ReadFromPeer(b []byte) (int, p2p.EndPoint, error) {
if p == nil {
return 0, nil, net.ErrClosed
}
conn.peers.Set(p.addr.String(), p.conn)
if p.pckt.typ == packetTypeNormal {
break
}
Expand Down

0 comments on commit 39d8d5b

Please sign in to comment.