From 5f31abae9e36bd202bbf6ef7db1376fd8e8d7c52 Mon Sep 17 00:00:00 2001 From: Asutorufa <16442314+Asutorufa@users.noreply.github.com> Date: Wed, 29 Jan 2025 15:02:40 +0800 Subject: [PATCH] change connection infos from map to struct --- app/docs/connections/components.tsx | 41 +++++++--- app/docs/connections/history/page.tsx | 6 +- app/docs/connections/page.tsx | 7 +- app/docs/pbes/statistic/config_pb.ts | 103 +++++++++++++++++++++++++- 4 files changed, 138 insertions(+), 19 deletions(-) diff --git a/app/docs/connections/components.tsx b/app/docs/connections/components.tsx index bb91d55..73b277f 100644 --- a/app/docs/connections/components.tsx +++ b/app/docs/connections/components.tsx @@ -1,17 +1,18 @@ +import { reflect } from "@bufbuild/protobuf/reflect"; import { FC, JSX } from "react"; import { ListGroup } from "react-bootstrap"; -import { connection, type } from "../pbes/statistic/config_pb"; +import { connection, connectionSchema, type } from "../pbes/statistic/config_pb"; export const ListGroupItem = (props: { itemKey: string, itemValue: string, showModal?: (hash: string) => void }) => { return ( <>
-
{props.itemKey}
+
{props.itemKey}
{ - (props.itemKey !== "Hash" || !props.showModal) ? props.itemValue : + (props.itemKey !== "hash" || !props.showModal) ? props.itemValue : { e.preventDefault(); if (props.showModal) props.showModal(props.itemValue) }} @@ -27,19 +28,39 @@ export const ListGroupItem = (props: { itemKey: string, itemValue: string, showM } export const ConnectionInfo: FC<{ value: connection, endContent?: JSX.Element, showModal?: (hash: string) => void }> = ({ value, endContent, showModal }) => { + + function rangeInfo(d: connection) { + const ref = reflect(connectionSchema, d) + + + return <> + { + ref.fields.map((f) => { + if (f.fieldKind == "message") return + + let valueStr = ""; + if (f.fieldKind === "enum") { + const value: number = ref.get(f) + valueStr = f.enum.value[value].name + } else { + const value = ref.get(f) + if (!value) return + valueStr = value.toString() + } + + return + }) + } + + } + return <> - { - Object.entries(value.extra) - .sort((a, b) => { return a <= b ? -1 : 1 }) - .map(([k, v]) => { - return - }) - } + {rangeInfo(value)} {endContent} diff --git a/app/docs/connections/history/page.tsx b/app/docs/connections/history/page.tsx index 04a255d..9c91dc5 100644 --- a/app/docs/connections/history/page.tsx +++ b/app/docs/connections/history/page.tsx @@ -22,7 +22,7 @@ function History() { const cth = (field: string) => setSortField(field)}>{field}{sortIcon(field)} const sortFieldFunc = (a: all_history, b: all_history) => { if (sort === "Host") return sortFunc(a.connection?.addr, b.connection?.addr) - else if (sort === "Proc") return sortFunc(a.connection?.extra.Process, b.connection?.extra.Process) + else if (sort === "Proc") return sortFunc(a.connection?.process, b.connection?.process) else if (sort === "Count") return sortFunc(a.count, b.count) else return sortFunc(timestampDate(a.time ?? TimestampZero), timestampDate(b.time ?? TimestampZero)) } @@ -75,10 +75,10 @@ function History() { setModalData({ show: true, data: v })}> {timestampDate(v.time!).toLocaleString()} {v.connection?.addr} - {v.connection?.extra.MODE} + {v.connection?.mode} {type[v.connection?.type?.connType ?? type.unknown]} {Number(v.count)} - {data.dumpProcessEnabled && {v.connection?.extra.Process}} + {data.dumpProcessEnabled && {v.connection?.process}} ) }) diff --git a/app/docs/connections/page.tsx b/app/docs/connections/page.tsx index 8d5a949..661c8f3 100644 --- a/app/docs/connections/page.tsx +++ b/app/docs/connections/page.tsx @@ -10,6 +10,7 @@ import Loading from "../common/loading"; import { FetchProtobuf, ProtoPath, WebsocketProtoServerStream } from "../common/proto"; import { GlobalToastContext } from "../common/toast"; import { NodeModal } from "../node/modal"; +import { mode } from "../pbes/config/bypass/bypass_pb"; import { connection, type } from "../pbes/statistic/config_pb"; import { connections, notify_data, notify_remove_connectionsSchema, total_flow } from "../pbes/statistic/grpc/config_pb"; import { ConnectionInfo } from "./components"; @@ -127,11 +128,11 @@ const AccordionItem = (props: { data: connection, showModal: (hash: string) => v
{props.data.id.toString()} {props.data.addr} - {props.data.extra.MODE} + {mode[props.data.mode]} {type[props.data.type?.connType ?? 0]} { - props.data.extra.Tag !== undefined && - {props.data.extra.Tag} + props.data.tag && + {props.data.tag} }
diff --git a/app/docs/pbes/statistic/config_pb.ts b/app/docs/pbes/statistic/config_pb.ts index 8c8a923..0dee72f 100644 --- a/app/docs/pbes/statistic/config_pb.ts +++ b/app/docs/pbes/statistic/config_pb.ts @@ -5,13 +5,15 @@ import type { GenEnum, GenFile, GenMessage } from "@bufbuild/protobuf/codegenv1"; import { enumDesc, fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv1"; import { file_google_protobuf_go_features } from "../google/protobuf/go_features_pb"; +import type { mode } from "../config/bypass/bypass_pb"; +import { file_config_bypass_bypass } from "../config/bypass/bypass_pb"; import type { Message } from "@bufbuild/protobuf"; /** * Describes the file statistic/config.proto. */ export const file_statistic_config: GenFile = /*@__PURE__*/ - fileDesc("ChZzdGF0aXN0aWMvY29uZmlnLnByb3RvEhF5dWhhaWluLnN0YXRpc3RpYyKEAQoIbmV0X3R5cGUSNQoJY29ubl90eXBlGAEgASgOMhcueXVoYWlpbi5zdGF0aXN0aWMudHlwZVIJY29ubl90eXBlEkEKD3VuZGVybHlpbmdfdHlwZRgCIAEoDjIXLnl1aGFpaW4uc3RhdGlzdGljLnR5cGVSD3VuZGVybHlpbmdfdHlwZSK8AQoKY29ubmVjdGlvbhIMCgRhZGRyGAEgASgJEgoKAmlkGAIgASgEEikKBHR5cGUYAyABKAsyGy55dWhhaWluLnN0YXRpc3RpYy5uZXRfdHlwZRI7CgVleHRyYRgEIAMoCzIoLnl1aGFpaW4uc3RhdGlzdGljLmNvbm5lY3Rpb24uRXh0cmFFbnRyeUICKAEaLAoKRXh0cmFFbnRyeRILCgNrZXkYASABKAkSDQoFdmFsdWUYAiABKAk6AjgBKo8BCgR0eXBlEgsKB3Vua25vd24QABIHCgN0Y3AQARIICgR0Y3A0EAISCAoEdGNwNhADEgcKA3VkcBAEEggKBHVkcDQQBRIICgR1ZHA2EAYSBgoCaXAQBxIHCgNpcDQQCBIHCgNpcDYQCRIICgR1bml4EAoSDAoIdW5peGdyYW0QCxIOCgp1bml4cGFja2V0EAxCO1oxZ2l0aHViLmNvbS9Bc3V0b3J1Z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oEdGNwNBACEggKBHRjcDYQAxIHCgN1ZHAQBBIICgR1ZHA0EAUSCAoEdWRwNhAGEgYKAmlwEAcSBwoDaXA0EAgSBwoDaXA2EAkSCAoEdW5peBAKEgwKCHVuaXhncmFtEAsSDgoKdW5peHBhY2tldBAMQjtaMWdpdGh1Yi5jb20vQXN1dG9ydWZhL3l1aGFpaW4vcGtnL3Byb3Rvcy9zdGF0aXN0aWOSAwXSPgIQA2IIZWRpdGlvbnNw6Ac", [file_google_protobuf_go_features, file_config_bypass_bypass]); /** * @generated from message yuhaiin.statistic.net_type @@ -55,9 +57,104 @@ export type connection = Message<"yuhaiin.statistic.connection"> & { type?: net_type; /** - * @generated from field: map extra = 4; + * @generated from field: string source = 5; */ - extra: { [key: string]: string }; + source: string; + + /** + * @generated from field: string inbound = 6; + */ + inbound: string; + + /** + * @generated from field: string outbound = 24; + */ + outbound: string; + + /** + * @generated from field: string destionation = 7; + */ + destionation: string; + + /** + * @generated from field: string fake_ip = 8 [json_name = "fake_ip"]; + */ + fakeIp: string; + + /** + * @generated from field: string hosts = 9; + */ + hosts: string; + + /** + * @generated from field: string domain = 10; + */ + domain: string; + + /** + * @generated from field: string ip = 11; + */ + ip: string; + + /** + * @generated from field: string tag = 12; + */ + tag: string; + + /** + * @generated from field: string hash = 13; + */ + hash: string; + + /** + * @generated from field: string protocol = 14; + */ + protocol: string; + + /** + * @generated from field: string process = 15; + */ + process: string; + + /** + * @generated from field: uint64 pid = 16; + */ + pid: bigint; + + /** + * @generated from field: uint64 uid = 17; + */ + uid: bigint; + + /** + * @generated from field: string tls_server_name = 18 [json_name = "tls_server_name"]; + */ + tlsServerName: string; + + /** + * @generated from field: string http_host = 19 [json_name = "http_host"]; + */ + httpHost: string; + + /** + * @generated from field: string component = 20; + */ + component: string; + + /** + * @generated from field: uint64 udp_migrate_id = 21 [json_name = "udp_migrate_id"]; + */ + udpMigrateId: bigint; + + /** + * @generated from field: yuhaiin.bypass.mode mode = 22; + */ + mode: mode; + + /** + * @generated from field: string mode_reason = 23 [json_name = "mode_reason"]; + */ + modeReason: string; }; /**