Skip to content

Commit da269c1

Browse files
committed
Add more CandidatePair stats
1 parent 334ba47 commit da269c1

File tree

3 files changed

+93
-16
lines changed

3 files changed

+93
-16
lines changed

lib/ex_ice/candidate_pair.ex

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ defmodule ExICE.CandidatePair do
1515
valid?: boolean(),
1616
last_seen: integer(),
1717
# stats
18+
packets_sent: non_neg_integer(),
19+
packets_received: non_neg_integer(),
20+
bytes_sent: non_neg_integer(),
21+
bytes_received: non_neg_integer(),
1822
requests_received: non_neg_integer(),
1923
requests_sent: non_neg_integer(),
2024
responses_received: non_neg_integer(),
2125
non_symmetric_responses_received: non_neg_integer(),
22-
responses_sent: non_neg_integer()
26+
responses_sent: non_neg_integer(),
27+
packets_discarded_on_send: non_neg_integer(),
28+
bytes_discarded_on_send: non_neg_integer()
2329
}
2430

2531
@enforce_keys [:id, :local_cand_id, :remote_cand_id, :priority]
@@ -29,10 +35,16 @@ defmodule ExICE.CandidatePair do
2935
state: :frozen,
3036
valid?: false,
3137
last_seen: nil,
38+
packets_sent: 0,
39+
packets_received: 0,
40+
bytes_sent: 0,
41+
bytes_received: 0,
3242
requests_received: 0,
3343
requests_sent: 0,
3444
responses_received: 0,
3545
non_symmetric_responses_received: 0,
36-
responses_sent: 0
46+
responses_sent: 0,
47+
packets_discarded_on_send: 0,
48+
bytes_discarded_on_send: 0
3749
]
3850
end

lib/ex_ice/priv/candidate_pair.ex

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ defmodule ExICE.Priv.CandidatePair do
2222
discovered_pair_id: integer() | nil,
2323
keepalive_timer: reference() | nil,
2424
last_seen: integer(),
25+
packets_sent: non_neg_integer(),
26+
packets_received: non_neg_integer(),
27+
bytes_sent: non_neg_integer(),
28+
bytes_received: non_neg_integer(),
2529
requests_received: non_neg_integer(),
2630
requests_sent: non_neg_integer(),
2731
responses_received: non_neg_integer(),
2832
non_symmetric_responses_received: non_neg_integer(),
29-
responses_sent: non_neg_integer()
33+
responses_sent: non_neg_integer(),
34+
packets_discarded_on_send: non_neg_integer(),
35+
bytes_discarded_on_send: non_neg_integer()
3036
}
3137

3238
@enforce_keys [:id, :local_cand_id, :remote_cand_id, :priority]
@@ -42,11 +48,17 @@ defmodule ExICE.Priv.CandidatePair do
4248
# Time when this pair has received some data
4349
# or sent conn check.
4450
last_seen: nil,
51+
packets_sent: 0,
52+
packets_received: 0,
53+
bytes_sent: 0,
54+
bytes_received: 0,
4555
requests_received: 0,
4656
requests_sent: 0,
4757
responses_received: 0,
4858
non_symmetric_responses_received: 0,
49-
responses_sent: 0
59+
responses_sent: 0,
60+
packets_discarded_on_send: 0,
61+
bytes_discarded_on_send: 0
5062
]
5163

5264
@doc false

lib/ex_ice/priv/ice_agent.ex

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -482,17 +482,35 @@ defmodule ExICE.Priv.ICEAgent do
482482
remote_cand = Map.fetch!(ice_agent.remote_cands, pair.remote_cand_id)
483483

484484
dst = {remote_cand.address, remote_cand.port}
485+
data_size = byte_size(data)
485486

