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
@@ -168,7 +170,7 @@ init(Parent, HelperSup, Ref) ->
168
170
{ok , Sock } = rabbit_networking :handshake (Ref ,
169
171
application :get_env (rabbit , proxy_protocol , false )),
170
172
Deb = sys :debug_options ([]),
171
- start_connection (Parent , HelperSup , Deb , Sock ).
173
+ start_connection (Parent , HelperSup , Ref , Deb , Sock ).
172
174
173
175
-spec system_continue (_ ,_ ,{[binary ()], non_neg_integer (), # v1 {}}) -> any ().
174
176
@@ -293,10 +295,10 @@ socket_op(Sock, Fun) ->
293
295
exit (normal )
294
296
end .
295
297
296
- -spec start_connection (pid (), pid (), any (), rabbit_net :socket ()) ->
298
+ -spec start_connection (pid (), pid (), ranch : ref (), any (), rabbit_net :socket ()) ->
297
299
no_return ().
298
300
299
- start_connection (Parent , HelperSup , Deb , Sock ) ->
301
+ start_connection (Parent , HelperSup , RanchRef , Deb , Sock ) ->
300
302
process_flag (trap_exit , true ),
301
303
RealSocket = rabbit_net :unwrap_socket (Sock ),
302
304
Name = case rabbit_net :connection_string (Sock , inbound ) of
@@ -314,6 +316,7 @@ start_connection(Parent, HelperSup, Deb, Sock) ->
314
316
socket_op (Sock , fun (S ) -> rabbit_net :socket_ends (S , inbound ) end ),
315
317
? store_proc_name (Name ),
316
318
State = # v1 {parent = Parent ,
319
+ ranch_ref = RanchRef ,
317
320
sock = RealSocket ,
318
321
connection = # connection {
319
322
name = Name ,
@@ -1213,17 +1216,16 @@ handle_method0(#'connection.tune_ok'{frame_max = FrameMax,
1213
1216
heartbeater = Heartbeater };
1214
1217
1215
1218
handle_method0 (# 'connection.open' {virtual_host = VHost },
1216
- State = # v1 {connection_state = opening ,
1219
+ State = # v1 {ranch_ref = RanchRef ,
1220
+ connection_state = opening ,
1217
1221
connection = Connection = # connection {
1218
1222
log_name = ConnName ,
1219
- host = Addr ,
1220
- port = Port ,
1221
1223
user = User = # user {username = Username },
1222
1224
protocol = Protocol },
1223
1225
helper_sup = SupPid ,
1224
1226
sock = Sock ,
1225
1227
throttle = Throttle }) ->
1226
- ok = is_over_node_connection_limit (Addr , Port ),
1228
+ ok = is_over_node_connection_limit (RanchRef ),
1227
1229
ok = is_over_vhost_connection_limit (VHost , User ),
1228
1230
ok = is_over_user_connection_limit (User ),
1229
1231
ok = rabbit_access_control :check_vhost_access (User , VHost , {socket , Sock }, #{}),
@@ -1324,13 +1326,12 @@ is_vhost_alive(VHostPath, User) ->
1324
1326
[VHostPath , User # user .username , VHostPath ])
1325
1327
end .
1326
1328
1327
- is_over_node_connection_limit (Addr , Port ) ->
1329
+ is_over_node_connection_limit (RanchRef ) ->
1328
1330
Limit = rabbit_misc :get_env (rabbit , connection_max , infinity ),
1329
1331
case Limit of
1330
1332
infinity -> ok ;
1331
1333
N when is_integer (N ) ->
1332
- Ref = rabbit_networking :ranch_ref (Addr , Port ),
1333
- #{active_connections := ActiveConns } = ranch :info (Ref ),
1334
+ #{active_connections := ActiveConns } = ranch :info (RanchRef ),
1334
1335
1335
1336
case ActiveConns > Limit of
1336
1337
false -> ok ;
0 commit comments