30 #ifndef FILETRANSFER_H 31 #define FILETRANSFER_H 75 #define PACKET_MAX_LENGTH 1500 77 #define TRANSFER_MAX_PROTOCOL_PACKET 225 78 #define TRANSFER_MAX_FILENAME 128 79 #ifndef COSMOS_WIN_BUILD_MSVC 80 #define TRANSFER_QUEUE_LIMIT ((TRANSFER_MAX_PROTOCOL_PACKET-(COSMOS_SIZEOF(PACKET_TYPE)+COSMOS_SIZEOF(PACKET_NODE_ID_TYPE)+COSMOS_SIZEOF(PACKET_TX_ID_TYPE)+COSMOS_MAX_NAME))/(COSMOS_SIZEOF(PACKET_TX_ID_TYPE))) 82 #define TRANSFER_QUEUE_LIMIT 100 149 #define PACKET_HEADER_OFFSET_TYPE 0 150 #define PACKET_HEADER_OFFSET_CRC (PACKET_HEADER_OFFSET_TYPE + COSMOS_SIZEOF(PACKET_TYPE)) 151 #define PACKET_HEADER_OFFSET_TOTAL (PACKET_HEADER_OFFSET_CRC + COSMOS_SIZEOF(PACKET_CRC)) 152 #define PACKET_HEADER_OFFSET_NODE_ID (PACKET_HEADER_OFFSET_TOTAL) 153 #define PACKET_HEADER_OFFSET_NODE_NAME (PACKET_HEADER_OFFSET_TOTAL + COSMOS_SIZEOF(PACKET_NODE_ID_TYPE)) 164 #define PACKET_HEARTBEAT_OFFSET_NODE_ID (PACKET_HEADER_OFFSET_TOTAL) 165 #define PACKET_HEARTBEAT_OFFSET_NODE_NAME (PACKET_HEADER_OFFSET_NODE_NAME) 166 #define PACKET_HEARTBEAT_OFFSET_BEAT_PERIOD (PACKET_HEARTBEAT_OFFSET_NODE_NAME + COSMOS_MAX_NAME) 167 #define PACKET_HEARTBEAT_OFFSET_THROUGHPUT (PACKET_HEARTBEAT_OFFSET_BEAT_PERIOD + 1) 168 #define PACKET_HEARTBEAT_OFFSET_FUNIXTIME (PACKET_HEARTBEAT_OFFSET_THROUGHPUT + 4) 169 #define PACKET_HEARTBEAT_OFFSET_TOTAL (PACKET_HEARTBEAT_OFFSET_FUNIXTIME + 8) 178 #define PACKET_MESSAGE_OFFSET_NODE_ID (PACKET_HEADER_OFFSET_TOTAL) 179 #define PACKET_MESSAGE_OFFSET_LENGTH (PACKET_MESSAGE_OFFSET_NODE_ID + 1) 180 #define PACKET_MESSAGE_OFFSET_BYTES (PACKET_MESSAGE_OFFSET_LENGTH + 1) 181 #define PACKET_MESSAGE_OFFSET_TOTAL (PACKET_MESSAGE_OFFSET_BYTES + TRANSFER_MAX_PROTOCOL_PACKET - 2) 190 #define PACKET_COMMAND_OFFSET_NODE_ID (PACKET_HEADER_OFFSET_TOTAL) 191 #define PACKET_COMMAND_OFFSET_LENGTH (PACKET_COMMAND_OFFSET_NODE_ID + 1) 192 #define PACKET_COMMAND_OFFSET_BYTES (PACKET_COMMAND_OFFSET_LENGTH + 1) 193 #define PACKET_COMMAND_OFFSET_TOTAL (PACKET_COMMAND_OFFSET_BYTES + TRANSFER_MAX_PROTOCOL_PACKET - 2) 201 #define PACKET_REQQUEUE_OFFSET_NODE_ID (PACKET_HEADER_OFFSET_TOTAL) 202 #define PACKET_REQQUEUE_OFFSET_NODE_NAME (PACKET_HEADER_OFFSET_NODE_NAME) 203 #define PACKET_REQQUEUE_OFFSET_TOTAL (PACKET_REQQUEUE_OFFSET_NODE_ID + COSMOS_MAX_NAME) 212 #define PACKET_QUEUE_OFFSET_NODE_ID (PACKET_HEADER_OFFSET_TOTAL) 213 #define PACKET_QUEUE_OFFSET_NODE_NAME (PACKET_HEADER_OFFSET_NODE_NAME) 214 #define PACKET_QUEUE_OFFSET_TX_ID (PACKET_QUEUE_OFFSET_NODE_NAME + COSMOS_MAX_NAME) 215 #define PACKET_QUEUE_OFFSET_TOTAL (PACKET_QUEUE_OFFSET_TX_ID + COSMOS_SIZEOF(PACKET_TX_ID_TYPE) * TRANSFER_QUEUE_LIMIT) 224 #define PACKET_REQMETA_OFFSET_NODE_ID (PACKET_HEADER_OFFSET_TOTAL) 225 #define PACKET_REQMETA_OFFSET_NODE_NAME (PACKET_HEADER_OFFSET_NODE_NAME) 226 #define PACKET_REQMETA_OFFSET_TX_ID (PACKET_REQMETA_OFFSET_NODE_NAME + COSMOS_MAX_NAME) 227 #define PACKET_REQMETA_OFFSET_TOTAL (PACKET_REQMETA_OFFSET_TX_ID + COSMOS_SIZEOF(PACKET_TX_ID_TYPE) * TRANSFER_QUEUE_LIMIT) 238 #define PACKET_METALONG_OFFSET_NODE_NAME (PACKET_HEADER_OFFSET_TOTAL) 239 #define PACKET_METALONG_OFFSET_TX_ID (PACKET_METALONG_OFFSET_NODE_NAME + COSMOS_MAX_NAME) 240 #define PACKET_METALONG_OFFSET_AGENT_NAME (PACKET_METALONG_OFFSET_TX_ID + COSMOS_SIZEOF(PACKET_TX_ID_TYPE)) 241 #define PACKET_METALONG_OFFSET_FILE_NAME (PACKET_METALONG_OFFSET_AGENT_NAME + COSMOS_MAX_NAME) 242 #define PACKET_METALONG_OFFSET_FILE_SIZE (PACKET_METALONG_OFFSET_FILE_NAME + TRANSFER_MAX_FILENAME) 243 #define PACKET_METALONG_OFFSET_TOTAL (PACKET_METALONG_OFFSET_FILE_SIZE + COSMOS_SIZEOF(PACKET_FILE_SIZE_TYPE)) 254 #define PACKET_METASHORT_OFFSET_NODE_ID (PACKET_HEADER_OFFSET_TOTAL) 255 #define PACKET_METASHORT_OFFSET_TX_ID (PACKET_METASHORT_OFFSET_NODE_ID + COSMOS_SIZEOF(PACKET_NODE_ID_TYPE)) 256 #define PACKET_METASHORT_OFFSET_AGENT_NAME (PACKET_METASHORT_OFFSET_TX_ID + COSMOS_SIZEOF(PACKET_TX_ID_TYPE)) 257 #define PACKET_METASHORT_OFFSET_FILE_NAME (PACKET_METASHORT_OFFSET_AGENT_NAME + COSMOS_MAX_NAME) 258 #define PACKET_METASHORT_OFFSET_FILE_SIZE (PACKET_METASHORT_OFFSET_FILE_NAME + TRANSFER_MAX_FILENAME) 259 #define PACKET_METASHORT_OFFSET_TOTAL (PACKET_METASHORT_OFFSET_FILE_SIZE + COSMOS_SIZEOF(PACKET_FILE_SIZE_TYPE)) 269 #define PACKET_REQDATA_OFFSET_NODE_ID (PACKET_HEADER_OFFSET_TOTAL) 270 #define PACKET_REQDATA_OFFSET_TX_ID (PACKET_REQDATA_OFFSET_NODE_ID + COSMOS_SIZEOF(PACKET_NODE_ID_TYPE)) 271 #define PACKET_REQDATA_OFFSET_HOLE_START (PACKET_REQDATA_OFFSET_TX_ID + COSMOS_SIZEOF(PACKET_TX_ID_TYPE)) 272 #define PACKET_REQDATA_OFFSET_HOLE_END (PACKET_REQDATA_OFFSET_HOLE_START + COSMOS_SIZEOF(PACKET_FILE_SIZE_TYPE)) 273 #define PACKET_REQDATA_OFFSET_TOTAL (PACKET_REQDATA_OFFSET_HOLE_END + COSMOS_SIZEOF(PACKET_FILE_SIZE_TYPE)) 284 #define PACKET_DATA_OFFSET_NODE_ID (PACKET_HEADER_OFFSET_TOTAL) 285 #define PACKET_DATA_OFFSET_TX_ID (PACKET_DATA_OFFSET_NODE_ID + COSMOS_SIZEOF(PACKET_NODE_ID_TYPE)) 286 #define PACKET_DATA_OFFSET_BYTE_COUNT (PACKET_DATA_OFFSET_TX_ID + COSMOS_SIZEOF(PACKET_TX_ID_TYPE)) 287 #define PACKET_DATA_OFFSET_CHUNK_START (PACKET_DATA_OFFSET_BYTE_COUNT + COSMOS_SIZEOF(PACKET_CHUNK_SIZE_TYPE)) 288 #define PACKET_DATA_OFFSET_CHUNK (PACKET_DATA_OFFSET_CHUNK_START + COSMOS_SIZEOF(PACKET_FILE_SIZE_TYPE)) 289 #define PACKET_DATA_OFFSET_HEADER_TOTAL (PACKET_DATA_OFFSET_CHUNK) 297 #define PACKET_COMPLETE_OFFSET_NODE_ID (PACKET_HEADER_OFFSET_TOTAL) 298 #define PACKET_COMPLETE_OFFSET_TX_ID (PACKET_COMPLETE_OFFSET_NODE_ID + COSMOS_SIZEOF(PACKET_NODE_ID_TYPE)) 299 #define PACKET_COMPLETE_OFFSET_TOTAL (PACKET_COMPLETE_OFFSET_TX_ID + COSMOS_SIZEOF(PACKET_TX_ID_TYPE)) 307 #define PACKET_CANCEL_OFFSET_NODE_ID (PACKET_HEADER_OFFSET_TOTAL) 308 #define PACKET_CANCEL_OFFSET_TX_ID (PACKET_CANCEL_OFFSET_NODE_ID + COSMOS_SIZEOF(PACKET_NODE_ID_TYPE)) 309 #define PACKET_CANCEL_OFFSET_TOTAL (PACKET_CANCEL_OFFSET_TX_ID + COSMOS_SIZEOF(PACKET_TX_ID_TYPE)) 372 bool IS_DATA(
const unsigned char);
#define TRANSFER_MAX_PROTOCOL_PACKET
Definition: transferlib.h:77
PACKET_BYTE length
Definition: transferlib.h:174
Definition: transferlib.h:205
uint8_t PACKET_TYPE
Definition: transferlib.h:141
PACKET_NODE_ID_TYPE node_id
Definition: transferlib.h:185
void extract_cancel(vector< PACKET_BYTE > &packet, packet_struct_cancel &cancel)
Definition: transferlib.cpp:99
#define TRANSFER_MAX_FILENAME
Definition: transferlib.h:78
PACKET_UNIXTIME_TYPE throughput
Definition: transferlib.h:160
void extract_reqdata(vector< PACKET_BYTE > &packet, packet_struct_reqdata &reqdata)
Definition: transferlib.cpp:150
PACKET_FILE_SIZE_TYPE chunk_end
Definition: transferlib.h:335
static const unsigned char STATE_REQMETA
Definition: transferlib.h:91
int32_t load_nodeids()
Definition: transferlib.cpp:549
void make_reqqueue_packet(vector< PACKET_BYTE > &packet, PACKET_NODE_ID_TYPE node_id, string node_name)
Definition: transferlib.cpp:257
PACKET_UNIXTIME_TYPE funixtime
Definition: transferlib.h:161
Definition: transferlib.h:291
PACKET_NODE_ID_TYPE node_id
Definition: transferlib.h:313
void make_command_packet(vector< PACKET_BYTE > &packet, PACKET_NODE_ID_TYPE node_id, string command)
Definition: transferlib.cpp:348
void extract_complete(vector< PACKET_BYTE > &packet, packet_struct_complete &complete)
Definition: transferlib.cpp:71
Definition: transferlib.h:332
bool IS_PUT_REQUEST(const unsigned char)
Definition: transferlib.h:338
void extract_data(vector< PACKET_BYTE > &packet, packet_struct_data &data)
uint16_t PACKET_CHUNK_SIZE_TYPE
Definition: transferlib.h:145
PACKET_NODE_ID_TYPE node_id
Definition: transferlib.h:263
packet_struct_heartbeat heartbeat
Definition: transferlib.h:319
#define COSMOS_MAX_NAME
Largest JSON name.
Definition: cosmos-defs.h:55
void print_cstring(uint8_t *buf, int siz)
Definition: transferlib.cpp:424
void show_fstream_state(std::ifstream &out)
------------— code above this line has be checked and de-Jonny-fied
Definition: transferlib.cpp:371
bool IS_DATA(const unsigned char)
Definition: transferlib.cpp:42
PACKET_CHUNK_SIZE_TYPE byte_count
Definition: transferlib.h:279
FILE * fp
Definition: transferlib.h:359
packet_struct_metashort metashort
Definition: transferlib.h:326
void extract_metadata(vector< PACKET_BYTE > &packet, packet_struct_metalong &meta)
Definition: transferlib.cpp:204
Definition: transferlib.h:155
void make_data_packet(vector< PACKET_BYTE > &packet, packet_struct_data data)
packet_struct_data data
Definition: transferlib.h:324
int32_t lookup_node_id(string node_name)
Definition: transferlib.cpp:514
PACKET_TX_ID_TYPE tx_id
Definition: transferlib.h:314
bool IS_COMPLETE(const unsigned char)
Definition: transferlib.cpp:45
static const unsigned char PACKET_QUEUE
Definition: transferlib.h:109
void print_cstring_hex_with_index(uint8_t *buf, int siz)
Definition: transferlib.cpp:461
PACKET_NODE_ID_TYPE node_id
Definition: transferlib.h:197
void print_cstring_hex(uint8_t *buf, int siz)
Definition: transferlib.cpp:452
static const unsigned char STATE_QUEUE
Definition: transferlib.h:90
uint16_t PACKET_CRC
Definition: transferlib.h:142
double savetime
Definition: transferlib.h:354
static const unsigned char STATE_METADATA
Definition: transferlib.h:92
static const unsigned char PACKET_METADATA
Definition: transferlib.h:103
packet_struct_queue queue
Definition: transferlib.h:321
bool IS_REQDATA(const unsigned char)
Definition: transferlib.cpp:43
void make_complete_packet(vector< PACKET_BYTE > &packet, packet_struct_complete complete)
Definition: transferlib.cpp:54
packet_struct_metalong metalong
Definition: transferlib.h:325
PACKET_TYPE salt_type(PACKET_TYPE type)
Definition: transferlib.cpp:485
Data Management header file.
string node_name
Definition: agent_001.cpp:46
PACKET_BYTE length
Definition: transferlib.h:186
static const unsigned char STATE_COMPLETE
Definition: transferlib.h:96
PACKET_TX_ID_TYPE tx_id
Definition: transferlib.h:264
PACKET_FILE_SIZE_TYPE chunk_start
Definition: transferlib.h:334
string lookup_node_id_name(PACKET_NODE_ID_TYPE node_id)
Definition: transferlib.cpp:536
Definition: transferlib.h:317
static const unsigned char STATE_REQQUEUE
Definition: transferlib.h:89
deque< file_progress > file_info
Definition: transferlib.h:358
static const unsigned char STATUS_ALL_GOOD
Definition: transferlib.h:120
PACKET_TX_ID_TYPE tx_id
Definition: transferlib.h:294
void extract_message(vector< PACKET_BYTE > &packet, packet_struct_message &message)
Definition: transferlib.cpp:341
static const unsigned char STATUS_3
Definition: transferlib.h:130
bool IS_REQUEST(const unsigned char)
Definition: transferlib.h:183
void make_cancel_packet(vector< PACKET_BYTE > &packet, packet_struct_cancel cancel)
Definition: transferlib.cpp:82
static const unsigned char STATUS_NEED_METADATA
Definition: transferlib.h:125
int32_t PACKET_FILE_SIZE_TYPE
Definition: transferlib.h:146
int32_t check_node_id(PACKET_NODE_ID_TYPE node_id)
Definition: transferlib.cpp:494
PACKET_NODE_ID_TYPE node_id
Definition: transferlib.h:207
bool IS_GET_REQUEST(const unsigned char)
uint8_t message[300]
Definition: kpc9612p_send.cpp:36
Definition: transferlib.h:86
Headers and definitions common to all COSMOS.
void unable_to_remove(string filename)
Definition: transferlib.cpp:480
PACKET_TX_ID_TYPE tx_id
Definition: transferlib.h:278
static const unsigned char STATE_SIZE
Definition: transferlib.h:97
Definition: transferlib.h:195
void make_message_packet(vector< PACKET_BYTE > &packet, PACKET_NODE_ID_TYPE node_id, string message)
Definition: transferlib.cpp:325
Definition: transferlib.h:261
void make_heartbeat_packet(vector< PACKET_BYTE > &packet, PACKET_NODE_ID_TYPE node_id, string node_name, uint8_t beat_period, uint32_t throughput, uint32_t funixtime)
Definition: transferlib.cpp:299
void extract_command(vector< PACKET_BYTE > &packet, packet_struct_command &command)
Definition: transferlib.cpp:364
#define TRANSFER_QUEUE_LIMIT
Definition: transferlib.h:80
string command
Definition: add_radio.cpp:27
uint32_t PACKET_UNIXTIME_TYPE
Definition: transferlib.h:147
static const unsigned char PACKET_REQDATA
Definition: transferlib.h:105
static const unsigned char STATUS_SUCCESS
Definition: transferlib.h:124
void extract_heartbeat(vector< PACKET_BYTE > &packet, packet_struct_heartbeat &heartbeat)
Definition: transferlib.cpp:316
static const unsigned char STATE_DATA
Definition: transferlib.h:94
static const unsigned char PACKET_MESSAGE
Definition: transferlib.h:112
PACKET_NODE_ID_TYPE node_id
Definition: transferlib.h:277
uint8_t PACKET_NODE_ID_TYPE
Definition: transferlib.h:143
uint8_t PACKET_TX_ID_TYPE
Definition: transferlib.h:144
packet_struct_raw raw
Definition: transferlib.h:329
void make_reqdata_packet(vector< PACKET_BYTE > &packet, packet_struct_reqdata reqdata)
Definition: transferlib.cpp:131
bool IS_DELETE_REQUEST(const unsigned char)
PACKET_NODE_ID_TYPE node_id
Definition: transferlib.h:303
Definition: transferlib.h:171
static const unsigned char PACKET_COMMAND
Definition: transferlib.h:113
bool IS_METADATA(const unsigned char)
Definition: transferlib.cpp:41
int32_t set_node_id(PACKET_NODE_ID_TYPE node_id, string node_name)
string agent_name
Definition: agent_001.cpp:47
bool IS_REQMETA(const unsigned char)
Definition: transferlib.cpp:44
Definition: transferlib.h:275
#define PACKET_MAX_LENGTH
Definition: transferlib.h:75
PACKET_FILE_SIZE_TYPE hole_start
Definition: transferlib.h:265
uint8_t PACKET_BYTE
Definition: transferlib.h:140
Definition: transferlib.h:118
packet_struct_reqqueue reqqueue
Definition: transferlib.h:320
vector< string > get_nodeids()
Definition: transferlib.cpp:616
PACKET_FILE_SIZE_TYPE hole_end
Definition: transferlib.h:266
static const unsigned char PACKET_REQMETA
Definition: transferlib.h:106
Definition: transferlib.h:311
PACKET_FILE_SIZE_TYPE chunk_start
Definition: transferlib.h:280
void print_cstring_with_index(uint8_t *buf, int siz)
Definition: transferlib.cpp:433
static const unsigned char STATUS_NO_FILE_FOUND
Definition: transferlib.h:122
PACKET_NODE_ID_TYPE node_id
Definition: transferlib.h:157
Definition: transferlib.h:101
packet_struct_cancel cancel
Definition: transferlib.h:323
char buf[128]
Definition: rw_test.cpp:40
void make_queue_packet(vector< PACKET_BYTE > &packet, PACKET_NODE_ID_TYPE node_id, string node_name, vector< PACKET_TX_ID_TYPE > queue)
Definition: transferlib.cpp:277
static const unsigned char STATE_NONE
Definition: transferlib.h:88
static const unsigned char STATE_CANCEL
Definition: transferlib.h:95
static const unsigned char PACKET_HEARTBEAT
Definition: transferlib.h:111
PACKET_NODE_ID_TYPE node_id
Definition: transferlib.h:173
static const unsigned char STATE_REQDATA
Definition: transferlib.h:93
static const unsigned char STATUS_2
Definition: transferlib.h:129
void make_metadata_packet(vector< PACKET_BYTE > &packet, packet_struct_metalong meta)
Definition: transferlib.cpp:163
static const unsigned char PACKET_DATA
Definition: transferlib.h:104
void extract_queue(vector< PACKET_BYTE > &packet, packet_struct_queue &queue)
Definition: transferlib.cpp:292
PACKET_BYTE beat_period
Definition: transferlib.h:159
static const unsigned char PACKET_CANCEL
Definition: transferlib.h:108
void make_reqmeta_packet(vector< PACKET_BYTE > &packet, PACKET_NODE_ID_TYPE node_id, string node_name, vector< PACKET_TX_ID_TYPE > reqmeta)
Definition: transferlib.cpp:110
int32_t get_file_size(string filename)
Get size of file.
Definition: transferlib.cpp:402
PACKET_TX_ID_TYPE tx_id
Definition: transferlib.h:304
void extract_reqmeta(vector< PACKET_BYTE > &packet, packet_struct_reqmeta &reqmeta)
Definition: transferlib.cpp:124
packet_struct_complete complete
Definition: transferlib.h:322
Definition: transferlib.h:301
packet_struct_reqdata reqdata
Definition: transferlib.h:327
static const unsigned char STATUS_BAD_TX_ID
Definition: transferlib.h:121
static const unsigned char PACKET_COMPLETE
Definition: transferlib.h:107
PACKET_NODE_ID_TYPE node_id
Definition: transferlib.h:293
static const unsigned char PACKET_REQQUEUE
Definition: transferlib.h:110
bool IS_MESSAGE(const unsigned char)
void extract_reqqueue(vector< PACKET_BYTE > &packet, packet_struct_reqqueue &reqqueue)
Definition: transferlib.cpp:271
packet_struct_reqmeta reqmeta
Definition: transferlib.h:328
static const unsigned char STATUS_HOLES_TO_FILL
Definition: transferlib.h:123