提交 716f0289 authored 作者: Mike Jerris's avatar Mike Jerris

Merge pull request #1234 in FS/freeswitch from…

Merge pull request #1234 in FS/freeswitch from feature/FS-9952-implementing-a-syncronized-scalable to master

* commit '7742dffa': (34 commits)
  FS-9952: Initial implementation of a very basic text chat system which introduced a number of supporting subsystems
  FS-9952: Added support to default ks_log system for including optional prefixes as desired, also added thread and time prefix options
  FS-9952: Big commit, first registered jsonrpc echo call successful, lots of cleanup remaining
  FS-9952: Intermediate commit for a fresh point to start retrofitting the jsonrpc code that is incomplete
  FS-9952: Some code refactoring and added TTL for sessions, currently harcoded at 5 seconds for testing purposes only and should come from config
  FS-9952: Preliminary session negotiations done, added a bunch of logging, fixed up cleanup code, needs more testing and more error handling
  FS-9952: Added the first half of the session negotations for the server side, untested as it requires the second half coming soon for client side
  FS-9952: A bunch of cleanup and shifting connections towards ID based passing instead of pointers, will replicate and adjust for session system next
  FS-9952: Add blade rpc error response creation
  FS-9952: Fix compile errors in test 64bit build
  FS-9952: Committing to show problem with ks_pool_resize
  FS-9952: Add query & tests for blade extention to rpc messages
  FS-9952: Add blade extention to rpc messages
  FS-9952: Some work towards client connectivity support, commit is to remove blade_message_t and get RPC stuff updated, code does not compile currently
  FS-9952: Added initial support for registering transports, and initial untested code for parsing identities
  FS-9952: Updated bladec test, it successfully listens for connections, further testing required
  FS-9952: Added envelope to queue sending messages, prepping for initial server transport testing
  FS-9952: Add rpc h files to ks
  FS-9952: Update for compile issues
  FS-9952: More work on the connection and transport code, couple things left to do but nearly ready for testing upto starting session negotiations
  ...
