cache the serialized OOB in the conn, not in the packet info

We're allocating a lot of packetInfo structs during the lifetime of a
connection. It's better to keep that struct as small as possible.
This commit is contained in:
Marten Seemann 2021-03-16 13:54:19 +08:00
parent 1186a3ed79
commit 162cb16b31
8 changed files with 23 additions and 19 deletions

View file

@ -556,7 +556,7 @@ func (s *baseServer) sendRetry(remoteAddr net.Addr, hdr *wire.Header, info *pack
if s.config.Tracer != nil {
s.config.Tracer.SentPacket(remoteAddr, &replyHdr.Header, protocol.ByteCount(buf.Len()), nil)
}
_, err = s.conn.WritePacket(buf.Bytes(), remoteAddr, info)
_, err = s.conn.WritePacket(buf.Bytes(), remoteAddr, info.OOB())
return err
}
@ -633,7 +633,7 @@ func (s *baseServer) sendError(remoteAddr net.Addr, hdr *wire.Header, sealer han
if s.config.Tracer != nil {
s.config.Tracer.SentPacket(remoteAddr, &replyHdr.Header, protocol.ByteCount(len(raw)), []logging.Frame{ccf})
}
_, err := s.conn.WritePacket(raw, remoteAddr, info)
_, err := s.conn.WritePacket(raw, remoteAddr, info.OOB())
return err
}
@ -656,7 +656,7 @@ func (s *baseServer) sendVersionNegotiationPacket(p *receivedPacket, hdr *wire.H
nil,
)
}
if _, err := s.conn.WritePacket(data, p.remoteAddr, p.info); err != nil {
if _, err := s.conn.WritePacket(data, p.remoteAddr, p.info.OOB()); err != nil {
s.logger.Debugf("Error sending Version Negotiation: %s", err)
}
}