├── bench
├── README.md
├── xkad_bench1
│ ├── clean.sh
│ ├── online
│ │ ├── ssh.sh
│ │ ├── ansible_stop.sh
│ │ ├── ansible_uptime.sh
│ │ ├── scp.sh
│ │ ├── ansible_deploy.sh
│ │ ├── ansible_run2.sh
│ │ ├── ansible_show.sh
│ │ ├── deploy.sh
│ │ ├── run1.sh
│ │ ├── run2fg.sh
│ │ ├── ansible_collect.sh
│ │ ├── run2.sh
│ │ ├── bridge_deploy.sh
│ │ ├── node.pem
│ │ └── bridge.pem
│ ├── stop.sh
│ ├── show.sh
│ ├── run2fg.sh
│ ├── run1.sh
│ ├── deploy.sh
│ └── run2.sh
├── CMakeLists.txt
├── node.proto
├── util.h
├── main.cc
└── util.cc
├── demo
├── conf
│ └── demo.conf
├── CMakeLists.txt
└── xkaddemo.xcodeproj
│ ├── xcuserdata
│ └── imac.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
│ └── xcshareddata
│ └── xcschemes
│ └── xkaddemo.xcscheme
├── proto
├── ledger.proto
└── kadmlia.proto
├── tests
├── CMakeLists.txt
├── lcov.sh
├── test_routing_table_heartbeat.cc
├── test_heartbeat_state.cc
├── test_node_info.cc
├── test_client_node_manager.cc
├── test_dynamic_xip_manager.cc
├── test_nat_handshake_manager.cc
├── test_main.cc
├── test_node_detection_manager.cc
├── test_bootstrap_cache.cc
├── node_mgr.h
├── test_local_node_info.cc
├── test_bootstrap_cache_helper.cc
├── test_kad_message_handler.cc
├── test_routing_table2.cc
├── test_nat_manager.cc
├── test_callback_manager.cc
├── node_mgr.cc
└── test_routing_utils.cc
├── xkad.xcodeproj
└── xcuserdata
│ └── imac.xcuserdatad
│ └── xcschemes
│ └── xcschememanagement.plist
├── CMakeLists.txt
├── nat_detect
├── nat_defines.h
├── nat_detect
│ └── nat_defines.h
├── nat_manager_intf.h
├── nat_handshake_manager.h
└── nat_manager.h
├── gossip
├── rumor_filter.h
├── rumor_def.h
├── rumor_message_manager.h
└── rumor_handler.h
├── src
├── nodeid_utils.cc
├── rumor_filter.cc
├── heartbeat_manager.cc
├── rumor_message_manager.cc
├── client_node_manager.cc
├── dynamic_xip_manager.cc
├── node_info.cc
├── local_node_info.cc
├── heartbeat_state.cc
├── bootstrap_cache.cc
├── callback_manager.cc
├── nat_handshake_manager.cc
├── node_detection_manager.cc
├── routing_utils.cc
├── rumor_handler.cc
└── kad_message_handler.cc
├── routing_table
├── nodeid_utils.h
├── heartbeat_state.h
├── heartbeat_manager.h
├── dynamic_xip_manager.h
├── client_node_manager.h
├── node_detection_manager.h
├── routing_table_heartbeat.h
├── nat_detect_manager.h
├── node_info.h
├── bootstrap_cache.h
├── callback_manager.h
├── kad_message_handler.h
├── bootstrap_cache_helper.h
├── local_node_info.h
└── routing_utils.h
└── README.md
/bench/README.md:
--------------------------------------------------------------------------------
1 | # brief
2 | single routing table
3 | with command line
4 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/clean.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | rm -rf log
4 | rm -rf core.*
5 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/online/ssh.sh:
--------------------------------------------------------------------------------
1 | ssh -p 1022 -i /root/blueshi/xkad_bench1/online/node.pem root@$1
2 |
--------------------------------------------------------------------------------
/demo/conf/demo.conf:
--------------------------------------------------------------------------------
1 | [node]
2 | local_ip=127.0.0.1
3 | local_port=8900
4 | first_node=true
5 | public_endpoints=127.0.0.1:8900
6 | country=US
7 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/stop.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | # kill -9 `ps -ef | grep xkad_bench | awk '{print $2}'`
4 | killall xkad_bench || echo "no such processes"
5 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/show.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | ps -ef | grep xkad_bench | grep -v grep | grep -v 'show.sh'
4 | /usr/sbin/lsof -nPi | grep xkad_ben
5 | uptime
6 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/online/ansible_stop.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | # stop
4 | ansible -i /root/blueshi/blue_hosts m_bg -m shell -a "cd /root/blueshi/xkad_bench1 && sh stop.sh"
5 |
--------------------------------------------------------------------------------
/bench/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | aux_source_directory(./ SRC)
3 | add_executable(xkad_bench ${SRC})
4 | add_dependencies(xkad_bench xkad)
5 | target_link_libraries(xkad_bench xkad)
6 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/run2fg.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | rm -rf log2
4 | mkdir -p log2
5 |
6 | # foreground
7 | ./xkad_bench -a 127.0.0.1 -l 8822 -L log2/8822.log -i 1 -p 127.0.0.1:8833
8 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/online/ansible_uptime.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | # collect fg
4 | ansible -i /root/blueshi/blue_hosts m_fg -m shell -a "uptime"
5 |
6 | # collect bg
7 | ansible -i /root/blueshi/blue_hosts m_bg -m shell -a "uptime"
8 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/online/scp.sh:
--------------------------------------------------------------------------------
1 | # scp -P 1022 -i node.pem topuser@$1:/root/blueshi/xkad_bench1/log.tgz ~/pub/xudp_core/$1_log.tgz
2 | scp -P 1022 -i xkad_bench1/online/node.pem topuser@$1:/root/blueshi/xkad_bench1/log.tgz /root/blueshi/log_collect/$1_log.tgz
3 |
--------------------------------------------------------------------------------
/proto/ledger.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package top.kadmlia.pb;
3 |
4 | message PbBootstrapEndpoint {
5 | string ip = 1;
6 | uint32 port = 2;
7 | }
8 |
9 | message PbBootstrapCache {
10 | repeated PbBootstrapEndpoint endpoints = 1;
11 | }
12 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/online/ansible_deploy.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | # rsync
4 | ansible -i /root/blueshi/blue_hosts m_fg -m synchronize -a "src=/root/blueshi dest=/root/"
5 |
6 | # rsync
7 | ansible -i /root/blueshi/blue_hosts m_bg -m synchronize -a "src=/root/blueshi dest=/root/"
8 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/run1.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | rm -rf log1
4 | mkdir -p log1
5 |
6 | ./xkad_bench -a 127.0.0.1 -l 8833 -L log1/first_node.log
7 | # ./xkad_bench -a 192.168.50.211 -l 8833 -L log1/first_node.log
8 | # ./xkad_bench -a 192.168.50.242 -l 8833 -L log1/first_node.log
9 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/online/ansible_run2.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | # # stop
4 | # ansible -i /root/blueshi/blue_hosts m_bg -m shell -a "cd /root/blueshi/xkad_bench1 && sh stop.sh"
5 |
6 | # run
7 | ansible -i /root/blueshi/blue_hosts m_bg -m shell -a "cd /root/blueshi/xkad_bench1 && sh online/run2.sh"
8 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/online/ansible_show.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | # show
4 | ansible -i /root/blueshi/blue_hosts m_bg -m shell -a "cd /root/blueshi/xkad_bench1 && sh show.sh"
5 |
6 | # grep core
7 | # ansible -i /root/blueshi/blue_hosts m_bg -m shell -a "cd /root/blueshi/xkad_bench1 && ls -l | grep core"
8 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/deploy.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | target=src/xtopcom/xkad/bench/xkad_bench1
4 |
5 | # copy xkad_bench
6 | rsync -avz cbuild/bin/Linux/xkad_bench $target/
7 | # rsync -avz cbuild/bin/Darwin/xkad_bench $target/
8 | # strip $target/xkad_bench
9 |
10 | # copy bench1
11 | rsync -avz $target ~/run/
12 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/online/deploy.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | target=src/xtopcom/xkad/bench/xkad_bench1
4 |
5 | # copy xkad_bench
6 | rsync -avz cbuild/bin/Linux/xkad_bench $target/
7 | # rsync -avz cbuild/bin/Darwin/xkad_bench $target/
8 | # strip $target/xkad_bench
9 |
10 | # copy bench1
11 | rsync -avz $target ~/run/
12 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/online/run1.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | rm -rf log
4 | rm -rf core.*
5 |
6 | mkdir -p log
7 | ulimit -c unlimited
8 |
9 | IP=`/usr/sbin/ip a | grep 'inet ' | grep -v 'inet 127.' | grep -v 'inet 10.' | grep -v 'inet 172.16.' | awk '{print $ 2}' | awk -F/ '{print $1}'`
10 | echo ${IP}
11 |
12 | ./xkad_bench -a ${IP} -l 11000 -L log/first_node.log
13 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/online/run2fg.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | rm -rf log
4 | rm -rf core.*
5 |
6 | mkdir -p log
7 | ulimit -c unlimited
8 |
9 | IP=`/usr/sbin/ip a | grep 'inet ' | grep -v 'inet 127.' | grep -v 'inet 10.' | grep -v 'inet 172.16.' | awk '{print $ 2}' | awk -F/ '{print $1}'`
10 | echo ${IP}
11 |
12 | ./xkad_bench -a ${IP} -l 10900 -L log/run2fg.log -i 1 -p 157.245.138.194:11000
13 |
--------------------------------------------------------------------------------
/tests/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
3 | aux_source_directory(./ xkad_test_dir)
4 | # set(xkad_test_dir ./test_routing_table3.cc ./test_main.cc)
5 | add_executable(xkad_test ${xkad_test_dir})
6 | add_dependencies(xkad_test xkad)
7 | target_link_libraries(xkad_test xkad gtest gmock)
8 |
9 | if(XENABLE_CODE_COVERAGE)
10 | target_link_libraries(xkad_test gcov)
11 | endif()
12 | endif()
13 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/online/ansible_collect.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | mkdir -p /root/blueshi_log_collect/x
4 |
5 | # collect fg
6 | ansible -i /root/blueshi/blue_hosts m_fg -m synchronize -a "src=/root/blueshi/xkad_bench1 dest=/root/blueshi_log_collect/x/{{inventory_hostname}} mode=pull"
7 |
8 | # collect bg
9 | ansible -i /root/blueshi/blue_hosts m_bg -m synchronize -a "src=/root/blueshi/xkad_bench1 dest=/root/blueshi_log_collect/x/{{inventory_hostname}} mode=pull"
10 |
--------------------------------------------------------------------------------
/xkad.xcodeproj/xcuserdata/imac.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | xkad.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 5
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.8)
2 |
3 | include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/proto)
4 |
5 | aux_source_directory(./src xkad_src)
6 | aux_source_directory(./proto xkad_src)
7 | add_library(xkad ${xkad_src})
8 |
9 | add_dependencies(xkad xpbase xtransport xledger)
10 | target_link_libraries(xkad xpbase xtransport xledger protobuf)
11 |
12 | if(XENABLE_TESTS)
13 | add_subdirectory(tests)
14 | add_subdirectory(bench)
15 | endif()
16 |
--------------------------------------------------------------------------------
/demo/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | remove_definitions(
2 | -DGOSSIP_WITH_WROUTER
3 | )
4 |
5 | aux_source_directory(./ xkad_demo_dir)
6 | add_executable(xkad_demo ${xkad_demo_dir})
7 |
8 | add_dependencies(xkad_demo xgossip xkad xxbase)
9 |
10 | target_link_libraries(xkad_demo
11 | xgossip
12 | xkad
13 | xtransport
14 | xpbase
15 | xcrypto
16 | xutility
17 | xxbase
18 | xledger
19 | protobuf
20 | -lgtest
21 | -lgmock
22 | -lpthread -ldl
23 | -lrt
24 | )
25 |
26 |
--------------------------------------------------------------------------------
/nat_detect/nat_defines.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017-2019 Telos Foundation & contributors
2 | // Distributed under the MIT software license, see the accompanying
3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 |
5 | #pragma once
6 |
7 | namespace top {
8 | namespace kadmlia {
9 |
10 | enum NatType {
11 | kNatTypeUnknown = 0,
12 | kNatTypePublic = 1,
13 | kNatTypeConeNormal = 2,
14 | kNatTypeConeAbnormal = 3,
15 | };
16 |
17 | } // namespace kadmlia
18 | } // namespace top
19 |
--------------------------------------------------------------------------------
/nat_detect/nat_detect/nat_defines.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017-2019 Telos Foundation & contributors
2 | // Distributed under the MIT software license, see the accompanying
3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 |
5 | #pragma once
6 |
7 | namespace top {
8 | namespace kadmlia {
9 |
10 | enum NatType {
11 | kNatTypeUnknown = 0,
12 | kNatTypePublic = 1,
13 | kNatTypeConeNormal = 2,
14 | kNatTypeConeAbnormal = 3,
15 | };
16 |
17 | } // namespace kadmlia
18 | } // namespace top
19 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/online/run2.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | killall -w xkad_bench || echo "no such process"
4 | rm -rf log
5 | rm -rf core.*
6 |
7 | mkdir -p log
8 | ulimit -c unlimited
9 |
10 | IP=`/usr/sbin/ip a | grep 'inet ' | grep -v 'inet 127.' | grep -v 'inet 10.' | grep -v 'inet 172.16.' | awk '{print $ 2}' | awk -F/ '{print $1}'`
11 | echo ${IP}
12 |
13 | for ((i=0;i<25;i++)); do
14 | echo "launching ${i} ..."
15 | PORT=$((10000+$i))
16 | nohup ./xkad_bench -a ${IP} -l $PORT -L log/${i}.log -i 1 -p 157.245.138.194:11000 -g 0 >/dev/null 2>&1 -D 0 &
17 | done
18 |
--------------------------------------------------------------------------------
/bench/xkad_bench1/online/bridge_deploy.sh:
--------------------------------------------------------------------------------
1 | set -e
2 |
3 | target=src/xtopcom/xkad/bench/xkad_bench1
4 |
5 | # copy xkad_bench
6 | rsync -avz cbuild/bin/Linux/xkad_bench $target/
7 | # rsync -avz cbuild/bin/Darwin/xkad_bench $target/
8 | # strip $target/xkad_bench
9 |
10 | # copy bench1
11 | # rsync -avz $target ~/run/
12 |
13 | ips=(
14 | "142.93.88.86"
15 | )
16 |
17 | for ip in ${ips[@]}; do
18 | echo "===== rsyncing $ip ... ====="
19 | rsync -avz -e "ssh -p 1022 -i src/xtopcom/xkad/bench/xkad_bench1/online/bridge.pem" $target root@$ip:~/blueshi/
20 | done
21 |
--------------------------------------------------------------------------------
/demo/xkaddemo.xcodeproj/xcuserdata/imac.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | xkaddemo.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 994ECA8C22B1EBA30035313B
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/gossip/rumor_filter.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017-2019 Telos Foundation & contributors
2 | // Distributed under the MIT software license, see the accompanying
3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 |
5 | #pragma once
6 | #include "xpbase/base/contain_template.h"
7 | #include "xtransport/proto/transport.pb.h"
8 | #include "xkad/proto/kadmlia.pb.h"
9 | #include "xkad/gossip/rumor_def.h"
10 |
11 | namespace top {
12 | namespace gossip {
13 |
14 | class RumorFilter :
15 | public ContainTemplate<
16 | uint32_t,
17 | kDefaultFilterSize,
18 | kRepeatedValueNum>{
19 | public:
20 | static RumorFilter* Instance();
21 | ~RumorFilter() {}
22 | bool FiltMessage(
23 | transport::protobuf::RoutingMessage&);
24 | private:
25 | RumorFilter() {}
26 | };
27 |
28 | typedef std::shared_ptr RumorFilterPtr;
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/nodeid_utils.cc:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017-2019 Telos Foundation & contributors
2 | // Distributed under the MIT software license, see the accompanying
3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 |
5 | #include "xkad/routing_table/nodeid_utils.h"
6 | #include "xbase/xhash.h"
7 |
8 | #include
9 |
10 | namespace top {
11 |
12 | namespace kadmlia {
13 |
14 | uint8_t GetWorldCountryID(const std::string& country_code) {
15 | uint32_t hash = base::xhash32_t::digest(country_code);
16 | return (hash & 0xFF000000);
17 | }
18 |
19 | uint32_t GetBusinessID(const std::string& business) {
20 | auto iter = BusinessID.find(business);
21 | if (iter == BusinessID.end()) {
22 | return std::numeric_limits::max();
23 | }
24 |
25 | return iter->second;
26 | }
27 |
28 | } // namespace kadmlia
29 |
30 | } // namespace top
31 |
--------------------------------------------------------------------------------
/gossip/rumor_def.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017-2019 Telos Foundation & contributors
2 | // Distributed under the MIT software license, see the accompanying
3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 |
5 | #pragma once
6 |
7 | #include
8 | #include
9 |
10 | #include "xpbase/base/top_string_util.h"
11 | #include "xkad/routing_table/routing_utils.h"
12 | #include "xkad/routing_table/routing_utils.h"
13 |
14 | namespace top {
15 |
16 | namespace gossip {
17 |
18 | static const int32_t kDefautHopCount = 10;
19 | static const int32_t kDefaultSpreadPeriod = 3 * 1000 * 1000;
20 | static const int32_t kDefaultFilterSize = 3024000u;
21 | static const int32_t kRepeatedValueNum = 1;
22 |
23 | struct RumorIdentity final : public kadmlia::MessageIdentity {
24 | RumorIdentity(
25 | const uint32_t in_message_id,
26 | const std::string& in_node_id)
27 | :kadmlia::MessageIdentity(in_message_id,in_node_id) {
28 | }
29 | ~RumorIdentity() {}
30 | };
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/routing_table/nodeid_utils.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017-2019 Telos Foundation & contributors
2 | // Distributed under the MIT software license, see the accompanying
3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 |
5 | #pragma once
6 |
7 | #include
8 | #include