xref: /aosp_15_r20/external/cronet/net/socket/udp_net_log_parameters.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/socket/udp_net_log_parameters.h"
6 
7 #include <utility>
8 
9 #include "base/values.h"
10 #include "net/base/ip_endpoint.h"
11 #include "net/log/net_log_values.h"
12 #include "net/log/net_log_with_source.h"
13 
14 namespace net {
15 
16 namespace {
17 
NetLogUDPDataTransferParams(int byte_count,const char * bytes,const IPEndPoint * address,NetLogCaptureMode capture_mode)18 base::Value::Dict NetLogUDPDataTransferParams(int byte_count,
19                                               const char* bytes,
20                                               const IPEndPoint* address,
21                                               NetLogCaptureMode capture_mode) {
22   auto dict = base::Value::Dict().Set("byte_count", byte_count);
23   if (NetLogCaptureIncludesSocketBytes(capture_mode))
24     dict.Set("bytes", NetLogBinaryValue(bytes, byte_count));
25   if (address)
26     dict.Set("address", address->ToString());
27   return dict;
28 }
29 
NetLogUDPConnectParams(const IPEndPoint & address,handles::NetworkHandle network)30 base::Value::Dict NetLogUDPConnectParams(const IPEndPoint& address,
31                                          handles::NetworkHandle network) {
32   auto dict = base::Value::Dict().Set("address", address.ToString());
33   if (network != handles::kInvalidNetworkHandle)
34     dict.Set("bound_to_network", static_cast<int>(network));
35   return dict;
36 }
37 
38 }  // namespace
39 
NetLogUDPDataTransfer(const NetLogWithSource & net_log,NetLogEventType type,int byte_count,const char * bytes,const IPEndPoint * address)40 void NetLogUDPDataTransfer(const NetLogWithSource& net_log,
41                            NetLogEventType type,
42                            int byte_count,
43                            const char* bytes,
44                            const IPEndPoint* address) {
45   DCHECK(bytes);
46   net_log.AddEvent(type, [&](NetLogCaptureMode capture_mode) {
47     return NetLogUDPDataTransferParams(byte_count, bytes, address,
48                                        capture_mode);
49   });
50 }
51 
CreateNetLogUDPConnectParams(const IPEndPoint & address,handles::NetworkHandle network)52 base::Value::Dict CreateNetLogUDPConnectParams(const IPEndPoint& address,
53                                                handles::NetworkHandle network) {
54   return NetLogUDPConnectParams(address, network);
55 }
56 
57 }  // namespace net
58