Skip to content

Widen speed limit types from uint16 to uint32#436

Open
got3nks wants to merge 2 commits intoamule-project:masterfrom
got3nks:pr/widen-speed-limits
Open

Widen speed limit types from uint16 to uint32#436
got3nks wants to merge 2 commits intoamule-project:masterfrom
got3nks:pr/widen-speed-limits

Conversation

@got3nks
Copy link
Copy Markdown
Contributor

@got3nks got3nks commented Apr 4, 2026

Summary

The upload/download speed limits (s_maxupload, s_maxdownload) and slot allocation (s_slotallocation) are stored as uint16, capping the configurable speed to 65534 kB/s (~524 Mbps) since 65535 is treated as unlimited. This is inadequate for modern gigabit+ connections.

  • Change s_maxupload, s_maxdownload, s_slotallocation from uint16 to uint32 in Preferences.h / Preferences.cpp, along with their getters and setters
  • Change GetMaxSlots() return type and local variables from uint16 to uint32 to prevent truncation when calculating slot counts from large speed values
  • Update SetPreferencesConnections() parameter types in RemoteConnect.h

Backward compatibility

  • The existing backwards compatibility check in CheckUlDlRatio() that maps 0xFFFF to UNLIMITED still works correctly with uint32
  • MkCfg_Int is templated and handles uint32 without changes
  • MAX_UP_CLIENTS_ALLOWED remains at 250 (unchanged)

EC protocol note

EC tags EC_TAG_CONN_MAX_UL, EC_TAG_CONN_MAX_DL, and EC_TAG_CONN_SLOT_ALLOCATION now carry uint32 values. The Apply() method uses oneTag->GetInt() which handles any integer size. EC clients sending these tags should encode them as 32-bit integers.

Files changed

File Changes
src/Preferences.h Type widening for declarations, getters, setters
src/Preferences.cpp Static definitions + setter implementations
src/UploadQueue.h GetMaxSlots() return type
src/UploadQueue.cpp GetMaxSlots() implementation + local vars
src/libs/ec/cpp/RemoteConnect.h EC client method parameter types

The upload/download speed limits (s_maxupload, s_maxdownload) and slot
allocation (s_slotallocation) were stored as uint16, capping configurable
speed to 65534 kB/s (~524 Mbps) since 65535 is treated as unlimited.
This is inadequate for modern gigabit+ connections.

Changes:

Preferences.h / Preferences.cpp:
- Change s_maxupload, s_maxdownload, s_slotallocation from uint16 to
  uint32, along with their getters and setters
- The existing backwards compatibility check in CheckUlDlRatio() that
  maps 0xFFFF to UNLIMITED still works correctly with uint32

UploadQueue.h / UploadQueue.cpp:
- Change GetMaxSlots() return type and local variables from uint16 to
  uint32 to prevent truncation when calculating slot counts from large
  speed values

RemoteConnect.h:
- Update SetPreferencesConnections() parameter types for
  MaxDownloadSpeed, MaxUploadSpeed, and UploadSlotAllocation from
  uint16 to uint32

EC protocol note:
- EC tags EC_TAG_CONN_MAX_UL, EC_TAG_CONN_MAX_DL, and
  EC_TAG_CONN_SLOT_ALLOCATION now carry uint32 values. EC clients
  reading these tags should use GetInt() which handles any integer
  size. Clients sending these tags should encode them as 32-bit.
@frnjjq
Copy link
Copy Markdown

frnjjq commented Apr 8, 2026

There is a documentation for the EC protocol. Maybe is great to add this change to the doc in order to keep it current.

Add Section 4 with a tag type reference for EC_TAG_PREFS_CONNECTIONS
subtags, noting that EC_TAG_CONN_MAX_DL, EC_TAG_CONN_MAX_UL, and
EC_TAG_CONN_SLOT_ALLOCATION were widened from uint16 to uint32.

Requested by reviewer on PR#436.
@got3nks
Copy link
Copy Markdown
Contributor Author

got3nks commented Apr 8, 2026

Good call, thank you! Added a new Section 4: Notable Tag Types to docs/EC_Protocol.txt that documents the data types of all EC_TAG_PREFS_CONNECTIONS subtags and calls out the uint16 → uint32 widening for EC_TAG_CONN_MAX_DL, EC_TAG_CONN_MAX_UL, and EC_TAG_CONN_SLOT_ALLOCATION.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants