22
33import lombok .extern .slf4j .Slf4j ;
44import org .tron .common .net .udp .message .UdpMessageTypeEnum ;
5+ import org .tron .common .overlay .message .Message ;
6+ import org .tron .core .net .message .FetchInvDataMessage ;
7+ import org .tron .core .net .message .InventoryMessage ;
58import org .tron .core .net .message .MessageTypes ;
9+ import org .tron .core .net .message .TransactionsMessage ;
610
711@ Slf4j
812public class MessageStatistics {
@@ -31,6 +35,39 @@ public class MessageStatistics {
3135 public final MessageCount tronInMessage = new MessageCount ();
3236 public final MessageCount tronOutMessage = new MessageCount ();
3337
38+ public final MessageCount tronInSyncBlockChain = new MessageCount ();
39+ public final MessageCount tronOutSyncBlockChain = new MessageCount ();
40+ public final MessageCount tronInBlockChainInventory = new MessageCount ();
41+ public final MessageCount tronOutBlockChainInventory = new MessageCount ();
42+
43+ public final MessageCount tronInTrxInventory = new MessageCount ();
44+ public final MessageCount tronOutTrxInventory = new MessageCount ();
45+ public final MessageCount tronInTrxInventoryElement = new MessageCount ();
46+ public final MessageCount tronOutTrxInventoryElement = new MessageCount ();
47+
48+ public final MessageCount tronInBlockInventory = new MessageCount ();
49+ public final MessageCount tronOutBlockInventory = new MessageCount ();
50+ public final MessageCount tronInBlockInventoryElement = new MessageCount ();
51+ public final MessageCount tronOutBlockInventoryElement = new MessageCount ();
52+
53+ public final MessageCount tronInTrxFetchInvData = new MessageCount ();
54+ public final MessageCount tronOutTrxFetchInvData = new MessageCount ();
55+ public final MessageCount tronInTrxFetchInvDataElement = new MessageCount ();
56+ public final MessageCount tronOutTrxFetchInvDataElement = new MessageCount ();
57+
58+ public final MessageCount tronInBlockFetchInvData = new MessageCount ();
59+ public final MessageCount tronOutBlockFetchInvData = new MessageCount ();
60+ public final MessageCount tronInBlockFetchInvDataElement = new MessageCount ();
61+ public final MessageCount tronOutBlockFetchInvDataElement = new MessageCount ();
62+
63+
64+ public final MessageCount tronInTrx = new MessageCount ();
65+ public final MessageCount tronOutTrx = new MessageCount ();
66+ public final MessageCount tronInTrxs = new MessageCount ();
67+ public final MessageCount tronOutTrxs = new MessageCount ();
68+ public final MessageCount tronInBlock = new MessageCount ();
69+ public final MessageCount tronOutBlock = new MessageCount ();
70+ public final MessageCount tronOutAdvBlock = new MessageCount ();
3471
3572 public void addUdpInMessage (UdpMessageTypeEnum type ){
3673 addUdpMessage (type , true );
@@ -40,12 +77,12 @@ public void addUdpOutMessage(UdpMessageTypeEnum type){
4077 addUdpMessage (type , false );
4178 }
4279
43- public void addTcpInMessage (MessageTypes type ){
44- addTcpMessage (type , true );
80+ public void addTcpInMessage (Message msg ){
81+ addTcpMessage (msg , true );
4582 }
4683
47- public void addTcpOutMessage (MessageTypes type ){
48- addTcpMessage (type , false );
84+ public void addTcpOutMessage (Message msg ){
85+ addTcpMessage (msg , false );
4986 }
5087
5188 private void addUdpMessage (UdpMessageTypeEnum type , boolean flag ){
@@ -67,8 +104,15 @@ private void addUdpMessage(UdpMessageTypeEnum type, boolean flag){
67104 }
68105 }
69106
70- private void addTcpMessage (MessageTypes type , boolean flag ){
71- switch (type ){
107+ private void addTcpMessage (Message msg , boolean flag ){
108+
109+ if (flag ) {
110+ tronInMessage .add ();
111+ } else {
112+ tronOutMessage .add ();
113+ }
114+
115+ switch (msg .getType ()){
72116 case P2P_HELLO :
73117 if (flag ) p2pInHello .add (); else p2pOutHello .add ();
74118 break ;
@@ -82,14 +126,69 @@ private void addTcpMessage(MessageTypes type, boolean flag){
82126 if (flag ) p2pInDisconnect .add (); else p2pOutDisconnect .add ();
83127 break ;
84128 case SYNC_BLOCK_CHAIN :
129+ if (flag ) tronInSyncBlockChain .add (); else tronOutSyncBlockChain .add ();
130+ break ;
85131 case BLOCK_CHAIN_INVENTORY :
132+ if (flag ) tronInBlockChainInventory .add (); else tronOutBlockChainInventory .add ();
133+ break ;
86134 case INVENTORY :
135+ InventoryMessage inventoryMessage = (InventoryMessage ) msg ;
136+ int inventorySize = inventoryMessage .getInventory ().getIdsCount ();
137+ if (flag ) {
138+ if (inventoryMessage .getInvMessageType () == MessageTypes .TRX ){
139+ tronInTrxInventory .add ();
140+ tronInTrxInventoryElement .add (inventorySize );
141+ }else {
142+ tronInBlockInventory .add ();
143+ tronInBlockInventoryElement .add (inventorySize );
144+ }
145+ } else {
146+ if (inventoryMessage .getInvMessageType () == MessageTypes .TRX ){
147+ tronOutTrxInventory .add ();
148+ tronOutTrxInventoryElement .add (inventorySize );
149+ }else {
150+ tronOutBlockInventory .add ();
151+ tronOutBlockInventoryElement .add (inventorySize );
152+ }
153+ }
154+ break ;
87155 case FETCH_INV_DATA :
88- case BLOCK :
156+ FetchInvDataMessage fetchInvDataMessage = (FetchInvDataMessage ) msg ;
157+ int fetchSize = fetchInvDataMessage .getInventory ().getIdsCount ();
158+ if (flag ) {
159+ if (fetchInvDataMessage .getInvMessageType () == MessageTypes .TRX ){
160+ tronInTrxFetchInvData .add ();
161+ tronInTrxFetchInvDataElement .add (fetchSize );
162+ }else {
163+ tronInBlockFetchInvData .add ();
164+ tronInBlockFetchInvDataElement .add (fetchSize );
165+ }
166+ } else {
167+ if (fetchInvDataMessage .getInvMessageType () == MessageTypes .TRX ){
168+ tronOutTrxFetchInvData .add ();
169+ tronOutTrxFetchInvDataElement .add (fetchSize );
170+ }else {
171+ tronOutBlockFetchInvData .add ();
172+ tronOutBlockFetchInvDataElement .add (fetchSize );
173+ }
174+ }
175+ break ;
89176 case TRXS :
177+ TransactionsMessage transactionsMessage = (TransactionsMessage )msg ;
178+ if (flag ) {
179+ tronInTrxs .add ();
180+ tronInTrx .add (transactionsMessage .getTransactions ().getTransactionsCount ());
181+ } else {
182+ tronOutTrxs .add ();
183+ tronOutTrx .add (transactionsMessage .getTransactions ().getTransactionsCount ());
184+ }
185+ break ;
90186 case TRX :
91187 if (flag ) tronInMessage .add (); else tronOutMessage .add ();
92188 break ;
189+ case BLOCK :
190+ if (flag ) tronInBlock .add (); tronOutBlock .add ();
191+ break ;
93192 default :
94193 break ;
95194 }
0 commit comments