Skip to content

Commit f015eba

Browse files
committed
Merge TASK-029: naming consistency — stop_and_wait, block_ip/unblock_ip
2 parents cf31239 + 87c871a commit f015eba

10 files changed

Lines changed: 259 additions & 324 deletions

File tree

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ Once a webserver is created, you can manage its execution through the following
544544
* _**void** webserver::start(**bool** blocking):_ Allows to start a server. If the `blocking` flag is passed as `true`, it will block the execution of the current thread until a call to stop on the same webserver object is performed.
545545
* _**void** webserver::stop():_ Allows to stop a server. It immediately stops it.
546546
* _**bool** webserver::is_running():_ Checks if a server is running
547-
* _**void** webserver::sweet_kill():_ Allows to stop a server. It doesn't guarantee an immediate halt to allow for thread termination and connection closure.
547+
* _**void** webserver::stop_and_wait():_ Stop the webserver and wait for in-flight handlers to complete before returning. Use `stop()` when no such guarantee is required.
548548
* _**int** webserver::quiesce():_ Quiesce the daemon: stop accepting new connections while letting in-flight requests complete. Returns the listen socket file descriptor (the caller can close it), or `-1` on error.
549549
* _**bool** webserver::run():_ Run the webserver's event loop once (non-blocking). For use with external event loops when the server is started without internal threading. Returns `true` on success.
550550
* _**bool** webserver::run_wait(**int32_t** millisec):_ Run the webserver's event loop, blocking until there is activity or the timeout expires. Pass `-1` for indefinite wait. Returns `true` on success.
@@ -946,10 +946,8 @@ libhttpserver provides natively a system to blacklist and whitelist IP addresses
946946
The system supports both IPV4 and IPV6 and manages them transparently. The only requirement is for ipv6 to be enabled on your server - you'll have to enable this by using the `use_ipv6` method on `create_webserver`.
947947
948948
You can explicitly ban or allow an IP address using the following methods on the `webserver` class:
949-
* _**void** ban_ip(**const std::string&** ip):_ Adds one IP (or a range of IPs) to the list of the banned ones. Takes in input a `string` that contains the IP (or range of IPs) to ban. To use when the `default_policy` is `ACCEPT`.
950-
* _**void** allow_ip(**const std::string&** ip):_ Adds one IP (or a range of IPs) to the list of the allowed ones. Takes in input a `string` that contains the IP (or range of IPs) to allow. To use when the `default_policy` is `REJECT`.
951-
* _**void** unban_ip(**const std::string&** ip):_ Removes one IP (or a range of IPs) from the list of the banned ones. Takes in input a `string` that contains the IP (or range of IPs) to remove from the list. To use when the `default_policy` is `ACCEPT`.
952-
* _**void** disallow_ip(**const std::string&** ip):_ Removes one IP (or a range of IPs) from the list of the allowed ones. Takes in input a `string` that contains the IP (or range of IPs) to remove from the list. To use when the `default_policy` is `REJECT`.
949+
* _**void** block_ip(**std::string_view** ip):_ Add one IP (or a range, e.g. `"127.0.0.*"`) to the block list. Connections from a matching address are refused at the policy callback. Intended for use under the default `ACCEPT` policy.
950+
* _**void** unblock_ip(**std::string_view** ip):_ Remove one IP (or a range) from the block list. Idempotent: removing an entry that is not currently blocked is a no-op.
953951
954952
### IP String Format
955953
The IP string format can represent both IPV4 and IPV6. Addresses will be normalized by the webserver to operate in the same sapce. Any valid IPV4 or IPV6 textual representation works.
@@ -977,10 +975,11 @@ Examples of valid IPs include:
977975
};
978976
979977
int main(int argc, char** argv) {
980-
webserver ws = create_webserver(8080)
981-
.default_policy(http::http_utils::REJECT);
978+
webserver ws = create_webserver(8080);
982979
983-
ws.allow_ip("127.0.0.1");
980+
// Refuse connections from this address; everything else is accepted
981+
// by default. Use a range like "127.0.0.*" to block a wildcard.
982+
ws.block_ip("10.0.0.1");
984983
985984
hello_world_resource hwr;
986985
ws.register_resource("/hello", &hwr);
@@ -1728,7 +1727,7 @@ You can also check this example on [github](https://github.com/etr/libhttpserver
17281727
std::cout << "HTTP 404 reason: "
17291728
<< http::http_utils::reason_phrase(404) << std::endl;
17301729

1731-
ws.sweet_kill();
1730+
ws.stop_and_wait();
17321731
return 0;
17331732
}
17341733
```

examples/daemon_info.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int main() {
5353
<< ". Press Ctrl+C to stop." << std::endl;
5454

5555
// Block until interrupted
56-
ws.sweet_kill();
56+
ws.stop_and_wait();
5757

5858
return 0;
5959
}

examples/minimal_ip_ban.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ class hello_world_resource : public httpserver::http_resource {
2929
}
3030
};
3131

32+
// TASK-029: The v2.0 public IP-control API is the pair block_ip / unblock_ip,
33+
// usable under the default ACCEPT policy. The historical allow_ip /
34+
// disallow_ip pair (under REJECT) was dropped from the public surface.
3235
int main() {
33-
httpserver::webserver ws = httpserver::create_webserver(8080).default_policy(httpserver::http::http_utils::REJECT);
36+
httpserver::webserver ws = httpserver::create_webserver(8080);
3437

35-
ws.allow_ip("127.0.0.1");
38+
ws.block_ip("10.0.0.1");
3639

3740
auto hwr = std::make_shared<hello_world_resource>();
3841
ws.register_path("/hello", hwr);

specs/tasks/M5-routing-lifecycle/TASK-029.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
Collapse synonyms to a single canonical verb per concept, per PRD §3.7.
99

1010
**Action Items:**
11-
- [ ] Rename `webserver::sweet_kill``webserver::stop_and_wait`. Remove the old name.
12-
- [ ] Add `webserver::block_ip(std::string_view ip)` and `webserver::unblock_ip(std::string_view ip)`.
13-
- [ ] Remove `ban_ip`, `unban_ip`, `allow_ip`, `disallow_ip` from the public API. The internal ban list remains; it's just exposed under one name pair.
14-
- [ ] Verify no `// NOLINT(runtime/explicit)` survives on related constructors (covered in TASK-030).
15-
- [ ] Verify `shoutCAST` is preserved as-is (only camelCase exception, per PRD §3.7).
11+
- [x] Rename `webserver::sweet_kill``webserver::stop_and_wait`. Remove the old name.
12+
- [x] Add `webserver::block_ip(std::string_view ip)` and `webserver::unblock_ip(std::string_view ip)`.
13+
- [x] Remove `ban_ip`, `unban_ip`, `allow_ip`, `disallow_ip` from the public API. The internal ban list remains; it's just exposed under one name pair.
14+
- [x] Verify no `// NOLINT(runtime/explicit)` survives on related constructors (covered in TASK-030).
15+
- [x] Verify `shoutCAST` is preserved as-is (only camelCase exception, per PRD §3.7).
1616

1717
**Dependencies:**
1818
- Blocked by: TASK-014
@@ -29,4 +29,4 @@ Collapse synonyms to a single canonical verb per concept, per PRD §3.7.
2929
**Related Requirements:** PRD-NAM-REQ-001, PRD-NAM-REQ-002, PRD-NAM-REQ-005
3030
**Related Decisions:** §3.7, OQ-004, OQ-005
3131

32-
**Status:** Not Started
32+
**Status:** Done

specs/tasks/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Nominally: **13 sequential tasks**, each S–XL. Most other tasks parallelize of
111111
| TASK-026 | Generic `webserver::route(method, path, handler)` | M4 | Done | TASK-005, TASK-025 |
112112
| TASK-027 | 3-tier route table with LRU cache | M5 | Done | TASK-005, TASK-014, TASK-021, TASK-024, TASK-025, TASK-026 |
113113
| TASK-028 | Routing-semantics regression gate | M5 | Done | TASK-027 |
114-
| TASK-029 | Naming consistency — `stop_and_wait`, `block_ip`/`unblock_ip` | M5 | Not Started | TASK-014 |
114+
| TASK-029 | Naming consistency — `stop_and_wait`, `block_ip`/`unblock_ip` | M5 | Done | TASK-014 |
115115
| TASK-030 | `_handler` suffix renames + `explicit` constructor | M5 | Not Started | TASK-014 |
116116
| TASK-031 | Handler error-propagation contract (DR-009) | M5 | Not Started | TASK-027, TASK-030 |
117117
| TASK-032 | Thread-safety contract stress test (DR-008) | M5 | Not Started | TASK-027, TASK-031 |

0 commit comments

Comments
 (0)