Skip to content

Commit a8faee4

Browse files
committed
Use peer_id for row key in peers table when available
Issue #310
1 parent d32a118 commit a8faee4

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/components/tables/peerstable.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
import type { AccessorFn, CellContext, ColumnDef } from "@tanstack/react-table";
20-
import React, { useMemo, useCallback, useContext } from "react";
20+
import React, { useMemo, useContext } from "react";
2121
import type { Torrent, PeerStats } from "rpc/torrent";
2222
import { bytesToHumanReadableStr } from "trutil";
2323
import { TrguiTable, useStandardSelect } from "./common";
@@ -105,9 +105,11 @@ const Columns = AllFields.map((field): ColumnDef<PeerStats> => {
105105
return column;
106106
});
107107

108-
export function PeersTable(props: { torrent: Torrent }) {
109-
const getRowId = useCallback((t: PeerStats) => `${t.address as string}:${t.port as number}`, []);
108+
function getRowId(peer: PeerStats) {
109+
return peer.peer_id !== undefined ? peer.peer_id : `${peer.address as string}:${peer.port as number}`;
110+
}
110111

112+
export function PeersTable(props: { torrent: Torrent }) {
111113
const [selected, selectedReducer] = useStandardSelect();
112114

113115
return <TrguiTable<PeerStats> {...{

src/rpc/transmission.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ export const PeerStatsFields = [
311311
"progress", // double
312312
"rateToClient", // (B/s) number
313313
"rateToPeer", // (B/s) number
314+
"peer_id", // string, available since 4.1.0
314315
] as const;
315316

316317
export type PeerStatsFieldsType = typeof PeerStatsFields[number];

0 commit comments

Comments
 (0)