DeterministicESPAsyncWebServer
v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
relay_listener.h
Go to the documentation of this file.
1
// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2
// SPDX-License-Identifier: AGPL-3.0-or-later
3
4
/**
5
* @file relay_listener.h
6
* @brief Server-side TCP relay / DNAT listener (DETWS_ENABLE_RELAY) - publish an internal
7
* `host:port` on a server port.
8
*
9
* Wires the pure relay engine (relay.h) into the server: an inbound connection accepted on a
10
* published port is bridged to an origin (an outbound `det_client` connection to the internal
11
* service). A ConnProto::PROTO_RELAY connection handler opens the origin on accept, pumps bytes both ways each
12
* poll (via det_relay_step), and tears both down on close - the DNAT return path is automatic.
13
*
14
* Usage (opt-in twice: compiled out by default, and inert until you publish a port):
15
* @code
16
* int32_t li = server.listen(8080, ConnProto::PROTO_RELAY); // front port 8080
17
* det_relay_publish((uint8_t)li, "192.168.1.60", 80); // -> internal 192.168.1.60:80
18
* @endcode
19
*
20
* Security: this is an open forward to whatever origin you publish - only publish trusted internal
21
* targets, and do not expose the front port to an untrusted network without an upstream ACL.
22
*
23
* @author Douglas Quigg (dstroy0)
24
* @date 2026
25
*/
26
27
#ifndef DETERMINISTICESPASYNCWEBSERVER_RELAY_LISTENER_H
28
#define DETERMINISTICESPASYNCWEBSERVER_RELAY_LISTENER_H
29
30
#include "
ServerConfig.h
"
31
32
#if DETWS_ENABLE_RELAY
33
34
#include <stdint.h>
35
36
/**
37
* @brief Bind a published listener to an origin. Call after `server.listen(port, ConnProto::PROTO_RELAY)` with
38
* the returned listener id; installs the ConnProto::PROTO_RELAY handler on the first call.
39
* @param listener_id the id returned by `server.listen(...)`.
40
* @param origin_host the internal host to forward to (dotted-quad or a name; copied).
41
* @param origin_port the internal port.
42
* @return true; false if the origin host is null/too long or the bind table is full
43
* (DETWS_RELAY_MAX_PUBLISH).
44
*/
45
bool
det_relay_publish(uint8_t listener_id,
const
char
*origin_host, uint16_t origin_port);
46
47
/** @brief Clear all published binds and active bridges (start from empty). */
48
void
det_relay_listener_reset(
void
);
49
50
#endif
// DETWS_ENABLE_RELAY
51
52
#endif
// DETERMINISTICESPASYNCWEBSERVER_RELAY_LISTENER_H
ServerConfig.h
User-facing configuration for DeterministicESPAsyncWebServer.
src
services
relay
relay_listener.h
Generated by
1.9.8