Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions hathor/cli/nginx_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,15 @@ def generate_nginx_config(openapi: dict[str, Any], *, out_file: TextIO, rate_k:
websocket_max_conn_per_ip = 10000
mining_websocket_max_conn_global = 1000
mining_websocket_max_conn_per_ip = 1000
event_websocket_max_conn_global = 1000
event_websocket_max_conn_per_ip = 1000
else:
websocket_max_conn_global = 4000
websocket_max_conn_per_ip = 10
mining_websocket_max_conn_global = 100
mining_websocket_max_conn_per_ip = 4
event_websocket_max_conn_global = 100
event_websocket_max_conn_per_ip = 4

header = f'''# THIS FILE WAS AUTOGENERATED BY THE `hathor-cli nginx-config` TOOL AT {datetime.now()}

Expand Down Expand Up @@ -231,6 +235,8 @@ def generate_nginx_config(openapi: dict[str, Any], *, out_file: TextIO, rate_k:
limit_conn_zone $per_ip_key zone=per_ip__ws:10m;
limit_conn_zone $global_key zone=global__mining_ws:32k;
limit_conn_zone $per_ip_key zone=per_ip__mining_ws:10m;
limit_conn_zone $global_key zone=global__event_ws:32k;
limit_conn_zone $per_ip_key zone=per_ip__event_ws:10m;
'''

server_open = f'''
Expand Down Expand Up @@ -282,6 +288,16 @@ def generate_nginx_config(openapi: dict[str, Any], *, out_file: TextIO, rate_k:
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://backend;
}}
location ~ ^/{api_prefix}/event_ws/?$ {{
limit_conn global__event_ws {event_websocket_max_conn_global};
limit_conn per_ip__event_ws {event_websocket_max_conn_per_ip};
include cors_params;
include proxy_params;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://backend;
}}'''
# TODO: maybe return 403 instead?
server_close = f'''
Expand Down
1 change: 1 addition & 0 deletions hathor/cli/openapi_files/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def register_resource(resource_class: ResourceClass) -> ResourceClass:
def get_registered_resources() -> list[type[Resource]]:
""" Returns a list with all the resources registered for the docs
"""
import hathor.event.resources.event # noqa: 401
import hathor.feature_activation.resources.feature # noqa: 401
import hathor.p2p.resources # noqa: 401
import hathor.profiler.resources # noqa: 401
Expand Down
18 changes: 17 additions & 1 deletion hathor/event/resources/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,23 @@ class GetEventsResponse(Response):

EventResource.openapi = {
'/event': {
'x-visibility': 'private',
'x-visibility': 'public',
'x-rate-limit': {
'global': [
{
'rate': '50r/s',
'burst': 100,
'delay': 50
}
],
'per-ip': [
{
'rate': '1r/s',
'burst': 10,
'delay': 3
}
]
},
'get': {
'operationId': 'event',
'summary': 'Hathor Events',
Expand Down