Skip to content

Commit

Permalink
Use only one packer for 0.6 and 0.7
Browse files Browse the repository at this point in the history
Keeps the code cleaner
  • Loading branch information
ChillerDragon committed Dec 19, 2024
1 parent 6f571b3 commit ae924fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 48 deletions.
59 changes: 16 additions & 43 deletions src/packet.asm
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,18 @@
push rdx
push rdi
push rsi
push r8

; copy dest
mov dword edx, [udp_payload_index]
lea rax, [udp_send_buf + PACKET_HEADER_LEN + edx]
; copy source
mov rdi, %1
; copy size
mov rsi, %2
call mem_copy

add dword [udp_payload_index], %2

pop rsi
pop rdi
pop rdx
pop rax
%endmacro

; packet6_pack_raw [buffer] [buffer size]
%macro packet6_pack_raw 2
; r8 is packet header len depending on connection version
; do not overwrite this anywhere in this function!
push rax
push rdx
push rdi
push rsi
call get_packet_header_len
mov r8d, eax
pop rax

; copy dest
mov dword edx, [udp_payload_index]
lea rax, [udp_send_buf + PACKET6_HEADER_LEN + edx]
lea rax, [udp_send_buf + r8d + edx]
; copy source
mov rdi, %1
; copy size
Expand All @@ -66,6 +50,7 @@

add dword [udp_payload_index], %2

pop r8
pop rsi
pop rdi
pop rdx
Expand All @@ -77,37 +62,25 @@
push rdx
push rdi
push rcx
push r8

; copy one byte
mov dword edx, [udp_payload_index]
lea rdi, [udp_send_buf + PACKET_HEADER_LEN + edx]
mov byte [rdi], %1

; increment payload index
inc edx
mov dword [udp_payload_index], edx

pop rcx
pop rdi
pop rdx
pop rax
%endmacro

%macro packet6_pack_byte 1
; r8 is packet header len depending on connection version
; do not overwrite this anywhere in this function!
push rax
push rdx
push rdi
push rcx
call get_packet_header_len
mov r8d, eax
pop rax

; copy one byte
mov dword edx, [udp_payload_index]
lea rdi, [udp_send_buf + PACKET6_HEADER_LEN + edx]
lea rdi, [udp_send_buf + r8d + edx]
mov byte [rdi], %1

; increment payload index
inc edx
mov dword [udp_payload_index], edx

pop r8
pop rcx
pop rdi
pop rdx
Expand Down
2 changes: 1 addition & 1 deletion src/packet_packer.asm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ send_packet6:
call set_packet_header

; append ddnet security token at the end of all packet payloads
packet6_pack_raw peer_token, 4
packet_pack_raw peer_token, 4

; buf
mov rax, udp_send_buf
Expand Down
8 changes: 4 additions & 4 deletions src/send_control.asm
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ send_ctrl_msg_connect6:
push rax


packet6_pack_byte MSG6_CTRL_CONNECT
packet6_pack_raw MAGIC_TKEN, 4
packet_pack_byte MSG6_CTRL_CONNECT
packet_pack_raw MAGIC_TKEN, 4

mov byte [out_packet_header_flags], PACKETFLAG6_CONTROL
mov byte [out_packet_header_num_chunks], 0
Expand All @@ -44,8 +44,8 @@ send_ctrl_msg_connect6:
send_ctrl6_msg_ack_accept:
push rax

packet6_pack_byte MSG6_CTRL_ACCEPT
; packet6_pack_raw [peer_token], 4
packet_pack_byte MSG6_CTRL_ACCEPT
; packet_pack_raw [peer_token], 4

mov byte [out_packet_header_flags], PACKETFLAG6_CONTROL
mov byte [out_packet_header_num_chunks], 0
Expand Down

0 comments on commit ae924fa

Please sign in to comment.