......@@ -11,18 +11,20 @@ libunqlite_la_CFLAGS = -DUNQLITE_ENABLE_THREADS
libunqlite_la_LIBADD = -lpthread
lib_LTLIBRARIES = libblade.la
libblade_la_SOURCES = src/blade.c src/blade_stack.c src/blade_peer.c src/bpcp.c src/blade_datastore.c
libblade_la_SOURCES = src/blade.c src/blade_stack.c
libblade_la_SOURCES += src/blade_datastore.c
libblade_la_SOURCES += src/blade_identity.c src/blade_module.c src/blade_connection.c
libblade_la_SOURCES += src/blade_session.c src/blade_protocol.c src/blade_space.c src/blade_method.c
libblade_la_SOURCES += src/blade_module_wss.c src/blade_module_chat.c
libblade_la_CFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS)
libblade_la_LDFLAGS = -version-info 0:1:0 -lncurses -lpthread -lm $(AM_LDFLAGS)
libblade_la_LDFLAGS = -version-info 0:1:0 -lncurses -lpthread -lm -lconfig $(AM_LDFLAGS)
libblade_la_LIBADD = libunqlite.la
library_includedir = $(prefix)/include
library_include_HEADERS = src/include/blade.h src/include/blade_types.h src/include/blade_stack.h src/include/blade_peer.h src/include/bpcp.h
library_include_HEADERS = src/include/blade.h src/include/blade_types.h src/include/blade_stack.h
library_include_HEADERS += src/include/blade_datastore.h
library_include_HEADERS += src/include/blade_identity.h src/include/blade_module.h src/include/blade_connection.h
library_include_HEADERS += src/include/blade_session.h src/include/blade_protocol.h src/include/blade_space.h src/include/blade_method.h
library_include_HEADERS += src/include/unqlite.h test/tap.h
tests: libblade.la
$(MAKE) -C test tests
差异被折叠。
......@@ -34,14 +34,12 @@
#include "blade.h"
typedef enum {
BDS_NONE = 0,
BDS_MYPOOL = (1 << 0),
} bdspvt_flag_t;
struct blade_datastore_s {
bdspvt_flag_t flags;
ks_pool_t *pool;
ks_thread_pool_t *tpool;
const char *config_database_path;
unqlite *db;
};
......@@ -58,8 +56,6 @@ typedef struct blade_datastore_fetch_userdata_s blade_datastore_fetch_userdata_t
KS_DECLARE(ks_status_t) blade_datastore_destroy(blade_datastore_t **bdsP)
{
blade_datastore_t *bds = NULL;
bdspvt_flag_t flags;
ks_pool_t *pool;
ks_assert(bdsP);
......@@ -68,41 +64,65 @@ KS_DECLARE(ks_status_t) blade_datastore_destroy(blade_datastore_t **bdsP)
ks_assert(bds);
flags = bds->flags;
pool = bds->pool;
if (bds->db) {
unqlite_close(bds->db);
bds->db = NULL;
}
blade_datastore_shutdown(bds);
ks_pool_free(bds->pool, &bds);
if (pool && (flags & BDS_MYPOOL)) ks_pool_close(&pool);
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_datastore_create(blade_datastore_t **bdsP, ks_pool_t *pool)
KS_DECLARE(ks_status_t) blade_datastore_create(blade_datastore_t **bdsP, ks_pool_t *pool, ks_thread_pool_t *tpool)
{
bdspvt_flag_t newflags = BDS_NONE;
blade_datastore_t *bds = NULL;
if (!pool) {
newflags |= BDS_MYPOOL;
ks_pool_open(&pool);
ks_assert(pool);
}
ks_assert(bdsP);
ks_assert(pool);
ks_assert(tpool);
bds = ks_pool_alloc(pool, sizeof(*bds));
bds->flags = newflags;
bds->pool = pool;
bds->tpool = tpool;
*bdsP = bds;
if (unqlite_open(&bds->db, NULL, UNQLITE_OPEN_IN_MEMORY) != UNQLITE_OK) {
return KS_STATUS_SUCCESS;
}
ks_status_t blade_datastore_config(blade_datastore_t *bds, config_setting_t *config)
{
config_setting_t *tmp;
config_setting_t *database = NULL;
const char *config_database_path = NULL;
ks_assert(bds);
if (!config) return KS_STATUS_FAIL;
if (!config_setting_is_group(config)) return KS_STATUS_FAIL;
database = config_setting_get_member(config, "database");
if (!database) return KS_STATUS_FAIL;
tmp = config_lookup_from(database, "path");
if (!tmp) return KS_STATUS_FAIL;
if (config_setting_type(tmp) != CONFIG_TYPE_STRING) return KS_STATUS_FAIL;
config_database_path = config_setting_get_string(tmp);
if (bds->config_database_path) ks_pool_free(bds->pool, &bds->config_database_path);
bds->config_database_path = ks_pstrdup(bds->pool, config_database_path);
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_datastore_startup(blade_datastore_t *bds, config_setting_t *config)
{
ks_assert(bds);
// @todo check if already started
if (blade_datastore_config(bds, config) != KS_STATUS_SUCCESS) return KS_STATUS_FAIL;
if (unqlite_open(&bds->db, bds->config_database_path, UNQLITE_OPEN_CREATE) != UNQLITE_OK) {
const char *errbuf = NULL;
blade_datastore_error(bds, &errbuf, NULL);
ks_log(KS_LOG_ERROR, "BDS Error: %s\n", errbuf);
ks_log(KS_LOG_ERROR, "BDS Open Error: %s\n", errbuf);
return KS_STATUS_FAIL;
}
......@@ -113,12 +133,21 @@ KS_DECLARE(ks_status_t) blade_datastore_create(blade_datastore_t **bdsP, ks_pool
return KS_STATUS_SUCCESS;
}
KS_DECLARE(void) blade_datastore_pulse(blade_datastore_t *bds, int32_t timeout)
KS_DECLARE(ks_status_t) blade_datastore_shutdown(blade_datastore_t *bds)
{
ks_assert(bds);
ks_assert(timeout >= 0);
if (bds->db) {
unqlite_close(bds->db);
bds->db = NULL;
}
if (bds->config_database_path) ks_pool_free(bds->pool, &bds->config_database_path);
return KS_STATUS_SUCCESS;
}
KS_DECLARE(void) blade_datastore_error(blade_datastore_t *bds, const char **buffer, int32_t *buffer_length)
{
ks_assert(bds);
......@@ -147,7 +176,7 @@ KS_DECLARE(ks_status_t) blade_datastore_store(blade_datastore_t *bds, const void
else {
const char *errbuf;
blade_datastore_error(bds, &errbuf, NULL);
ks_log(KS_LOG_ERROR, "BDS Error: %s\n", errbuf);
ks_log(KS_LOG_ERROR, "BDS Store Error: %s\n", errbuf);
ret = KS_STATUS_FAIL;
}
......@@ -196,10 +225,11 @@ KS_DECLARE(ks_status_t) blade_datastore_fetch(blade_datastore_t *bds,
if (rc != UNQLITE_OK) {
if (rc == UNQLITE_BUSY) ret = KS_STATUS_TIMEOUT;
else if(rc == UNQLITE_NOTFOUND) ret = KS_STATUS_NOT_FOUND;
else {
const char *errbuf;
blade_datastore_error(bds, &errbuf, NULL);
ks_log(KS_LOG_ERROR, "BDS Error: %s\n", errbuf);
ks_log(KS_LOG_ERROR, "BDS Fetch Error: %s\n", errbuf);
ret = KS_STATUS_FAIL;
}
......
/*
* Copyright (c) 2017, Shane Bryldt
* 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.
*/
#include "blade.h"
struct blade_identity_s {
ks_pool_t *pool;
const char *uri;
const char *components;
const char *name;
const char *domain;
const char *resource;
ks_hash_t *parameters;
};
KS_DECLARE(ks_status_t) blade_identity_create(blade_identity_t **biP, ks_pool_t *pool)
{
blade_identity_t *bi = NULL;
ks_assert(biP);
ks_assert(pool);
bi = ks_pool_alloc(pool, sizeof(blade_identity_t));
bi->pool = pool;
*biP = bi;
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_identity_destroy(blade_identity_t **biP)
{
blade_identity_t *bi = NULL;
ks_assert(biP);
ks_assert(*biP);
bi = *biP;
if (bi->uri) {
ks_pool_free(bi->pool, &bi->uri);
ks_pool_free(bi->pool, &bi->components);
}
if (bi->parameters) ks_hash_destroy(&bi->parameters);
ks_pool_free(bi->pool, biP);
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_identity_parse(blade_identity_t *bi, const char *uri)
{
char *tmp = NULL;
char *tmp2 = NULL;
ks_assert(bi);
ks_assert(uri);
ks_log(KS_LOG_DEBUG, "Parsing URI: %s\n", uri);
if (bi->uri) {
ks_pool_free(bi->pool, &bi->uri);
ks_pool_free(bi->pool, &bi->components);
}
bi->uri = ks_pstrdup(bi->pool, uri);
bi->components = tmp = ks_pstrdup(bi->pool, uri);
bi->name = tmp;
if (!(tmp = strchr(tmp, '@'))) return KS_STATUS_FAIL;
*tmp++ = '\0';
bi->domain = tmp2 = tmp;
if ((tmp = strchr(tmp, '/'))) {
*tmp++ = '\0';
bi->resource = tmp2 = tmp;
} else tmp = tmp2;
if ((tmp = strchr(tmp, '?'))) {
*tmp++ = '\0';
while (tmp) {
char *key = tmp;
char *val = NULL;
if (!(tmp = strchr(tmp, '='))) return KS_STATUS_FAIL;
*tmp++ = '\0';
val = tmp;
if ((tmp = strchr(tmp, '&'))) {
*tmp++ = '\0';
}
if (!bi->parameters) {
ks_hash_create(&bi->parameters, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_NOLOCK | KS_HASH_FLAG_DUP_CHECK, bi->pool);
ks_assert(bi->parameters);
}
ks_hash_insert(bi->parameters, key, val);
}
}
return KS_STATUS_SUCCESS;
}
KS_DECLARE(const char *) blade_identity_uri(blade_identity_t *bi)
{
ks_assert(bi);
return bi->uri;
}
KS_DECLARE(const char *) blade_identity_parameter_get(blade_identity_t *bi, const char *key)
{
ks_assert(bi);
ks_assert(key);
return (const char *)ks_hash_search(bi->parameters, (void *)key, KS_UNLOCKED);
}
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
/*
* Copyright (c) 2007-2014, Anthony Minessale II
* Copyright (c) 2017, Shane Bryldt
* 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
......@@ -33,69 +33,79 @@
#include "blade.h"
struct blade_method_s {
blade_handle_t *handle;
ks_pool_t *pool;
/*
blade_space_t *space;
const char *name;
Find bootstrap addr.
Make a WSS connection to get validated and get group keys.
Broadcast/Announce existence.
blade_request_callback_t callback;
// @todo more fun descriptive information about the call for remote registrations
};
HEADER
KS_DECLARE(ks_status_t) blade_method_create(blade_method_t **bmP, blade_space_t *bs, const char *name, blade_request_callback_t callback)
{
blade_handle_t *bh = NULL;
blade_method_t *bm = NULL;
ks_pool_t *pool = NULL;
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Ver |r|R|U|U| Channel no | Packet Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SEQ |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PAYLOAD ...... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ks_assert(bmP);
ks_assert(bs);
ks_assert(name);
r = IS Response
R = IS Retransmission
U = Unused
bh = blade_space_handle_get(bs);
ks_assert(bh);
PAYLOAD
pool = blade_handle_pool_get(bh);
ks_assert(pool);
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Instruction | Datatype | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| PAYLOAD ..... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
bm = ks_pool_alloc(pool, sizeof(blade_method_t));
bm->handle = bh;
bm->pool = pool;
bm->space = bs;
bm->name = name; // @todo dup and keep copy? should mostly be literals
bm->callback = callback;
*bmP = bm;
*/
ks_log(KS_LOG_DEBUG, "Method Created: %s.%s\n", blade_space_path_get(bs), name);
return KS_STATUS_SUCCESS;
}
typedef struct bpcp_header_s {
uint32_t header;
uint64_t seq;
} bpcp_header_t;
KS_DECLARE(ks_status_t) blade_method_destroy(blade_method_t **bmP)
{
blade_method_t *bm = NULL;
typedef struct bpcp_channel_nfo_s {
char *channel_name;
unsigned char key[crypto_generichash_BYTES];
uint32_t ttl;
} bpcp_channel_nfo_t;
ks_assert(bmP);
ks_assert(*bmP);
typedef struct bpcp_handle_s {
ks_socket_t sock;
ks_sockaddr_t local_addr;
ks_sockaddr_t bootstrap_addr;
ks_hash_t *channel_nfo_hash;
} bpcp_handle_t;
bm = *bmP;
ks_log(KS_LOG_DEBUG, "Method Destroyed: %s.%s\n", blade_space_path_get(bm->space), bm->name);
ks_pool_free(bm->pool, bmP);
KS_DECLARE(ks_status_t) bpcp_create(bpcp_handle_t **handle,
const char *local_addr, ks_port_t local_port,
const char *bootstrap_addr, ks_port_t bootstrap_port)
{
return KS_STATUS_SUCCESS;
}
KS_DECLARE(const char *) blade_method_name_get(blade_method_t *bm)
{
ks_assert(bm);
return bm->name;
}
KS_DECLARE(blade_request_callback_t) blade_method_callback_get(blade_method_t *bm)
{
ks_assert(bm);
return bm->callback;
}
/* For Emacs:
* Local Variables:
* mode:c
......
/*
* Copyright (c) 2007-2014, Anthony Minessale II
* Copyright (c) 2017, Shane Bryldt
* 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
......@@ -33,111 +33,66 @@
#include "blade.h"
#define KS_DHT_TPOOL_MIN 2
#define KS_DHT_TPOOL_MAX 8
#define KS_DHT_TPOOL_STACK (1024 * 256)
#define KS_DHT_TPOOL_IDLE 10
typedef enum {
BP_NONE = 0,
BP_MYPOOL = (1 << 0),
BP_MYTPOOL = (1 << 1)
} bppvt_flag_t;
struct blade_peer_s {
bppvt_flag_t flags;
struct blade_module_s {
blade_handle_t *handle;
ks_pool_t *pool;
ks_thread_pool_t *tpool;
ks_dht_t *dht;
void *module_data;
blade_module_callbacks_t *module_callbacks;
};
KS_DECLARE(ks_status_t) blade_peer_destroy(blade_peer_t **bpP)
KS_DECLARE(ks_status_t) blade_module_create(blade_module_t **bmP, blade_handle_t *bh, void *module_data, blade_module_callbacks_t *module_callbacks)
{
blade_peer_t *bp = NULL;
bppvt_flag_t flags;
ks_pool_t *pool;
blade_module_t *bm = NULL;
ks_pool_t *pool = NULL;
ks_assert(bpP);
ks_assert(bmP);
ks_assert(bh);
ks_assert(module_data);
ks_assert(module_callbacks);
bp = *bpP;
*bpP = NULL;
pool = blade_handle_pool_get(bh);
ks_assert(bp);
flags = bp->flags;
pool = bp->pool;
if (bp->dht) ks_dht_destroy(&bp->dht);
if (bp->tpool && (flags & BP_MYTPOOL)) ks_thread_pool_destroy(&bp->tpool);
ks_pool_free(bp->pool, &bp);
if (pool && (flags & BP_MYPOOL)) ks_pool_close(&pool);
bm = ks_pool_alloc(pool, sizeof(blade_module_t));
bm->handle = bh;
bm->pool = pool;
bm->module_data = module_data;
bm->module_callbacks = module_callbacks;
*bmP = bm;
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_peer_create(blade_peer_t **bpP, ks_pool_t *pool, ks_thread_pool_t *tpool, ks_dht_nodeid_t *nodeid)
KS_DECLARE(ks_status_t) blade_module_destroy(blade_module_t **bmP)
{
bppvt_flag_t newflags = BP_NONE;
blade_peer_t *bp = NULL;
ks_dht_t *dht = NULL;
if (!pool) {
newflags |= BP_MYPOOL;
ks_pool_open(&pool);
ks_assert(pool);
}
if (!tpool) {
newflags |= BP_MYTPOOL;
ks_thread_pool_create(&tpool, BLADE_PEER_TPOOL_MIN, BLADE_PEER_TPOOL_MAX, BLADE_PEER_TPOOL_STACK, KS_PRI_NORMAL, BLADE_PEER_TPOOL_IDLE);
ks_assert(tpool);
}
ks_dht_create(&dht, pool, tpool, nodeid);
ks_assert(dht);
bp = ks_pool_alloc(pool, sizeof(*bp));
bp->flags = newflags;
bp->pool = pool;
bp->tpool = tpool;
bp->dht = dht;
*bpP = bp;
blade_module_t *bm = NULL;
return KS_STATUS_SUCCESS;
}
ks_assert(bmP);
ks_assert(*bmP);
KS_DECLARE(ks_dht_nodeid_t *) blade_peer_myid(blade_peer_t *bp)
{
ks_assert(bp);
ks_assert(bp->dht);
bm = *bmP;
return &bp->dht->nodeid;
}
ks_pool_free(bm->pool, bmP);
KS_DECLARE(void) blade_peer_autoroute(blade_peer_t *bp, ks_bool_t autoroute, ks_port_t port)
{
ks_assert(bp);
ks_dht_autoroute(bp->dht, autoroute, port);
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_peer_bind(blade_peer_t *bp, const ks_sockaddr_t *addr, ks_dht_endpoint_t **endpoint)
KS_DECLARE(blade_handle_t *) blade_module_handle_get(blade_module_t *bm)
{
ks_assert(bp);
ks_assert(addr);
ks_assert(bm);
return ks_dht_bind(bp->dht, addr, endpoint);
return bm->handle;
}
KS_DECLARE(void) blade_peer_pulse(blade_peer_t *bp, int32_t timeout)
KS_DECLARE(void *) blade_module_data_get(blade_module_t *bm)
{
ks_assert(bp);
ks_assert(timeout >= 0);
ks_assert(bm);
ks_dht_pulse(bp->dht, timeout);
return bm->module_data;
}
/* For Emacs:
* Local Variables:
* mode:c
......
差异被折叠。
差异被折叠。
/*
* Copyright (c) 2017, Shane Bryldt
* 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.
*/
#include "blade.h"
KS_DECLARE(ks_status_t) blade_request_create(blade_request_t **breqP,
blade_handle_t *bh,
const char *session_id,
cJSON *json,
blade_response_callback_t callback)
{
blade_request_t *breq = NULL;
ks_pool_t *pool = NULL;
ks_assert(breqP);
ks_assert(bh);
ks_assert(session_id);
ks_assert(json);
pool = blade_handle_pool_get(bh);
ks_assert(pool);
breq = ks_pool_alloc(pool, sizeof(blade_request_t));
breq->handle = bh;
breq->pool = pool;
breq->session_id = ks_pstrdup(pool, session_id);
breq->message = cJSON_Duplicate(json, 1);
breq->message_id = cJSON_GetObjectCstr(breq->message, "id");
breq->callback = callback;
*breqP = breq;
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_request_destroy(blade_request_t **breqP)
{
blade_request_t *breq = NULL;
ks_assert(breqP);
ks_assert(*breqP);
breq = *breqP;
ks_pool_free(breq->pool, (void **)&breq->session_id);
cJSON_Delete(breq->message);
ks_pool_free(breq->pool, breqP);
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_response_create(blade_response_t **bresP,
blade_handle_t *bh,
const char *session_id,
blade_request_t *breq,
cJSON *json)
{
blade_response_t *bres = NULL;
ks_pool_t *pool = NULL;
ks_assert(bresP);
ks_assert(bh);
ks_assert(session_id);
ks_assert(breq);
ks_assert(json);
pool = blade_handle_pool_get(bh);
ks_assert(pool);
bres = ks_pool_alloc(pool, sizeof(blade_response_t));
bres->handle = bh;
bres->pool = pool;
bres->session_id = ks_pstrdup(pool, session_id);
bres->request = breq;
bres->message = cJSON_Duplicate(json, 1);
*bresP = bres;
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_response_destroy(blade_response_t **bresP)
{
blade_response_t *bres = NULL;
ks_assert(bresP);
ks_assert(*bresP);
bres = *bresP;
ks_pool_free(bres->pool, (void **)&bres->session_id);
blade_request_destroy(&bres->request);
cJSON_Delete(bres->message);
ks_pool_free(bres->pool, bresP);
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_event_create(blade_event_t **bevP,
blade_handle_t *bh,
const char *session_id,
cJSON *json)
{
blade_event_t *bev = NULL;
ks_pool_t *pool = NULL;
ks_assert(bevP);
ks_assert(bh);
ks_assert(session_id);
ks_assert(json);
pool = blade_handle_pool_get(bh);
ks_assert(pool);
bev = ks_pool_alloc(pool, sizeof(blade_event_t));
bev->handle = bh;
bev->pool = pool;
bev->session_id = ks_pstrdup(pool, session_id);
bev->message = cJSON_Duplicate(json, 1);
*bevP = bev;
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_event_destroy(blade_event_t **bevP)
{
blade_event_t *bev = NULL;
ks_assert(bevP);
ks_assert(*bevP);
bev = *bevP;
ks_pool_free(bev->pool, (void **)&bev->session_id);
cJSON_Delete(bev->message);
ks_pool_free(bev->pool, bevP);
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_rpc_request_create(ks_pool_t *pool, cJSON **json, cJSON **params, const char **id, const char *method)
{
cJSON *root = NULL;
cJSON *p = NULL;
uuid_t msgid;
const char *mid = NULL;
ks_assert(pool);
ks_assert(json);
ks_assert(method);
root = cJSON_CreateObject();
cJSON_AddStringToObject(root, "jsonrpc", "2.0");
ks_uuid(&msgid);
mid = ks_uuid_str(pool, &msgid);
cJSON_AddStringToObject(root, "id", mid);
ks_pool_free(pool, &mid);
cJSON_AddStringToObject(root, "method", method);
p = cJSON_CreateObject();
cJSON_AddItemToObject(root, "params", p);
*json = root;
if (params) *params = p;
if (id) *id = cJSON_GetObjectCstr(root, "id");
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_rpc_response_create(ks_pool_t *pool, cJSON **json, cJSON **result, const char *id)
{
cJSON *root = NULL;
cJSON *r = NULL;
ks_assert(pool);
ks_assert(json);
ks_assert(id);
root = cJSON_CreateObject();
cJSON_AddStringToObject(root, "jsonrpc", "2.0");
cJSON_AddStringToObject(root, "id", id);
r = cJSON_CreateObject();
cJSON_AddItemToObject(root, "result", r);
*json = root;
if (result) *result = r;
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_rpc_error_create(ks_pool_t *pool, cJSON **json, cJSON **error, const char *id, int32_t code, const char *message)
{
cJSON *root = NULL;
cJSON *e = NULL;
ks_assert(pool);
ks_assert(json);
ks_assert(id);
ks_assert(message);
root = cJSON_CreateObject();
cJSON_AddStringToObject(root, "jsonrpc", "2.0");
cJSON_AddStringToObject(root, "id", id);
e = cJSON_CreateObject();
cJSON_AddNumberToObject(e, "code", code);
cJSON_AddStringToObject(e, "message", message);
cJSON_AddItemToObject(root, "error", e);
*json = root;
if (error) *error = e;
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_rpc_event_create(ks_pool_t *pool, cJSON **json, cJSON **result, const char *event)
{
cJSON *root = NULL;
cJSON *b = NULL;
cJSON *r = NULL;
ks_assert(pool);
ks_assert(json);
ks_assert(event);
root = cJSON_CreateObject();
cJSON_AddStringToObject(root, "jsonrpc", "2.0");
b = cJSON_CreateObject();
cJSON_AddStringToObject(b, "event", event);
cJSON_AddItemToObject(root, "blade", b);
if (result) {
r = cJSON_CreateObject();
cJSON_AddItemToObject(root, "result", r);
*result = r;
}
*json = root;
return KS_STATUS_SUCCESS;
}
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
差异被折叠。
/*
* Copyright (c) 2017, Shane Bryldt
* 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.
*/
#include "blade.h"
struct blade_space_s {
blade_handle_t *handle;
ks_pool_t *pool;
blade_module_t *module;
const char *path;
ks_hash_t *methods;
};
KS_DECLARE(ks_status_t) blade_space_create(blade_space_t **bsP, blade_handle_t *bh, blade_module_t *bm, const char *path)
{
blade_space_t *bs = NULL;
ks_pool_t *pool = NULL;
ks_assert(bsP);
ks_assert(bh);
ks_assert(path);
pool = blade_handle_pool_get(bh);
bs = ks_pool_alloc(pool, sizeof(blade_space_t));
bs->handle = bh;
bs->pool = pool;
bs->module = bm;
bs->path = path; // @todo dup and keep copy? should mostly be literals
ks_hash_create(&bs->methods, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_NOLOCK | KS_HASH_FLAG_DUP_CHECK, bs->pool);
ks_assert(bs);
*bsP = bs;
ks_log(KS_LOG_DEBUG, "Space Created: %s\n", path);
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_space_destroy(blade_space_t **bsP)
{
blade_space_t *bs = NULL;
ks_hash_iterator_t *it = NULL;
ks_assert(bsP);
ks_assert(*bsP);
bs = *bsP;
for (it = ks_hash_first(bs->methods, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
void *key = NULL;
blade_method_t *value = NULL;
ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
blade_method_destroy(&value);
}
ks_hash_destroy(&bs->methods);
ks_log(KS_LOG_DEBUG, "Space Destroyed: %s\n", bs->path);
ks_pool_free(bs->pool, bsP);
return KS_STATUS_SUCCESS;
}
KS_DECLARE(blade_handle_t *) blade_space_handle_get(blade_space_t *bs)
{
ks_assert(bs);
return bs->handle;
}
KS_DECLARE(blade_module_t *) blade_space_module_get(blade_space_t *bs)
{
ks_assert(bs);
return bs->module;
}
KS_DECLARE(const char *) blade_space_path_get(blade_space_t *bs)
{
ks_assert(bs);
return bs->path;
}
KS_DECLARE(ks_status_t) blade_space_methods_add(blade_space_t *bs, blade_method_t *bm)
{
ks_status_t ret = KS_STATUS_SUCCESS;
const char *name = NULL;
blade_method_t *bm_old = NULL;
ks_assert(bs);
ks_assert(bm);
name = blade_method_name_get(bm);
ks_assert(name);
ks_hash_write_lock(bs->methods);
bm_old = ks_hash_search(bs->methods, (void *)name, KS_UNLOCKED);
if (bm_old) ks_hash_remove(bs->methods, (void *)name);
ret = ks_hash_insert(bs->methods, (void *)name, (void *)bm);
ks_hash_write_unlock(bs->methods);
if (bm_old) blade_method_destroy(&bm_old);
return ret;
}
KS_DECLARE(ks_status_t) blade_space_methods_remove(blade_space_t *bs, blade_method_t *bm)
{
ks_status_t ret = KS_STATUS_SUCCESS;
const char *name = NULL;
ks_assert(bs);
ks_assert(bm);
name = blade_method_name_get(bm);
ks_assert(name);
ks_hash_write_lock(bs->methods);
ks_hash_remove(bs->methods, (void *)name);
ks_hash_write_unlock(bs->methods);
return ret;
}
KS_DECLARE(blade_method_t *) blade_space_methods_get(blade_space_t *bs, const char *name)
{
blade_method_t *bm = NULL;
ks_assert(bs);
ks_assert(name);
ks_hash_read_lock(bs->methods);
bm = ks_hash_search(bs->methods, (void *)name, KS_UNLOCKED);
ks_hash_read_unlock(bs->methods);
return bm;
}
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
/*
* Copyright (c) 2007-2014, Anthony Minessale II
* 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
......@@ -36,12 +36,18 @@
#include <ks.h>
#include <ks_dht.h>
#include <sodium.h>
#include <libconfig.h>
#include "unqlite.h"
#include "blade_types.h"
#include "blade_stack.h"
#include "blade_peer.h"
#include "blade_identity.h"
#include "blade_module.h"
#include "blade_connection.h"
#include "blade_session.h"
#include "blade_protocol.h"
#include "blade_datastore.h"
#include "bpcp.h"
#include "blade_space.h"
#include "blade_method.h"
KS_BEGIN_EXTERN_C
......
/*
* Copyright (c) 2017, Shane Bryldt
* 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 _BLADE_CONNECTION_H_
#define _BLADE_CONNECTION_H_
#include <blade.h>
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_connection_create(blade_connection_t **bcP,
blade_handle_t *bh,
void *transport_data,
blade_transport_callbacks_t *transport_callbacks);
KS_DECLARE(ks_status_t) blade_connection_destroy(blade_connection_t **bcP);
KS_DECLARE(ks_status_t) blade_connection_startup(blade_connection_t *bc, blade_connection_direction_t direction);
KS_DECLARE(ks_status_t) blade_connection_shutdown(blade_connection_t *bc);
KS_DECLARE(blade_handle_t *) blade_connection_handle_get(blade_connection_t *bc);
KS_DECLARE(ks_pool_t *) blade_connection_pool_get(blade_connection_t *bc);
KS_DECLARE(const char *) blade_connection_id_get(blade_connection_t *bc);
KS_DECLARE(ks_status_t) blade_connection_read_lock(blade_connection_t *bc, ks_bool_t block);
KS_DECLARE(ks_status_t) blade_connection_read_unlock(blade_connection_t *bc);
KS_DECLARE(ks_status_t) blade_connection_write_lock(blade_connection_t *bc, ks_bool_t block);
KS_DECLARE(ks_status_t) blade_connection_write_unlock(blade_connection_t *bc);
KS_DECLARE(void *) blade_connection_transport_init_get(blade_connection_t *bc);
KS_DECLARE(void *) blade_connection_transport_get(blade_connection_t *bc);
KS_DECLARE(void) blade_connection_transport_set(blade_connection_t *bc, void *transport_data);
KS_DECLARE(void) blade_connection_state_set(blade_connection_t *bc, blade_connection_state_t state);
KS_DECLARE(void) blade_connection_disconnect(blade_connection_t *bc);
KS_DECLARE(blade_connection_rank_t) blade_connection_rank(blade_connection_t *bc, blade_identity_t *target);
KS_DECLARE(ks_status_t) blade_connection_sending_push(blade_connection_t *bc, cJSON *json);
KS_DECLARE(ks_status_t) blade_connection_sending_pop(blade_connection_t *bc, cJSON **json);
KS_DECLARE(const char *) blade_connection_session_get(blade_connection_t *bc);
KS_DECLARE(void) blade_connection_session_set(blade_connection_t *bc, const char *id);
KS_END_EXTERN_C
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
......@@ -36,9 +36,11 @@
#include <blade.h>
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_datastore_create(blade_datastore_t **bdsP, ks_pool_t *pool);
KS_DECLARE(ks_status_t) blade_datastore_create(blade_datastore_t **bdsP, ks_pool_t *pool, ks_thread_pool_t *tpool);
KS_DECLARE(ks_status_t) blade_datastore_destroy(blade_datastore_t **bdsP);
KS_DECLARE(void) blade_datastore_pulse(blade_datastore_t *bds, int32_t timeout);
KS_DECLARE(ks_status_t) blade_datastore_startup(blade_datastore_t *bds, config_setting_t *config);
KS_DECLARE(ks_status_t) blade_datastore_shutdown(blade_datastore_t *bds);
KS_DECLARE(void) blade_datastore_error(blade_datastore_t *bds, const char **buffer, int32_t *buffer_length);
KS_DECLARE(ks_status_t) blade_datastore_store(blade_datastore_t *bds, const void *key, int32_t key_length, const void *data, int64_t data_length);
KS_DECLARE(ks_status_t) blade_datastore_fetch(blade_datastore_t *bds,
......
/*
* Copyright (c) 2007-2014, Anthony Minessale II
* Copyright (c) 2017, Shane Bryldt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -31,22 +31,16 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _BPCP_H_
#define _BPCP_H_
#ifndef _BLADE_IDENTITY_H_
#define _BLADE_IDENTITY_H_
#include <blade.h>
#define BLADE_PEER_TPOOL_MIN 2
#define BLADE_PEER_TPOOL_MAX 8
#define BLADE_PEER_TPOOL_STACK (1024 * 256)
#define BLADE_PEER_TPOOL_IDLE 10
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_peer_create(blade_peer_t **bpP, ks_pool_t *pool, ks_thread_pool_t *tpool, ks_dht_nodeid_t *nodeid);
KS_DECLARE(ks_status_t) blade_peer_destroy(blade_peer_t **bpP);
KS_DECLARE(ks_dht_nodeid_t *) blade_peer_myid(blade_peer_t *bp);
KS_DECLARE(void) blade_peer_autoroute(blade_peer_t *bp, ks_bool_t autoroute, ks_port_t port);
KS_DECLARE(ks_status_t) blade_peer_bind(blade_peer_t *bp, const ks_sockaddr_t *addr, ks_dht_endpoint_t **endpoint);
KS_DECLARE(void) blade_peer_pulse(blade_peer_t *bp, int32_t timeout);
KS_DECLARE(ks_status_t) blade_identity_create(blade_identity_t **biP, ks_pool_t *pool);
KS_DECLARE(ks_status_t) blade_identity_destroy(blade_identity_t **biP);
KS_DECLARE(ks_status_t) blade_identity_parse(blade_identity_t *bi, const char *uri);
KS_DECLARE(const char *) blade_identity_uri(blade_identity_t *bi);
KS_DECLARE(const char *) blade_identity_parameter_get(blade_identity_t *bi, const char *key);
KS_END_EXTERN_C
#endif
......
/*
* Copyright (c) 2017, Shane Bryldt
* 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 _BLADE_METHOD_H_
#define _BLADE_METHOD_H_
#include <blade.h>
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_method_create(blade_method_t **bmP, blade_space_t *bs, const char *name, blade_request_callback_t callback);
KS_DECLARE(ks_status_t) blade_method_destroy(blade_method_t **bmP);
KS_DECLARE(const char *) blade_method_name_get(blade_method_t *bm);
KS_DECLARE(blade_request_callback_t) blade_method_callback_get(blade_method_t *bm);
KS_END_EXTERN_C
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
/*
* Copyright (c) 2017, Shane Bryldt
* 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 _BLADE_MODULE_H_
#define _BLADE_MODULE_H_
#include <blade.h>
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_module_create(blade_module_t **bmP, blade_handle_t *bh, void *module_data, blade_module_callbacks_t *module_callbacks);
KS_DECLARE(ks_status_t) blade_module_destroy(blade_module_t **bmP);
KS_DECLARE(blade_handle_t *) blade_module_handle_get(blade_module_t *bm);
KS_DECLARE(void *) blade_module_data_get(blade_module_t *bm);
// @todo very temporary, this is just here to get the wss module loaded until DSO is in place
KS_DECLARE(ks_status_t) blade_module_wss_on_load(blade_module_t **bmP, blade_handle_t *bh);
KS_DECLARE(ks_status_t) blade_module_wss_on_unload(blade_module_t *bm);
KS_DECLARE(ks_status_t) blade_module_wss_on_startup(blade_module_t *bm, config_setting_t *config);
KS_DECLARE(ks_status_t) blade_module_wss_on_shutdown(blade_module_t *bm);
KS_DECLARE(ks_status_t) blade_module_chat_on_load(blade_module_t **bmP, blade_handle_t *bh);
KS_DECLARE(ks_status_t) blade_module_chat_on_unload(blade_module_t *bm);
KS_DECLARE(ks_status_t) blade_module_chat_on_startup(blade_module_t *bm, config_setting_t *config);
KS_DECLARE(ks_status_t) blade_module_chat_on_shutdown(blade_module_t *bm);
KS_END_EXTERN_C
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
/*
* Copyright (c) 2017, Shane Bryldt
* 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 _BLADE_PROTOCOL_H_
#define _BLADE_PROTOCOL_H_
#include <blade.h>
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_request_create(blade_request_t **breqP,
blade_handle_t *bh,
const char *session_id,
cJSON *json,
blade_response_callback_t callback);
KS_DECLARE(ks_status_t) blade_request_destroy(blade_request_t **breqP);
KS_DECLARE(ks_status_t) blade_response_create(blade_response_t **bresP, blade_handle_t *bh, const char *session_id, blade_request_t *breq, cJSON *json);
KS_DECLARE(ks_status_t) blade_response_destroy(blade_response_t **bresP);
KS_DECLARE(ks_status_t) blade_event_create(blade_event_t **bevP, blade_handle_t *bh, const char *session_id, cJSON *json);
KS_DECLARE(ks_status_t) blade_event_destroy(blade_event_t **bevP);
KS_DECLARE(ks_status_t) blade_rpc_request_create(ks_pool_t *pool, cJSON **json, cJSON **params, const char **id, const char *method);
KS_DECLARE(ks_status_t) blade_rpc_response_create(ks_pool_t *pool, cJSON **json, cJSON **result, const char *id);
KS_DECLARE(ks_status_t) blade_rpc_error_create(ks_pool_t *pool, cJSON **json, cJSON **error, const char *id, int32_t code, const char *message);
KS_DECLARE(ks_status_t) blade_rpc_event_create(ks_pool_t *pool, cJSON **json, cJSON **result, const char *event);
KS_END_EXTERN_C
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
/*
* Copyright (c) 2017, Shane Bryldt
* 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 _BLADE_SESSION_H_
#define _BLADE_SESSION_H_
#include <blade.h>
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_session_create(blade_session_t **bsP, blade_handle_t *bh);
KS_DECLARE(ks_status_t) blade_session_destroy(blade_session_t **bsP);
KS_DECLARE(ks_status_t) blade_session_startup(blade_session_t *bs);
KS_DECLARE(ks_status_t) blade_session_shutdown(blade_session_t *bs);
KS_DECLARE(blade_handle_t *) blade_session_handle_get(blade_session_t *bs);
KS_DECLARE(ks_pool_t *) blade_session_pool_get(blade_session_t *bs);
KS_DECLARE(const char *) blade_session_id_get(blade_session_t *bs);
KS_DECLARE(void) blade_session_id_set(blade_session_t *bs, const char *id);
KS_DECLARE(blade_session_state_t) blade_session_state_get(blade_session_t *bs);
KS_DECLARE(cJSON *) blade_session_properties_get(blade_session_t *bs);
KS_DECLARE(ks_status_t) blade_session_read_lock(blade_session_t *bs, ks_bool_t block);
KS_DECLARE(ks_status_t) blade_session_read_unlock(blade_session_t *bs);
KS_DECLARE(ks_status_t) blade_session_write_lock(blade_session_t *bs, ks_bool_t block);
KS_DECLARE(ks_status_t) blade_session_write_unlock(blade_session_t *bs);
KS_DECLARE(ks_status_t) blade_session_properties_read_lock(blade_session_t *bs, ks_bool_t block);
KS_DECLARE(ks_status_t) blade_session_properties_read_unlock(blade_session_t *bs);
KS_DECLARE(ks_status_t) blade_session_properties_write_lock(blade_session_t *bs, ks_bool_t block);
KS_DECLARE(ks_status_t) blade_session_properties_write_unlock(blade_session_t *bs);
KS_DECLARE(void) blade_session_state_set(blade_session_t *bs, blade_session_state_t state);
KS_DECLARE(void) blade_session_hangup(blade_session_t *bs);
KS_DECLARE(ks_bool_t) blade_session_terminating(blade_session_t *bs);
KS_DECLARE(ks_status_t) blade_session_connections_add(blade_session_t *bs, const char *id);
KS_DECLARE(ks_status_t) blade_session_connections_remove(blade_session_t *bs, const char *id);
KS_DECLARE(ks_status_t) blade_session_send(blade_session_t *bs, cJSON *json, blade_response_callback_t callback);
KS_DECLARE(ks_status_t) blade_session_sending_push(blade_session_t *bs, cJSON *json);
KS_DECLARE(ks_status_t) blade_session_sending_pop(blade_session_t *bs, cJSON **json);
KS_DECLARE(ks_status_t) blade_session_receiving_push(blade_session_t *bs, cJSON *json);
KS_DECLARE(ks_status_t) blade_session_receiving_pop(blade_session_t *bs, cJSON **json);
KS_END_EXTERN_C
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
/*
* Copyright (c) 2017, Shane Bryldt
* 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 _BLADE_SPACE_H_
#define _BLADE_SPACE_H_
#include <blade.h>
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_space_create(blade_space_t **bsP, blade_handle_t *bh, blade_module_t *bm, const char *path);
KS_DECLARE(ks_status_t) blade_space_destroy(blade_space_t **bsP);
KS_DECLARE(blade_handle_t *) blade_space_handle_get(blade_space_t *bs);
KS_DECLARE(blade_module_t *) blade_space_module_get(blade_space_t *bs);
KS_DECLARE(const char *) blade_space_path_get(blade_space_t *bs);
KS_DECLARE(ks_status_t) blade_space_methods_add(blade_space_t *bs, blade_method_t *bm);
KS_DECLARE(ks_status_t) blade_space_methods_remove(blade_space_t *bs, blade_method_t *bm);
KS_DECLARE(blade_method_t *) blade_space_methods_get(blade_space_t *bs, const char *name);
KS_END_EXTERN_C
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
/*
* Copyright (c) 2007-2014, Anthony Minessale II
* 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
......@@ -42,12 +42,42 @@
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_handle_destroy(blade_handle_t **bhP);
KS_DECLARE(ks_status_t) blade_handle_create(blade_handle_t **bhP, ks_pool_t *pool, ks_thread_pool_t *tpool, const char *nodeid);
KS_DECLARE(void) blade_handle_myid(blade_handle_t *bh, char *buffer);
KS_DECLARE(void) blade_handle_autoroute(blade_handle_t *bh, ks_bool_t autoroute, ks_port_t port);
KS_DECLARE(ks_status_t) blade_handle_bind(blade_handle_t *bh, const char *ip, ks_port_t port, ks_dht_endpoint_t **endpoint);
KS_DECLARE(void) blade_handle_pulse(blade_handle_t *bh, int32_t timeout);
KS_DECLARE(void) blade_handle_datastore_start(blade_handle_t *bh);
KS_DECLARE(ks_status_t) blade_handle_create(blade_handle_t **bhP, ks_pool_t *pool, ks_thread_pool_t *tpool);
KS_DECLARE(ks_status_t) blade_handle_startup(blade_handle_t *bh, config_setting_t *config);
KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh);
KS_DECLARE(ks_pool_t *) blade_handle_pool_get(blade_handle_t *bh);
KS_DECLARE(ks_thread_pool_t *) blade_handle_tpool_get(blade_handle_t *bh);
KS_DECLARE(ks_status_t) blade_handle_transport_register(blade_handle_t *bh, blade_module_t *bm, const char *name, blade_transport_callbacks_t *callbacks);
KS_DECLARE(ks_status_t) blade_handle_transport_unregister(blade_handle_t *bh, const char *name);
KS_DECLARE(ks_status_t) blade_handle_space_register(blade_space_t *bs);
KS_DECLARE(ks_status_t) blade_handle_space_unregister(blade_space_t *bs);
KS_DECLARE(blade_space_t *) blade_handle_space_lookup(blade_handle_t *bh, const char *path);
KS_DECLARE(ks_status_t) blade_handle_event_register(blade_handle_t *bh, const char *event, blade_event_callback_t callback);
KS_DECLARE(ks_status_t) blade_handle_event_unregister(blade_handle_t *bh, const char *event);
KS_DECLARE(blade_event_callback_t) blade_handle_event_lookup(blade_handle_t *bh, const char *event);
KS_DECLARE(ks_status_t) blade_handle_connect(blade_handle_t *bh, blade_connection_t **bcP, blade_identity_t *target, const char *session_id);
KS_DECLARE(blade_connection_t *) blade_handle_connections_get(blade_handle_t *bh, const char *cid);
KS_DECLARE(ks_status_t) blade_handle_connections_add(blade_connection_t *bc);
KS_DECLARE(ks_status_t) blade_handle_connections_remove(blade_connection_t *bc);
KS_DECLARE(blade_session_t *) blade_handle_sessions_get(blade_handle_t *bh, const char *sid);
KS_DECLARE(ks_status_t) blade_handle_sessions_add(blade_session_t *bs);
KS_DECLARE(ks_status_t) blade_handle_sessions_remove(blade_session_t *bs);
KS_DECLARE(void) blade_handle_sessions_send(blade_handle_t *bh, list_t *sessions, const char *exclude, cJSON *json);
KS_DECLARE(ks_status_t) blade_handle_session_state_callback_register(blade_handle_t *bh, void *data, blade_session_state_callback_t callback, const char **id);
KS_DECLARE(ks_status_t) blade_handle_session_state_callback_unregister(blade_handle_t *bh, const char *id);
KS_DECLARE(void) blade_handle_session_state_callbacks_execute(blade_session_t *bs, blade_session_state_condition_t condition);
KS_DECLARE(blade_request_t *) blade_handle_requests_get(blade_handle_t *bh, const char *mid);
KS_DECLARE(ks_status_t) blade_handle_requests_add(blade_request_t *br);
KS_DECLARE(ks_status_t) blade_handle_requests_remove(blade_request_t *br);
KS_DECLARE(ks_bool_t) blade_handle_datastore_available(blade_handle_t *bh);
KS_DECLARE(ks_status_t) blade_handle_datastore_store(blade_handle_t *bh, const void *key, int32_t key_length, const void *data, int64_t data_length);
KS_DECLARE(ks_status_t) blade_handle_datastore_fetch(blade_handle_t *bh,
blade_datastore_fetch_callback_t callback,
......
/*
* Copyright (c) 2007-2014, Anthony Minessale II
* 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
......@@ -34,15 +34,157 @@
#ifndef _BLADE_TYPES_H_
#define _BLADE_TYPES_H_
#include <ks.h>
#include <libconfig.h>
KS_BEGIN_EXTERN_C
typedef struct blade_handle_s blade_handle_t;
typedef struct blade_peer_s blade_peer_t;
typedef struct blade_identity_s blade_identity_t;
typedef struct blade_module_s blade_module_t;
typedef struct blade_module_callbacks_s blade_module_callbacks_t;
typedef struct blade_transport_callbacks_s blade_transport_callbacks_t;
typedef struct blade_session_callbacks_s blade_session_callbacks_t;
typedef struct blade_connection_s blade_connection_t;
typedef struct blade_session_s blade_session_t;
typedef struct blade_request_s blade_request_t;
typedef struct blade_response_s blade_response_t;
typedef struct blade_event_s blade_event_t;
typedef struct blade_space_s blade_space_t;
typedef struct blade_method_s blade_method_t;
typedef struct blade_datastore_s blade_datastore_t;
typedef ks_bool_t (*blade_request_callback_t)(blade_module_t *bm, blade_request_t *breq);
typedef ks_bool_t (*blade_response_callback_t)(blade_response_t *bres);
typedef ks_bool_t (*blade_event_callback_t)(blade_event_t *bev);
typedef ks_bool_t (*blade_datastore_fetch_callback_t)(blade_datastore_t *bds, const void *data, uint32_t data_length, void *userdata);
typedef enum {
BLADE_CONNECTION_STATE_NONE,
BLADE_CONNECTION_STATE_DISCONNECT,
BLADE_CONNECTION_STATE_NEW,
BLADE_CONNECTION_STATE_CONNECT,
BLADE_CONNECTION_STATE_ATTACH,
BLADE_CONNECTION_STATE_DETACH,
BLADE_CONNECTION_STATE_READY,
} blade_connection_state_t;
typedef enum {
BLADE_CONNECTION_DIRECTION_INBOUND,
BLADE_CONNECTION_DIRECTION_OUTBOUND,
} blade_connection_direction_t;
typedef enum {
BLADE_CONNECTION_STATE_CONDITION_PRE,
BLADE_CONNECTION_STATE_CONDITION_POST,
} blade_connection_state_condition_t;
typedef enum {
BLADE_CONNECTION_STATE_HOOK_SUCCESS,
BLADE_CONNECTION_STATE_HOOK_DISCONNECT,
BLADE_CONNECTION_STATE_HOOK_BYPASS,
} blade_connection_state_hook_t;
typedef enum {
BLADE_CONNECTION_RANK_POOR,
BLADE_CONNECTION_RANK_AVERAGE,
BLADE_CONNECTION_RANK_GOOD,
BLADE_CONNECTION_RANK_GREAT,
} blade_connection_rank_t;
typedef enum {
BLADE_SESSION_STATE_CONDITION_PRE,
BLADE_SESSION_STATE_CONDITION_POST,
} blade_session_state_condition_t;
typedef enum {
BLADE_SESSION_STATE_NONE,
BLADE_SESSION_STATE_DESTROY,
BLADE_SESSION_STATE_HANGUP,
BLADE_SESSION_STATE_CONNECT,
BLADE_SESSION_STATE_ATTACH,
BLADE_SESSION_STATE_DETACH,
BLADE_SESSION_STATE_READY,
} blade_session_state_t;
typedef ks_status_t (*blade_module_load_callback_t)(blade_module_t **bmP, blade_handle_t *bh);
typedef ks_status_t (*blade_module_unload_callback_t)(blade_module_t *bm);
typedef ks_status_t (*blade_module_startup_callback_t)(blade_module_t *bm, config_setting_t *config);
typedef ks_status_t (*blade_module_shutdown_callback_t)(blade_module_t *bm);
struct blade_module_callbacks_s {
blade_module_load_callback_t onload;
blade_module_unload_callback_t onunload;
blade_module_startup_callback_t onstartup;
blade_module_shutdown_callback_t onshutdown;
};
typedef ks_status_t (*blade_transport_connect_callback_t)(blade_connection_t **bcP, blade_module_t *bm, blade_identity_t *target, const char *session_id);
typedef blade_connection_rank_t (*blade_transport_rank_callback_t)(blade_connection_t *bc, blade_identity_t *target);
typedef ks_status_t (*blade_transport_send_callback_t)(blade_connection_t *bc, cJSON *json);
typedef ks_status_t (*blade_transport_receive_callback_t)(blade_connection_t *bc, cJSON **json);
typedef blade_connection_state_hook_t (*blade_transport_state_callback_t)(blade_connection_t *bc, blade_connection_state_condition_t condition);
struct blade_transport_callbacks_s {
blade_transport_connect_callback_t onconnect;
blade_transport_rank_callback_t onrank;
blade_transport_send_callback_t onsend;
blade_transport_receive_callback_t onreceive;
blade_transport_state_callback_t onstate_disconnect_inbound;
blade_transport_state_callback_t onstate_disconnect_outbound;
blade_transport_state_callback_t onstate_new_inbound;
blade_transport_state_callback_t onstate_new_outbound;
blade_transport_state_callback_t onstate_connect_inbound;
blade_transport_state_callback_t onstate_connect_outbound;
blade_transport_state_callback_t onstate_attach_inbound;
blade_transport_state_callback_t onstate_attach_outbound;
blade_transport_state_callback_t onstate_detach_inbound;
blade_transport_state_callback_t onstate_detach_outbound;
blade_transport_state_callback_t onstate_ready_inbound;
blade_transport_state_callback_t onstate_ready_outbound;
};
typedef void (*blade_session_state_callback_t)(blade_session_t *bs, blade_session_state_condition_t condition, void *data);
struct blade_request_s {
blade_handle_t *handle;
ks_pool_t *pool;
const char *session_id;
cJSON *message;
const char *message_id; // pulled from message for easier keying
blade_response_callback_t callback;
// @todo ttl to wait for response before injecting an error response locally
// @todo rpc response callback
};
struct blade_response_s {
blade_handle_t *handle;
ks_pool_t *pool;
const char *session_id;
blade_request_t *request;
cJSON *message;
};
struct blade_event_s {
blade_handle_t *handle;
ks_pool_t *pool;
const char *session_id;
cJSON *message;
};
KS_END_EXTERN_C
#endif
......
AM_CFLAGS += -I$(abs_top_srcdir)/src/include -g -ggdb -O0
TEST_LDADD = $(abs_top_builddir)/libblade.la
AM_CFLAGS += -I$(abs_top_srcdir)/src/include -g -ggdb -O0
TEST_LDADD = $(abs_top_builddir)/libblade.la -lconfig -lm -lpthread
check_PROGRAMS =
check_PROGRAMS += testbuild
testbuild_SOURCES = testbuild.c tap.c
testbuild_CFLAGS = $(AM_CFLAGS)
......@@ -12,6 +13,11 @@ bladec_SOURCES = bladec.c tap.c
bladec_CFLAGS = $(AM_CFLAGS)
bladec_LDADD = $(TEST_LDADD)
check_PROGRAMS += blades
blades_SOURCES = blades.c tap.c
blades_CFLAGS = $(AM_CFLAGS)
blades_LDADD = $(TEST_LDADD)
TESTS=$(check_PROGRAMS)
......
blade:
{
identity = "peer@domain";
datastore:
{
database:
{
path = ":mem:";
};
};
};
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论