Locked in dht version
This commit is contained in:
parent
bd9f219b50
commit
41ef0e5492
4 changed files with 3083 additions and 15 deletions
66
include/libp2p/routing/dht.h
Normal file
66
include/libp2p/routing/dht.h
Normal 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
|
|
@ -2,7 +2,7 @@ DHT_DIR = dht
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -O0 -I../include -I../../c-multiaddr/include -I$(DHT_DIR) -g3
|
CFLAGS = -O0 -I../include -I../../c-multiaddr/include -I$(DHT_DIR) -g3
|
||||||
LFLAGS =
|
LFLAGS =
|
||||||
DEPS = $(DHT_DIR)/dht.h
|
DEPS = # $(DHT_DIR)/dht.h
|
||||||
OBJS = kademlia.o dht.o
|
OBJS = kademlia.o dht.o
|
||||||
|
|
||||||
%.o: %.c $(DEPS)
|
%.o: %.c $(DEPS)
|
||||||
|
@ -13,12 +13,13 @@ all: $(OBJS)
|
||||||
$(DHT_DIR)/dht.h:
|
$(DHT_DIR)/dht.h:
|
||||||
git clone https://github.com/jech/dht.git $(DHT_DIR)
|
git clone https://github.com/jech/dht.git $(DHT_DIR)
|
||||||
|
|
||||||
dht.c: $(DEPS)
|
#dht.c: $(DEPS)
|
||||||
ln -s $(DHT_DIR)/dht.c .
|
# ln -s $(DHT_DIR)/dht.c .
|
||||||
|
|
||||||
kademlia_test: $(OBJS)
|
kademlia_test: $(OBJS)
|
||||||
$(CC) -o kademlia_test kademlia_test.c kademlia.o dht.o $(CFLAGS) -pthread ../libp2p.a ../../c-multiaddr/libmultiaddr.a -lm
|
$(CC) -o kademlia_test kademlia_test.c kademlia.o dht.o $(CFLAGS) -pthread ../libp2p.a ../../c-multiaddr/libmultiaddr.a -lm
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f kademlia_test $(OBJS) dht.c
|
rm -f kademlia_test $(OBJS)
|
||||||
rm -rf $(DHT_DIR)
|
#dht.c
|
||||||
|
#rm -rf $(DHT_DIR)
|
||||||
|
|
2997
routing/dht.c
Normal file
2997
routing/dht.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -16,7 +16,7 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <libp2p/crypto/sha256.h>
|
#include <libp2p/crypto/sha256.h>
|
||||||
#include <libp2p/routing/kademlia.h>
|
#include <libp2p/routing/kademlia.h>
|
||||||
#include <dht.h>
|
#include <libp2p/routing/dht.h>
|
||||||
#include <multiaddr/multiaddr.h>
|
#include <multiaddr/multiaddr.h>
|
||||||
|
|
||||||
extern FILE *dht_debug;
|
extern FILE *dht_debug;
|
||||||
|
@ -72,15 +72,17 @@ struct search_struct {
|
||||||
struct search_struct *next;
|
struct search_struct *next;
|
||||||
} *search_result = NULL;
|
} *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
|
* The call-back function is called by the DHT whenever something
|
||||||
when a search completes, but this may be extended in future versions. */
|
* interesting happens. Right now, it only happens when we get a new value or
|
||||||
static void
|
* when a search completes, but this may be extended in future versions.
|
||||||
callback(void *closure,
|
* @param closure
|
||||||
int event,
|
* @param event the event
|
||||||
const unsigned char *info_hash,
|
* @param info_hash the hash to work with
|
||||||
const void *data, size_t data_len)
|
* @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
|
struct search_struct *sp, *rp = NULL; // struct pointer and result pointer
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
|
@ -311,6 +313,7 @@ void *kademlia_thread (void *ptr)
|
||||||
return 0; // end thread.
|
return 0; // end thread.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return (void*)1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int search_kademlia_internal (unsigned char* id, int port, int to)
|
int search_kademlia_internal (unsigned char* id, int port, int to)
|
||||||
|
@ -373,6 +376,7 @@ void *announce_thread (void *ptr)
|
||||||
// Empty list, just wait.
|
// Empty list, just wait.
|
||||||
sleep (ANNOUNCE_WAIT_TIME);
|
sleep (ANNOUNCE_WAIT_TIME);
|
||||||
}
|
}
|
||||||
|
return (void*)1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int announce_kademlia (char* peer_id, uint16_t port)
|
int announce_kademlia (char* peer_id, uint16_t port)
|
||||||
|
|
Loading…
Reference in a new issue