Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/typepayload #200

Merged
merged 19 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
src/commands_creator.c: resend cmd
  • Loading branch information
angelskieglazki committed Apr 6, 2021
commit d52c97af5b539c3a6567f62408fcedc92d7fa947
20 changes: 20 additions & 0 deletions src/commands_creator.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,24 @@ uint8_t* createCmdConnectPacket(ksnetEvMgrClass *event_manager, char *name, char
free(full_type);

return (uint8_t *)packet;
}


// Create resend command buffer and Send command to r-host
// Command data format: to, cmd, data, data_len
uint8_t* createCmdResendPacket(char *to, uint8_t cmd, void *data, size_t data_len, size_t *size_out) {


size_t ptr = 0;
const size_t to_len = strlen(to) + 1;

*size_out = to_len + sizeof(cmd) + data_len;
uint8_t *packet = malloc(*size_out);
memset(packet, '\0', *size_out);

memcpy(packet + ptr, to, to_len); ptr += to_len;
memcpy(packet + ptr, &cmd, sizeof(uint8_t)); ptr += sizeof(uint8_t);
memcpy(packet + ptr, data, data_len); ptr += data_len;

return (uint8_t*)packet;
}
2 changes: 1 addition & 1 deletion src/commands_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ typedef struct connect_r_packet {
uint8_t* createCmdConnectRPacketUdp(ksnetEvMgrClass *event_manager, size_t *size_out);
uint8_t* createCmdConnectRPacketTcp(ksnetEvMgrClass *event_manager, size_t *size_out);
uint8_t* createCmdConnectPacket(ksnetEvMgrClass *event_manager, char *name, char *addr, uint32_t port, size_t *size_out);

uint8_t* createCmdResendPacket(char *to, uint8_t cmd, void *data, size_t data_len, size_t *size_out);
#endif
21 changes: 0 additions & 21 deletions src/net_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,27 +454,6 @@ ksnet_arp_data *ksnCoreSendCmdto(ksnCoreClass *kc, char *to, uint8_t cmd,
// Send to r-host
else {
ksn_printf(ke, MODULE, DEBUG, "Sending a command %d is not possible, because peer: \"%s\" not found.\n", (int)cmd, to);
// If connected to r-host
// char *r_host = ke->teo_cfg.r_host_name;
// if(r_host[0] && (arp = (ksnet_arp_data *)ksnetArpGet(kc->ka, r_host)) != NULL) {

// #ifdef DEBUG_KSNET
// ksn_printf(ke, MODULE, DEBUG,
// "resend command to peer \"%s\" to r-host\n", to);
// #endif

// // Create resend command buffer and Send command to r-host
// // Command data format: to, cmd, data, data_len
// size_t ptr = 0;
// const size_t to_len = strlen(to) + 1;
// const size_t buf_len = to_len + sizeof(cmd) + data_len;
// char *buf = malloc(buf_len);
// memcpy(buf + ptr, to, to_len); ptr += to_len;
// memcpy(buf + ptr, &cmd, sizeof(uint8_t)); ptr += sizeof(uint8_t);
// memcpy(buf + ptr, data, data_len); ptr += data_len;
// ksnCoreSendto(kc, arp->addr, arp->port, CMD_RESEND, buf, buf_len);
// free(buf);
// }
}

return arp;
Expand Down