Skip to content

Commit

Permalink
Fix #19
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed Apr 19, 2024
1 parent a7988cd commit 154bc35
Show file tree
Hide file tree
Showing 8 changed files with 911 additions and 18,389 deletions.
560 changes: 0 additions & 560 deletions __tests__/fixtures/batched-butterfly-hourglass.puml

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions __tests__/fixtures/batched-butterfly-triangle.puml
Original file line number Diff line number Diff line change
@@ -1,41 +1,20 @@
@startuml messages
Alice -[#orange]-> Bob: meet
Alice -[#blue]-> Bob: probe genRanHex0
Bob -[#purple]-> Alice: have-probes
Bob -[#orange]-> Charlie: meet
Bob -[#blue]-> Charlie: probe genRanHex0
Bob -[#blue]-> Charlie: probe genRanHex1
Alice -[#purple]-> Bob: okay-to-send-probes
Charlie -[#purple]-> Bob: have-probes
Charlie -[#orange]-> Alice: meet
Charlie -[#blue]-> Alice: probe genRanHex0
Charlie -[#blue]-> Alice: probe genRanHex1
Charlie -[#blue]-> Alice: probe genRanHex2
Bob -[#blue]-> Alice: probe genRanHex1
Bob -[#purple]-> Charlie: okay-to-send-probes
Alice -[#purple]-> Charlie: have-probes
Alice -[#red]-> Charlie: loop genRanHex0 genRanHex3
Alice -[#purple]-> Bob: have-probes
Charlie -[#blue]-> Bob: probe genRanHex2
Charlie -[#purple]-> Alice: okay-to-send-probes
Charlie -[#red]-> Bob: loop genRanHex0 genRanHex3
Bob -[#purple]-> Alice: okay-to-send-probes
Bob -[#purple]-> Alice: have-probes
Bob -[#purple]-> Charlie: have-probes
Bob -[#red]-> Alice: loop genRanHex0 genRanHex3
Alice -[#blue]-> Bob: probe genRanHex2
Alice -[#blue]-> Bob: probe genRanHex4
Alice -[#purple]-> Bob: okay-to-send-probes
Charlie -[#purple]-> Bob: okay-to-send-probes
Bob -[#blue]-> Alice: probe genRanHex5
Bob -[#blue]-> Charlie: probe genRanHex4
Alice -[#purple]-> Bob: have-probes
Alice -[#blue]-> Charlie: probe genRanHex5
Charlie -[#purple]-> Bob: have-probes
Charlie -[#purple]-> Alice: have-probes
Bob -[#purple]-> Alice: okay-to-send-probes
Bob -[#purple]-> Charlie: okay-to-send-probes
Alice -[#purple]-> Charlie: okay-to-send-probes
Charlie -[#blue]-> Bob: probe genRanHex5
Charlie -[#blue]-> Alice: probe genRanHex4
Bob -[#red]-> Charlie: loop genRanHex5 genRanHex6
Expand Down
17,015 changes: 882 additions & 16,133 deletions __tests__/fixtures/batched-giraffe-hourglass.json

Large diffs are not rendered by default.

1,670 changes: 0 additions & 1,670 deletions __tests__/fixtures/batched-giraffe-hourglass.puml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions __tests__/fixtures/batched-giraffe-triangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"loop-found genRanHex1 genRanHex5",
"[Node#receiveMessage] Alice receives message from Bob",
"[TraceEngine] handling trace message from Bob: trace genRanHex2 genRanHex8 genRanHex10",
"checking if we have seenThisTraceBefore genRanHex2 genRanHex8 genRanHex10 in undefined",
"[Node#lookup-probe] Alice is looking up probe genRanHex2",
"[TraceEngine] forwarding a counter-probe-wise trace message from Bob: trace genRanHex2 genRanHex8 genRanHex10",
"Looking for other leg genRanHex2 genRanHex8 genRanHex10 in {\"Bob\":\"genRanHex10\"}",
Expand Down Expand Up @@ -160,6 +161,7 @@
"[Node#receiveMessage] Bob receives message from Alice",
"[Node#receiveMessage] Bob receives message from Alice",
"[TraceEngine] handling trace message from Alice: trace genRanHex1 genRanHex5 genRanHex7",
"checking if we have seenThisTraceBefore genRanHex1 genRanHex5 genRanHex7 in undefined",
"[Node#lookup-probe] Bob is looking up probe genRanHex1",
"[TraceEngine] forwarding a counter-probe-wise trace message from Alice: trace genRanHex1 genRanHex5 genRanHex7",
"Looking for other leg genRanHex1 genRanHex5 genRanHex7 in {\"Alice\":\"genRanHex7\"}",
Expand All @@ -172,6 +174,7 @@
"Bob raises hand to Charlie",
"[Node#receiveMessage] Bob receives message from Charlie",
"[TraceEngine] handling trace message from Charlie: trace genRanHex0 genRanHex3 genRanHex4",
"checking if we have seenThisTraceBefore genRanHex0 genRanHex3 genRanHex4 in undefined",
"[Node#lookup-probe] Bob is looking up probe genRanHex0",
"[TraceEngine] forwarding a counter-probe-wise trace message from Charlie: trace genRanHex0 genRanHex3 genRanHex4",
"Looking for other leg genRanHex0 genRanHex3 genRanHex4 in {\"Charlie\":\"genRanHex4\"}",
Expand All @@ -180,6 +183,7 @@
"[Node#sendTraceMessage] Bob sends trace message to Alice: trace genRanHex0 genRanHex3 genRanHex4",
"[Node#receiveMessage] Bob receives message from Charlie",
"[TraceEngine] handling trace message from Charlie: trace genRanHex1 genRanHex5 genRanHex6",
"checking if we have seenThisTraceBefore genRanHex1 genRanHex5 genRanHex6 in {\"Alice\":\"genRanHex7\"}",
"[Node#lookup-probe] Bob is looking up probe genRanHex1",
"[TraceEngine] forwarding a counter-probe-wise trace message from Charlie: trace genRanHex1 genRanHex5 genRanHex6",
"Looking for other leg genRanHex1 genRanHex5 genRanHex6 in {\"Alice\":\"genRanHex7\",\"Charlie\":\"genRanHex6\"}",
Expand Down Expand Up @@ -235,6 +239,7 @@
"[Node#receiveMessage] Charlie receives message from Alice",
"[Node#receiveMessage] Charlie receives message from Alice",
"[TraceEngine] handling trace message from Alice: trace genRanHex0 genRanHex3 genRanHex4",
"checking if we have seenThisTraceBefore genRanHex0 genRanHex3 genRanHex4 in undefined",
"[Node#lookup-probe] Charlie is looking up probe genRanHex0",
"[TraceEngine] forwarding a counter-probe-wise trace message from Alice: trace genRanHex0 genRanHex3 genRanHex4",
"Looking for other leg genRanHex0 genRanHex3 genRanHex4 in {\"Alice\":\"genRanHex4\"}",
Expand All @@ -243,6 +248,7 @@
"[Node#sendTraceMessage] Charlie sends trace message to Bob: trace genRanHex0 genRanHex3 genRanHex4",
"[Node#receiveMessage] Charlie receives message from Alice",
"[TraceEngine] handling trace message from Alice: trace genRanHex1 genRanHex5 genRanHex6",
"checking if we have seenThisTraceBefore genRanHex1 genRanHex5 genRanHex6 in undefined",
"[Node#lookup-probe] Charlie is looking up probe genRanHex1",
"[TraceEngine] forwarding a counter-probe-wise trace message from Alice: trace genRanHex1 genRanHex5 genRanHex6",
"Looking for other leg genRanHex1 genRanHex5 genRanHex6 in {\"Alice\":\"genRanHex6\"}",
Expand All @@ -252,12 +258,14 @@
"[Node#receiveMessage] Charlie receives message from Bob",
"[Node#receiveMessage] Charlie receives message from Bob",
"[TraceEngine] handling trace message from Bob: trace genRanHex2 genRanHex8 genRanHex9",
"checking if we have seenThisTraceBefore genRanHex2 genRanHex8 genRanHex9 in undefined",
"[Node#lookup-probe] Charlie is looking up probe genRanHex2",
"[TraceEngine] forwarding a counter-probe-wise trace message from Bob: trace genRanHex2 genRanHex8 genRanHex9",
"Looking for other leg genRanHex2 genRanHex8 genRanHex9 in {\"Bob\":\"genRanHex9\"}",
"[TraceEngine] in the context of trace message from Bob: trace genRanHex2 genRanHex8 genRanHex9, we found these counter-probe-wise next hops: [], and otherLeg undefined",
"[Node#receiveMessage] Charlie receives message from Alice",
"[TraceEngine] handling trace message from Alice: trace genRanHex2 genRanHex8 genRanHex10",
"checking if we have seenThisTraceBefore genRanHex2 genRanHex8 genRanHex10 in {\"Bob\":\"genRanHex9\"}",
"[Node#lookup-probe] Charlie is looking up probe genRanHex2",
"[TraceEngine] forwarding a counter-probe-wise trace message from Alice: trace genRanHex2 genRanHex8 genRanHex10",
"Looking for other leg genRanHex2 genRanHex8 genRanHex10 in {\"Bob\":\"genRanHex9\",\"Alice\":\"genRanHex10\"}",
Expand Down
3 changes: 0 additions & 3 deletions __tests__/fixtures/batched-giraffe-triangle.puml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
@startuml messages
Alice -[#orange]-> Bob: meet
Alice -[#blue]-> Bob: probe genRanHex0
Bob -[#orange]-> Charlie: meet
Bob -[#blue]-> Charlie: probe genRanHex0
Bob -[#blue]-> Charlie: probe genRanHex1
Charlie -[#orange]-> Alice: meet
Charlie -[#blue]-> Alice: probe genRanHex0
Charlie -[#blue]-> Alice: probe genRanHex1
Charlie -[#blue]-> Alice: probe genRanHex2
Expand Down
16 changes: 14 additions & 2 deletions src/engine/tracesengine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,28 @@ export class TracesEngine extends EventEmitter {
this.emit('message', from, `trace ${probeId} ${traceId} ${legId}`);
});
}
seenThisTraceBefore(probeId: string, traceId: string, legId: string): boolean {
const legs = this.getLegsForwarded(probeId, traceId);
this.emit('debug', `checking if we have seenThisTraceBefore ${probeId} ${traceId} ${legId} in ${JSON.stringify(legs)}`);
if (typeof legs === 'undefined') {
return false;
}
return Object.values(legs).includes(legId);
}
handleTraceMessage(sender: string, message: string): void {
this.emit('debug', `[TraceEngine] handling trace message from ${sender}: ${message}`);
const [messageType, probeId, traceId, legId] = message.split(' ');
if (messageType !== 'trace') {
throw new Error(`expected trace message but got ${messageType}`);
}
if (this.wasCreatedByUs(probeId, traceId)) {
this.emit('debug', `loop-found ${probeId} ${traceId}`);
this.emit('loop-found', probeId, traceId);
return;
}
if (messageType !== 'trace') {
throw new Error(`expected trace message but got ${messageType}`);
if (this.seenThisTraceBefore(probeId, traceId, legId)) {
this.emit('debug', `seen this trace before ${probeId} ${traceId} ${legId}`);
return;
}
this.logTraceMessage(sender,probeId, traceId, legId);
this.emit('lookup-probe', probeId, (probeFrom: string[], probeTo: string[]) => {
Expand Down
7 changes: 7 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ function createLine(entry: Entry): string {
if ((entry.message === 'have-probes') || (entry.message === 'okay-to-send-probes')) {
return '';
}
const parts = entry.message.toString().split(' ');
if (parts.length < 2) {
return '';
}
// if ((parts[0] !== 'meet') && (parts[1] !== 'genRanHex2')) {
// return '';
// }
const color = colors[entry.message.toString().split(' ')[0]] || 'black';
return `${entry.sender} -[#${color}]-> ${entry.receiver}: ${entry.message}\n`;
}
Expand Down

0 comments on commit 154bc35

Please sign in to comment.