66
66
-record (v1 , {
67
67
% % parent process
68
68
parent ,
69
+ % % Ranch ref
70
+ ranch_ref ,
69
71
% % socket
70
72
sock ,
71
73
% % connection state, see connection record
@@ -162,7 +164,7 @@ init(Parent, HelperSup, Ref) ->
162
164
{ok , Sock } = rabbit_networking :handshake (Ref ,
163
165
application :get_env (rabbit , proxy_protocol , false )),
164
166
Deb = sys :debug_options ([]),
165
- start_connection (Parent , HelperSup , Deb , Sock ).
167
+ start_connection (Parent , HelperSup , Ref , Deb , Sock ).
166
168
167
169
-spec system_continue (_ ,_ ,{[binary ()], non_neg_integer (), # v1 {}}) -> any ().
168
170
@@ -289,10 +291,10 @@ socket_op(Sock, Fun) ->
289
291
exit (normal )
290
292
end .
291
293
292
- -spec start_connection (pid (), pid (), any (), rabbit_net :socket ()) ->
294
+ -spec start_connection (pid (), pid (), ranch : ref (), any (), rabbit_net :socket ()) ->
293
295
no_return ().
294
296
295
- start_connection (Parent , HelperSup , Deb , Sock ) ->
297
+ start_connection (Parent , HelperSup , RanchRef , Deb , Sock ) ->
296
298
process_flag (trap_exit , true ),
297
299
RealSocket = rabbit_net :unwrap_socket (Sock ),
298
300
Name = case rabbit_net :connection_string (Sock , inbound ) of
@@ -310,6 +312,7 @@ start_connection(Parent, HelperSup, Deb, Sock) ->
310
312
socket_op (Sock , fun (S ) -> rabbit_net :socket_ends (S , inbound ) end ),
311
313
? store_proc_name (Name ),
312
314
State = # v1 {parent = Parent ,
315
+ ranch_ref = RanchRef ,
313
316
sock = RealSocket ,
314
317
connection = # connection {
315
318
name = Name ,
@@ -1209,17 +1212,16 @@ handle_method0(#'connection.tune_ok'{frame_max = FrameMax,
1209
1212
heartbeater = Heartbeater };
1210
1213
1211
1214
handle_method0 (# 'connection.open' {virtual_host = VHost },
1212
- State = # v1 {connection_state = opening ,
1215
+ State = # v1 {ranch_ref = RanchRef ,
1216
+ connection_state = opening ,
1213
1217
connection = Connection = # connection {
1214
1218
log_name = ConnName ,
1215
- host = Addr ,
1216
- port = Port ,
1217
1219
user = User = # user {username = Username },
1218
1220
protocol = Protocol },
1219
1221
helper_sup = SupPid ,
1220
1222
sock = Sock ,
1221
1223
throttle = Throttle }) ->
1222
- ok = is_over_node_connection_limit (Addr , Port ),
1224
+ ok = is_over_node_connection_limit (RanchRef ),
1223
1225
ok = is_over_vhost_connection_limit (VHost , User ),
1224
1226
ok = is_over_user_connection_limit (User ),
1225
1227
ok = rabbit_access_control :check_vhost_access (User , VHost , {socket , Sock }, #{}),
@@ -1320,13 +1322,12 @@ is_vhost_alive(VHostPath, User) ->
1320
1322
[VHostPath , User # user .username , VHostPath ])
1321
1323
end .
1322
1324
1323
- is_over_node_connection_limit (Addr , Port ) ->
1325
+ is_over_node_connection_limit (RanchRef ) ->
1324
1326
Limit = rabbit_misc :get_env (rabbit , connection_max , infinity ),
1325
1327
case Limit of
1326
1328
infinity -> ok ;
1327
1329
N when is_integer (N ) ->
1328
- Ref = rabbit_networking :ranch_ref (Addr , Port ),
1329
- #{active_connections := ActiveConns } = ranch :info (Ref ),
1330
+ #{active_connections := ActiveConns } = ranch :info (RanchRef ),
1330
1331
1331
1332
case ActiveConns > Limit of
1332
1333
false -> ok ;
0 commit comments