Locked in dht version

yamux
John Jones 2017-03-23 15:03:13 -05:00
parent bd9f219b50
commit 41ef0e5492
4 changed files with 3083 additions and 15 deletions

View File

@ -0,0 +1,66 @@
/*
Copyright (c) 2009-2011 by Juliusz Chroboczek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef void
dht_callback(void *closure, int event,
const unsigned char *info_hash,
const void *data, size_t data_len);
#define DHT_EVENT_NONE 0
#define DHT_EVENT_VALUES 1
#define DHT_EVENT_VALUES6 2
#define DHT_EVENT_SEARCH_DONE 3
#define DHT_EVENT_SEARCH_DONE6 4
extern FILE *dht_debug;
int dht_init(int s, int s6, const unsigned char *id, const unsigned char *v);
int dht_insert_node(const unsigned char *id, struct sockaddr *sa, int salen);
int dht_ping_node(const struct sockaddr *sa, int salen);
int dht_periodic(const void *buf, size_t buflen,
const struct sockaddr *from, int fromlen,
time_t *tosleep, dht_callback *callback, void *closure);
int dht_search(const unsigned char *id, int port, int af,
dht_callback *callback, void *closure);
int dht_nodes(int af,
int *good_return, int *dubious_return, int *cached_return,
int *incoming_return);
void dht_dump_tables(FILE *f);
int dht_get_nodes(struct sockaddr_in *sin, int *num,
struct sockaddr_in6 *sin6, int *num6);
int dht_uninit(void);
/* This must be provided by the user. */
int dht_blacklisted(const struct sockaddr *sa, int salen);
void dht_hash(void *hash_return, int hash_size,
const void *v1, int len1,
const void *v2, int len2,
const void *v3, int len3);
int dht_random_bytes(void *buf, size_t size);
#ifdef __cplusplus
}
#endif

View File

@ -2,7 +2,7 @@ DHT_DIR = dht
CC = gcc
CFLAGS = -O0 -I../include -I../../c-multiaddr/include -I$(DHT_DIR) -g3
LFLAGS =
DEPS = $(DHT_DIR)/dht.h
DEPS = # $(DHT_DIR)/dht.h
OBJS = kademlia.o dht.o
%.o: %.c $(DEPS)
@ -13,12 +13,13 @@ all: $(OBJS)
$(DHT_DIR)/dht.h:
git clone https://github.com/jech/dht.git $(DHT_DIR)
dht.c: $(DEPS)
ln -s $(DHT_DIR)/dht.c .
#dht.c: $(DEPS)
# ln -s $(DHT_DIR)/dht.c .
kademlia_test: $(OBJS)
$(CC) -o kademlia_test kademlia_test.c kademlia.o dht.o $(CFLAGS) -pthread ../libp2p.a ../../c-multiaddr/libmultiaddr.a -lm
clean:
rm -f kademlia_test $(OBJS) dht.c
rm -rf $(DHT_DIR)
rm -f kademlia_test $(OBJS)
#dht.c
#rm -rf $(DHT_DIR)

2997
routing/dht.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@
#include <pthread.h>
#include <libp2p/crypto/sha256.h>
#include <libp2p/routing/kademlia.h>
#include <dht.h>
#include <libp2p/routing/dht.h>
#include <multiaddr/multiaddr.h>
extern FILE *dht_debug;
@ -72,15 +72,17 @@ struct search_struct {
struct search_struct *next;
} *search_result = NULL;
/* The call-back function is called by the DHT whenever something
interesting happens. Right now, it only happens when we get a new value or
when a search completes, but this may be extended in future versions. */
static void
callback(void *closure,
int event,
const unsigned char *info_hash,
const void *data, size_t data_len)
{
/***
* The call-back function is called by the DHT whenever something
* interesting happens. Right now, it only happens when we get a new value or
* when a search completes, but this may be extended in future versions.
* @param closure
* @param event the event
* @param info_hash the hash to work with
* @param data the new value to be added
* @param data_len the length of the data
*/
static void callback(void *closure, int event, const unsigned char *info_hash, const void *data, size_t data_len) {
struct search_struct *sp, *rp = NULL; // struct pointer and result pointer
switch (event) {
@ -311,6 +313,7 @@ void *kademlia_thread (void *ptr)
return 0; // end thread.
}
}
return (void*)1;
}
int search_kademlia_internal (unsigned char* id, int port, int to)
@ -373,6 +376,7 @@ void *announce_thread (void *ptr)
// Empty list, just wait.
sleep (ANNOUNCE_WAIT_TIME);
}
return (void*)1;
}
int announce_kademlia (char* peer_id, uint16_t port)