Skip to content

Commit 312fb02

Browse files
committed
fix: check neighbors before sending packet
1 parent be89df4 commit 312fb02

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/types/packet.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ export class Packet extends Graphics {
193193
export function sendPacket(
194194
viewgraph: ViewGraph,
195195
packetType: string,
196-
originId: number,
197-
destinationId: number,
196+
originId: DeviceId,
197+
destinationId: DeviceId,
198198
) {
199199
console.log(
200200
`Sending ${packetType} packet from ${originId} to ${destinationId}`,
@@ -233,5 +233,11 @@ export function sendPacket(
233233
console.warn(`No se encontró un dispositivo con ID ${originId}.`);
234234
return;
235235
}
236-
packet.traverseEdge(originConnections[0], originId);
236+
let firstEdge = originConnections.find((edge) => {
237+
return edge.otherEnd(originId) === destinationId;
238+
});
239+
if (firstEdge === undefined) {
240+
firstEdge = originConnections[0];
241+
}
242+
packet.traverseEdge(firstEdge, originId);
237243
}

0 commit comments

Comments
 (0)