renders the list of peers and details panel This code is unrelated to USDT, BCC and BPF.
(screen, peers, cur_list_pos, scroll, ROWS_AVALIABLE_FOR_LIST, info_panel)
| 202 | |
| 203 | |
| 204 | def render(screen, peers, cur_list_pos, scroll, ROWS_AVALIABLE_FOR_LIST, info_panel): |
| 205 | """ renders the list of peers and details panel |
| 206 | |
| 207 | This code is unrelated to USDT, BCC and BPF. |
| 208 | """ |
| 209 | header_format = "%6s %-20s %-20s %-22s %-67s" |
| 210 | row_format = "%6s %-5d %9d byte %-5d %9d byte %-22s %-67s" |
| 211 | |
| 212 | screen.addstr(0, 1, (" P2P Message Monitor "), curses.A_REVERSE) |
| 213 | screen.addstr( |
| 214 | 1, 0, (" Navigate with UP/DOWN or J/K and select a peer with ENTER or SPACE to see individual P2P messages"), curses.A_NORMAL) |
| 215 | screen.addstr(3, 0, |
| 216 | header_format % ("PEER", "OUTBOUND", "INBOUND", "TYPE", "ADDR"), curses.A_BOLD | curses.A_UNDERLINE) |
| 217 | peer_list = sorted(peers.keys())[scroll:ROWS_AVALIABLE_FOR_LIST+scroll] |
| 218 | for i, peer_id in enumerate(peer_list): |
| 219 | peer = peers[peer_id] |
| 220 | screen.addstr(i + 4, 0, |
| 221 | row_format % (peer.id, peer.total_outbound_msgs, peer.total_outbound_bytes, |
| 222 | peer.total_inbound_msgs, peer.total_inbound_bytes, |
| 223 | peer.connection_type, peer.address), |
| 224 | curses.A_REVERSE if i + scroll == cur_list_pos else curses.A_NORMAL) |
| 225 | if i + scroll == cur_list_pos: |
| 226 | info_window = info_panel.window() |
| 227 | info_window.erase() |
| 228 | info_window.border( |
| 229 | ord("|"), ord("|"), ord("-"), ord("-"), |
| 230 | ord("-"), ord("-"), ord("-"), ord("-")) |
| 231 | |
| 232 | info_window.addstr( |
| 233 | 1, 1, f"PEER {peer.id} ({peer.address})".center(68), curses.A_REVERSE | curses.A_BOLD) |
| 234 | info_window.addstr( |
| 235 | 2, 1, f" OUR NODE{peer.connection_type:^54}PEER ", |
| 236 | curses.A_BOLD) |
| 237 | for i, msg in enumerate(peer.last_messages): |
| 238 | if msg.inbound: |
| 239 | info_window.addstr( |
| 240 | i + 3, 1, "%68s" % |
| 241 | (f"<--- {msg.msg_type} ({msg.size} bytes) "), curses.A_NORMAL) |
| 242 | else: |
| 243 | info_window.addstr( |
| 244 | i + 3, 1, " %s (%d byte) --->" % |
| 245 | (msg.msg_type, msg.size), curses.A_NORMAL) |
| 246 | |
| 247 | |
| 248 | if __name__ == "__main__": |