mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-14 08:05:37 +00:00
FS-9775: Match up datatypes, alloc node_t, remove ks_dht_bucket.h
This commit is contained in:
parent
c8c2dc87f7
commit
aa47b4bec2
@ -30,7 +30,7 @@ library_include_HEADERS += src/include/ks_dso.h src/include/ks_platform.h src/in
|
||||
library_include_HEADERS += src/include/ks_printf.h src/include/ks_hash.h src/include/ks_ssl.h src/include/kws.h
|
||||
library_include_HEADERS += src/utp/utp_internal.h src/utp/utp.h src/utp/utp_types.h src/utp/utp_callbacks.h src/utp/utp_templates.h
|
||||
library_include_HEADERS += src/utp/utp_hash.h src/utp/utp_packedsockaddr.h src/utp/utp_utils.h src/include/ks_utp.h
|
||||
library_include_HEADERS += src/dht/ks_dht.h src/dht/ks_dht-int.h src/dht/ks_dht_bucket.h
|
||||
library_include_HEADERS += src/dht/ks_dht.h src/dht/ks_dht-int.h
|
||||
|
||||
tests: libks.la
|
||||
$(MAKE) -C test tests
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#include "ks.h"
|
||||
#include "ks_bencode.h"
|
||||
#include "ks_dht_bucket.h"
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
|
||||
@ -25,7 +24,9 @@ typedef struct ks_dht_nodeid_s ks_dht_nodeid_t;
|
||||
typedef struct ks_dht_message_s ks_dht_message_t;
|
||||
typedef struct ks_dht_endpoint_s ks_dht_endpoint_t;
|
||||
typedef struct ks_dht_transaction_s ks_dht_transaction_t;
|
||||
|
||||
typedef struct ks_dht_node_s ks_dht_node_t;
|
||||
typedef struct ks_dhtrt_routetable_s ks_dhtrt_routetable_t;
|
||||
typedef struct ks_dhtrt_querynodes_s ks_dhtrt_querynodes_t;
|
||||
|
||||
typedef ks_status_t (*ks_dht_message_callback_t)(ks_dht_t *dht, ks_dht_message_t *message);
|
||||
|
||||
@ -36,6 +37,29 @@ struct ks_dht_nodeid_s {
|
||||
uint8_t id[KS_DHT_NODEID_SIZE];
|
||||
};
|
||||
|
||||
enum ipfamily { ifv4=AF_INET, ifv6=AF_INET6, ifboth=AF_INET+AF_INET6};
|
||||
|
||||
struct ks_dht_node_s {
|
||||
ks_dht_nodeid_t nodeid;
|
||||
ks_sockaddr_t addr;
|
||||
enum ipfamily family; /* in: AF_INET or AF_INET6 or both */
|
||||
ks_dhtrt_routetable_t* table;
|
||||
};
|
||||
|
||||
struct ks_dhtrt_routetable_s {
|
||||
void* internal;
|
||||
ks_pool_t* pool;
|
||||
ks_logger_t logger;
|
||||
};
|
||||
|
||||
struct ks_dhtrt_querynodes_s {
|
||||
ks_dht_nodeid_t nodeid; /* in: id to query */
|
||||
enum ipfamily family; /* in: AF_INET or AF_INET6 or both */
|
||||
uint8_t max; /* in: maximum to return */
|
||||
uint8_t count; /* out: number returned */
|
||||
ks_dht_node_t* nodes[ KS_DHT_MESSAGE_QUERY_MAX_SIZE]; /* out: array of peers (ks_dht_node_t* nodes[incount]) */
|
||||
};
|
||||
|
||||
struct ks_dht_message_s {
|
||||
ks_pool_t *pool;
|
||||
ks_dht_endpoint_t *endpoint;
|
||||
@ -91,8 +115,8 @@ struct ks_dht_s {
|
||||
volatile uint32_t transactionid_next;
|
||||
ks_hash_t *transactions_hash;
|
||||
|
||||
ks_dhtrt_routetable *rt_ipv4;
|
||||
ks_dhtrt_routetable *rt_ipv6;
|
||||
ks_dhtrt_routetable_t *rt_ipv4;
|
||||
ks_dhtrt_routetable_t *rt_ipv6;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -156,6 +180,33 @@ KS_DECLARE(ks_status_t) ks_dht_transaction_init(ks_dht_transaction_t *transactio
|
||||
uint32_t transactionid,
|
||||
ks_dht_message_callback_t callback);
|
||||
KS_DECLARE(ks_status_t) ks_dht_transaction_deinit(ks_dht_transaction_t *transaction);
|
||||
|
||||
|
||||
/**
|
||||
* route table methods
|
||||
*
|
||||
*/
|
||||
KS_DECLARE(ks_dhtrt_routetable_t*) ks_dhtrt_initroute( ks_pool_t *pool, ks_dht_nodeid_t nodeid);
|
||||
KS_DECLARE(void) ks_dhtrt_deinitroute(ks_dhtrt_routetable_t* table );
|
||||
|
||||
KS_DECLARE(ks_status_t) ks_dhtrt_create_node(ks_dhtrt_routetable_t* table,
|
||||
ks_dht_nodeid_t nodeid,
|
||||
char* ip, unsigned short port,
|
||||
ks_dht_node_t** node);
|
||||
|
||||
KS_DECLARE(ks_status_t) ks_dhtrt_delete_node(ks_dhtrt_routetable_t* table, ks_dht_node_t* node);
|
||||
|
||||
KS_DECLARE(ks_status_t) ks_dhtrt_touch_node(ks_dhtrt_routetable_t* table, ks_dht_nodeid_t nodeid);
|
||||
KS_DECLARE(ks_status_t) ks_dhtrt_expire_node(ks_dhtrt_routetable_t* table, ks_dht_nodeid_t nodeid);
|
||||
|
||||
KS_DECLARE(uint8_t) ks_dhtrt_findclosest_nodes(ks_dhtrt_routetable_t* table, ks_dhtrt_querynodes_t* query);
|
||||
KS_DECLARE(ks_dht_node_t*) ks_dhtrt_find_node(ks_dhtrt_routetable_t* table, ks_dht_nodeid_t id);
|
||||
|
||||
KS_DECLARE(void) ks_dhtrt_process_table(ks_dhtrt_routetable_t* table);
|
||||
|
||||
/* debugging aids */
|
||||
KS_DECLARE(void) ks_dhtrt_dump(ks_dhtrt_routetable_t* table, int level);
|
||||
|
||||
|
||||
KS_END_EXTERN_C
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Colm Quinn
|
||||
* 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 original author; nor the names of any 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 _KS_DHT_BUCKETS_H_
|
||||
#define _KS_DHT_BUCKETS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define KS_BEGIN_EXTERN_C extern "C" {
|
||||
#define KS_END_EXTERN_C }
|
||||
#else
|
||||
#define KS_BEGIN_EXTERN_C
|
||||
#define KS_END_EXTERN_C
|
||||
#endif
|
||||
|
||||
#include "ks.h"
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
|
||||
/* @todo: temporary - replace with real definiton when available */
|
||||
typedef void ks_dht_node_t;
|
||||
|
||||
|
||||
enum ks_dhtrt_nodestate_t {DHTRT_UNKNOWN, DHTRT_ACTIVE, DHTRT_SUSPECT, DHTRT_EXPIRED};
|
||||
|
||||
typedef ks_status_t (*ks_dhtrt_callback)(ks_dht_node_t*, enum ks_dhtrt_nodestate_t);
|
||||
|
||||
|
||||
/* for testing */
|
||||
#define KS_DHT_BUCKETSIZE 20
|
||||
#define KS_DHT_IDSIZE 20
|
||||
|
||||
|
||||
typedef struct ks_dhtrt_node_s {
|
||||
unsigned char id[KS_DHT_IDSIZE];
|
||||
ks_dht_node_t* handle;
|
||||
} ks_dhtrt_node;
|
||||
|
||||
typedef struct ks_dhtrt_routetable_s {
|
||||
void* internal; /* ks_dhtrt_internal */
|
||||
ks_pool_t* pool; /* */
|
||||
ks_logger_t logger;
|
||||
} ks_dhtrt_routetable;
|
||||
|
||||
typedef struct ks_dhtrt_querynodes_s {
|
||||
unsigned char id[KS_DHT_IDSIZE]; /* in: id to query */
|
||||
uint8_t max; /* in: maximum to return */
|
||||
uint8_t count; /* out: number returned */
|
||||
ks_dht_node_t* nodes[KS_DHT_BUCKETSIZE]; /* out: array of peers (ks_dht_node_t* peer[incount]) */
|
||||
} ks_dhtrt_querynodes;
|
||||
|
||||
|
||||
typedef unsigned char ks_dhtrt_nodeid[KS_DHT_IDSIZE];
|
||||
|
||||
/* methods */
|
||||
|
||||
ks_dhtrt_routetable* ks_dhtrt_initroute( ks_pool_t *pool, ks_dhtrt_nodeid localid);
|
||||
ks_status_t ks_dhtrt_registercallback(ks_dhtrt_callback, enum ks_dhtrt_nodestate_t);
|
||||
void ks_dhtrt_deinitroute(ks_dhtrt_routetable* table );
|
||||
|
||||
ks_dhtrt_node* ks_dhtrt_create_node(ks_dhtrt_routetable* table, ks_dhtrt_nodeid nodeid, ks_dht_node_t* node);
|
||||
ks_status_t ks_dhtrt_delete_node(ks_dhtrt_routetable* table, ks_dhtrt_node* node);
|
||||
|
||||
ks_status_t ks_dhtrt_touch_node(ks_dhtrt_routetable* table, ks_dhtrt_nodeid nodeid);
|
||||
ks_status_t ks_dhtrt_expire_node(ks_dhtrt_routetable* table, ks_dhtrt_nodeid nodeid);
|
||||
|
||||
uint8_t ks_dhtrt_findclosest_nodes(ks_dhtrt_routetable* table, ks_dhtrt_querynodes* query);
|
||||
ks_dht_node_t* ks_dhtrt_find_node(ks_dhtrt_routetable* table, ks_dhtrt_nodeid id);
|
||||
|
||||
|
||||
/* debugging aids */
|
||||
void ks_dhtrt_dump(ks_dhtrt_routetable* table, int level);
|
||||
void ks_dhtrt_process_table(ks_dhtrt_routetable* table);
|
||||
|
||||
|
||||
KS_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user