# SPDX-License-Identifier: MIT
# Copyright (c) 2025 aetherd Contributors

if ZEPHYR_AETHERD_MODULE

menuconfig AETHERD
	bool "aetherd - 9P-based BBS server"
	depends on NINEP
	depends on NINEP_SERVER
	help
	  Enable aetherd, a filesystem-oriented bulletin board system served
	  over the 9P protocol. Inspired by Plan 9's 9bbs and Citadel BBS.

if AETHERD

config AETHERD_MAX_ROOMS
	int "Maximum number of BBS rooms"
	default 16
	help
	  Maximum number of BBS rooms (message boards).

config AETHERD_MAX_USERS
	int "Maximum number of registered users"
	default 32
	help
	  Maximum number of user accounts.

config AETHERD_MAX_MESSAGES_PER_ROOM
	int "Maximum messages per room"
	default 100
	help
	  Maximum number of messages stored per room.

config AETHERD_MAX_MESSAGE_SIZE
	int "Maximum message size in bytes"
	default 4096
	help
	  Maximum size of a single message body.

config AETHERD_MAX_USERNAME_LEN
	int "Maximum username length"
	default 32

config AETHERD_MAX_PASSWORD_LEN
	int "Maximum password length"
	default 64

config AETHERD_MAX_ROOMNAME_LEN
	int "Maximum room name length"
	default 32

config AETHERD_MAX_BANS
	int "Maximum number of ban entries"
	default 64
	help
	  Maximum number of CGA-based ban entries. Reduce for constrained
	  devices (each entry is ~400 bytes).

config AETHERD_MAX_GROUP_MEMBERS
	int "Maximum group memberships"
	default 32
	help
	  Maximum total (group, CGA) memberships across all groups in the
	  Unix/Plan 9-style group store. Each entry is ~160 bytes. Reduce for
	  constrained devices; raise on hubs with many contributors.

config AETHERD_MAX_SESSIONS
	int "Maximum concurrent authenticated sessions"
	default 4
	help
	  Maximum number of concurrent authenticated sessions. Each session
	  tracks username, CGA, and rate-limit state (~270 bytes each).

config AETHERD_POST_RATE_LIMIT_SEC
	int "Rate limit for posts in seconds"
	default 30
	help
	  Minimum number of seconds between posts from the same user.
	  Set to 0 to disable rate limiting. Admins are exempt from rate limits.

menuconfig AETHERD_CHAT
	bool "Enable aetherd chat subsystem"
	default y
	help
	  Enable real-time chat functionality with blocking reads,
	  ring buffers, and multi-user support.

if AETHERD_CHAT

config AETHERD_CHAT_MAX_ROOMS
	int "Maximum number of chat rooms"
	default 4
	help
	  Maximum number of concurrent chat rooms.

config AETHERD_CHAT_MAX_MESSAGES
	int "Maximum messages per room (ring buffer size)"
	default 50
	help
	  Number of messages to keep in ring buffer per room.

config AETHERD_CHAT_MAX_MESSAGE_LEN
	int "Maximum message length"
	default 256
	help
	  Maximum length of a single chat message.

config AETHERD_CHAT_MAX_USERS
	int "Maximum concurrent chat users"
	default 8
	help
	  Maximum number of users that can be tracked for chat.

config AETHERD_CHAT_READ_TIMEOUT_SEC
	int "Chat read timeout in seconds (sysop shell only)"
	default 30
	help
	  Timeout for the internal blocking chat reader used by the sysop
	  shell (bbs chat monitor / bbs chat read). 9P chat reads do not use
	  this: they park indefinitely via the server's deferred-read
	  mechanism and are answered by the next post, a Tflush, or clunk.

config AETHERD_CHAT_MAX_STREAMS
	int "Maximum concurrently open chat-room fids"
	default 16
	help
	  Each 9P client holding a chat room file open consumes one stream
	  slot (per-fid read cursor plus parked-read state, ~64 bytes).
	  Reads beyond this limit fail with "no space left on device".

endif # AETHERD_CHAT

menuconfig AETHERD_GFX
	bool "Enable aetherd gfx (served draw device)"
	default n
	help
	  Serve graphical BBS sessions under /gfx (docs/GFX_DEVICE_SPEC.md).
	  The server composes scenes into a per-session raster and streams
	  draw(3)-format messages to clients through ordinary 9P reads.
	  Each session allocates width*height bytes from the heap, so keep
	  the defaults small on constrained targets.

if AETHERD_GFX

