mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
* also send session ticket when 0-RTT is disabled for go1.21 * allow session ticket without transport parameters * do not include transport parameters for non-0RTT session ticket * remove the test assertion because it is not supported for go1.20 * Update internal/handshake/session_ticket.go Co-authored-by: Marten Seemann <martenseemann@gmail.com> * add a 0-RTT argument to unmarshaling session tickets * bump sessionTicketRevision to 4 * check if non-0-RTT session ticket has expected length * change parameter order * add test checks --------- Co-authored-by: Marten Seemann <martenseemann@gmail.com>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package handshake
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/quic-go/quic-go/internal/wire"
|
|
"github.com/quic-go/quic-go/quicvarint"
|
|
)
|
|
|
|
const sessionTicketRevision = 4
|
|
|
|
type sessionTicket struct {
|
|
Parameters *wire.TransportParameters
|
|
RTT time.Duration // to be encoded in mus
|
|
}
|
|
|
|
func (t *sessionTicket) Marshal() []byte {
|
|
b := make([]byte, 0, 256)
|
|
b = quicvarint.Append(b, sessionTicketRevision)
|
|
b = quicvarint.Append(b, uint64(t.RTT.Microseconds()))
|
|
if t.Parameters == nil {
|
|
return b
|
|
}
|
|
return t.Parameters.MarshalForSessionTicket(b)
|
|
}
|
|
|
|
func (t *sessionTicket) Unmarshal(b []byte, using0RTT bool) error {
|
|
r := bytes.NewReader(b)
|
|
rev, err := quicvarint.Read(r)
|
|
if err != nil {
|
|
return errors.New("failed to read session ticket revision")
|
|
}
|
|
if rev != sessionTicketRevision {
|
|
return fmt.Errorf("unknown session ticket revision: %d", rev)
|
|
}
|
|
rtt, err := quicvarint.Read(r)
|
|
if err != nil {
|
|
return errors.New("failed to read RTT")
|
|
}
|
|
if using0RTT {
|
|
var tp wire.TransportParameters
|
|
if err := tp.UnmarshalFromSessionTicket(r); err != nil {
|
|
return fmt.Errorf("unmarshaling transport parameters from session ticket failed: %s", err.Error())
|
|
}
|
|
t.Parameters = &tp
|
|
} else if r.Len() > 0 {
|
|
return fmt.Errorf("the session ticket has more bytes than expected")
|
|
}
|
|
t.RTT = time.Duration(rtt) * time.Microsecond
|
|
return nil
|
|
}
|