提交 a95f8a8e authored 作者: Shane Bryldt's avatar Shane Bryldt

FS-10166: Removed old DHT tests and stuff related to libtorrent, and a…

FS-10166: Removed old DHT tests and stuff related to libtorrent, and a straggling diff related to old DHT.
上级 5cff01b2
差异被折叠。
......@@ -54,37 +54,7 @@ testwebsock_SOURCES = testwebsock.c tap.c
testwebsock_CFLAGS = $(AM_CFLAGS)
testwebsock_LDADD = $(TEST_LDADD)
#check_PROGRAMS += testdht
#testdht_SOURCES = testdht.c tap.c
#testdht_CFLAGS = $(AM_CFLAGS)
#testdht_LDADD = $(TEST_LDADD)
#check_PROGRAMS += testdht_net
#testdht_net_SOURCES = testdht-net.c tap.c
#testdht_net_CFLAGS = $(AM_CFLAGS)
#testdht_net_LDADD = $(TEST_LDADD)
#check_PROGRAMS += testdht_msg
#testdht_msg_SOURCES = testdht-msg.c tap.c
#testdht_msg_CFLAGS = $(AM_CFLAGS)
#testdht_msg_LDADD = $(TEST_LDADD)
#check_PROGRAMS += dht_example
#dht_example_SOURCES = dht-example.c
#dht_example_CFLAGS = $(AM_CFLAGS)
#dht_example_LDADD = $(abs_top_builddir)/libks.la $(openssl_LIBS) -ledit -lpthread
#check_PROGRAMS += libtorrent_example
#libtorrent_example_SOURCES = libtorrent-example.c
#libtorrent_example_CFLAGS = $(AM_CFLAGS)
#libtorrent_example_LDADD = $(abs_top_builddir)/libks.la $(abs_top_builddir)/test/libtorrent.so /usr/lib/x86_64-linux-gnu/libboost_system.a $(openssl_LIBS) -ledit -lpthread -ltorrent-rasterbar -lstdc++
TESTS=$(check_PROGRAMS)
tests: $(check_PROGRAMS)
$(abs_top_builddir)/test/libtorrent.so: $(abs_top_builddir)/test/libtorrent.o
g++ -shared -o $(abs_top_builddir)/test/libtorrent.so $(abs_top_builddir)/test/libtorrent.o
$(abs_top_builddir)/test/libtorrent.o: $(abs_top_builddir)/test/libtorrent.cpp
g++ -c -fPIC -o $(abs_top_builddir)/test/libtorrent.o -I$(abs_top_builddir)/test/ $(abs_top_builddir)/test/libtorrent.cpp
差异被折叠。
/* This example code was written by Juliusz Chroboczek.
You are free to cut'n'paste from it to your heart's content. */
/* For crypt */
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <sys/signal.h>
#include "ks.h"
#include "histedit.h"
#include "libtorrent.h"
static char * prompt(EditLine *e) {
return "dht> ";
}
typedef struct dht_globals_s {
int exiting;
} dht_globals_t;
int
main(int argc, char **argv)
{
dht_globals_t globals = {0};
int opt;
EditLine *el;
History *myhistory;
int count;
const char *line;
HistEvent ev;
ks_status_t status = KS_STATUS_SUCCESS;
// ks_pool_t *pool;
void *session = session_create(SES_LISTENPORT, 8090,
SES_LISTENPORT_END, 8098,
TAG_END);
session_start_dht(session);
globals.exiting = 0;
el = el_init("test", stdin, stdout, stderr);
el_set(el, EL_PROMPT, &prompt);
el_set(el, EL_EDITOR, "emacs");
myhistory = history_init();
history(myhistory, &ev, H_SETSIZE, 800);
el_set(el, EL_HIST, history, myhistory);
ks_global_set_default_logger(7);
while(1) {
opt = getopt(argc, argv, "hb:");
if(opt < 0)
break;
switch(opt) {
case 'b': {
printf("Not yet implemented\n");
goto usage;
}
break;
default:
goto usage;
}
}
/*
ks_pool_open(&pool);
status = ks_thread_create_ex(&threads[0], dht_event_thread, &globals, KS_THREAD_FLAG_DETATCHED, KS_THREAD_DEFAULT_STACK, KS_PRI_NORMAL, pool);
*/
if ( status != KS_STATUS_SUCCESS) {
printf("Failed to start DHT event thread\n");
exit(1);
}
while ( !globals.exiting ) {
line = el_gets(el, &count);
if (count > 1) {
int line_len = (int)strlen(line) - 1;
history(myhistory, &ev, H_ENTER, line);
if (!strncmp(line, "quit", 4)) {
globals.exiting = 1;
} else if (!strncmp(line, "loglevel", 8)) {
ks_global_set_default_logger(atoi(line + 9));
} else if (!strncmp(line, "peer_dump", 9)) {
printf("Not yet implemented\n");
} else if (!strncmp(line, "search", 6)) {
printf("Not yet implemented\n");
} else if (!strncmp(line, "announce", 8)) {
printf("Not yet implemented\n");
} else {
printf("Unknown command entered[%.*s]\n", line_len, line);
}
}
}
history_end(myhistory);
el_end(el);
session_close(session);
return 0;
usage:
printf("Usage: dht-example [-4] [-6] [-i filename] [-b address]...\n"
" port [address port]...\n");
exit(1);
}
差异被折叠。
/*
Copyright (c) 2009, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LIBTORRENT_H
#define LIBTORRENT_H
enum tags
{
TAG_END = 0,
SES_FINGERPRINT, // char const*, 2 character string
SES_LISTENPORT, // int
SES_LISTENPORT_END, // int
SES_VERSION_MAJOR, // int
SES_VERSION_MINOR, // int
SES_VERSION_TINY, // int
SES_VERSION_TAG, // int
SES_FLAGS, // int
SES_ALERT_MASK, // int
SES_LISTEN_INTERFACE, // char const*
// === add_torrent tags ===
// identifying the torrent to add
TOR_FILENAME = 0x100, // char const*
TOR_TORRENT, // char const*, specify size of buffer with TOR_TORRENT_SIZE
TOR_TORRENT_SIZE, // int
TOR_INFOHASH, // char const*, must point to a 20 byte array
TOR_INFOHASH_HEX, // char const*, must point to a 40 byte string
TOR_MAGNETLINK, // char const*, url
TOR_TRACKER_URL, // char const*
TOR_RESUME_DATA, // char const*
TOR_RESUME_DATA_SIZE, // int
TOR_SAVE_PATH, // char const*
TOR_NAME, // char const*
TOR_PAUSED, // int
TOR_AUTO_MANAGED, // int
TOR_DUPLICATE_IS_ERROR, // int
TOR_USER_DATA, //void*
TOR_SEED_MODE, // int
TOR_OVERRIDE_RESUME_DATA, // int
TOR_STORAGE_MODE, // int
SET_UPLOAD_RATE_LIMIT = 0x200, // int
SET_DOWNLOAD_RATE_LIMIT, // int
SET_LOCAL_UPLOAD_RATE_LIMIT, // int
SET_LOCAL_DOWNLOAD_RATE_LIMIT, // int
SET_MAX_UPLOAD_SLOTS, // int
SET_MAX_CONNECTIONS, // int
SET_SEQUENTIAL_DOWNLOAD, // int, torrent only
SET_SUPER_SEEDING, // int, torrent only
SET_HALF_OPEN_LIMIT, // int, session only
SET_PEER_PROXY, // proxy_setting const*, session_only
SET_WEB_SEED_PROXY, // proxy_setting const*, session_only
SET_TRACKER_PROXY, // proxy_setting const*, session_only
SET_DHT_PROXY, // proxy_setting const*, session_only
SET_PROXY, // proxy_setting const*, session_only
};
struct proxy_setting
{
char hostname[256];
int port;
char username[256];
char password[256];
int type;
};
enum proxy_type_t
{
proxy_none,
proxy_socks4,
proxy_socks5,
proxy_socks5_pw,
proxy_http,
proxy_http_pw
};
enum storage_mode_t
{
storage_mode_allocate = 0,
storage_mode_sparse,
storage_mode_compact
};
enum state_t
{
queued_for_checking,
checking_files,
downloading_metadata,
downloading,
finished,
seeding,
allocating,
checking_resume_data
};
struct torrent_status
{
enum state_t state;
int paused;
float progress;
char error[1024];
int next_announce;
int announce_interval;
char current_tracker[512];
long long total_download;
long long total_upload;
long long total_payload_download;
long long total_payload_upload;
long long total_failed_bytes;
long long total_redundant_bytes;
float download_rate;
float upload_rate;
float download_payload_rate;
float upload_payload_rate;
int num_seeds;
int num_peers;
int num_complete;
int num_incomplete;
int list_seeds;
int list_peers;
int connect_candidates;
// what to do?
// bitfield pieces;
int num_pieces;
long long total_done;
long long total_wanted_done;
long long total_wanted;
float distributed_copies;
int block_size;
int num_uploads;
int num_connections;
int uploads_limit;
int connections_limit;
// enum storage_mode_t storage_mode;
int up_bandwidth_queue;
int down_bandwidth_queue;
long long all_time_upload;
long long all_time_download;
int active_time;
int seeding_time;
int seed_rank;
int last_scrape;
int has_incoming;
int sparse_regions;
int seed_mode;
};
struct session_status
{
int has_incoming_connections;
float upload_rate;
float download_rate;
long long total_download;
long long total_upload;
float payload_upload_rate;
float payload_download_rate;
long long total_payload_download;
long long total_payload_upload;
float ip_overhead_upload_rate;
float ip_overhead_download_rate;
long long total_ip_overhead_download;
long long total_ip_overhead_upload;
float dht_upload_rate;
float dht_download_rate;
long long total_dht_download;
long long total_dht_upload;
float tracker_upload_rate;
float tracker_download_rate;
long long total_tracker_download;
long long total_tracker_upload;
long long total_redundant_bytes;
long long total_failed_bytes;
int num_peers;
int num_unchoked;
int allowed_upload_slots;
int up_bandwidth_queue;
int down_bandwidth_queue;
int up_bandwidth_bytes_queue;
int down_bandwidth_bytes_queue;
int optimistic_unchoke_counter;
int unchoke_counter;
int dht_nodes;
int dht_node_cache;
int dht_torrents;
long long dht_global_nodes;
// std::vector<dht_lookup> active_requests;
};
#ifdef __cplusplus
extern "C"
{
#endif
// the functions whose signature ends with:
// , int first_tag, ...);
// takes a tag list. The tag list is a series
// of tag-value pairs. The tags are constants
// identifying which property the value controls.
// The type of the value varies between tags.
// The enumeration above specifies which type
// it expects. All tag lists must always be
// terminated by TAG_END.
// use SES_* tags in tag list
void* session_create(int first_tag, ...);
void session_close(void* ses);
void session_start_dht(void *ses);
// use TOR_* tags in tag list
int session_add_torrent(void* ses, int first_tag, ...);
void session_remove_torrent(void* ses, int tor, int flags);
int session_get_status(void* ses, struct session_status* s, int struct_size);
// use SET_* tags in tag list
int session_set_settings(void* ses, int first_tag, ...);
int session_get_setting(void* ses, int tag, void* value, int* value_size);
int torrent_get_status(int tor, struct torrent_status* s, int struct_size);
// use SET_* tags in tag list
int torrent_set_settings(int tor, int first_tag, ...);
int torrent_get_setting(int tor, int tag, void* value, int* value_size);
#ifdef __cplusplus
}
#endif
#endif
#include <ks.h>
#include <tap.h>
/*
Test should cover all cases of DHT message construction and parsing tests
* init ks
* init a client if required
* TODO: list out msg construction and parsing tests
* Immutable messages:
* 1. create and validate single immutable messages, and handle error cases such as too large, etc.
* Mutable messages:
* 1. Create message error cases
* 2. Create initial message cases
* 3. Update message cases
* 4.
* cleanup ks
*/
int main() {
done_testing();
}
#include <ks.h>
#include <tap.h>
/*
Test should cover all cases of DHT networking for ipv4 and ipv6
* Find ip
* init 2 or more clients(with dedicated ports)
* add ip to clients
* TODO: list out nework specific tests.
* shutdown clients
* cleanup ks
*/
int main() {
done_testing();
}
#include <ks.h>
#include <tap.h>
/*
Test should cover end to end DHT functionality that isn't covered by a more specific test file
* Find ip
* init 2 or more clients(with dedicated ports)
* add ip to clients
* exchange peers between clients
* shutdown clients
* cleanup ks
*/
int main() {
int err = 0;
char v4[48] = {0}, v6[48] = {0};
int mask = 0, have_v4 = 0, have_v6 = 0;
int A_port = 5998, B_port = 5999;
dht_handle_t *A_h = NULL, *B_h = NULL;
ks_dht_af_flag_t af_flags = 0;
static ks_sockaddr_t bootstrap[1];
err = ks_init();
ok(!err);
err = ks_find_local_ip(v4, sizeof(v4), &mask, AF_INET, NULL);
ok(err == KS_STATUS_SUCCESS);
have_v4 = !zstr_buf(v4);
err = ks_find_local_ip(v6, sizeof(v6), NULL, AF_INET6, NULL);
ok(err == KS_STATUS_SUCCESS);
have_v6 = !zstr_buf(v6);
ok(have_v4 || have_v6);
if (have_v4) {
af_flags |= KS_DHT_AF_INET4;
}
diag("Adding local bind ipv4 of (%s) %d\n", v4, have_v4);
if (have_v6) {
af_flags |= KS_DHT_AF_INET6;
}
diag("Adding local bind ipv6 of (%s) %d\n", v6, have_v6);
err = ks_dht_init(&A_h, af_flags, NULL, A_port);
ok(err == KS_STATUS_SUCCESS);
if (have_v4) {
err = ks_dht_add_ip(A_h, v4, A_port);
ok(err == KS_STATUS_SUCCESS);
}
if (have_v6) {
err = ks_dht_add_ip(A_h, v6, A_port);
ok(err == KS_STATUS_SUCCESS);
}
err = ks_dht_init(&B_h, af_flags, NULL, B_port);
ok(err == KS_STATUS_SUCCESS);
if (have_v4) {
err = ks_dht_add_ip(B_h, v4, B_port);
ok(err == KS_STATUS_SUCCESS);
}
if (have_v6) {
err = ks_dht_add_ip(B_h, v6, B_port);
ok(err == KS_STATUS_SUCCESS);
}
ks_dht_start(A_h);
ks_dht_start(B_h);
ks_addr_set(&bootstrap[0], v4, B_port, 0);
/* Have A ping B */
dht_ping_node(A_h, &bootstrap[0]);
/* Start test series */
/* Absent in Test and Example App */
/*
This function is called from the test app, with the intent of processing and handling network packets(buf, buflen, from).
Tests for this function should include successful processing of new inbound messages, as well as validation of bad inbound messages.
KS_DECLARE(int) dht_periodic(dht_handle_t *h, const void *buf, size_t buflen, ks_sockaddr_t *from); */
/*
This function is like the dht_ping_node, except it only adds the node, and waits for dht_periodic to decide when to ping the node.
Doing a node ping first confirms that we have working networking to the new remote node.
KS_DECLARE(int) dht_insert_node(dht_handle_t *h, const unsigned char *id, ks_sockaddr_t *sa); */
/*
Queries for node stats. Will be used for validating that a node was successfully added. Call before the ping, ping, call after, and compare.
KS_DECLARE(int) dht_nodes(dht_handle_t *h, int af, int *good_return, int *dubious_return, int *cached_return, int *incoming_return); */
/*
Sets(or changes?) the local DHT listening port. Would be very interesting to see what happens if this is called after nodes are pinged.
KS_DECLARE(void) ks_dht_set_port(dht_handle_t *h, unsigned int port); */
/* Present in Example App but Absent in Test */
/*
ks_dht_send_message_mutable_cjson(h, alice_secretkey, alice_publickey, NULL, message_id, 1, output, 600); */
/*
ks_separate_string(cmd_dup, " ", argv, (sizeof(argv) / sizeof(argv[0]))); */
/*
ks_dht_api_find_node(h, argv[2], argv[3], ipv6); */
/*
ks_global_set_default_logger(atoi(line + 9)); */
/*
ks_dht_set_param(h, DHT_PARAM_AUTOROUTE, KS_TRUE); */
/*
Like dht_periodic, except executes only one loop of work.
ks_dht_one_loop(h, 0); */
/*
Returns a list of local bindings. Most useful after the DHT_PARAM_AUTOROUTE to return which routes it bound to.
ks_dht_get_bind_addrs(h, &bindings, &len); */
/*
Callback for different message type actions. Called from the dht_periodic functions.
ks_dht_set_callback(h, callback, NULL); */
/*
Executes a search for a particular SHA hash. Pings known nodes to see if they have the hash. callback is called with results.
dht_search(h, hash, globals.port, AF_INET, callback, NULL); */
/*
Print the contents of the 'dht tables' to stdout. Need a version that gets info in a testable format.
dht_dump_tables(h, stdout); */
/* dht_get_nodes(h, sin, &num, sin6, &num6); */
/*
Shuts down the DHT handle, and should properly clean up.
dht_uninit(&h); */
/* Cleanup and shutdown */
todo("ks_dht_stop()");
todo("ks_dht_destroy()");
err = ks_shutdown();
ok(!err);
done_testing();
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论