config AETHERD_GFX_MAX_SESSIONS
	int "Maximum concurrent gfx sessions"
	default 4

config AETHERD_GFX_DEFAULT_WIDTH
	int "Default session width (pixels)"
	default 320

config AETHERD_GFX_DEFAULT_HEIGHT
	int "Default session height (pixels)"
	default 240

config AETHERD_GFX_MAX_WIDTH
	int "Maximum negotiable width"
	default 800

config AETHERD_GFX_MAX_HEIGHT
	int "Maximum negotiable height"
	default 800

config AETHERD_GFX_BROADCAST
	bool "Broadcast / theater (sysop screen share)"
	default y
	help
	  /gfx/broadcast: a sysop streams 'F' frames (m8 or k1 packing) up
	  and aetherd rebroadcasts them into every tuned-in session's
	  raster (GFX_DEVICE_SPEC.md section 10). Costs one extra w*h m8
	  source buffer while a broadcast is live.

config AETHERD_GFX_TV
	bool "TV channels (video feeds, unix decoder slaves)"
	default n
	depends on AETHERD_GFX
	help
	  /tv: tune sessions into video feeds. A channel is a gopher or
	  http m3u playlist (e.g. bitreich bitflix), or a fediverse
	  account whose media posts are looped as clips
	  (mastodon://host/user). Channel decode runs in per-channel
	  subprocesses via ffmpeg and curl, so this is unix-port only;
	  Zephyr builds leave it off (any client can still watch a unix
	  server's channels — decode is server-side).

config AETHERD_GFX_BROADCAST_GRACE_SEC
	int "Broadcast reconnect grace (seconds)"
	depends on AETHERD_GFX_BROADCAST
	default 30
	help
	  When the sender fid drops without an explicit 'end', keep the
	  broadcast resumable (viewers hold the last frame) this long.

endif # AETHERD_GFX

config AETHERD_GOPHER
	bool "Enable gopher presentation layer"
	default n
	help
	  Portable gopher (RFC 1436 + FRST dialect) rendering of the BBS
	  namespace per docs/GOPHER_FINGER_SPEC.md. This builds the
	  protocol core only; a transport (listener) must be provided by
	  the application or platform layer.

config AETHERD_FINGER
	bool "Enable finger presentation layer"
	default n
	help
	  Portable finger (RFC 1288 subset) rendering of presence,
	  user profiles/plans, and room status per
	  docs/GOPHER_FINGER_SPEC.md. Protocol core only; the listener
	  is provided by the application or platform layer.

config AETHERD_GOPHER_NET
	bool "Zephyr TCP listener for gopher"
	default n
	depends on AETHERD_GOPHER && NET_SOCKETS && NET_TCP && NET_IPV4
	help
	  On-device TCP listener thread for the gopher presentation layer
	  (aetherd_gopher_net.c). Start it with aetherd_gopher_net_start()
	  once the network interface has an address. The unix daemon has
	  its own listener (unix/src/gopher_server.c) and does not use this.

config AETHERD_GOPHER_NET_STACK_SIZE
	int "gopher listener thread stack size"
	default 4096
	depends on AETHERD_GOPHER_NET
	help
	  Stack for the gopher accept/handle thread. The menu renderer uses
	  a few hundred bytes of stack buffers per call; bump this if you
	  see a stack overflow on deep selectors.

config AETHERD_FINGER_NET
	bool "Zephyr TCP listener for finger"
	default n
	depends on AETHERD_FINGER && NET_SOCKETS && NET_TCP && NET_IPV4
	help
	  On-device TCP listener thread for the finger presentation layer
	  (aetherd_gopher_net.c). Start it with aetherd_finger_net_start()
	  once the network interface has an address.

config AETHERD_FINGER_NET_STACK_SIZE
	int "finger listener thread stack size"
	default 3072
	depends on AETHERD_FINGER_NET
	help
	  Stack for the finger accept/handle thread.

menuconfig AETHERD_GAMES
	bool "Enable aetherd games subsystem"
	default y
	help
	  Enable turn-based multiplayer games with generic lobby infrastructure.
	  Supports tic-tac-toe, checkers, chess, and other board games.

if AETHERD_GAMES

config AETHERD_GAMES_MAX_ACTIVE
	int "Maximum concurrent active games"
	default 16
	help
	  Maximum number of games that can be active simultaneously.

config AETHERD_GAMES_EVENT_BUF_SIZE
	int "Event buffer size per game"
	default 2048
	help
	  Size of the event stream ring buffer for each game (for watch file).

endif # AETHERD_GAMES

menuconfig AETHERD_FTN
	bool "Enable FTN (FidoNet Technology Network) subsystem"
	default n
	help
	  Enable FidoNet-style message network support. This allows aetherd
	  to participate in FidoNet-compatible networks like FSXNET.

	  The FTN subsystem exposes a filesystem interface (/ftn/) that
	  transports (BINKP, sneakernet, etc.) can read and write packets to.

if AETHERD_FTN

config AETHERD_FTN_MAX_AREAS
	int "Maximum echo areas"
	default 32
	help
	  Maximum number of FTN echo areas (message conferences) that can
	  be subscribed to.

config AETHERD_FTN_MAX_PACKET_SIZE
	int "Maximum packet size in bytes"
	default 65536
	help
	  Maximum size of a Type-2+ packet. Packets larger than this will
	  be rejected.

config AETHERD_FTN_SEEN_DAYS
	int "Days to keep SEEN-BY entries"
	default 30
	help
	  Number of days to keep SEEN-BY dupe detection entries before
	  pruning. Older entries are removed to save memory.

config AETHERD_FTN_ADDRESS_LEN
	int "Maximum FTN address length"
	default 32
	help
	  Maximum length of an FTN address string (e.g., "21:1/100.0").

config AETHERD_FTN_PACKET_TTL_HOURS
	int "Outbound packet TTL in hours"
	default 24
	help
	  Time-to-live for packets in outbound/broadcast directory.
	  Packets older than this are pruned to prevent unbounded growth.

	  For high-traffic areas with frequent couriers: 6-12 hours
	  For low-traffic areas with sparse couriers: 48-72 hours
	  For hub nodes: 12-24 hours (balance between availability and freshness)

	  Set to 0 to disable time-based pruning (use count-based only).

config AETHERD_FTN_MAX_BROADCAST_PACKETS
	int "Maximum packets in broadcast directory"
	default 100
	help
	  Safety limit for packets in outbound/broadcast. When exceeded,
	  oldest packets are pruned regardless of TTL.

	  For memory-constrained devices: 25-50
	  For normal nodes: 100
	  For hub nodes with more storage: 200-500

config AETHERD_FTN_BINKP
	bool "Enable BINKP transport for FTN"
	default y if NET_SOCKETS
	depends on NET_SOCKETS || !ZEPHYR_AETHERD_MODULE
	help
	  Enable BINKP protocol support for FTN packet exchange over TCP/IP.
	  This allows aetherd to poll remote FTN nodes for mail exchange.

	  On Zephyr, this requires CONFIG_NETWORKING and CONFIG_NET_SOCKETS.
	  On Unix, this is always available.

if AETHERD_FTN_BINKP

config AETHERD_FTN_BINKP_PORT
	int "Default BINKP port"
	default 24554
	help
	  Default port for BINKP connections. Standard FidoNet BINKP uses 24554.

endif # AETHERD_FTN_BINKP

config AETHERD_FTN_SCHEDULER
	bool "Automatic FTN scan/poll/toss scheduler"
	default n
	help
	  Run a background thread that periodically exports new BBS messages
	  to outbound packets, polls configured BINKP routes, and tosses
	  inbound packets (interval set via poll_interval in the FTN config
	  or /ftn/ctl). Also auto-starts the BINKP server when a binkp_listen
	  port is configured.

	  Costs one thread (plus one for the BINKP server). With BINKP
	  enabled the threads need ~40KB stacks each (a 32KB BINKP session
	  receive buffer lives on the stack) - leave disabled on
	  memory-constrained devices and drive /ftn/ctl manually or via
	  courier instead.

endif # AETHERD_FTN

menuconfig AETHERD_NET
	bool "Enable Plan 9-style /net/tcp filesystem"
	depends on NET_SOCKETS
	depends on NET_TCP
	help
	  Expose the host TCP stack as a Plan 9 /net/tcp filesystem.
	  Allows 9P clients to make outbound TCP connections through
	  this device, enabling BLE-to-WiFi gateway functionality.

if AETHERD_NET

config AETHERD_NET_MAX_CONNECTIONS
	int "Maximum concurrent /net/tcp connections"
	default 8
	help
	  Maximum number of concurrent TCP connections managed by the
	  /net/tcp filesystem. Each connection uses a socket fd and
	  pre-allocated node structures. Reduce for memory-constrained devices.

endif # AETHERD_NET

endif # AETHERD

endif # ZEPHYR_AETHERD_MODULE
