Skip to content

Commit

Permalink
change connection infos from map to struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Asutorufa committed Jan 29, 2025
1 parent df1ec15 commit 5f31aba
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 19 deletions.
41 changes: 31 additions & 10 deletions app/docs/connections/components.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<ListGroup.Item>
<div className="d-sm-flex">
<div className="endpoint-name flex-grow-1 notranslate">{props.itemKey}</div>
<div className="endpoint-name flex-grow-1 notranslate text-capitalize">{props.itemKey}</div>

<div className="notranslate text-break" style={{ opacity: 0.6 }}>
{
(props.itemKey !== "Hash" || !props.showModal) ? props.itemValue :
(props.itemKey !== "hash" || !props.showModal) ? props.itemValue :
<a
href="#"
onClick={(e) => { e.preventDefault(); if (props.showModal) props.showModal(props.itemValue) }}
Expand All @@ -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<typeof f>(f)
if (!value) return
valueStr = value.toString()
}

return <ListGroupItem itemKey={f.name.replaceAll("_", " ")} itemValue={valueStr} key={f.name} showModal={showModal} />
})
}
</>
}

return <>
<ListGroup variant="flush">
<ListGroupItem itemKey="Addr" itemValue={value.addr} />
<ListGroupItem itemKey="Type" itemValue={type[value.type?.connType ?? 0]} />
<ListGroupItem itemKey="Underlying" itemValue={type[value.type?.underlyingType ?? 0]} />

{
Object.entries(value.extra)
.sort((a, b) => { return a <= b ? -1 : 1 })
.map(([k, v]) => {
return <ListGroupItem itemKey={k} itemValue={v} key={k} showModal={showModal} />
})
}
{rangeInfo(value)}

{endContent}
</ListGroup>
Expand Down
6 changes: 3 additions & 3 deletions app/docs/connections/history/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function History() {
const cth = (field: string) => <th className={styles.clickable} onClick={() => setSortField(field)}>{field}{sortIcon(field)}</th>
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))
}
Expand Down Expand Up @@ -75,10 +75,10 @@ function History() {
<tr key={"bh-" + index} onClick={() => setModalData({ show: true, data: v })}>
<td>{timestampDate(v.time!).toLocaleString()}</td>
<td>{v.connection?.addr}</td>
<td>{v.connection?.extra.MODE}</td>
<td>{v.connection?.mode}</td>
<td>{type[v.connection?.type?.connType ?? type.unknown]}</td>
<td>{Number(v.count)}</td>
{data.dumpProcessEnabled && <td>{v.connection?.extra.Process}</td>}
{data.dumpProcessEnabled && <td>{v.connection?.process}</td>}
</tr>
)
})
Expand Down
7 changes: 4 additions & 3 deletions app/docs/connections/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -127,11 +128,11 @@ const AccordionItem = (props: { data: connection, showModal: (hash: string) => v
<div className="d-line text-break">
<code className="ms-2">{props.data.id.toString()}</code>
<span className="ms-2">{props.data.addr}</span>
<Badge className="bg-light rounded-pill text-dark ms-1 text-uppercase">{props.data.extra.MODE}</Badge>
<Badge className="bg-light rounded-pill text-dark ms-1 text-uppercase">{mode[props.data.mode]}</Badge>
<Badge className="bg-light rounded-pill text-dark ms-1 text-uppercase">{type[props.data.type?.connType ?? 0]}</Badge>
{
props.data.extra.Tag !== undefined &&
<Badge className="bg-light rounded-pill text-dark ms-1 text-uppercase">{props.data.extra.Tag}</Badge>
props.data.tag &&
<Badge className="bg-light rounded-pill text-dark ms-1 text-uppercase">{props.data.tag}</Badge>
}
</div>
</Accordion.Header>
Expand Down
103 changes: 100 additions & 3 deletions app/docs/pbes/statistic/config_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("ChZzdGF0aXN0aWMvY29uZmlnLnByb3RvEhF5dWhhaWluLnN0YXRpc3RpYyKEAQoIbmV0X3R5cGUSNQoJY29ubl90eXBlGAEgASgOMhcueXVoYWlpbi5zdGF0aXN0aWMudHlwZVIJY29ubl90eXBlEkEKD3VuZGVybHlpbmdfdHlwZRgCIAEoDjIXLnl1aGFpaW4uc3RhdGlzdGljLnR5cGVSD3VuZGVybHlpbmdfdHlwZSK8AQoKY29ubmVjdGlvbh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XAYCyABKAkSCwoDdGFnGAwgASgJEgwKBGhhc2gYDSABKAkSEAoIcHJvdG9jb2wYDiABKAkSDwoHcHJvY2VzcxgPIAEoCRILCgNwaWQYECABKAQSCwoDdWlkGBEgASgEEigKD3Rsc19zZXJ2ZXJfbmFtZRgSIAEoCVIPdGxzX3NlcnZlcl9uYW1lEhwKCWh0dHBfaG9zdBgTIAEoCVIJaHR0cF9ob3N0EhEKCWNvbXBvbmVudBgUIAEoCRImCg51ZHBfbWlncmF0ZV9pZBgVIAEoBFIOdWRwX21pZ3JhdGVfaWQSIgoEbW9kZRgWIAEoDjIULnl1aGFpaW4uYnlwYXNzLm1vZGUSIAoLbW9kZV9yZWFzb24YFyABKAlSC21vZGVfcmVhc29uSgQIBBAFUgVleHRyYSqPAQoEdHlwZRILCgd1bmtub3duEAASBwoDdGNwEAESCAoEdGNwNBACEggKBHRjcDYQAxIHCgN1ZHAQBBIICgR1ZHA0EAUSCAoEdWRwNhAGEgYKAmlwEAcSBwoDaXA0EAgSBwoDaXA2EAkSCAoEdW5peBAKEgwKCHVuaXhncmFtEAsSDgoKdW5peHBhY2tldBAMQjtaMWdpdGh1Yi5jb20vQXN1dG9ydWZhL3l1aGFpaW4vcGtnL3Byb3Rvcy9zdGF0aXN0aWOSAwXSPgIQA2IIZWRpdGlvbnNw6Ac", [file_google_protobuf_go_features, file_config_bypass_bypass]);

/**
* @generated from message yuhaiin.statistic.net_type
Expand Down Expand Up @@ -55,9 +57,104 @@ export type connection = Message<"yuhaiin.statistic.connection"> & {
type?: net_type;

/**
* @generated from field: map<string, string> 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;
};

/**
Expand Down

0 comments on commit 5f31aba

Please sign in to comment.