COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
transferlib.h
Go to the documentation of this file.
1 /********************************************************************
2 * Copyright (C) 2015 by Interstel Technologies, Inc.
3 * and Hawaii Space Flight Laboratory.
4 *
5 * This file is part of the COSMOS/core that is the central
6 * module for COSMOS. For more information on COSMOS go to
7 * <http://cosmos-project.com>
8 *
9 * The COSMOS/core software is licenced under the
10 * GNU Lesser General Public License (LGPL) version 3 licence.
11 *
12 * You should have received a copy of the
13 * GNU Lesser General Public License
14 * If not, go to <http://www.gnu.org/licenses/>
15 *
16 * COSMOS/core is free software: you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public License
18 * as published by the Free Software Foundation, either version 3 of
19 * the License, or (at your option) any later version.
20 *
21 * COSMOS/core is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * Refer to the "licences" folder for further information on the
27 * condititons and terms to use this software.
28 ********************************************************************/
29 
30 #ifndef FILETRANSFER_H
31 #define FILETRANSFER_H
32 
37 
59 // cosmos includes
60 #include "support/configCosmos.h"
61 #include "support/datalib.h"
62 
63 // c++ includes
64 //#include <cstring>
65 //#include <algorithm>
66 //#include <iostream>
67 //#include <fstream>
68 //#include <string>
69 //#include <sys/stat.h>
70 
74 
75 #define PACKET_MAX_LENGTH 1500
76 // Radios are only allowing 253 byte packet. IP/UDP header is 28 bytes.
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)))
81 #else
82 #define TRANSFER_QUEUE_LIMIT 100
83 #endif
84 //#define MESSAGE_MAX_PACKET (TRANSFER_MAX_PROTOCOL_PACKET-(COSMOS_SIZEOF(PACKET_TYPE)+COSMOS_SIZEOF(PACKET_TX_ID_TYPE)))
85 
86 namespace STATE_TYPE
87 {
88  static const unsigned char STATE_NONE = 0x00;
89  static const unsigned char STATE_REQQUEUE = 0x01;
90  static const unsigned char STATE_QUEUE = 0x02;
91  static const unsigned char STATE_REQMETA = 0x03;
92  static const unsigned char STATE_METADATA = 0x04;
93  static const unsigned char STATE_REQDATA = 0x05;
94  static const unsigned char STATE_DATA = 0x06;
95  static const unsigned char STATE_CANCEL = 0x07;
96  static const unsigned char STATE_COMPLETE = 0x08;
97  static const unsigned char STATE_SIZE = 0x09;
98 }
99 using namespace STATE_TYPE;
100 
101 namespace PACKET_TYPE_STUFF {
102  //these bits reserved for PACKET_TYPES
103  static const unsigned char PACKET_METADATA = 0xf;
104  static const unsigned char PACKET_DATA = 0xe;
105  static const unsigned char PACKET_REQDATA = 0xd;
106  static const unsigned char PACKET_REQMETA = 0xc;
107  static const unsigned char PACKET_COMPLETE = 0xb;
108  static const unsigned char PACKET_CANCEL = 0xa;
109  static const unsigned char PACKET_QUEUE = 0x9;
110  static const unsigned char PACKET_REQQUEUE = 0x8;
111  static const unsigned char PACKET_HEARTBEAT = 0x7;
112  static const unsigned char PACKET_MESSAGE = 0x6;
113  static const unsigned char PACKET_COMMAND = 0x5;
114 }
115 
116 using namespace PACKET_TYPE_STUFF;
117 
118 namespace STATUS_TYPE {
119  //these bits reserved for PACKET_TYPES
120  static const unsigned char STATUS_ALL_GOOD = 128; //10000000
121  static const unsigned char STATUS_BAD_TX_ID = 64; //01000000
122  static const unsigned char STATUS_NO_FILE_FOUND = 32; //00100000
123  static const unsigned char STATUS_HOLES_TO_FILL = 16; //00010000
124  static const unsigned char STATUS_SUCCESS = 8; //00001000
125  static const unsigned char STATUS_NEED_METADATA = 4; //00000100
126 
127  //these bits reserved for future STATUS_TYPES
128  //static const unsigned char STATUS_1 = 4; //00000100
129  static const unsigned char STATUS_2 = 2; //00000010
130  static const unsigned char STATUS_3 = 1; //00000001
131 }
132 
133 using namespace STATUS_TYPE;
135 
139 
140 typedef uint8_t PACKET_BYTE;
141 typedef uint8_t PACKET_TYPE;
142 typedef uint16_t PACKET_CRC;
143 typedef uint8_t PACKET_NODE_ID_TYPE;
144 typedef uint8_t PACKET_TX_ID_TYPE;
145 typedef uint16_t PACKET_CHUNK_SIZE_TYPE;
146 typedef int32_t PACKET_FILE_SIZE_TYPE;
147 typedef uint32_t PACKET_UNIXTIME_TYPE;
148 
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))
154 
155 typedef struct
156 {
163 
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)
170 
171 typedef struct
172 {
177 
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)
182 
183 typedef struct
184 {
189 
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)
194 
195 typedef struct
196 {
200 
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)
204 
205 typedef struct
206 {
211 
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)
216 
217 typedef struct
218 {
223 
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)
228 
229 typedef struct
230 {
234  char file_name[TRANSFER_MAX_FILENAME];
237 
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))
244 
245 typedef struct
246 {
250  char file_name[TRANSFER_MAX_FILENAME];
253 
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))
260 
261 typedef struct
262 {
268 
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))
274 
275 typedef struct
276 {
283 
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)
290 
291 typedef struct
292 {
296 
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))
300 
301 typedef struct
302 {
306 
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))
310 
311 typedef struct
312 {
316 
317 typedef union
318 {
331 
332 typedef struct
333 {
336 } file_progress;
337 
338 typedef struct
339 {
341  bool enabled=false;
342  bool havemeta=false;
343  bool havedata=false;
344  bool sendmeta=false;
345  bool sentmeta=false;
346  bool senddata=false;
347  bool sentdata=false;
348  bool complete=false;
349  string node_name="";
350  string agent_name="";
351  string file_name="";
352  string filepath="";
353  string temppath="";
354  double savetime;
355  double datatime=0.;
357  PACKET_FILE_SIZE_TYPE total_bytes=0;
358  deque<file_progress> file_info;
359  FILE * fp;
360 } tx_progress;
361 
363 
367 
368 //functions to verify whether a packet is a particular type
369 bool IS_MESSAGE(const unsigned char);
370 bool IS_REQUEST(const unsigned char);
371 bool IS_METADATA(const unsigned char);
372 bool IS_DATA(const unsigned char);
373 bool IS_REQDATA(const unsigned char);
374 bool IS_REQMETA(const unsigned char);
375 bool IS_COMPLETE(const unsigned char);
376 
377 //functions to verify whether a request is of a particular type
378 bool IS_GET_REQUEST(const unsigned char);
379 bool IS_PUT_REQUEST(const unsigned char);
380 bool IS_DELETE_REQUEST(const unsigned char);
381 
382 void make_metadata_packet(vector<PACKET_BYTE>& packet, packet_struct_metalong meta);
383 void make_metadata_packet(vector<PACKET_BYTE>& packet, PACKET_TX_ID_TYPE tx_id, char* file_name, PACKET_FILE_SIZE_TYPE file_size, char* node_name, char* agent_name);
384 void make_metadata_packet(vector<PACKET_BYTE>& packet, packet_struct_metashort meta);
385 void make_metadata_packet(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE node_id, PACKET_TX_ID_TYPE tx_id, char* file_name, PACKET_FILE_SIZE_TYPE file_size, char* agent_name);
386 void extract_metadata(vector<PACKET_BYTE>& packet, packet_struct_metalong& meta);
387 void extract_metadata(vector<PACKET_BYTE>& packet, PACKET_TX_ID_TYPE& tx_id, char* file_name, PACKET_FILE_SIZE_TYPE& file_size, char* node_name, char* agent_name);
388 void extract_metadata(vector<PACKET_BYTE>& packet, packet_struct_metashort& meta);
389 void extract_metadata(vector<PACKET_BYTE>& packet, PACKET_TX_ID_TYPE& tx_id, char* file_name, PACKET_FILE_SIZE_TYPE& file_size, PACKET_NODE_ID_TYPE& node_id, char* agent_name);
390 
391 void make_data_packet(vector<PACKET_BYTE>& packet, packet_struct_data data);
392 void make_data_packet(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE node_id, PACKET_TX_ID_TYPE tx_id, PACKET_CHUNK_SIZE_TYPE byte_count, PACKET_FILE_SIZE_TYPE chunk_start, PACKET_BYTE* chunk);
393 void extract_data(vector<PACKET_BYTE>& packet, packet_struct_data& data);
394 void extract_data(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE& node_id, PACKET_TX_ID_TYPE& tx_id, PACKET_CHUNK_SIZE_TYPE& byte_count, PACKET_FILE_SIZE_TYPE& chunk_start, PACKET_BYTE* chunk);
395 
396 void make_reqdata_packet(vector<PACKET_BYTE>& packet, packet_struct_reqdata reqdata);
397 void make_reqdata_packet(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE node_id, PACKET_TX_ID_TYPE tx_id, PACKET_FILE_SIZE_TYPE hole_start, PACKET_FILE_SIZE_TYPE hole_end);
398 void extract_reqdata(vector<PACKET_BYTE>& packet, packet_struct_reqdata& reqdata);
399 void extract_reqdata(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE &node_id, PACKET_TX_ID_TYPE& tx_id, PACKET_FILE_SIZE_TYPE& hole_start, PACKET_FILE_SIZE_TYPE& hole_end);
400 
401 void make_reqmeta_packet(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE node_id, string node_name, vector<PACKET_TX_ID_TYPE> reqmeta);
402 void extract_reqmeta(vector<PACKET_BYTE>& packet, packet_struct_reqmeta& reqmeta);
403 
404 void make_complete_packet(vector<PACKET_BYTE>& packet, packet_struct_complete complete);
405 void make_complete_packet(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE node_id, PACKET_TX_ID_TYPE tx_id);
406 void extract_complete(vector<PACKET_BYTE>& packet, packet_struct_complete& complete);
407 void extract_complete(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE &node_id, PACKET_TX_ID_TYPE& tx_id);
408 
409 void make_cancel_packet(vector<PACKET_BYTE>& packet, packet_struct_cancel cancel);
410 void make_cancel_packet(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE node_id, PACKET_TX_ID_TYPE tx_id);
411 void extract_cancel(vector<PACKET_BYTE>& packet, packet_struct_cancel& cancel);
412 void extract_cancel(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE &node_id, PACKET_TX_ID_TYPE& tx_id);
413 
414 void make_reqqueue_packet(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE node_id, string node_name);
415 void extract_reqqueue(vector<PACKET_BYTE>& packet, packet_struct_reqqueue& reqqueue);
416 
417 void make_queue_packet(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE node_id, string node_name, vector<PACKET_TX_ID_TYPE> queue);
418 void extract_queue(vector<PACKET_BYTE>& packet, packet_struct_queue& queue);
419 
420 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);
421 void extract_heartbeat(vector<PACKET_BYTE>& packet, packet_struct_heartbeat& heartbeat);
422 
423 void make_message_packet(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE node_id, string message);
424 void extract_message(vector<PACKET_BYTE>& packet, packet_struct_message& message);
425 void make_command_packet(vector<PACKET_BYTE>& packet, PACKET_NODE_ID_TYPE node_id, string command);
426 void extract_command(vector<PACKET_BYTE>& packet, packet_struct_command& command);
427 
428 int32_t check_node_id(PACKET_NODE_ID_TYPE node_id);
429 //int32_t lookup_node_id(PACKET_NODE_ID_TYPE node_id);
430 int32_t lookup_node_id(string node_name);
431 int32_t set_node_id(PACKET_NODE_ID_TYPE node_id, string node_name);
433 int32_t load_nodeids();
434 vector <string> get_nodeids();
435 
436 //void make_message_packet(vector<PACKET_BYTE>& packet, packet_struct_message message);
437 //void make_message_packet(vector<PACKET_BYTE>& packet, PACKET_TX_ID_TYPE tx_id);
438 //void extract_message(vector<PACKET_BYTE>& packet, packet_struct_message& message);
439 //void extract_message(vector<PACKET_BYTE>& packet, PACKET_TX_ID_TYPE& tx_id);
440 
441 //void make_send_packet(vector<PACKET_BYTE>& packet, PACKET_TX_ID_TYPE tx_id);
442 //void extract_send(vector<PACKET_BYTE>& packet, PACKET_TX_ID_TYPE &tx_id);
443 
444 
446 
447 //Function to extract necessary fields from a received request packet
448 /*
449 void extract_request(uint8_t* packet, PACKET_TX_ID_TYPE tx_id, char* filename, char* to_node, char* to_agent, char* from_node, char* from_agent);
450 */
451 
452 
453 void show_fstream_state(std::ifstream& out);
454 //Function which gets the size of a file
455 int32_t get_file_size(string filename);
456 int32_t get_file_size(const char* filename);
457 
458 void print_cstring(uint8_t* buf, int siz);
459 void print_cstring_with_index(uint8_t* buf, int siz);
460 void print_cstring_hex(uint8_t* buf, int siz);
461 void print_cstring_hex_with_index(uint8_t* buf, int siz);
462 
463 void unable_to_remove(string filename);
466 #endif
#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
Definition: transferlib.h:229
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)
PACKET_TX_ID_TYPE tx_id
Definition: transferlib.h:248
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)
Definition: transferlib.h:245
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:219
PACKET_NODE_ID_TYPE node_id
Definition: transferlib.h:197
void print_cstring_hex(uint8_t *buf, int siz)
Definition: transferlib.cpp:452
PACKET_NODE_ID_TYPE node_id
Definition: transferlib.h:247
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
Definition: transferlib.h:217
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_FILE_SIZE_TYPE file_size
Definition: transferlib.h:235
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:232
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_FILE_SIZE_TYPE file_size
Definition: transferlib.h:251
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