486487
case do_send(ice_agent, local_cand, dst, data) do
487488
{:ok, ice_agent} ->
488-
%{
489-
ice_agent
490-
| bytes_sent: ice_agent.bytes_sent + byte_size(data),
491-
packets_sent: ice_agent.packets_sent + 1
489+
pair = %CandidatePair{
490+
pair
491+
| packets_sent: pair.packets_sent + 1,
492+
bytes_sent: pair.bytes_sent + data_size
492493
}
493494

495+
ice_agent =
496+
%{
497+
ice_agent
498+
| bytes_sent: ice_agent.bytes_sent + data_size,
499+
packets_sent: ice_agent.packets_sent + 1
500+
}
501+
502+
put_in(ice_agent.checklist[pair.id], pair)
503+
494504
{:error, ice_agent} ->
495-
ice_agent
505+
pair = Map.fetch!(ice_agent.checklist, pair.id)
506+
507+
pair = %CandidatePair{
508+
pair
509+
| packets_discarded_on_send: pair.packets_discarded_on_send + 1,
510+
bytes_discarded_on_send: pair.bytes_discarded_on_send + data_size
511+
}
512+
513+
put_in(ice_agent.checklist[pair.id], pair)
496514
end
497515
end
498516

@@ -639,7 +657,15 @@ defmodule ExICE.Priv.ICEAgent do
639657
ice_agent
640658

641659
{:error, ice_agent} ->
642-
ice_agent
660+
data_size = byte_size(conn_check.raw_req)
661+
662+
pair = %CandidatePair{
663+
pair
664+
| packets_discarded_on_send: pair.packets_discarded_on_send + 1,
665+
bytes_discarded_on_send: pair.bytes_discarded_on_send + data_size
666+
}
667+
668+
put_in(ice_agent.checklist[pair.id], pair)
643669
end
644670
end
645671

@@ -1284,14 +1310,22 @@ defmodule ExICE.Priv.ICEAgent do
12841310
end
12851311

12861312
defp do_handle_data_message(ice_agent, pair, packet) do
1287-
pair = %CandidatePair{pair | last_seen: now()}
1313+
data_size = byte_size(packet)
1314+
1315+
pair = %CandidatePair{
1316+
pair
1317+
| last_seen: now(),
1318+
packets_received: pair.packets_received + 1,
1319+
bytes_received: pair.bytes_received + data_size
1320+
}
1321+
12881322
ice_agent = put_in(ice_agent.checklist[pair.id], pair)
12891323

12901324
notify(ice_agent.on_data, {:data, packet})
12911325

12921326
%{
12931327
ice_agent
1294-
| bytes_received: ice_agent.bytes_received + byte_size(packet),
1328+
| bytes_received: ice_agent.bytes_received + data_size,
12951329
packets_received: ice_agent.packets_received + 1
12961330
}
12971331
end
@@ -2013,7 +2047,13 @@ defmodule ExICE.Priv.ICEAgent do
20132047
put_in(ice_agent.checklist[pair.id], pair)
20142048

20152049
{:error, ice_agent} ->
2016-
ice_agent
2050+
pair = %CandidatePair{
2051+
pair
2052+
| packets_discarded_on_send: pair.packets_discarded_on_send + 1,
2053+
bytes_discarded_on_send: pair.bytes_discarded_on_send + byte_size(resp)
2054+
}
2055+
2056+
put_in(ice_agent.checklist[pair.id], pair)
20172057
end
20182058
end
20192059

@@ -2781,18 +2821,25 @@ defmodule ExICE.Priv.ICEAgent do
27812821
remote_cand = Map.fetch!(ice_agent.remote_cands, pair.remote_cand_id)
27822822

27832823
req = binding_request(ice_agent, local_cand, false)
2824+
raw_req = Message.encode(req)
27842825

27852826
dst = {remote_cand.address, remote_cand.port}
27862827

2787-
case do_send(ice_agent, local_cand, dst, Message.encode(req)) do
2828+
case do_send(ice_agent, local_cand, dst, raw_req) do
27882829
{:ok, ice_agent} ->
27892830
pair = %CandidatePair{pair | requests_sent: pair.requests_sent + 1}
27902831
ice_agent = put_in(ice_agent.checklist[pair.id], pair)
27912832
keepalives = Map.put(ice_agent.keepalives, req.transaction_id, pair.id)
27922833
%__MODULE__{ice_agent | keepalives: keepalives}
27932834

27942835
{:error, ice_agent} ->
2795-
ice_agent
2836+
pair = %CandidatePair{
2837+
pair
2838+
| packets_discarded_on_send: pair.packets_discarded_on_send + 1,
2839+
bytes_discarded_on_send: pair.bytes_discarded_on_send + byte_size(raw_req)
2840+
}
2841+
2842+
put_in(ice_agent.checklist[pair.id], pair)
27962843
end
27972844
end
27982845

@@ -2833,7 +2880,13 @@ defmodule ExICE.Priv.ICEAgent do
28332880
%__MODULE__{ice_agent | conn_checks: conn_checks, checklist: checklist}
28342881

28352882
{:error, ice_agent} ->
2836-
ice_agent
2883+
pair = %CandidatePair{
2884+
pair
2885+
| packets_discarded_on_send: pair.packets_discarded_on_send + 1,
2886+
bytes_discarded_on_send: pair.bytes_discarded_on_send + byte_size(raw_req)
2887+
}
2888+
2889+
put_in(ice_agent.checklist[pair.id], pair)
28372890
end
28382891
end
28392892

0 commit comments

Comments
 (0)