mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-20 07:51:38 +02:00
refactor(agent/stream): update header size calculation and field types
- Adjusted headerSize calculation to reflect the correct size based on field definitions. - Changed HostLength and PortLength types from uint8 to byte. - Updated PROTOCOL.md to reflect the new header size and structure.
This commit is contained in:
@@ -12,9 +12,8 @@ The on-wire header is a fixed-size binary blob:
|
|||||||
- `PortLength` (1 byte)
|
- `PortLength` (1 byte)
|
||||||
- `Port` (5 bytes, NUL padded)
|
- `Port` (5 bytes, NUL padded)
|
||||||
- `Checksum` (4 bytes, big-endian CRC32)
|
- `Checksum` (4 bytes, big-endian CRC32)
|
||||||
- `Padding` (14 bytes)
|
|
||||||
|
|
||||||
Total: `headerSize = 8 + 1 + 255 + 1 + 5 + 4 + 14 = 288` bytes.
|
Total: `headerSize = 8 + 1 + 255 + 1 + 5 + 4 = 273` bytes.
|
||||||
|
|
||||||
Checksum is `crc32.ChecksumIEEE(header[0:headerSize-4])`.
|
Checksum is `crc32.ChecksumIEEE(header[0:headerSize-4])`.
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const (
|
|||||||
portSize = 5
|
portSize = 5
|
||||||
checksumSize = 4 // crc32 checksum
|
checksumSize = 4 // crc32 checksum
|
||||||
|
|
||||||
headerSize = 288
|
headerSize = versionSize + 1 + hostSize + 1 + portSize + checksumSize
|
||||||
)
|
)
|
||||||
|
|
||||||
var version = [versionSize]byte{'0', '.', '1', '.', '0', 0, 0, 0}
|
var version = [versionSize]byte{'0', '.', '1', '.', '0', 0, 0, 0}
|
||||||
@@ -25,15 +25,13 @@ var ErrInvalidHeader = errors.New("invalid header")
|
|||||||
type StreamRequestHeader struct {
|
type StreamRequestHeader struct {
|
||||||
Version [versionSize]byte
|
Version [versionSize]byte
|
||||||
|
|
||||||
HostLength uint8
|
HostLength byte
|
||||||
Host [hostSize]byte
|
Host [hostSize]byte
|
||||||
|
|
||||||
PortLength uint8
|
PortLength byte
|
||||||
Port [portSize]byte
|
Port [portSize]byte
|
||||||
|
|
||||||
Checksum [checksumSize]byte
|
Checksum [checksumSize]byte
|
||||||
|
|
||||||
_ [14]byte // padding to make the header size match the size of the struct
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -51,9 +49,9 @@ func NewStreamRequestHeader(host, port string) (*StreamRequestHeader, error) {
|
|||||||
}
|
}
|
||||||
header := &StreamRequestHeader{}
|
header := &StreamRequestHeader{}
|
||||||
copy(header.Version[:], version[:])
|
copy(header.Version[:], version[:])
|
||||||
header.HostLength = uint8(len(host))
|
header.HostLength = byte(len(host))
|
||||||
copy(header.Host[:], host)
|
copy(header.Host[:], host)
|
||||||
header.PortLength = uint8(len(port))
|
header.PortLength = byte(len(port))
|
||||||
copy(header.Port[:], port)
|
copy(header.Port[:], port)
|
||||||
header.updateChecksum()
|
header.updateChecksum()
|
||||||
return header, nil
|
return header, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user