Skip to content

Commit f8e647d

Browse files
authored
Store IP in order
* begin the feature * add a Constructor to assign 15 characters as maximum to the ip * Add store ip to server socket to * make string pointer so no copy. Only change where the pointers points
1 parent c63f359 commit f8e647d

4 files changed

Lines changed: 21 additions & 9 deletions

File tree

Inc/HALAL/Models/Packets/Order.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010
#include "HALAL/Models/Packets/OrderProtocol.hpp"
1111

1212
class Order : public Packet{
13-
public:
13+
public:
14+
string *remote_ip;
15+
static map<uint16_t,Order*> orders;
1416
virtual void set_callback(void(*callback)(void)) = 0;
1517
virtual void process() = 0;
1618
virtual void parse(OrderProtocol* socket, uint8_t* data) = 0;
19+
void store_ip_order(string &ip){
20+
remote_ip = &ip;
21+
}
1722
void parse(uint8_t* data) override {
1823
parse(nullptr, data);
1924
}
@@ -22,20 +27,17 @@ class Order : public Packet{
2227
}
2328
static void process_data(OrderProtocol* socket, uint8_t* data) {
2429
uint16_t id = Packet::get_id(data);
25-
if (orders.contains(id)) {
30+
if (orders.contains(id)){
2631
orders[id]->parse(socket, data);
2732
orders[id]->process();
2833
}
29-
}
30-
31-
protected:
32-
static map<uint16_t,Order*> orders;
34+
}
3335
};
3436

3537
template<size_t BufferLength,class... Types> requires NotCallablePack<Types*...>
3638
class StackOrder : public StackPacket<BufferLength,Types...>, public Order{
3739
public:
38-
StackOrder(uint16_t id,void(*callback)(void), Types*... values) : StackPacket<BufferLength,Types...>(id,values...), callback(callback) {orders[id] = this;}
40+
StackOrder(uint16_t id,void(*callback)(void), Types*... values) : StackPacket<BufferLength,Types...>(id,values...), callback(callback) {orders[id] = this; }
3941
StackOrder(uint16_t id, Types*... values) : StackPacket<BufferLength,Types...>(id,values...) {orders[id] = this;}
4042
void(*callback)(void) = nullptr;
4143
void set_callback(void(*callback)(void)) override {

Inc/HALAL/Services/Communication/Ethernet/TCP/Socket.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "HALAL/Models/Packets/Packet.hpp"
1212
#include "HALAL/Models/Packets/Order.hpp"
1313
#include "HALAL/Models/Packets/OrderProtocol.hpp"
14+
#include "HALAL/Models/Packets/Packet.hpp"
1415
#ifdef HAL_ETH_MODULE_ENABLED
1516

1617
#define PBUF_POOL_MEMORY_DESC_POSITION 8

Src/HALAL/Services/Communication/Ethernet/TCP/ServerSocket.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ void ServerSocket::process_data(){
121121
rx_packet_buffer.pop();
122122
uint8_t* new_data = (uint8_t*)(packet->payload);
123123
tcp_recved(client_control_block, packet->tot_len);
124-
Order::process_data(this, new_data);
124+
uint16_t id = Packet::get_id(new_data);
125+
if (Order::orders.contains(id)) {
126+
Order::orders[id]->store_ip_order(remote_ip.string_address);
127+
Order::process_data(this, new_data);
128+
}
125129
pbuf_free(packet);
126130
}
127131
}

Src/HALAL/Services/Communication/Ethernet/TCP/Socket.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ void Socket::process_data(){
142142
rx_packet_buffer.pop();
143143
uint8_t* new_data = (uint8_t*)(packet->payload);
144144
tcp_recved(socket_control_block, packet->tot_len);
145-
Order::process_data(this, new_data);
145+
uint16_t id = Packet::get_id(new_data);
146+
if (Order:: orders.contains(id)) {
147+
Order::orders[id]->store_ip_order(remote_ip.string_address);
148+
Order::process_data(this, new_data);
149+
}
150+
146151
pbuf_free(packet);
147152
}
148153
}

0 commit comments

Comments
 (0)