Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions muxer/segment.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
package muxer

import (
"math"
"time"
)

Expand Down Expand Up @@ -45,14 +46,21 @@ type Segment struct {
// NewSegment returns a new Segment given a protocol ID, payload bytes, and whether the segment
// is a response
func NewSegment(protocolId uint16, payload []byte, isResponse bool) *Segment {
// time since unix epoch even as nanoseconds will not overflow soon
// #nosec G115
header := SegmentHeader{
Timestamp: uint32(time.Now().UnixNano() & 0xffffffff),
ProtocolId: protocolId,
}
if isResponse {
header.ProtocolId = header.ProtocolId + segmentProtocolIdResponseFlag
}
header.PayloadLength = uint16(len(payload))
size := len(payload)
if size > SegmentMaxPayloadLength || size > math.MaxUint16 {
return nil
}
// payload size fits within length
header.PayloadLength = uint16(size)
segment := &Segment{
SegmentHeader: header,
Payload: payload,
Expand Down
Loading