solved compilation errors | changed header includes, makefile flags, pointers to arrays
This commit is contained in:
parent
45cdc1409c
commit
cdef7ee0ac
5
Makefile
5
Makefile
@ -1,16 +1,17 @@
|
|||||||
TARGET ?= dazibao
|
TARGET ?= dazibao
|
||||||
SRC_DIRS ?= ./src/*
|
SRC_DIRS ?= ./src/*
|
||||||
CC := gcc
|
CC := gcc
|
||||||
CFLAGS= -O2 -Wall -lssl -lcrypto
|
CFLAGS= -O2 -Wall
|
||||||
SRCS := $(shell find $(SRC_DIRS) -name *.c -or -name *.s)
|
SRCS := $(shell find $(SRC_DIRS) -name *.c -or -name *.s)
|
||||||
OBJS := $(addsuffix .o,$(basename $(SRCS)))
|
OBJS := $(addsuffix .o,$(basename $(SRCS)))
|
||||||
DEPS := $(OBJS:.o=.d)
|
DEPS := $(OBJS:.o=.d)
|
||||||
|
SSLFLAGS = -lssl -lcrypto
|
||||||
|
|
||||||
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
|
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
|
||||||
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
|
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
|
||||||
|
|
||||||
$(TARGET): $(OBJS)
|
$(TARGET): $(OBJS)
|
||||||
$(CC) $(CFLAGS) $(OBJS) -o $@ $(LOADLIBES) $(LDLIBS)
|
$(CC) $(CFLAGS) $(OBJS) -o $@ $(LOADLIBES) $(LDLIBS) $(SSLFLAGS)
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
@ -8,16 +8,16 @@
|
|||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
|
||||||
// Hash a single data
|
// Hash a single data
|
||||||
void hash_data(struct pub_data *data, unsigned char *buf);
|
void hash_data(pub_data *data, unsigned char *buf);
|
||||||
|
|
||||||
// Hash every data contained in data_list then return a network hash
|
// Hash every data contained in data_list then return a network hash
|
||||||
void hash_network(struct list *data_list, unsigned char *buf);
|
void hash_network(list *data_list, unsigned char *buf);
|
||||||
|
|
||||||
// Truncate 32 octet hash to 16 octets
|
// Truncate 32 octet hash to 16 octets
|
||||||
void hash_trunc(unsigned char *hash256bit, unsigned char *buf);
|
void hash_trunc(unsigned char *hash256bit, unsigned char *buf);
|
||||||
|
|
||||||
// Concat all fields of data and put them in buf
|
// Concat all fields of data and put them in buf
|
||||||
void concat_data(struct pub_data *data, unsigned char *buf);
|
void concat_data(pub_data *data, unsigned char *buf);
|
||||||
|
|
||||||
// Concat hash2 to hash1 (hash1 is modified)
|
// Concat hash2 to hash1 (hash1 is modified)
|
||||||
void concat_hash(unsigned char *hash1, unsigned char *hash2, size_t size);
|
void concat_hash(unsigned char *hash1, unsigned char *hash2, size_t size);
|
||||||
|
BIN
src/hash.o
Normal file
BIN
src/hash.o
Normal file
Binary file not shown.
15
src/node.c
15
src/node.c
@ -163,7 +163,7 @@ void add_data(unsigned char len, long id, short seqno, char *data) {
|
|||||||
|
|
||||||
/* ---- Fin fonctions utilitaires ---- */
|
/* ---- Fin fonctions utilitaires ---- */
|
||||||
|
|
||||||
int send_tlv(union tlv * tlv_to_send, int tlv_size, struct sockaddr_in6 * dest_list[], int dest_list_size, int socket_num){
|
int send_tlv(union tlv * tlv_to_send, int tlv_size, struct sockaddr_in6 * dest_list, int dest_list_size, int socket_num){
|
||||||
// debug_print("Building packet to send a TLV.");
|
// debug_print("Building packet to send a TLV.");
|
||||||
|
|
||||||
// We first need to build the packet,
|
// We first need to build the packet,
|
||||||
@ -276,7 +276,7 @@ int validate_tlv(char *data, int pos, short packet_len){
|
|||||||
// For every packet recivied,
|
// For every packet recivied,
|
||||||
// then we make sure it's conform
|
// then we make sure it's conform
|
||||||
// We then extract the data from it to make it easy to work with
|
// We then extract the data from it to make it easy to work with
|
||||||
int check_header(char * received_datagram[], int buffer_len, struct packet * packet_to_return){
|
int check_header(char * received_datagram, int buffer_len, struct packet * packet_to_return){
|
||||||
|
|
||||||
packet_to_return = (packet*) received_datagram;
|
packet_to_return = (packet*) received_datagram;
|
||||||
|
|
||||||
@ -309,9 +309,10 @@ int update_neighbours(){
|
|||||||
};
|
};
|
||||||
|
|
||||||
// We then look at the differents TLVs in the packet.
|
// We then look at the differents TLVs in the packet.
|
||||||
int work_with_tlvs(char * data[], short packet_len, struct sockaddr_in6 sender){
|
int work_with_tlvs(char * data, short packet_len, struct sockaddr_in6 sender){
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
unsigned char tlv_len, hash[16], warn[32];
|
unsigned char tlv_len, hash[16];
|
||||||
|
char warn[32];
|
||||||
tlv new_tlv, cur_tlv;
|
tlv new_tlv, cur_tlv;
|
||||||
list *tmp_list;
|
list *tmp_list;
|
||||||
pub_data *pdata;
|
pub_data *pdata;
|
||||||
@ -531,8 +532,8 @@ void listen_for_packets(){
|
|||||||
|
|
||||||
// We verify the received packet is well formated,
|
// We verify the received packet is well formated,
|
||||||
// and we return it in the struct designed to work with it.
|
// and we return it in the struct designed to work with it.
|
||||||
struct packet * formated_rec_datagram;
|
struct packet formated_rec_datagram;
|
||||||
if(check_header(&req, 1024, formated_rec_datagram) < 0){
|
if(check_header(req, 1024, &formated_rec_datagram) < 0){
|
||||||
perror(">> Error while checking the header, aborting this packet, by choice, and conviction.");
|
perror(">> Error while checking the header, aborting this packet, by choice, and conviction.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -541,7 +542,7 @@ void listen_for_packets(){
|
|||||||
|
|
||||||
// struct tlv_list received_tlvs;
|
// struct tlv_list received_tlvs;
|
||||||
// if (validate_tlvs(formated_rec_datagram) < 0)
|
// if (validate_tlvs(formated_rec_datagram) < 0)
|
||||||
int nbr_success_tlv = work_with_tlvs(&req, 1024, sender);
|
int nbr_success_tlv = work_with_tlvs(req, 1024, sender);
|
||||||
if (nbr_success_tlv < 0){
|
if (nbr_success_tlv < 0){
|
||||||
perror(">> Error while treating the TLVs of the packet.");
|
perror(">> Error while treating the TLVs of the packet.");
|
||||||
printf(">> Managed to deal with %i TLVs\n", -nbr_success_tlv );
|
printf(">> Managed to deal with %i TLVs\n", -nbr_success_tlv );
|
||||||
|
44
src/node.h
44
src/node.h
@ -11,20 +11,6 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tlv.h"
|
|
||||||
#include "hash.h"
|
|
||||||
#include "parser.h"
|
|
||||||
|
|
||||||
// On which port do we listen to
|
|
||||||
#define LISTEN_PORT 1212
|
|
||||||
|
|
||||||
// The node ID
|
|
||||||
#define NODE_ID 42675882021843277
|
|
||||||
|
|
||||||
// The number of neighbours
|
|
||||||
// The neighbour table has 15 entries
|
|
||||||
#define NEIGHBOUR_MAX 15
|
|
||||||
|
|
||||||
/* la table de voisins, qui est indexée par adresses de socket (des paires (IP, Port)),
|
/* la table de voisins, qui est indexée par adresses de socket (des paires (IP, Port)),
|
||||||
* et dont chaque entrée contient un booléen indiquant si le pair est permanent
|
* et dont chaque entrée contient un booléen indiquant si le pair est permanent
|
||||||
* (configuré au lancement) ou transitoire, et la date de dernière réception d’un
|
* (configuré au lancement) ou transitoire, et la date de dernière réception d’un
|
||||||
@ -45,7 +31,7 @@ typedef struct neighbour_peer {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct pub_data {
|
typedef struct pub_data {
|
||||||
unsigned char length;
|
unsigned char length;
|
||||||
long id;
|
long id;
|
||||||
short seqno;
|
short seqno;
|
||||||
char *data;
|
char *data;
|
||||||
@ -53,10 +39,24 @@ typedef struct pub_data {
|
|||||||
|
|
||||||
// General list
|
// General list
|
||||||
typedef struct list {
|
typedef struct list {
|
||||||
void *data;
|
void *data;
|
||||||
void *next;
|
void *next;
|
||||||
} list;
|
} list;
|
||||||
|
|
||||||
|
#include "tlv.h"
|
||||||
|
#include "hash.h"
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
|
// On which port do we listen to
|
||||||
|
#define LISTEN_PORT 1212
|
||||||
|
|
||||||
|
// The node ID
|
||||||
|
#define NODE_ID 42675882021843277
|
||||||
|
|
||||||
|
// The number of neighbours
|
||||||
|
// The neighbour table has 15 entries
|
||||||
|
#define NEIGHBOUR_MAX 15
|
||||||
|
|
||||||
// Static variables
|
// Static variables
|
||||||
static list *data_list;
|
static list *data_list;
|
||||||
static list *neighbour_list;
|
static list *neighbour_list;
|
||||||
@ -66,13 +66,13 @@ static list *neighbour_list;
|
|||||||
// fonctions signatures
|
// fonctions signatures
|
||||||
void listen_for_packets();
|
void listen_for_packets();
|
||||||
|
|
||||||
int check_header(char * received_datagram[], int buffer_len, struct packet * packet_to_return);
|
int check_header(char * received_datagram, int buffer_len, packet * packet_to_return);
|
||||||
|
|
||||||
int validate_tlvs(struct packet * pack, struct tlv_list * tlv_l);
|
int validate_tlv(char *data, int pos, short packet_len);
|
||||||
|
|
||||||
int update_neighbours();
|
int update_neighbours();
|
||||||
|
|
||||||
int work_with_tlvs(char * data[], short packet_len, struct sockaddr_in6 sender);
|
int work_with_tlvs(char * data, short packet_len, struct sockaddr_in6 sender);
|
||||||
|
|
||||||
void add_tlv(struct packet *packet, union tlv *tlv, char type);
|
void add_tlv(struct packet *packet, union tlv *tlv, char type);
|
||||||
|
|
||||||
@ -81,12 +81,12 @@ void add_tlv(struct packet *packet, union tlv *tlv, char type);
|
|||||||
/* Takes a TLV and sends it over to everyone in the list of addresses.
|
/* Takes a TLV and sends it over to everyone in the list of addresses.
|
||||||
* Returns -1 in case of error, 0 otherwise.
|
* Returns -1 in case of error, 0 otherwise.
|
||||||
*/
|
*/
|
||||||
int send_tlv(union tlv * tlv_to_send, int tlv_size, struct sockaddr_in6 * dest_list[], int dest_list_size, int socket_num);
|
int send_tlv(union tlv * tlv_to_send, int tlv_size, struct sockaddr_in6 * dest_list, int dest_list_size, int socket_num);
|
||||||
|
|
||||||
/* Takes a list of TLV and sends them over to everyone in the list of addresses.
|
/* Takes a list of TLV and sends them over to everyone in the list of addresses.
|
||||||
* Returns -1 in case of error, 0 otherwise.
|
* Returns -1 in case of error, 0 otherwise.
|
||||||
*/
|
*/
|
||||||
int send_tlvs(struct list * tlv_list, int tlv_size, struct sockaddr_in6 * dest_list[], int dest_list_size, int socket_num);
|
int send_tlvs(struct list * tlv_list, int tlv_size, struct sockaddr_in6 * dest_list, int dest_list_size, int socket_num);
|
||||||
|
|
||||||
// threaded functions
|
// threaded functions
|
||||||
void t_ask_for_more_peers();
|
void t_ask_for_more_peers();
|
||||||
|
BIN
src/node.o
Normal file
BIN
src/node.o
Normal file
Binary file not shown.
BIN
src/parser.o
Normal file
BIN
src/parser.o
Normal file
Binary file not shown.
10
src/tlv.h
10
src/tlv.h
@ -5,10 +5,6 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "node.h"
|
|
||||||
#include "hash.h"
|
|
||||||
#include "parser.h"
|
|
||||||
|
|
||||||
#define LEN_NEIGHBOUR_REQ 0
|
#define LEN_NEIGHBOUR_REQ 0
|
||||||
#define LEN_NEIGHBOUR 18
|
#define LEN_NEIGHBOUR 18
|
||||||
#define LEN_NETWORK_HASH 16
|
#define LEN_NETWORK_HASH 16
|
||||||
@ -111,6 +107,10 @@ typedef union tlv {
|
|||||||
warning *warning;
|
warning *warning;
|
||||||
} tlv;
|
} tlv;
|
||||||
|
|
||||||
|
#include "node.h"
|
||||||
|
#include "hash.h"
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
// build tlv from token
|
// build tlv from token
|
||||||
int build_tlv(tlv *tlv, struct cmd_token token);
|
int build_tlv(tlv *tlv, struct cmd_token token);
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ int build_pad1(tlv *tlv);
|
|||||||
int build_padn(tlv *tlv, size_t len);
|
int build_padn(tlv *tlv, size_t len);
|
||||||
int build_neighbour_req(union tlv *tlv);
|
int build_neighbour_req(union tlv *tlv);
|
||||||
int build_neighbour(tlv *tlv, struct in6_addr ip, short port);
|
int build_neighbour(tlv *tlv, struct in6_addr ip, short port);
|
||||||
int build_network_hash(tlv *tlv, struct list *data_list);
|
int build_network_hash(tlv *tlv, list *data_list);
|
||||||
int build_network_state_req(tlv *tlv);
|
int build_network_state_req(tlv *tlv);
|
||||||
int build_node_hash(tlv *tlv, long node_id, short seqno, char *data);
|
int build_node_hash(tlv *tlv, long node_id, short seqno, char *data);
|
||||||
int build_node_state_req(tlv *tlv, long node_id);
|
int build_node_state_req(tlv *tlv, long node_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user