summaryrefslogtreecommitdiff
path: root/core/DHT.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/DHT.h')
-rw-r--r--core/DHT.h74
1 files changed, 9 insertions, 65 deletions
diff --git a/core/DHT.h b/core/DHT.h
index c35b17d5..edd4236a 100644
--- a/core/DHT.h
+++ b/core/DHT.h
@@ -1,25 +1,14 @@
1#ifndef DHT_H 1/* DHT.h
2#define DHT_H 2*
3 3* An implementation of the DHT as seen in docs/DHT.txt
4#include <stdlib.h> 4*
5#include <stdio.h> 5*/
6#include <stdint.h>
7#include <string.h>
8#include <time.h>
9 6
10#ifdef WIN32 //Put win32 includes here
11 7
12#include <winsock2.h> 8#ifndef DHT_H
13#include <windows.h> 9#define DHT_H
14
15#else //Linux includes
16
17#include <fcntl.h>
18#include <sys/socket.h>
19#include <netinet/in.h>
20#include <errno.h>
21 10
22#endif 11#include "network.h"
23 12
24//Current time, unix format 13//Current time, unix format
25#define unix_time() ((uint32_t)time(NULL)) 14#define unix_time() ((uint32_t)time(NULL))
@@ -27,24 +16,6 @@
27//size of the client_id in bytes 16//size of the client_id in bytes
28#define CLIENT_ID_SIZE 32 17#define CLIENT_ID_SIZE 32
29 18
30#define MAX_UDP_PACKET_SIZE 65507
31
32typedef union
33{
34 uint8_t c[4];
35 uint16_t s[2];
36 uint32_t i;
37}IP;
38
39typedef struct
40{
41 IP ip;
42 uint16_t port;
43 //not used for anything right now
44 uint16_t padding;
45}IP_Port;
46
47
48typedef struct 19typedef struct
49{ 20{
50 char client_id[CLIENT_ID_SIZE]; 21 char client_id[CLIENT_ID_SIZE];
@@ -77,19 +48,6 @@ typedef struct
77}Pinged; 48}Pinged;
78 49
79 50
80typedef struct
81{
82 int16_t family;
83 uint16_t port;
84 IP ip;
85 uint8_t zeroes[8];
86 #ifdef ENABLE_IPV6
87 uint8_t zeroes2[12];
88 #endif
89}ADDR;
90
91
92
93//Add a new friend to the friends list 51//Add a new friend to the friends list
94//client_id must be CLIENT_ID_SIZE bytes long. 52//client_id must be CLIENT_ID_SIZE bytes long.
95//returns 0 if success 53//returns 0 if success
@@ -133,11 +91,8 @@ void bootstrap(IP_Port ip_port);
133//Global variables 91//Global variables
134 92
135//Our client id 93//Our client id
136char self_client_id[CLIENT_ID_SIZE]; 94extern char self_client_id[CLIENT_ID_SIZE];
137 95
138//Our UDP socket.
139//We only use one so it's much easier to have it as a global variable
140int sock;
141 96
142//TODO: Move these out of here and put them into the .c file. 97//TODO: Move these out of here and put them into the .c file.
143//A list of the clients mathematically closest to ours. 98//A list of the clients mathematically closest to ours.
@@ -162,15 +117,4 @@ Pinged pings[LPING_ARRAY];
162Pinged send_nodes[LSEND_NODES_ARRAY]; 117Pinged send_nodes[LSEND_NODES_ARRAY];
163 118
164 119
165//Basic network functions:
166//TODO: put them somewhere else than here
167
168//Function to send packet(data) of length length to ip_port
169int sendpacket(IP_Port ip_port, char * data, uint32_t length);
170
171//Function to recieve data, ip and port of sender is put into ip_port
172//the packet data into data
173//the packet length into length.
174int recievepacket(IP_Port * ip_port, char * data, uint32_t * length);
175
176#endif \ No newline at end of file 120#endif \ No newline at end of file