pass around receivedPacket as struct instead of as pointer (#3823)

This commit is contained in:
Marten Seemann 2023-06-03 10:08:58 +03:00 committed by GitHub
parent 591ab1ab5e
commit 072a602cc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 96 additions and 94 deletions

View file

@ -79,16 +79,16 @@ type basicConn struct {
var _ rawConn = &basicConn{}
func (c *basicConn) ReadPacket() (*receivedPacket, error) {
func (c *basicConn) ReadPacket() (receivedPacket, error) {
buffer := getPacketBuffer()
// The packet size should not exceed protocol.MaxPacketBufferSize bytes
// If it does, we only read a truncated packet, which will then end up undecryptable
buffer.Data = buffer.Data[:protocol.MaxPacketBufferSize]
n, addr, err := c.PacketConn.ReadFrom(buffer.Data)
if err != nil {
return nil, err
return receivedPacket{}, err
}
return &receivedPacket{
return receivedPacket{
remoteAddr: addr,
rcvTime: time.Now(),
data: buffer.Data[:n],