github.com/yaling888/clash@v1.53.0/transport/header/utp/utp.go (about)

     1  package utp
     2  
     3  import (
     4  	"encoding/binary"
     5  	"math/rand/v2"
     6  )
     7  
     8  type UTP struct {
     9  	header       byte
    10  	extension    byte
    11  	connectionID uint16
    12  }
    13  
    14  func (*UTP) Size() int {
    15  	return 4
    16  }
    17  
    18  func (u *UTP) Fill(b []byte) {
    19  	binary.BigEndian.PutUint16(b, u.connectionID)
    20  	b[2] = u.header
    21  	b[3] = u.extension
    22  }
    23  
    24  func New() *UTP {
    25  	return &UTP{
    26  		header:       1,
    27  		extension:    0,
    28  		connectionID: uint16(rand.Uint64() >> 49),
    29  	}
    30  }