Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
eb57b791
提交
eb57b791
authored
1月 27, 2017
作者:
Shane Bryldt
提交者:
Mike Jerris
3月 22, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-9952: Temporary commit for some peer review
上级
2bce38af
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
967 行增加
和
143 行删除
+967
-143
Makefile.am
libs/libblade/Makefile.am
+4
-4
blade_datastore.c
libs/libblade/src/blade_datastore.c
+86
-12
blade_directory.c
libs/libblade/src/blade_directory.c
+165
-0
blade_peer.c
libs/libblade/src/blade_peer.c
+104
-31
blade_service.c
libs/libblade/src/blade_service.c
+401
-0
blade_stack.c
libs/libblade/src/blade_stack.c
+57
-40
blade.h
libs/libblade/src/include/blade.h
+3
-0
blade_datastore.h
libs/libblade/src/include/blade_datastore.h
+9
-2
blade_directory.h
libs/libblade/src/include/blade_directory.h
+61
-0
blade_peer.h
libs/libblade/src/include/blade_peer.h
+3
-5
blade_service.h
libs/libblade/src/include/blade_service.h
+61
-0
blade_stack.h
libs/libblade/src/include/blade_stack.h
+7
-6
blade_types.h
libs/libblade/src/include/blade_types.h
+2
-0
bladec.c
libs/libblade/test/bladec.c
+4
-43
没有找到文件。
libs/libblade/Makefile.am
浏览文件 @
eb57b791
...
@@ -11,13 +11,13 @@ libunqlite_la_CFLAGS = -DUNQLITE_ENABLE_THREADS
...
@@ -11,13 +11,13 @@ libunqlite_la_CFLAGS = -DUNQLITE_ENABLE_THREADS
libunqlite_la_LIBADD
=
-lpthread
libunqlite_la_LIBADD
=
-lpthread
lib_LTLIBRARIES
=
libblade.la
lib_LTLIBRARIES
=
libblade.la
libblade_la_SOURCES
=
src/blade.c src/blade_stack.c src/blade_peer.c src/b
pcp.c src/blade_datastore
.c
libblade_la_SOURCES
=
src/blade.c src/blade_stack.c src/blade_peer.c src/b
lade_service.c src/bpcp.c src/blade_datastore.c src/blade_directory
.c
libblade_la_CFLAGS
=
$(AM_CFLAGS)
$(AM_CPPFLAGS)
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
libblade_la_LIBADD
=
libunqlite.la
library_includedir
=
$(prefix)
/include
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/b
pcp
.h
library_include_HEADERS
=
src/include/blade.h src/include/blade_types.h src/include/blade_stack.h src/include/blade_peer.h src/include/b
lade_service
.h
library_include_HEADERS
+=
src/include/b
lade_datastore
.h
library_include_HEADERS
+=
src/include/b
pcp.h src/include/blade_datastore.h src/include/blade_directory
.h
library_include_HEADERS
+=
src/include/unqlite.h
test
/tap.h
library_include_HEADERS
+=
src/include/unqlite.h
test
/tap.h
tests
:
libblade.la
tests
:
libblade.la
...
...
libs/libblade/src/blade_datastore.c
浏览文件 @
eb57b791
...
@@ -37,12 +37,19 @@
...
@@ -37,12 +37,19 @@
typedef
enum
{
typedef
enum
{
BDS_NONE
=
0
,
BDS_NONE
=
0
,
BDS_MYPOOL
=
(
1
<<
0
),
BDS_MYPOOL
=
(
1
<<
0
),
BDS_MYTPOOL
=
(
1
<<
1
),
}
bdspvt_flag_t
;
}
bdspvt_flag_t
;
struct
blade_datastore_s
{
struct
blade_datastore_s
{
bdspvt_flag_t
flags
;
bdspvt_flag_t
flags
;
ks_pool_t
*
pool
;
ks_pool_t
*
pool
;
ks_thread_pool_t
*
tpool
;
const
char
*
config_database_path
;
//config_setting_t *config_service;
unqlite
*
db
;
unqlite
*
db
;
//blade_service_t *service;
};
};
struct
blade_datastore_fetch_userdata_s
struct
blade_datastore_fetch_userdata_s
...
@@ -71,11 +78,10 @@ KS_DECLARE(ks_status_t) blade_datastore_destroy(blade_datastore_t **bdsP)
...
@@ -71,11 +78,10 @@ KS_DECLARE(ks_status_t) blade_datastore_destroy(blade_datastore_t **bdsP)
flags
=
bds
->
flags
;
flags
=
bds
->
flags
;
pool
=
bds
->
pool
;
pool
=
bds
->
pool
;
if
(
bds
->
db
)
{
blade_datastore_shutdown
(
bds
);
unqlite_close
(
bds
->
db
);
bds
->
db
=
NULL
;
}
if
(
bds
->
tpool
&&
(
flags
&
BDS_MYTPOOL
))
ks_thread_pool_destroy
(
&
bds
->
tpool
);
ks_pool_free
(
bds
->
pool
,
&
bds
);
ks_pool_free
(
bds
->
pool
,
&
bds
);
if
(
pool
&&
(
flags
&
BDS_MYPOOL
))
ks_pool_close
(
&
pool
);
if
(
pool
&&
(
flags
&
BDS_MYPOOL
))
ks_pool_close
(
&
pool
);
...
@@ -83,7 +89,7 @@ KS_DECLARE(ks_status_t) blade_datastore_destroy(blade_datastore_t **bdsP)
...
@@ -83,7 +89,7 @@ KS_DECLARE(ks_status_t) blade_datastore_destroy(blade_datastore_t **bdsP)
return
KS_STATUS_SUCCESS
;
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
;
bdspvt_flag_t
newflags
=
BDS_NONE
;
blade_datastore_t
*
bds
=
NULL
;
blade_datastore_t
*
bds
=
NULL
;
...
@@ -93,16 +99,67 @@ KS_DECLARE(ks_status_t) blade_datastore_create(blade_datastore_t **bdsP, ks_pool
...
@@ -93,16 +99,67 @@ KS_DECLARE(ks_status_t) blade_datastore_create(blade_datastore_t **bdsP, ks_pool
ks_pool_open
(
&
pool
);
ks_pool_open
(
&
pool
);
ks_assert
(
pool
);
ks_assert
(
pool
);
}
}
// @todo: move thread pool creation to startup which allows thread pool to be configurable
if
(
!
tpool
)
{
newflags
|=
BDS_MYTPOOL
;
ks_thread_pool_create
(
&
tpool
,
BLADE_DATASTORE_TPOOL_MIN
,
BLADE_DATASTORE_TPOOL_MAX
,
BLADE_DATASTORE_TPOOL_STACK
,
KS_PRI_NORMAL
,
BLADE_DATASTORE_TPOOL_IDLE
);
ks_assert
(
tpool
);
}
bds
=
ks_pool_alloc
(
pool
,
sizeof
(
*
bds
));
bds
=
ks_pool_alloc
(
pool
,
sizeof
(
*
bds
));
bds
->
flags
=
newflags
;
bds
->
flags
=
newflags
;
bds
->
pool
=
pool
;
bds
->
pool
=
pool
;
bds
->
tpool
=
tpool
;
*
bdsP
=
bds
;
*
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
;
//config_setting_t *service = 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
);
//service = config_setting_get_member(config, "service");
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
);
//bds->config_service = service;
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, NULL, UNQLITE_OPEN_IN_MEMORY) != UNQLITE_OK) {
if
(
unqlite_open
(
&
bds
->
db
,
bds
->
config_database_path
,
UNQLITE_OPEN_CREATE
)
!=
UNQLITE_OK
)
{
const
char
*
errbuf
=
NULL
;
const
char
*
errbuf
=
NULL
;
blade_datastore_error
(
bds
,
&
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
;
return
KS_STATUS_FAIL
;
}
}
...
@@ -110,15 +167,31 @@ KS_DECLARE(ks_status_t) blade_datastore_create(blade_datastore_t **bdsP, ks_pool
...
@@ -110,15 +167,31 @@ KS_DECLARE(ks_status_t) blade_datastore_create(blade_datastore_t **bdsP, ks_pool
// @todo VM init if document store is used (and output consumer callback)
// @todo VM init if document store is used (and output consumer callback)
//blade_service_create(&bds->service, bds->pool, bds->tpool);
//ks_assert(bds->service);
//blade_service_startup(bds->service, bds->config_service);
return
KS_STATUS_SUCCESS
;
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
(
bds
);
ks_assert
(
timeout
>=
0
);
//if (bds->service) blade_service_destroy(&bds->service);
if
(
bds
->
db
)
{
unqlite_close
(
bds
->
db
);
bds
->
db
=
NULL
;
}
if
(
bds
->
config_database_path
)
ks_pool_free
(
bds
->
pool
,
&
bds
->
config_database_path
);
//bds->config_service = NULL;
return
KS_STATUS_SUCCESS
;
}
}
KS_DECLARE
(
void
)
blade_datastore_error
(
blade_datastore_t
*
bds
,
const
char
**
buffer
,
int32_t
*
buffer_length
)
KS_DECLARE
(
void
)
blade_datastore_error
(
blade_datastore_t
*
bds
,
const
char
**
buffer
,
int32_t
*
buffer_length
)
{
{
ks_assert
(
bds
);
ks_assert
(
bds
);
...
@@ -147,7 +220,7 @@ KS_DECLARE(ks_status_t) blade_datastore_store(blade_datastore_t *bds, const void
...
@@ -147,7 +220,7 @@ KS_DECLARE(ks_status_t) blade_datastore_store(blade_datastore_t *bds, const void
else
{
else
{
const
char
*
errbuf
;
const
char
*
errbuf
;
blade_datastore_error
(
bds
,
&
errbuf
,
NULL
);
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
;
ret
=
KS_STATUS_FAIL
;
}
}
...
@@ -196,10 +269,11 @@ KS_DECLARE(ks_status_t) blade_datastore_fetch(blade_datastore_t *bds,
...
@@ -196,10 +269,11 @@ KS_DECLARE(ks_status_t) blade_datastore_fetch(blade_datastore_t *bds,
if
(
rc
!=
UNQLITE_OK
)
{
if
(
rc
!=
UNQLITE_OK
)
{
if
(
rc
==
UNQLITE_BUSY
)
ret
=
KS_STATUS_TIMEOUT
;
if
(
rc
==
UNQLITE_BUSY
)
ret
=
KS_STATUS_TIMEOUT
;
else
if
(
rc
==
UNQLITE_NOTFOUND
)
ret
=
KS_STATUS_NOT_FOUND
;
else
{
else
{
const
char
*
errbuf
;
const
char
*
errbuf
;
blade_datastore_error
(
bds
,
&
errbuf
,
NULL
);
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
;
ret
=
KS_STATUS_FAIL
;
}
}
...
...
libs/libblade/src/blade_directory.c
0 → 100644
浏览文件 @
eb57b791
/*
* 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
* 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"
typedef
enum
{
BD_NONE
=
0
,
BD_MYPOOL
=
(
1
<<
0
),
BD_MYTPOOL
=
(
1
<<
1
),
}
bdpvt_flag_t
;
struct
blade_directory_s
{
bdpvt_flag_t
flags
;
ks_pool_t
*
pool
;
ks_thread_pool_t
*
tpool
;
config_setting_t
*
config_service
;
blade_service_t
*
service
;
};
KS_DECLARE
(
ks_status_t
)
blade_directory_destroy
(
blade_directory_t
**
bdP
)
{
blade_directory_t
*
bd
=
NULL
;
bdpvt_flag_t
flags
;
ks_pool_t
*
pool
;
ks_assert
(
bdP
);
bd
=
*
bdP
;
*
bdP
=
NULL
;
ks_assert
(
bd
);
flags
=
bd
->
flags
;
pool
=
bd
->
pool
;
blade_directory_shutdown
(
bd
);
if
(
bd
->
tpool
&&
(
flags
&
BD_MYTPOOL
))
ks_thread_pool_destroy
(
&
bd
->
tpool
);
ks_pool_free
(
bd
->
pool
,
&
bd
);
if
(
pool
&&
(
flags
&
BD_MYPOOL
))
ks_pool_close
(
&
pool
);
return
KS_STATUS_SUCCESS
;
}
KS_DECLARE
(
ks_status_t
)
blade_directory_create
(
blade_directory_t
**
bdP
,
ks_pool_t
*
pool
,
ks_thread_pool_t
*
tpool
)
{
bdpvt_flag_t
newflags
=
BD_NONE
;
blade_directory_t
*
bd
=
NULL
;
if
(
!
pool
)
{
newflags
|=
BD_MYPOOL
;
ks_pool_open
(
&
pool
);
ks_assert
(
pool
);
}
// @todo: move thread pool creation to startup which allows thread pool to be configurable
if
(
!
tpool
)
{
newflags
|=
BD_MYTPOOL
;
ks_thread_pool_create
(
&
tpool
,
BLADE_DIRECTORY_TPOOL_MIN
,
BLADE_DIRECTORY_TPOOL_MAX
,
BLADE_DIRECTORY_TPOOL_STACK
,
KS_PRI_NORMAL
,
BLADE_DIRECTORY_TPOOL_IDLE
);
ks_assert
(
tpool
);
}
bd
=
ks_pool_alloc
(
pool
,
sizeof
(
*
bd
));
bd
->
flags
=
newflags
;
bd
->
pool
=
pool
;
bd
->
tpool
=
tpool
;
*
bdP
=
bd
;
return
KS_STATUS_SUCCESS
;
}
ks_status_t
blade_directory_config
(
blade_directory_t
*
bd
,
config_setting_t
*
config
)
{
config_setting_t
*
service
=
NULL
;
ks_assert
(
bd
);
if
(
!
config
)
return
KS_STATUS_FAIL
;
if
(
!
config_setting_is_group
(
config
))
return
KS_STATUS_FAIL
;
service
=
config_setting_get_member
(
config
,
"service"
);
if
(
!
service
)
return
KS_STATUS_FAIL
;
bd
->
config_service
=
service
;
return
KS_STATUS_SUCCESS
;
}
KS_DECLARE
(
ks_status_t
)
blade_directory_startup
(
blade_directory_t
*
bd
,
config_setting_t
*
config
)
{
ks_assert
(
bd
);
blade_directory_shutdown
(
bd
);
if
(
blade_directory_config
(
bd
,
config
)
!=
KS_STATUS_SUCCESS
)
return
KS_STATUS_FAIL
;
blade_service_create
(
&
bd
->
service
,
bd
->
pool
,
bd
->
tpool
);
ks_assert
(
bd
->
service
);
if
(
blade_service_startup
(
bd
->
service
,
bd
->
config_service
)
!=
KS_STATUS_SUCCESS
)
return
KS_STATUS_FAIL
;
return
KS_STATUS_SUCCESS
;
}
KS_DECLARE
(
ks_status_t
)
blade_directory_shutdown
(
blade_directory_t
*
bd
)
{
ks_assert
(
bd
);
if
(
bd
->
service
)
blade_service_destroy
(
&
bd
->
service
);
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:
*/
libs/libblade/src/blade_peer.c
浏览文件 @
eb57b791
...
@@ -33,11 +33,6 @@
...
@@ -33,11 +33,6 @@
#include "blade.h"
#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
{
typedef
enum
{
BP_NONE
=
0
,
BP_NONE
=
0
,
BP_MYPOOL
=
(
1
<<
0
),
BP_MYPOOL
=
(
1
<<
0
),
...
@@ -48,10 +43,20 @@ struct blade_peer_s {
...
@@ -48,10 +43,20 @@ struct blade_peer_s {
bppvt_flag_t
flags
;
bppvt_flag_t
flags
;
ks_pool_t
*
pool
;
ks_pool_t
*
pool
;
ks_thread_pool_t
*
tpool
;
ks_thread_pool_t
*
tpool
;
ks_dht_t
*
dht
;
blade_service_t
*
service
;
ks_bool_t
shutdown
;
kws_t
*
kws
;
ks_thread_t
*
kws_thread
;
ks_q_t
*
messages_sending
;
ks_q_t
*
messages_receiving
;
};
};
void
*
blade_peer_kws_thread
(
ks_thread_t
*
thread
,
void
*
data
);
KS_DECLARE
(
ks_status_t
)
blade_peer_destroy
(
blade_peer_t
**
bpP
)
KS_DECLARE
(
ks_status_t
)
blade_peer_destroy
(
blade_peer_t
**
bpP
)
{
{
blade_peer_t
*
bp
=
NULL
;
blade_peer_t
*
bp
=
NULL
;
...
@@ -68,7 +73,11 @@ KS_DECLARE(ks_status_t) blade_peer_destroy(blade_peer_t **bpP)
...
@@ -68,7 +73,11 @@ KS_DECLARE(ks_status_t) blade_peer_destroy(blade_peer_t **bpP)
flags
=
bp
->
flags
;
flags
=
bp
->
flags
;
pool
=
bp
->
pool
;
pool
=
bp
->
pool
;
if
(
bp
->
dht
)
ks_dht_destroy
(
&
bp
->
dht
);
blade_peer_shutdown
(
bp
);
ks_q_destroy
(
&
bp
->
messages_sending
);
ks_q_destroy
(
&
bp
->
messages_receiving
);
if
(
bp
->
tpool
&&
(
flags
&
BP_MYTPOOL
))
ks_thread_pool_destroy
(
&
bp
->
tpool
);
if
(
bp
->
tpool
&&
(
flags
&
BP_MYTPOOL
))
ks_thread_pool_destroy
(
&
bp
->
tpool
);
ks_pool_free
(
bp
->
pool
,
&
bp
);
ks_pool_free
(
bp
->
pool
,
&
bp
);
...
@@ -78,11 +87,13 @@ KS_DECLARE(ks_status_t) blade_peer_destroy(blade_peer_t **bpP)
...
@@ -78,11 +87,13 @@ KS_DECLARE(ks_status_t) blade_peer_destroy(blade_peer_t **bpP)
return
KS_STATUS_SUCCESS
;
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_peer_create
(
blade_peer_t
**
bpP
,
ks_pool_t
*
pool
,
ks_thread_pool_t
*
tpool
,
blade_service_t
*
service
)
{
{
bppvt_flag_t
newflags
=
BP_NONE
;
bppvt_flag_t
newflags
=
BP_NONE
;
blade_peer_t
*
bp
=
NULL
;
blade_peer_t
*
bp
=
NULL
;
ks_dht_t
*
dht
=
NULL
;
ks_assert
(
bpP
);
ks_assert
(
service
);
if
(
!
pool
)
{
if
(
!
pool
)
{
newflags
|=
BP_MYPOOL
;
newflags
|=
BP_MYPOOL
;
...
@@ -94,50 +105,112 @@ KS_DECLARE(ks_status_t) blade_peer_create(blade_peer_t **bpP, ks_pool_t *pool, k
...
@@ -94,50 +105,112 @@ KS_DECLARE(ks_status_t) blade_peer_create(blade_peer_t **bpP, ks_pool_t *pool, k
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_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_assert
(
tpool
);
}
}
ks_dht_create
(
&
dht
,
pool
,
tpool
,
nodeid
);
ks_assert
(
dht
);
bp
=
ks_pool_alloc
(
pool
,
sizeof
(
*
bp
));
bp
=
ks_pool_alloc
(
pool
,
sizeof
(
*
bp
));
bp
->
flags
=
newflags
;
bp
->
flags
=
newflags
;
bp
->
pool
=
pool
;
bp
->
pool
=
pool
;
bp
->
tpool
=
tpool
;
bp
->
tpool
=
tpool
;
bp
->
dht
=
dht
;
bp
->
service
=
service
;
ks_q_create
(
&
bp
->
messages_sending
,
pool
,
0
);
ks_q_create
(
&
bp
->
messages_receiving
,
pool
,
0
);
*
bpP
=
bp
;
*
bpP
=
bp
;
return
KS_STATUS_SUCCESS
;
return
KS_STATUS_SUCCESS
;
}
}
KS_DECLARE
(
ks_
dht_nodeid_t
*
)
blade_peer_myid
(
blade_peer_t
*
bp
)
KS_DECLARE
(
ks_
status_t
)
blade_peer_startup
(
blade_peer_t
*
bp
,
kws_t
*
kws
)
{
{
ks_assert
(
bp
);
ks_assert
(
bp
);
ks_assert
(
bp
->
dht
);
ks_assert
(
kws
);
return
&
bp
->
dht
->
nodeid
;
}
KS_DECLARE
(
void
)
blade_peer_autoroute
(
blade_peer_t
*
bp
,
ks_bool_t
autoroute
,
ks_port_t
port
)
// @todo: consider using a recycle queue for blade_peer_t in blade_service_t, just need to call startup then
{
ks_assert
(
bp
);
blade_peer_shutdown
(
bp
);
ks_dht_autoroute
(
bp
->
dht
,
autoroute
,
port
);
bp
->
kws
=
kws
;
if
(
ks_thread_create_ex
(
&
bp
->
kws_thread
,
blade_peer_kws_thread
,
bp
,
KS_THREAD_FLAG_DEFAULT
,
KS_THREAD_DEFAULT_STACK
,
KS_PRI_NORMAL
,
bp
->
pool
)
!=
KS_STATUS_SUCCESS
)
return
KS_STATUS_FAIL
;
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
(
ks_status_t
)
blade_peer_
shutdown
(
blade_peer_t
*
bp
)
{
{
ks_assert
(
bp
);
ks_assert
(
bp
);
ks_assert
(
addr
);
return
ks_dht_bind
(
bp
->
dht
,
addr
,
endpoint
);
bp
->
shutdown
=
KS_TRUE
;
if
(
bp
->
kws_thread
)
{
ks_thread_join
(
bp
->
kws_thread
);
ks_pool_free
(
bp
->
pool
,
&
bp
->
kws_thread
);
}
if
(
bp
->
kws
)
kws_destroy
(
&
bp
->
kws
);
bp
->
shutdown
=
KS_FALSE
;
return
KS_STATUS_SUCCESS
;
}
}
KS_DECLARE
(
void
)
blade_peer_pulse
(
blade_peer_t
*
bp
,
int32_t
timeout
)
void
*
blade_peer_kws_thread
(
ks_thread_t
*
thread
,
void
*
data
)
{
{
ks_assert
(
bp
);
blade_peer_t
*
peer
;
ks_assert
(
timeout
>=
0
);
kws_opcode_t
opcode
;
uint8_t
*
data
;
ks_dht_pulse
(
bp
->
dht
,
timeout
);
ks_size_t
data_len
;
blade_message_t
*
message
;
ks_assert
(
thread
);
ks_assert
(
data
);
peer
=
(
blade_peer_t
*
)
data
;
while
(
!
peer
->
shutdown
)
{
// @todo use nonblocking kws mode so that if no data at all is available yet we can still do other things such as sending messages before trying again
// or easier alternative, just use ks_poll (or select) to check if there is a POLLIN event pending, but this requires direct access to the socket, or
// kws can be updated to add a function to poll the inner socket for events (IE, kws_poll(kws, &inbool, NULL, &errbool, timeout))
data_len
=
kws_read_frame
(
peer
->
kws
,
&
opcode
,
&
data
);
if
(
data_len
<=
0
)
{
// @todo error handling, strerror(ks_errno())
// 0 means socket closed with WS_NONE, which closes websocket with no additional reason
// -1 means socket closed with a general failure
// -2 means nonblocking wait
// other values are based on WS_XXX reasons
// negative values are based on reasons, except for -1 is but -2 is nonblocking wait, and
// @todo: this way of disconnecting would have the service periodically check the list of connected peers for those that are disconnecting,
// remove them from the connected peer list, and then call peer destroy which will wait for this thread to rejoin which it already will have,
// and then destroy the inner kws and finish any cleanup of the actual socket if neccessary, and can still call an ondisconnected callback
// at the service level
peer
->
disconnecting
=
KS_TRUE
;
break
;
}
// @todo this will check the discarded queue first and realloc if there is not enough space, otherwise allocate a message, and finally copy the data
if
(
blade_handle_message_claim
(
peer
->
service
->
handle
,
&
message
,
data
,
data_len
)
!=
KS_STATUS_SUCCESS
||
!
message
)
{
// @todo error handling
// just drop the peer for now, the only failure scenarios are asserted OOM, or if the discard queue pop fails
peer
->
disconnecting
=
KS_TRUE
;
break
;
}
ks_q_push
(
peer
->
messages_receiving
,
message
);
// @todo callback up the stack to indicate a message has been received and can be popped (more efficient than constantly polling by popping)?
if
(
ks_q_trypop
(
peer
->
messages_sending
,
&
message
)
==
KS_STATUS_SUCCESS
)
{
}
}
return
NULL
;
}
}
/* For Emacs:
/* For Emacs:
* Local Variables:
* Local Variables:
* mode:c
* mode:c
...
...
libs/libblade/src/blade_service.c
0 → 100644
浏览文件 @
eb57b791
差异被折叠。
点击展开。
libs/libblade/src/blade_stack.c
浏览文件 @
eb57b791
...
@@ -43,7 +43,12 @@ struct blade_handle_s {
...
@@ -43,7 +43,12 @@ struct blade_handle_s {
bhpvt_flag_t
flags
;
bhpvt_flag_t
flags
;
ks_pool_t
*
pool
;
ks_pool_t
*
pool
;
ks_thread_pool_t
*
tpool
;
ks_thread_pool_t
*
tpool
;
blade_peer_t
*
peer
;
config_setting_t
*
config_datastore
;
config_setting_t
*
config_directory
;
//blade_peer_t *peer;
blade_directory_t
*
directory
;
blade_datastore_t
*
datastore
;
blade_datastore_t
*
datastore
;
};
};
...
@@ -64,9 +69,9 @@ KS_DECLARE(ks_status_t) blade_handle_destroy(blade_handle_t **bhP)
...
@@ -64,9 +69,9 @@ KS_DECLARE(ks_status_t) blade_handle_destroy(blade_handle_t **bhP)
flags
=
bh
->
flags
;
flags
=
bh
->
flags
;
pool
=
bh
->
pool
;
pool
=
bh
->
pool
;
if
(
bh
->
datastore
)
blade_datastore_destroy
(
&
bh
->
datastore
);
blade_handle_shutdown
(
bh
);
blade_peer_destroy
(
&
bh
->
peer
);
//
blade_peer_destroy(&bh->peer);
if
(
bh
->
tpool
&&
(
flags
&
BH_MYTPOOL
))
ks_thread_pool_destroy
(
&
bh
->
tpool
);
if
(
bh
->
tpool
&&
(
flags
&
BH_MYTPOOL
))
ks_thread_pool_destroy
(
&
bh
->
tpool
);
ks_pool_free
(
bh
->
pool
,
&
bh
);
ks_pool_free
(
bh
->
pool
,
&
bh
);
...
@@ -78,14 +83,12 @@ KS_DECLARE(ks_status_t) blade_handle_destroy(blade_handle_t **bhP)
...
@@ -78,14 +83,12 @@ KS_DECLARE(ks_status_t) blade_handle_destroy(blade_handle_t **bhP)
return
KS_STATUS_SUCCESS
;
return
KS_STATUS_SUCCESS
;
}
}
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
(
ks_status_t
)
blade_handle_create
(
blade_handle_t
**
bhP
,
ks_pool_t
*
pool
,
ks_thread_pool_t
*
tpool
)
{
{
bhpvt_flag_t
newflags
=
BH_NONE
;
bhpvt_flag_t
newflags
=
BH_NONE
;
blade_handle_t
*
bh
=
NULL
;
blade_handle_t
*
bh
=
NULL
;
ks_dht_nodeid_t
nid
;
ks_assert
(
nodeid
);
ks_assert
(
bhP
);
ks_assert
(
strlen
(
nodeid
)
==
(
KS_DHT_NODEID_SIZE
*
2
));
if
(
!
pool
)
{
if
(
!
pool
)
{
newflags
|=
BH_MYPOOL
;
newflags
|=
BH_MYPOOL
;
...
@@ -101,75 +104,88 @@ KS_DECLARE(ks_status_t) blade_handle_create(blade_handle_t **bhP, ks_pool_t *poo
...
@@ -101,75 +104,88 @@ KS_DECLARE(ks_status_t) blade_handle_create(blade_handle_t **bhP, ks_pool_t *poo
bh
->
flags
=
newflags
;
bh
->
flags
=
newflags
;
bh
->
pool
=
pool
;
bh
->
pool
=
pool
;
bh
->
tpool
=
tpool
;
bh
->
tpool
=
tpool
;
ks_dht_dehex
(
nid
.
id
,
nodeid
,
KS_DHT_NODEID_SIZE
);
//blade_peer_create(&bh->peer, bh->pool, bh->tpool);
blade_peer_create
(
&
bh
->
peer
,
bh
->
pool
,
bh
->
tpool
,
&
nid
);
*
bhP
=
bh
;
*
bhP
=
bh
;
return
KS_STATUS_SUCCESS
;
return
KS_STATUS_SUCCESS
;
}
}
KS_DECLARE
(
void
)
blade_handle_myid
(
blade_handle_t
*
bh
,
char
*
buffer
)
ks_status_t
blade_handle_config
(
blade_handle_t
*
bh
,
config_setting_t
*
config
)
{
{
ks_dht_nodeid_t
*
nodeid
=
NULL
;
config_setting_t
*
datastore
=
NULL
;
config_setting_t
*
directory
=
NULL
;
ks_assert
(
bh
);
ks_assert
(
bh
);
ks_assert
(
bh
->
peer
);
nodeid
=
blade_peer_myid
(
bh
->
peer
);
if
(
!
config
)
return
KS_STATUS_FAIL
;
ks_dht_hex
(
nodeid
->
id
,
buffer
,
KS_DHT_NODEID_SIZE
);
if
(
!
config_setting_is_group
(
config
))
return
KS_STATUS_FAIL
;
datastore
=
config_setting_get_member
(
config
,
"datastore"
);
//if (datastore && !config_setting_is_group(datastore)) return KS_STATUS_FAIL;
directory
=
config_setting_get_member
(
config
,
"directory"
);
//if (directory && !config_setting_is_group(directory)) return KS_STATUS_FAIL;
bh
->
config_datastore
=
datastore
;
bh
->
config_directory
=
directory
;
return
KS_STATUS_SUCCESS
;
}
}
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_startup
(
blade_handle_t
*
bh
,
config_setting_t
*
config
)
{
{
ks_assert
(
bh
);
ks_assert
(
bh
);
ks_assert
(
bh
->
peer
);
blade_peer_autoroute
(
bh
->
peer
,
autoroute
,
port
);
if
(
blade_handle_config
(
bh
,
config
)
!=
KS_STATUS_SUCCESS
)
return
KS_STATUS_FAIL
;
if
(
bh
->
config_datastore
&&
!
blade_handle_datastore_available
(
bh
))
{
blade_datastore_create
(
&
bh
->
datastore
,
bh
->
pool
,
bh
->
tpool
);
blade_datastore_startup
(
bh
->
datastore
,
bh
->
config_datastore
);
}
if
(
bh
->
config_directory
&&
!
blade_handle_directory_available
(
bh
))
{
blade_directory_create
(
&
bh
->
directory
,
bh
->
pool
,
bh
->
tpool
);
blade_directory_startup
(
bh
->
directory
,
config
);
}
return
KS_STATUS_SUCCESS
;
}
}
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
(
ks_status_t
)
blade_handle_
shutdown
(
blade_handle_t
*
bh
)
{
{
ks_sockaddr_t
addr
;
int
family
=
AF_INET
;
ks_assert
(
bh
);
ks_assert
(
bh
);
ks_assert
(
ip
);
ks_assert
(
port
);
if
(
ip
[
1
]
!=
'.'
&&
ip
[
2
]
!=
'.'
&&
ip
[
3
]
!=
'.'
)
family
=
AF_INET6
;
ks_addr_set
(
&
addr
,
ip
,
port
,
family
);
if
(
blade_handle_directory_available
(
bh
))
blade_directory_destroy
(
&
bh
->
directory
);
return
blade_peer_bind
(
bh
->
peer
,
&
addr
,
endpoint
);
if
(
blade_handle_datastore_available
(
bh
))
blade_datastore_destroy
(
&
bh
->
datastore
);
return
KS_STATUS_SUCCESS
;
}
}
KS_DECLARE
(
void
)
blade_handle_pulse
(
blade_handle_t
*
bh
,
int32_t
timeout
)
KS_DECLARE
(
ks_bool_t
)
blade_handle_datastore_available
(
blade_handle_t
*
bh
)
{
{
ks_assert
(
bh
);
ks_assert
(
bh
);
ks_assert
(
timeout
>=
0
);
blade_peer_pulse
(
bh
->
peer
,
timeout
);
return
bh
->
datastore
!=
NULL
;
if
(
bh
->
datastore
)
blade_datastore_pulse
(
bh
->
datastore
,
timeout
);
}
}
KS_DECLARE
(
ks_bool_t
)
blade_handle_directory_available
(
blade_handle_t
*
bh
)
KS_DECLARE
(
void
)
blade_handle_datastore_start
(
blade_handle_t
*
bh
)
{
{
ks_assert
(
bh
);
ks_assert
(
bh
);
if
(
bh
->
datastore
)
return
;
return
bh
->
directory
!=
NULL
;
blade_datastore_create
(
&
bh
->
datastore
,
bh
->
pool
);
}
}
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_store
(
blade_handle_t
*
bh
,
const
void
*
key
,
int32_t
key_length
,
const
void
*
data
,
int64_t
data_length
)
{
{
ks_assert
(
bh
);
ks_assert
(
bh
);
ks_assert
(
bh
->
datastore
);
ks_assert
(
key
);
ks_assert
(
key
);
ks_assert
(
key_length
>
0
);
ks_assert
(
key_length
>
0
);
ks_assert
(
data
);
ks_assert
(
data
);
ks_assert
(
data_length
>
0
);
ks_assert
(
data_length
>
0
);
if
(
!
blade_handle_datastore_available
(
bh
))
return
KS_STATUS_INACTIVE
;
return
blade_datastore_store
(
bh
->
datastore
,
key
,
key_length
,
data
,
data_length
);
return
blade_datastore_store
(
bh
->
datastore
,
key
,
key_length
,
data
,
data_length
);
}
}
...
@@ -181,11 +197,12 @@ KS_DECLARE(ks_status_t) blade_handle_datastore_fetch(blade_handle_t *bh,
...
@@ -181,11 +197,12 @@ KS_DECLARE(ks_status_t) blade_handle_datastore_fetch(blade_handle_t *bh,
void
*
userdata
)
void
*
userdata
)
{
{
ks_assert
(
bh
);
ks_assert
(
bh
);
ks_assert
(
bh
->
datastore
);
ks_assert
(
callback
);
ks_assert
(
callback
);
ks_assert
(
key
);
ks_assert
(
key
);
ks_assert
(
key_length
>
0
);
ks_assert
(
key_length
>
0
);
if
(
!
blade_handle_datastore_available
(
bh
))
return
KS_STATUS_INACTIVE
;
return
blade_datastore_fetch
(
bh
->
datastore
,
callback
,
key
,
key_length
,
userdata
);
return
blade_datastore_fetch
(
bh
->
datastore
,
callback
,
key
,
key_length
,
userdata
);
}
}
...
...
libs/libblade/src/include/blade.h
浏览文件 @
eb57b791
...
@@ -36,11 +36,14 @@
...
@@ -36,11 +36,14 @@
#include <ks.h>
#include <ks.h>
#include <ks_dht.h>
#include <ks_dht.h>
#include <sodium.h>
#include <sodium.h>
#include <libconfig.h>
#include "unqlite.h"
#include "unqlite.h"
#include "blade_types.h"
#include "blade_types.h"
#include "blade_stack.h"
#include "blade_stack.h"
#include "blade_peer.h"
#include "blade_peer.h"
#include "blade_service.h"
#include "blade_datastore.h"
#include "blade_datastore.h"
#include "blade_directory.h"
#include "bpcp.h"
#include "bpcp.h"
KS_BEGIN_EXTERN_C
KS_BEGIN_EXTERN_C
...
...
libs/libblade/src/include/blade_datastore.h
浏览文件 @
eb57b791
...
@@ -35,10 +35,17 @@
...
@@ -35,10 +35,17 @@
#define _BLADE_DATASTORE_H_
#define _BLADE_DATASTORE_H_
#include <blade.h>
#include <blade.h>
#define BLADE_DATASTORE_TPOOL_MIN 2
#define BLADE_DATASTORE_TPOOL_MAX 8
#define BLADE_DATASTORE_TPOOL_STACK (1024 * 256)
#define BLADE_DATASTORE_TPOOL_IDLE 10
KS_BEGIN_EXTERN_C
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
(
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
(
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_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
,
KS_DECLARE
(
ks_status_t
)
blade_datastore_fetch
(
blade_datastore_t
*
bds
,
...
...
libs/libblade/src/include/blade_directory.h
0 → 100644
浏览文件 @
eb57b791
/*
* 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
* 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_DIRECTORY_H_
#define _BLADE_DIRECTORY_H_
#include <blade.h>
#define BLADE_DIRECTORY_TPOOL_MIN 2
#define BLADE_DIRECTORY_TPOOL_MAX 8
#define BLADE_DIRECTORY_TPOOL_STACK (1024 * 256)
#define BLADE_DIRECTORY_TPOOL_IDLE 10
KS_BEGIN_EXTERN_C
KS_DECLARE
(
ks_status_t
)
blade_directory_create
(
blade_directory_t
**
bdP
,
ks_pool_t
*
pool
,
ks_thread_pool_t
*
tpool
);
KS_DECLARE
(
ks_status_t
)
blade_directory_destroy
(
blade_directory_t
**
bdP
);
KS_DECLARE
(
ks_status_t
)
blade_directory_startup
(
blade_directory_t
*
bd
,
config_setting_t
*
config
);
KS_DECLARE
(
ks_status_t
)
blade_directory_shutdown
(
blade_directory_t
*
bd
);
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:
*/
libs/libblade/src/include/blade_peer.h
浏览文件 @
eb57b791
...
@@ -41,12 +41,10 @@
...
@@ -41,12 +41,10 @@
#define BLADE_PEER_TPOOL_IDLE 10
#define BLADE_PEER_TPOOL_IDLE 10
KS_BEGIN_EXTERN_C
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_create
(
blade_peer_t
**
bpP
,
ks_pool_t
*
pool
,
ks_thread_pool_t
*
tpool
);
KS_DECLARE
(
ks_status_t
)
blade_peer_destroy
(
blade_peer_t
**
bpP
);
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
(
ks_status_t
)
blade_peer_startup
(
blade_peer_t
*
bp
,
kws_t
*
kws
);
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_shutdown
(
blade_peer_t
*
bp
);
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_END_EXTERN_C
KS_END_EXTERN_C
#endif
#endif
...
...
libs/libblade/src/include/blade_service.h
0 → 100644
浏览文件 @
eb57b791
/*
* 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
* 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_SERVICE_H_
#define _BLADE_SERVICE_H_
#include <blade.h>
#define BLADE_SERVICE_TPOOL_MIN 2
#define BLADE_SERVICE_TPOOL_MAX 8
#define BLADE_SERVICE_TPOOL_STACK (1024 * 256)
#define BLADE_SERVICE_TPOOL_IDLE 10
KS_BEGIN_EXTERN_C
KS_DECLARE
(
ks_status_t
)
blade_service_create
(
blade_service_t
**
bsP
,
ks_pool_t
*
pool
,
ks_thread_pool_t
*
tpool
);
KS_DECLARE
(
ks_status_t
)
blade_service_destroy
(
blade_service_t
**
bsP
);
KS_DECLARE
(
ks_status_t
)
blade_service_startup
(
blade_service_t
*
bs
,
config_setting_t
*
config
);
KS_DECLARE
(
ks_status_t
)
blade_service_shutdown
(
blade_service_t
*
bs
);
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:
*/
libs/libblade/src/include/blade_stack.h
浏览文件 @
eb57b791
...
@@ -42,12 +42,13 @@
...
@@ -42,12 +42,13 @@
KS_BEGIN_EXTERN_C
KS_BEGIN_EXTERN_C
KS_DECLARE
(
ks_status_t
)
blade_handle_destroy
(
blade_handle_t
**
bhP
);
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
(
ks_status_t
)
blade_handle_create
(
blade_handle_t
**
bhP
,
ks_pool_t
*
pool
,
ks_thread_pool_t
*
tpool
);
KS_DECLARE
(
void
)
blade_handle_myid
(
blade_handle_t
*
bh
,
char
*
buffer
);
KS_DECLARE
(
ks_status_t
)
blade_handle_startup
(
blade_handle_t
*
bh
,
config_setting_t
*
config
);
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_shutdown
(
blade_handle_t
*
bh
);
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
(
ks_bool_t
)
blade_handle_datastore_available
(
blade_handle_t
*
bh
);
KS_DECLARE
(
void
)
blade_handle_datastore_start
(
blade_handle_t
*
bh
);
KS_DECLARE
(
ks_bool_t
)
blade_handle_directory_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_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
,
KS_DECLARE
(
ks_status_t
)
blade_handle_datastore_fetch
(
blade_handle_t
*
bh
,
blade_datastore_fetch_callback_t
callback
,
blade_datastore_fetch_callback_t
callback
,
...
...
libs/libblade/src/include/blade_types.h
浏览文件 @
eb57b791
...
@@ -39,7 +39,9 @@ KS_BEGIN_EXTERN_C
...
@@ -39,7 +39,9 @@ KS_BEGIN_EXTERN_C
typedef
struct
blade_handle_s
blade_handle_t
;
typedef
struct
blade_handle_s
blade_handle_t
;
typedef
struct
blade_peer_s
blade_peer_t
;
typedef
struct
blade_peer_s
blade_peer_t
;
typedef
struct
blade_service_s
blade_service_t
;
typedef
struct
blade_datastore_s
blade_datastore_t
;
typedef
struct
blade_datastore_s
blade_datastore_t
;
typedef
struct
blade_directory_s
blade_directory_t
;
typedef
ks_bool_t
(
*
blade_datastore_fetch_callback_t
)(
blade_datastore_t
*
bds
,
const
void
*
data
,
uint32_t
data_length
,
void
*
userdata
);
typedef
ks_bool_t
(
*
blade_datastore_fetch_callback_t
)(
blade_datastore_t
*
bds
,
const
void
*
data
,
uint32_t
data_length
,
void
*
userdata
);
...
...
libs/libblade/test/bladec.c
浏览文件 @
eb57b791
...
@@ -28,16 +28,12 @@ struct command_def_s {
...
@@ -28,16 +28,12 @@ struct command_def_s {
void
command_test
(
blade_handle_t
*
bh
,
char
*
args
);
void
command_test
(
blade_handle_t
*
bh
,
char
*
args
);
void
command_quit
(
blade_handle_t
*
bh
,
char
*
args
);
void
command_quit
(
blade_handle_t
*
bh
,
char
*
args
);
void
command_myid
(
blade_handle_t
*
bh
,
char
*
args
);
void
command_bind
(
blade_handle_t
*
bh
,
char
*
args
);
void
command_store
(
blade_handle_t
*
bh
,
char
*
args
);
void
command_store
(
blade_handle_t
*
bh
,
char
*
args
);
void
command_fetch
(
blade_handle_t
*
bh
,
char
*
args
);
void
command_fetch
(
blade_handle_t
*
bh
,
char
*
args
);
static
const
struct
command_def_s
command_defs
[]
=
{
static
const
struct
command_def_s
command_defs
[]
=
{
{
"test"
,
command_test
},
{
"test"
,
command_test
},
{
"quit"
,
command_quit
},
{
"quit"
,
command_quit
},
{
"myid"
,
command_myid
},
{
"bind"
,
command_bind
},
{
"store"
,
command_store
},
{
"store"
,
command_store
},
{
"fetch"
,
command_fetch
},
{
"fetch"
,
command_fetch
},
...
@@ -48,19 +44,12 @@ static const struct command_def_s command_defs[] = {
...
@@ -48,19 +44,12 @@ static const struct command_def_s command_defs[] = {
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
blade_handle_t
*
bh
=
NULL
;
blade_handle_t
*
bh
=
NULL
;
const
char
*
nodeid
;
ks_assert
(
argc
>=
2
);
nodeid
=
argv
[
1
];
ks_global_set_default_logger
(
KS_LOG_LEVEL_DEBUG
);
ks_global_set_default_logger
(
KS_LOG_LEVEL_DEBUG
);
blade_init
();
blade_init
();
blade_handle_create
(
&
bh
,
NULL
,
NULL
,
nodeid
);
blade_handle_create
(
&
bh
,
NULL
,
NULL
);
blade_handle_autoroute
(
bh
,
KS_TRUE
,
KS_DHT_DEFAULT_PORT
);
loop
(
bh
);
loop
(
bh
);
...
@@ -121,7 +110,7 @@ void loop(blade_handle_t *bh)
...
@@ -121,7 +110,7 @@ void loop(blade_handle_t *bh)
// @todo lines must not exceed 512 bytes, treat as error and ignore buffer until next new line?
// @todo lines must not exceed 512 bytes, treat as error and ignore buffer until next new line?
ks_assert
(
0
);
ks_assert
(
0
);
}
}
blade_handle_pulse
(
bh
,
1
);
blade_handle_pulse
(
bh
);
}
}
}
}
...
@@ -179,34 +168,6 @@ void command_quit(blade_handle_t *bh, char *args)
...
@@ -179,34 +168,6 @@ void command_quit(blade_handle_t *bh, char *args)
g_shutdown
=
KS_TRUE
;
g_shutdown
=
KS_TRUE
;
}
}
void
command_myid
(
blade_handle_t
*
bh
,
char
*
args
)
{
char
buf
[
KS_DHT_NODEID_SIZE
*
2
+
1
];
ks_assert
(
bh
);
ks_assert
(
args
);
blade_handle_myid
(
bh
,
buf
);
ks_log
(
KS_LOG_INFO
,
"%s
\n
"
,
buf
);
}
void
command_bind
(
blade_handle_t
*
bh
,
char
*
args
)
{
char
*
ip
=
NULL
;
char
*
port
=
NULL
;
ks_port_t
p
;
ks_assert
(
args
);
parse_argument
(
&
args
,
&
ip
,
' '
);
parse_argument
(
&
args
,
&
port
,
' '
);
p
=
atoi
(
port
);
// @todo use strtol for error handling
blade_handle_bind
(
bh
,
ip
,
p
,
NULL
);
}
void
command_store
(
blade_handle_t
*
bh
,
char
*
args
)
void
command_store
(
blade_handle_t
*
bh
,
char
*
args
)
{
{
char
*
key
;
char
*
key
;
...
@@ -214,7 +175,7 @@ void command_store(blade_handle_t *bh, char *args)
...
@@ -214,7 +175,7 @@ void command_store(blade_handle_t *bh, char *args)
ks_assert
(
args
);
ks_assert
(
args
);
blade_handle_datastore_start
(
bh
);
blade_handle_datastore_start
up
(
bh
,
NULL
);
parse_argument
(
&
args
,
&
key
,
' '
);
parse_argument
(
&
args
,
&
key
,
' '
);
parse_argument
(
&
args
,
&
data
,
' '
);
parse_argument
(
&
args
,
&
data
,
' '
);
...
@@ -234,7 +195,7 @@ void command_fetch(blade_handle_t *bh, char *args)
...
@@ -234,7 +195,7 @@ void command_fetch(blade_handle_t *bh, char *args)
ks_assert
(
args
);
ks_assert
(
args
);
blade_handle_datastore_start
(
bh
);
blade_handle_datastore_start
up
(
bh
,
NULL
);
parse_argument
(
&
args
,
&
key
,
' '
);
parse_argument
(
&
args
,
&
key
,
' '
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论