This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar/src/packet/packet_private.h

143 lines
3.4 KiB
C
Raw Normal View History

#ifndef _PACKET_PRIVATE_H
#define _PACKET_PRIVATE_H
2023-12-11 16:22:46 +08:00
#ifdef __cpluscplus
extern "C"
{
#endif
2023-12-15 18:57:13 +08:00
#include <stdint.h>
#include <stdio.h>
2024-01-26 14:41:40 +08:00
#include "log.h"
#include "tuple.h"
#include "packet.h"
2023-12-15 18:57:13 +08:00
#define PACKET_MAX_LAYERS 32
2024-01-26 14:41:40 +08:00
#define PACKET_LOG_ERROR(format, ...) LOG_ERROR("packet", format, ##__VA_ARGS__)
#define PACKET_LOG_DEBUG(format, ...) LOG_DEBUG("packet", format, ##__VA_ARGS__)
2023-12-15 18:57:13 +08:00
enum ldbc_method
{
LDBC_METHOD_HASH_INT_IP = 1,
LDBC_METHOD_HASH_EXT_IP = 2,
LDBC_METHOD_HASH_INT_IP_AND_EXT_IP = 3,
LDBC_METHOD_HASH_INNERMOST_INT_IP = 4,
LDBC_METHOD_HASH_INNERMOST_EXT_IP = 5,
};
enum packet_direction
{
PACKET_DIRECTION_I2E = 0,
PACKET_DIRECTION_E2I = 1,
};
enum packet_action
{
PACKET_ACTION_FORWARD = 0,
PACKET_ACTION_DROP = 1,
};
enum packet_type
{
PACKET_TYPE_DATA = 0,
PACKET_TYPE_CTRL = 1,
};
struct metadata
{
#define MAX_SID_NUM 8
#define MAX_ROUTE_LEN 64
struct
{
uint16_t list[MAX_SID_NUM];
uint16_t used;
} sid;
struct
{
char data[MAX_ROUTE_LEN];
uint16_t len;
} route;
2024-04-10 17:50:51 +08:00
void *io_ctx;
uint64_t domain;
uint64_t session_id;
enum packet_direction direction;
enum packet_action action;
enum packet_type type;
};
2023-12-15 18:57:13 +08:00
struct packet
{
struct packet_layer layers[PACKET_MAX_LAYERS];
struct packet_layer *frag_layer; // fragment layer
2023-12-15 18:57:13 +08:00
int8_t layers_used;
int8_t layers_size;
const char *data_ptr;
uint16_t data_len;
bool need_free;
struct metadata meta;
2023-12-15 18:57:13 +08:00
};
// return innermost payload
const char *packet_parse(struct packet *pkt, const char *data, uint16_t len);
void packet_print(const struct packet *pkt);
2023-12-15 18:57:13 +08:00
// direction 1: E2I
// direction 0: I2E
uint64_t packet_get_hash(const struct packet *pkt, enum ldbc_method method, int direction);
// return 0: success
// return -1: failed
int packet_set_sid(struct packet *pkt, uint16_t *sid, int num);
// return number of sid
int packet_get_sid(const struct packet *pkt, uint16_t *sid, int size);
// return 0: success
// return -1: failed
int packet_prepend_sid(struct packet *pkt, uint16_t sid);
// return 0: success
// return -1: failed
int packet_append_sid(struct packet *pkt, uint16_t sid);
// return 0: success
// return -1: failed
int packet_set_route_ctx(struct packet *pkt, const char *route, int len);
// return len of route ctx
int packet_get_route_ctx(const struct packet *pkt, char *buff, int size);
2024-04-10 17:50:51 +08:00
void packet_set_io_ctx(struct packet *pkt, void *ctx);
void *packet_get_io_ctx(const struct packet *pkt);
void packet_set_domain(struct packet *pkt, uint64_t domain);
uint64_t packet_get_domain(const struct packet *pkt);
void packet_set_session_id(struct packet *pkt, uint64_t session_id);
uint64_t packet_get_session_id(const struct packet *pkt);
void packet_set_direction(struct packet *pkt, enum packet_direction direction);
enum packet_direction packet_get_direction(const struct packet *pkt);
void packet_set_action(struct packet *pkt, enum packet_action action);
enum packet_action packet_get_action(const struct packet *pkt);
void packet_set_type(struct packet *pkt, enum packet_type type);
enum packet_type packet_get_type(const struct packet *pkt);
struct packet *packet_new(uint16_t pkt_len);
void packet_free(struct packet *pkt);
struct packet *packet_dup(const struct packet *pkt);
const char *packet_get_data(const struct packet *pkt);
uint16_t packet_get_len(const struct packet *pkt);
bool packet_is_fragment(const struct packet *pkt);
2023-12-11 16:22:46 +08:00
#ifdef __cpluscplus
}
#endif
#endif