mirror of
https://github.com/sigcn/pg.git
synced 2026-04-22 21:17:04 +08:00
p2p: try lead disco before peer relay
This commit is contained in:
+4
-3
@@ -121,15 +121,16 @@ func (c *PacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if !errors.Is(err, udp.ErrUDPConnInactive) {
|
||||
c.TryLeadDisco(datagram.PeerID)
|
||||
}
|
||||
|
||||
if relay := c.relayPeer(datagram.PeerID); relay != "" {
|
||||
if n, err = c.udpConn.RelayTo(relay, p, datagram.PeerID); err == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if !errors.Is(err, udp.ErrUDPConnInactive) {
|
||||
c.TryLeadDisco(datagram.PeerID)
|
||||
}
|
||||
return len(p), c.wsConn.WriteTo(p, datagram.PeerID, disco.CONTROL_RELAY)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user