only cache talk request

This commit is contained in:
thinkAfCod 2025-02-03 09:29:26 +08:00
parent 618559ee75
commit b1fa06e1a2

View file

@ -600,25 +600,30 @@ func (t *UDPv5) dispatch() {
t.sendNextCall(c.id) t.sendNextCall(c.id)
case r := <-t.sendCh: case r := <-t.sendCh:
// make send request by another thread also be cached to handle WHOAREYOU if _, ok := r.msg.(*v5wire.TalkResponse); ok {
c := &callV5{id: r.destID, addr: r.destAddr} // send a TalkResponse out
c.node = r.destNode t.send(r.destID, r.destAddr, r.msg, nil)
c.packet = r.msg } else {
c.reqid = make([]byte, 8) // send out a TalkRequest that is a UTP packet for portal network
c.ch = make(chan v5wire.Packet, 1) // request should be cached to handle WHOAREYOU
c.err = make(chan error, 1) c := &callV5{id: r.destID, addr: r.destAddr}
// Assign request ID. c.node = r.destNode
if tq, ok := r.msg.(*v5wire.TalkRequest); ok { c.packet = r.msg
if len(tq.ReqID) == 0 { c.reqid = make([]byte, 8)
crand.Read(c.reqid) c.ch = make(chan v5wire.Packet, 1)
c.packet.SetRequestID(c.reqid) c.err = make(chan error, 1)
// Assign request ID.
if tq, ok := r.msg.(*v5wire.TalkRequest); ok {
if len(tq.ReqID) == 0 {
crand.Read(c.reqid)
c.packet.SetRequestID(c.reqid)
}
} }
nonce, _ := t.send(c.id, c.addr, c.packet, nil)
c.nonce = nonce
t.activeCallByAuth[nonce] = c
t.startResponseTimeout(c)
} }
nonce, _ := t.send(c.id, c.addr, c.packet, nil)
c.nonce = nonce
t.activeCallByAuth[nonce] = c
t.startResponseTimeout(c)
case p := <-t.packetInCh: case p := <-t.packetInCh:
t.handlePacket(p.Data, p.Addr) t.handlePacket(p.Data, p.Addr)
// Arm next read. // Arm next read.