add hub limits to constants and include in WELCOME message construction

This commit is contained in:
kc1awv
2026-01-15 15:59:31 -05:00
parent 02edfd7e38
commit 47ae1930a7
2 changed files with 31 additions and 1 deletions
+8
View File
@@ -45,6 +45,14 @@ B_HELLO_NICK_LEGACY = 64
B_WELCOME_HUB = 0
B_WELCOME_VER = 1
B_WELCOME_CAPS = 2
B_WELCOME_LIMITS = 3
# Hub Limits map keys (within B_WELCOME_LIMITS)
B_LIMIT_MAX_NICK_BYTES = 0
B_LIMIT_MAX_ROOM_NAME_BYTES = 1
B_LIMIT_MAX_MSG_BODY_BYTES = 2
B_LIMIT_MAX_ROOMS_PER_SESSION = 3
B_LIMIT_RATE_LIMIT_MSGS_PER_MINUTE = 4
# Capabilities map keys (values are advisory). Keep these small and numeric.
CAP_RESOURCE_ENVELOPE = 0
+23 -1
View File
@@ -7,7 +7,19 @@ from typing import TYPE_CHECKING, Any
import RNS
from .codec import encode
from .constants import B_WELCOME_HUB, B_WELCOME_VER, T_ERROR, T_NOTICE, T_WELCOME
from .constants import (
B_LIMIT_MAX_MSG_BODY_BYTES,
B_LIMIT_MAX_NICK_BYTES,
B_LIMIT_MAX_ROOM_NAME_BYTES,
B_LIMIT_MAX_ROOMS_PER_SESSION,
B_LIMIT_RATE_LIMIT_MSGS_PER_MINUTE,
B_WELCOME_HUB,
B_WELCOME_LIMITS,
B_WELCOME_VER,
T_ERROR,
T_NOTICE,
T_WELCOME,
)
from .envelope import make_envelope
if TYPE_CHECKING:
@@ -118,9 +130,19 @@ class MessageHelper:
from . import __version__
# Build hub limits map with integer keys per spec
limits: dict[int, int] = {
B_LIMIT_MAX_NICK_BYTES: self.hub.config.max_nick_bytes,
B_LIMIT_MAX_ROOM_NAME_BYTES: self.hub.config.max_room_name_bytes,
B_LIMIT_MAX_MSG_BODY_BYTES: self.hub.config.max_msg_body_bytes,
B_LIMIT_MAX_ROOMS_PER_SESSION: self.hub.config.max_rooms_per_session,
B_LIMIT_RATE_LIMIT_MSGS_PER_MINUTE: self.hub.config.rate_limit_msgs_per_minute,
}
body_w: dict[int, Any] = {
B_WELCOME_HUB: self.hub.config.hub_name,
B_WELCOME_VER: str(__version__),
B_WELCOME_LIMITS: limits,
}
welcome = make_envelope(T_WELCOME, src=self.hub.identity.hash, body=body_w)