Skip to content

Commit d9e7c1e

Browse files
committed
fix: data packets not showing
1 parent e2a4fb5 commit d9e7c1e

File tree

1 file changed

+60
-19
lines changed

1 file changed

+60
-19
lines changed

src/utils/getPacketForStep.ts

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,116 @@
1-
import { PACKET_TYPES } from '@/data'
1+
import { PACKET_TYPES, type PacketTypes } from '@/data'
2+
import type { ValueOf } from './types'
23

34
export type PacketStep = {
45
id: string
5-
type: {
6-
name: string
7-
color: string
8-
}
6+
type: ValueOf<PacketTypes>
97
from: 'client' | 'server'
108
to: 'client' | 'server'
119
data?: string
1210
}
1311

1412
function getPacketForStep(step: number) {
13+
if (step === 3) {
14+
console.log('step % 2 === 1', step % 2 === 1)
15+
}
16+
if (step === 4) {
17+
console.log('step % 2 === 1', step % 2 === 1)
18+
}
19+
if (step === 5) {
20+
console.log('step % 2 === 1', step % 2 === 1)
21+
}
22+
if (step === 6) {
23+
console.log('step % 2 === 1', step % 2 === 1)
24+
}
25+
if (step === 7) {
26+
console.log('step % 2 === 1', step % 2 === 1)
27+
}
28+
if (step === 8) {
29+
console.log('step % 2 === 1', step % 2 === 1)
30+
}
1531
const packetStepMap: Record<number, PacketStep | null> = {
1632
0: {
17-
// SYN
1833
id: `packet-${Date.now()}`,
1934
type: PACKET_TYPES.SYN,
2035
from: 'client',
2136
to: 'server',
2237
},
2338
1: {
24-
// SYN-ACK
2539
id: `packet-${Date.now()}`,
2640
type: PACKET_TYPES.SYN_ACK,
2741
from: 'server',
2842
to: 'client',
2943
},
3044
2: {
31-
// ACK
3245
id: `packet-${Date.now()}`,
3346
type: PACKET_TYPES.ACK,
3447
from: 'client',
3548
to: 'server',
3649
},
37-
3: null, // DATA 1
38-
4: null, // DATA 2
39-
5: null, // DATA 3
40-
6: null, // DATA 4
41-
7: null, // DATA 5
50+
3: {
51+
id: `packet-${Date.now()}`,
52+
type: PACKET_TYPES.DATA,
53+
from: step % 2 === 1 ? 'client' : 'server',
54+
to: step % 2 === 1 ? 'server' : 'client',
55+
data: 'Data Packer 1',
56+
},
57+
4: {
58+
id: `packet-${Date.now()}`,
59+
type: PACKET_TYPES.DATA,
60+
from: step % 2 === 1 ? 'client' : 'server',
61+
to: step % 2 === 1 ? 'server' : 'client',
62+
data: 'Data Packer 2',
63+
},
64+
65+
5: {
66+
id: `packet-${Date.now()}`,
67+
type: PACKET_TYPES.DATA,
68+
from: step % 2 === 1 ? 'client' : 'server',
69+
to: step % 2 === 1 ? 'server' : 'client',
70+
data: 'Data Packer 3',
71+
},
72+
73+
6: {
74+
id: `packet-${Date.now()}`,
75+
type: PACKET_TYPES.DATA,
76+
from: step % 2 === 1 ? 'client' : 'server',
77+
to: step % 2 === 1 ? 'server' : 'client',
78+
data: 'Data Packer 4',
79+
},
80+
81+
7: {
82+
id: `packet-${Date.now()}`,
83+
type: PACKET_TYPES.DATA,
84+
from: step % 2 === 1 ? 'client' : 'server',
85+
to: step % 2 === 1 ? 'server' : 'client',
86+
data: 'Data Packer 5',
87+
},
4288
8: {
43-
// DATA 6
4489
id: `packet-${Date.now()}`,
4590
type: PACKET_TYPES.DATA,
4691
from: step % 2 === 1 ? 'client' : 'server',
4792
to: step % 2 === 1 ? 'server' : 'client',
48-
data: `Data Packet ${Math.floor(step / 2)}`,
93+
data: 'Data Packer 5',
4994
},
5095
9: {
51-
// FIN from client
5296
id: `packet-${Date.now()}`,
5397
type: PACKET_TYPES.FIN,
5498
from: 'client',
5599
to: 'server',
56100
},
57101
10: {
58-
// ACK from server
59102
id: `packet-${Date.now()}`,
60103
type: PACKET_TYPES.ACK,
61104
from: 'server',
62105
to: 'client',
63106
},
64107
11: {
65-
// FIN from server
66108
id: `packet-${Date.now()}`,
67109
type: PACKET_TYPES.FIN,
68110
from: 'server',
69111
to: 'client',
70112
},
71113
12: {
72-
// ACK from client
73114
id: `packet-${Date.now()}`,
74115
type: PACKET_TYPES.ACK,
75116
from: 'client',

0 commit comments

Comments
 (0)